:root {
  --bg: #717980;
  --panel: rgba(234, 239, 236, 0.92);
  --panel-strong: rgba(255, 255, 255, 0.9);
  --border: rgba(28, 53, 62, 0.14);
  --ink: #15313a;
  --muted: #526a72;
  --accent: #16606a;
  --accent-soft: #d8ecee;
  --warm: #cc6f2c;
  --shadow: 0 22px 60px rgba(20, 40, 50, 0.16);
  --layers-panel: rgba(25, 33, 38, 0.94);
  --layers-panel-border: rgba(154, 193, 201, 0.16);
  --layers-card: linear-gradient(180deg, rgba(41, 52, 59, 0.96), rgba(26, 34, 39, 0.96));
  --layers-card-border: rgba(132, 176, 185, 0.18);
  --layers-ink: #edf6f5;
  --layers-muted: #a9bcc1;
  --layers-field: rgba(14, 20, 24, 0.9);
  --radius-xl: 26px;
  --radius-lg: 18px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(116, 135, 142, 0.55), transparent 34%),
    radial-gradient(circle at top right, rgba(126, 118, 113, 0.28), transparent 26%),
    linear-gradient(180deg, #7b858c 0%, #626a70 100%);
  color: var(--ink);
  font-family: "Montserrat", "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  overflow: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  gap: 18px;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  padding: 18px;
  overflow: hidden;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  overflow: auto;
  overscroll-behavior: contain;
  min-height: 0;
}

.panel-header h1,
.section-heading h2 {
  margin: 0;
  font-family: "Montserrat", "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  letter-spacing: -0.02em;
}

.panel-header h1 {
  font-size: clamp(2rem, 4vw, 2.7rem);
  line-height: 1;
  margin-top: 6px;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  font-weight: 700;
}

.panel-copy,
.section-heading p,
.layer-note {
  color: var(--muted);
  line-height: 1.45;
}

.panel-copy {
  margin: 12px 0 0;
}

.status-row,
.layer-title-row,
.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.button-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.summary-chip,
.toolbar-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(17, 83, 92, 0.1);
  color: var(--accent);
  font-size: 0.92rem;
  font-weight: 700;
}

.toolbar-chip {
  background: rgba(245, 247, 243, 0.9);
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 10px 26px rgba(23, 48, 57, 0.14);
}

.ghost-button,
.mini-button {
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.76);
  font: inherit;
  transition:
    transform 140ms ease,
    background 140ms ease,
    border-color 140ms ease;
}

.ghost-button {
  padding: 10px 14px;
}

.mini-button {
  padding: 8px 12px;
  font-size: 0.9rem;
}

.ghost-button:hover,
.mini-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(22, 96, 106, 0.3);
}

.control-section {
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--panel-strong);
  border: 1px solid var(--border);
}

.control-panel .control-section:first-of-type {
  background:
    radial-gradient(circle at top right, rgba(93, 133, 143, 0.22), transparent 34%),
    linear-gradient(180deg, rgba(26, 34, 39, 0.99), rgba(12, 17, 20, 0.99));
  border-color: var(--layers-panel-border);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 18px 30px rgba(8, 12, 15, 0.2);
}

.control-panel .control-section:first-of-type .section-heading h2,
.control-panel .control-section:first-of-type .toggle,
.control-panel .control-section:first-of-type .field span {
  color: var(--layers-ink);
}

.control-panel .control-section:first-of-type .section-heading p,
.control-panel .control-section:first-of-type .layer-note,
.control-panel .control-section:first-of-type .player-label,
.control-panel .control-section:first-of-type .player-caption,
.control-panel .control-section:first-of-type .field {
  color: var(--layers-muted);
}

.section-heading {
  margin-bottom: 14px;
}

.section-heading p,
.layer-note {
  margin: 6px 0 0;
  font-size: 0.95rem;
}

.layer-card {
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(22, 96, 106, 0.09);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(242, 247, 246, 0.88));
}

.control-panel .control-section:first-of-type .layer-card {
  border-color: var(--layers-card-border);
  background:
    radial-gradient(circle at top right, rgba(76, 122, 134, 0.12), transparent 34%),
    var(--layers-card);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 12px 22px rgba(7, 10, 13, 0.22);
}

