:root {
  --page-bg: #f4efe6;
  --panel-bg: rgba(21, 34, 31, 0.94);
  --panel-border: rgba(255, 255, 255, 0.12);
  --panel-text: #f6f2e8;
  --panel-muted: rgba(246, 242, 232, 0.68);
  --surface-2: rgba(255, 255, 255, 0.08);
  --surface-3: rgba(255, 255, 255, 0.14);
  --accent: #f3b93a;
  --accent-strong: #f07b3f;
  --safe: #4db8b3;
  --route-clear: #3ea3ff;
  --route-warning: #f3b93a;
  --route-blocked: #e35959;
  --start: #86d3ff;
  --shelter: #9ae383;
  --blockage: #ff7b72;
  --shadow: 0 20px 60px rgba(12, 16, 21, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(243, 185, 58, 0.16), transparent 24rem),
    radial-gradient(circle at bottom right, rgba(62, 163, 255, 0.14), transparent 26rem),
    var(--page-bg);
  color: var(--panel-text);
  font-family: 'Space Grotesk', sans-serif;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  min-height: 100dvh;
}

.control-panel {
  position: relative;
  z-index: 2;
  padding: 1.5rem;
  background: linear-gradient(180deg, rgba(21, 34, 31, 0.98), rgba(18, 30, 28, 0.92));
  border-right: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.eyebrow {
  display: inline-flex;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: rgba(243, 185, 58, 0.14);
  color: var(--accent);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p,
ul,
dl {
  margin: 0;
}

h1 {
  margin-top: 1rem;
  font-size: clamp(1.85rem, 2vw, 2.3rem);
  line-height: 1;
}

h2 {
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.intro,
.muted,
.status-text {
  color: var(--panel-muted);
}

.intro {
  margin-top: 0.85rem;
  line-height: 1.55;
}

.panel-section {
  margin-top: 1.35rem;
  padding: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--panel-border);
  border-radius: 1.1rem;
  backdrop-filter: blur(18px);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.tool-button,
.secondary-button {
  padding: 0.85rem 0.95rem;
  border-radius: 0.9rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--panel-text);
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.tool-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.13);
}

.tool-button.is-active {
  background: linear-gradient(135deg, rgba(243, 185, 58, 0.18), rgba(240, 123, 63, 0.26));
  box-shadow: inset 0 0 0 1px rgba(243, 185, 58, 0.36);
}

.tool-button.danger {
  color: #ffd8d2;
}

.summary-panel {
  background:
    linear-gradient(135deg, rgba(243, 185, 58, 0.07), transparent 52%),
    rgba(255, 255, 255, 0.08);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  font-size: 0.84rem;
  font-family: 'IBM Plex Mono', monospace;
}

.status-loading {
  background: rgba(134, 211, 255, 0.16);
  color: #b7e7ff;
}

.status-clear {
  background: rgba(77, 184, 179, 0.16);
  color: #9cf7ee;
}

.status-warning {
  background: rgba(243, 185, 58, 0.18);
  color: #ffd890;
}

.status-danger {
  background: rgba(227, 89, 89, 0.18);
  color: #ffb9b9;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem 1rem;
  margin-top: 1rem;
}

.metrics dt {
  margin-bottom: 0.35rem;
  color: var(--panel-muted);
  font-size: 0.85rem;
}

.metrics dd {
  font-size: 1.1rem;
  font-weight: 500;
}

.status-text {
  margin-top: 0.9rem;
  line-height: 1.5;
}

.error-text {
  margin-top: 0.8rem;
  color: #ffb9b9;
  line-height: 1.45;
}

.button-help {
  margin-top: 0.7rem;
  color: var(--panel-muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.85rem;
}

.secondary-button {
  flex: 1 1 9rem;
}

.accent-button {
  margin-top: 0.95rem;
  width: 100%;
  background: linear-gradient(135deg, rgba(243, 185, 58, 0.22), rgba(62, 163, 255, 0.18));
  box-shadow: inset 0 0 0 1px rgba(243, 185, 58, 0.2);
}

.subtle-button {
  background: rgba(255, 255, 255, 0.05);
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
}

.secondary-button:disabled:hover {
  background: rgba(255, 255, 255, 0.08);
}

.scenario-list,
.legend-list {
  list-style: none;
  padding: 0;
}

.scenario-list {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.95rem;
}

.scenario-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem 0.85rem;
  border-radius: 0.9rem;
  background: rgba(255, 255, 255, 0.05);
}

.scenario-item strong {
  display: block;
  font-size: 0.95rem;
}

.scenario-meta {
  display: block;
  margin-top: 0.2rem;
  color: var(--panel-muted);
  font-size: 0.84rem;
  font-family: 'IBM Plex Mono', monospace;
}

.scenario-chip {
  flex-shrink: 0;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-family: 'IBM Plex Mono', monospace;
}

.chip-start {
  background: rgba(134, 211, 255, 0.18);
  color: var(--start);
}

.chip-shelter {
  background: rgba(154, 227, 131, 0.16);
  color: var(--shelter);
}

.chip-shelter-active {
  box-shadow: inset 0 0 0 1px rgba(243, 185, 58, 0.36);
  color: #ffe0a0;
}

.chip-blockage {
  background: rgba(255, 123, 114, 0.15);
  color: var(--blockage);
}

.legend-list {
  display: grid;
  gap: 0.7rem;
  margin-top: 0.9rem;
  color: var(--panel-muted);
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.legend-dot,
.legend-line {
  flex-shrink: 0;
}

.legend-dot {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
}

.legend-start {
  background: var(--start);
}

.legend-shelter {
  background: var(--shelter);
}

.legend-blockage {
  background: var(--blockage);
}

.legend-line {
  width: 1.3rem;
  height: 0.3rem;
  border-radius: 999px;
  background: var(--route-clear);
}

.map-shell {
  position: relative;
  min-height: 100dvh;
}

#map {
  position: absolute;
  inset: 0;
}

.map-hint {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  max-width: 22rem;
  padding: 0.9rem 1rem;
  border-radius: 1rem;
  background: rgba(21, 34, 31, 0.74);
  color: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(18px);
  line-height: 1.45;
}

.mapboxgl-ctrl-bottom-left,
.mapboxgl-ctrl-bottom-right {
  z-index: 1;
}

.marker {
  display: grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.84);
  color: #12201b;
  font-size: 0.7rem;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(10, 18, 24, 0.32);
  user-select: none;
}

