:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --panel: #fffdf8;
  --ink: #1d2526;
  --muted: #66706b;
  --line: #d9d3c7;
  --accent: #247c7a;
  --accent-strong: #145f5d;
  --gold: #c8842f;
  --red: #b84a3a;
  --green: #5c8a43;
  --shadow: 0 12px 30px rgba(42, 45, 38, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
  max-width: 100%;
}

main {
  width: min(1180px, calc(100vw - 32px));
  margin: 24px auto 48px;
}

.app-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  min-height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.88);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 4;
}

.brand {
  font-weight: 800;
  letter-spacing: 0;
}

.nav {
  display: flex;
  gap: 6px;
}

.nav a {
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 6px;
}

.nav a:hover {
  color: var(--ink);
  background: #ebe6dc;
}

.source-pill,
.sample-banner {
  color: var(--muted);
  font-size: 0.85rem;
}

.source-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  white-space: nowrap;
}

.sample-banner {
  width: min(1180px, calc(100vw - 32px));
  margin: 14px auto 0;
  padding: 10px 12px;
  border: 1px solid #e4cda8;
  border-radius: 8px;
  background: #fff7e8;
}

.workspace,
.lab-layout {
  display: grid;
  gap: 16px;
  align-items: start;
}

.workspace {
  grid-template-columns: minmax(0, 1fr) 330px;
}

.lab-layout {
  grid-template-columns: minmax(0, 1fr) 360px;
}

.controls-panel {
  grid-column: 1 / -1;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.primary-panel {
  min-width: 0;
  padding: 18px;
}

.side-panel,
.controls-panel {
  padding: 16px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-header.compact {
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 6vw, 3.4rem);
  line-height: 1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

h2 {
  margin-bottom: 0;
  font-size: 1.1rem;
  line-height: 1.2;
}

.icon-button,
.text-button,
.candidate-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  font-size: 1.25rem;
}

.text-button {
  min-height: 42px;
  padding: 0 16px;
  font-weight: 800;
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.candidate-button {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  text-align: left;
  overflow-wrap: anywhere;
}

.candidate-button span {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.85rem;
}

.icon-button:hover,
.text-button:hover,
.candidate-button:hover {
  border-color: var(--accent-strong);
  transform: translateY(-1px);
}

.text-button:hover {
  background: var(--accent-strong);
}

.candidate-button:disabled {
  cursor: default;
  color: var(--muted);
  transform: none;
}

.map-frame {
  display: grid;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}

.map-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.map-button {
  width: 34px;
  height: 34px;
  font-size: 1rem;
}

.map-button.zoom-level {
  width: 54px;
  font-size: 0.85rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.map-button:disabled {
  cursor: default;
  opacity: 0.45;
  transform: none;
}

.plot-shell {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 340px;
  overflow: hidden;
}

.plot {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
}

.map-frame .plot {
  touch-action: none;
}

.plot-bg {
  fill: #fbf8f1;
  stroke: var(--line);
}

.axis {
  stroke: #e6dfd2;
  stroke-width: 1;
}

.point circle {
  fill: var(--gold);
  stroke: #ffffff;
  stroke-width: 2;
}

.point.start circle {
  fill: #2f5f90;
}

.point.target circle {
  fill: var(--accent);
}

.point.current circle {
  fill: var(--red);
}

.point.waypoint circle {
  fill: var(--green);
}

.route-line {
  stroke: rgba(36, 124, 122, 0.42);
  stroke-width: 3;
  stroke-linecap: round;
}

.path-line {
  fill: none;
  stroke: rgba(184, 74, 58, 0.68);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.point circle.correct-dot {
  fill: var(--green);
}

.point-label,
.target-label {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #fbf8f1;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.target-label {
  fill: var(--accent-strong);
}

.option-grid {
  display: grid;
  gap: 10px;
}

.route-form {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.route-form label {
  display: grid;
  gap: 6px;
}

.route-form span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.route-form input,
.route-form select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--ink);
  padding: 0 11px;
}

.route-form .text-button {
  width: 100%;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e9e0d2;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 220ms ease;
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  color: var(--muted);
  margin: 12px 0 18px;
}

.stat-row strong {
  color: var(--ink);
}

.feedback {
  display: none;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ecf5f3;
  color: var(--accent-strong);
  font-weight: 750;
}

.feedback.visible {
  display: block;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 160px 120px auto;
  gap: 12px;
  align-items: end;
}

.toolbar label {
  display: grid;
  gap: 6px;
}

.toolbar span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.toolbar input,
.toolbar select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  padding: 0 11px;
}

.neighbors-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.neighbors-table th,
.neighbors-table td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.neighbors-table th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.route-strip {
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(120px, 1fr) minmax(0, max-content);
  align-items: center;
  gap: 12px;
  margin: 8px 0 12px;
  font-weight: 800;
  min-width: 0;
}

.route-strip-wide span {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trail-box {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.trail-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.trail-chip {
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbf8f1;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
}

.finish-box {
  padding: 18px;
  border: 1px solid #bad3ad;
  border-radius: 8px;
  background: #f0f7ed;
}

.navigate-finish {
  margin: 12px 0 14px;
}

.navigate-finish h2 {
  margin-bottom: 12px;
}

.finish-path {
  display: block;
}

.finish-path-text {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #bad3ad;
  border-radius: 8px;
  background: #fbfff8;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.9rem;
  font-weight: 750;
  line-height: 1.5;
  white-space: pre-wrap;
  user-select: all;
}

.instructions-layout {
  max-width: 860px;
  margin: 0 auto;
}

.instructions-panel {
  display: grid;
  gap: 18px;
}

.instructions-panel h1 {
  margin-bottom: 2px;
}

.instruction-steps {
  display: grid;
  gap: 18px;
}

.instruction-steps section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.instruction-steps h2 {
  margin-bottom: 6px;
}

.instruction-steps p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

@media (max-width: 880px) {
  main {
    width: min(1180px, calc(100vw - 20px));
    margin: 14px auto 32px;
  }

  .app-header {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px 16px;
  }

  .nav {
    overflow-x: auto;
    max-width: 100%;
  }

  .source-pill {
    width: fit-content;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .workspace,
  .lab-layout {
    grid-template-columns: 1fr;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .plot-shell {
    min-height: 280px;
  }
}

@media (max-width: 560px) {
  .primary-panel,
  .side-panel,
  .controls-panel {
    padding: 12px;
  }

  .panel-header {
    gap: 12px;
    margin-bottom: 14px;
  }

  .route-strip {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .route-strip-wide span {
    max-width: 100%;
  }

  .stat-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    margin-bottom: 14px;
  }

  .stat-row span {
    min-width: 0;
  }

  .map-toolbar {
    justify-content: flex-start;
  }

  .plot-shell {
    aspect-ratio: 4 / 3;
    min-height: 220px;
  }

  .point-label,
  .target-label {
    font-size: 11px;
  }

  .neighbors-table {
    display: block;
    overflow-x: auto;
  }
}