.control-panel .control-section:first-of-type .mini-button:not(.radar-player-button) {
  border-color: rgba(120, 164, 175, 0.22);
  background:
    linear-gradient(180deg, rgba(34, 47, 53, 0.96), rgba(20, 28, 33, 0.96));
  color: var(--layers-ink);
}

.control-panel .control-section:first-of-type .mini-button:not(.radar-player-button):hover {
  background:
    linear-gradient(180deg, rgba(42, 58, 66, 0.98), rgba(24, 34, 40, 0.98));
  border-color: rgba(141, 190, 201, 0.34);
}

.control-panel .control-section:first-of-type select,
.control-panel .control-section:first-of-type .player-block,
.control-panel .control-section:first-of-type input[type="range"] {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.layer-card + .layer-card {
  margin-top: 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.toggle input {
  inline-size: 18px;
  block-size: 18px;
  accent-color: var(--accent);
}

.control-panel .control-section:first-of-type .toggle input {
  accent-color: #57a8b2;
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.92rem;
  color: var(--muted);
}

.compact-field {
  margin-top: 10px;
}

.player-block {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(22, 96, 106, 0.09);
  background: rgba(242, 247, 246, 0.82);
}

.control-panel .control-section:first-of-type .player-block {
  border-color: rgba(110, 150, 160, 0.16);
  background: rgba(12, 18, 22, 0.76);
}

.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.player-label,
.player-caption {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.player-caption {
  margin: 8px 0 0;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  appearance: none;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.control-panel .control-section:first-of-type select {
  border-color: rgba(121, 158, 167, 0.2);
  background: var(--layers-field);
  color: var(--layers-ink);
}

.control-panel .control-section:first-of-type input[type="range"] {
  accent-color: #d28948;
}

input[type="range"] {
  accent-color: var(--warm);
}

.radar-player-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border-color: rgba(102, 183, 215, 0.26);
  background:
    linear-gradient(180deg, rgba(12, 53, 70, 0.96), rgba(8, 31, 44, 0.96));
  color: #e9f8ff;
}

.radar-player-button::before {
  content: "";
  display: inline-block;
  flex: 0 0 auto;
}

.radar-player-button[data-state="play"]::before {
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 11px solid #79dbff;
  filter: drop-shadow(0 0 8px rgba(121, 219, 255, 0.24));
}

.radar-player-button[data-state="pause"]::before {
  width: 11px;
  height: 13px;
  border-left: 4px solid #79dbff;
  border-right: 4px solid #79dbff;
  filter: drop-shadow(0 0 8px rgba(121, 219, 255, 0.2));
}

.radar-player-button:hover {
  border-color: rgba(133, 214, 244, 0.4);
  background:
    linear-gradient(180deg, rgba(14, 69, 91, 0.98), rgba(9, 42, 59, 0.98));
  transform: translateY(-1px);
}

.radar-player-button-text {
  display: inline-block;
}

.radar-timeline-slider {
  accent-color: #4fc0f1;
}

.radar-timeline-slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(53, 94, 122, 0.88), rgba(74, 188, 240, 0.92));
}

.radar-timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(220, 248, 255, 0.95);
  background: #8ce4ff;
  box-shadow: 0 0 0 4px rgba(62, 178, 224, 0.18);
}

.radar-timeline-slider::-moz-range-track {
  height: 8px;
  border: 0;
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(53, 94, 122, 0.88), rgba(74, 188, 240, 0.92));
}

.radar-timeline-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(220, 248, 255, 0.95);
  background: #8ce4ff;
  box-shadow: 0 0 0 4px rgba(62, 178, 224, 0.18);
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.93rem;
}

.legend-dot {
  inline-size: 12px;
  block-size: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.4);
  background: #aaa;
}

.below-recommended {
  background: #ff8785;
}

.low-runnable {
  background: #83edaa;
}

.medium-runnable {
  background: #59e78d;
}

.high-runnable {
  background: #2fe170;
}