.marker-start {
  background: var(--start);
}

.marker-shelter {
  background: var(--shelter);
}

.marker-shelter.is-selected {
  transform: scale(1.08);
  box-shadow:
    0 0 0 4px rgba(243, 185, 58, 0.2),
    0 8px 18px rgba(10, 18, 24, 0.32);
}

.marker-blockage {
  background: var(--blockage);
  color: #fff3f0;
}

@media (max-width: 980px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
  }

  .control-panel {
    order: 2;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--panel-border);
    border-radius: 1.5rem 1.5rem 0 0;
    margin-top: -1rem;
    background: linear-gradient(180deg, rgba(21, 34, 31, 0.98), rgba(18, 30, 28, 0.96));
  }

  .map-shell {
    order: 1;
    min-height: 54dvh;
  }

  #map {
    position: relative;
    min-height: 54dvh;
  }

  .map-hint {
    right: 0.85rem;
    bottom: 0.85rem;
    left: 0.85rem;
    max-width: none;
    padding: 0.8rem 0.9rem;
    font-size: 0.92rem;
  }

  .section-heading {
    flex-direction: column;
    gap: 0.35rem;
  }

  .section-heading .muted {
    display: block;
  }

  .metrics {
    gap: 0.8rem;
  }

  .scenario-item {
    align-items: flex-start;
  }

  .scenario-chip {
    margin-left: auto;
  }

  .legend-list li {
    align-items: flex-start;
  }
}

@media (max-width: 640px) {
  .control-panel {
    padding: 0.9rem 0.9rem calc(0.9rem + env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 1.7rem;
  }

  .intro {
    font-size: 0.96rem;
  }

  .panel-section {
    margin-top: 1rem;
    padding: 0.9rem;
  }

  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .metrics dd {
    font-size: 1rem;
  }

  .action-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
  }

  .action-row .secondary-button:last-child {
    grid-column: 1 / -1;
  }

  .secondary-button,
  .tool-button {
    min-height: 3rem;
    padding: 0.8rem 0.85rem;
  }

  .scenario-item {
    flex-wrap: wrap;
    padding: 0.7rem 0.75rem;
  }

  .scenario-chip {
    margin-left: 0;
  }

  .map-shell {
    min-height: 50dvh;
  }

  #map {
    min-height: 50dvh;
  }

  .map-hint {
    font-size: 0.88rem;
    line-height: 1.4;
  }
}

@media (max-width: 420px) {
  .control-panel {
    padding: 0.8rem 0.8rem calc(0.8rem + env(safe-area-inset-bottom));
  }

  .eyebrow {
    font-size: 0.72rem;
  }

  h1 {
    font-size: 1.52rem;
  }

  .toolbar,
  .metrics,
  .action-row {
    grid-template-columns: 1fr;
  }

  .action-row .secondary-button:last-child {
    grid-column: auto;
  }

  .status-badge {
    width: 100%;
    justify-content: center;
  }

  .map-shell {
    min-height: 46dvh;
  }

  #map {
    min-height: 46dvh;
  }
}