.above-recommended {
  background: #68dfe9;
}

.stale {
  background: #dfe3e6;
}

.source-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 10px;
}

.source-list a {
  color: var(--accent);
}

.map-stage {
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--radius-xl);
  border: 1px solid rgba(18, 43, 54, 0.14);
  box-shadow: var(--shadow);
}

.map-toolbar {
  position: absolute;
  top: 18px;
  left: 18px;
  right: 18px;
  z-index: 600;
  pointer-events: none;
}

.map-toolbar > * {
  pointer-events: auto;
}

.map-legend-overlay {
  position: absolute;
  top: 72px;
  right: 18px;
  z-index: 610;
  inline-size: fit-content;
  max-inline-size: min(540px, calc(100% - 36px));
  max-block-size: calc(100% - 96px);
  overflow: auto;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid rgba(18, 43, 54, 0.14);
  background: rgba(251, 252, 248, 0.95);
  box-shadow: 0 18px 42px rgba(23, 48, 57, 0.16);
  backdrop-filter: blur(12px);
}

.legend-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.legend-overlay-header h2 {
  margin: 0;
  font-size: 1rem;
}

.legend-overlay-body {
  display: grid;
  gap: 12px;
  inline-size: fit-content;
  max-inline-size: 100%;
}

.legend-panel {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(22, 96, 106, 0.09);
  background: rgba(255, 255, 255, 0.82);
  inline-size: fit-content;
  max-inline-size: 100%;
}

.legend-panel h3 {
  margin: 0;
  font-size: 0.98rem;
}

.legend-panel p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.legend-items {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.legend-row {
  display: grid;
  grid-template-columns: 22px max-content;
  gap: 10px;
  align-items: start;
}

.legend-swatch {
  inline-size: 22px;
  block-size: 22px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(240, 244, 244, 0.8));
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

.legend-text {
  font-size: 0.9rem;
  line-height: 1.35;
  white-space: nowrap;
  max-inline-size: 100%;
}

.legend-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #dbe6e7;
}

.maplibregl-popup-content,
.maplibregl-popup-tip {
  background: rgba(251, 252, 248, 0.96);
  color: var(--ink);
}

.maplibregl-popup-content {
  padding: 14px 16px;
  border-radius: 14px;
  box-shadow: 0 14px 36px rgba(23, 48, 57, 0.16);
}

.maplibregl-popup-close-button {
  color: var(--muted);
  font-size: 18px;
  padding: 6px 10px;
}

.maplibregl-ctrl-group {
  border: 1px solid rgba(18, 43, 54, 0.14);
  box-shadow: 0 10px 26px rgba(23, 48, 57, 0.14);
}

.maplibregl-ctrl-group button {
  inline-size: 34px;
  block-size: 34px;
}

.popup-title {
  margin: 0 0 8px;
  font-size: 1rem;
}

.popup-copy {
  margin: 4px 0;
  line-height: 1.45;
}

.popup-copy a {
  color: var(--accent);
}

.popup-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
    height: 100vh;
    height: 100dvh;
  }

  .control-panel {
    order: 2;
    max-height: 38vh;
  }

  .map-stage {
    height: min(62vh, 62dvh);
  }

  #map-status {
    display: none;
  }

  .control-panel .control-section:first-of-type {
    padding: 12px;
  }

  .control-panel .control-section:first-of-type .section-heading {
    margin-bottom: 10px;
  }

  .control-panel .control-section:first-of-type .section-heading p,
  .control-panel .control-section:first-of-type .layer-note {
    display: none;
  }

  .control-panel .control-section:first-of-type .layer-card {
    padding: 11px;
  }

  .control-panel .control-section:first-of-type .layer-card + .layer-card {
    margin-top: 8px;
  }

  .control-panel .control-section:first-of-type .field,
  .control-panel .control-section:first-of-type .player-block {
    margin-top: 9px;
  }

  .control-panel .control-section:first-of-type .player-block {
    padding: 10px;
  }

  .control-panel .control-section:first-of-type .player-caption {
    margin-top: 6px;
  }

  #map {
    height: 100%;
  }
}
