* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0b1220;
  --panel: #11192a;
  --line: #1e293b;
  --text: #e8eef6;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-fill: #2563eb; /* darker than --accent so white text passes 4.5:1 */
  --c0: rgb(59, 130, 246);
  --c1: rgb(249, 115, 22);
  --train: #c4b5fd;
  --test: #2dd4bf;
  --oob: #f472b6;
  --one: #94a3b8;
}

html, body {
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* Sized for the site's iframe: about 960 x 860 on desktop. */
#app {
  display: grid;
  height: 100%;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "header header"
    "lessons lessons"
    "map trees"
    "acc controls"
    "footer footer";
}

header {
  grid-area: header;
  padding: 0.7rem 1rem 0.6rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 1.3rem; letter-spacing: -0.01em; }
header p { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }

/* ---- Walkthrough ---- */
#lessons {
  grid-area: lessons;
  padding: 0.55rem 1rem 0.6rem;
  border-bottom: 1px solid var(--line);
  background: #0e1626;
}
.lesson-buttons { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.lesson-buttons button {
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
  border-radius: 999px;
  min-height: 30px;
}
.lesson-buttons button[aria-pressed="true"], .seg button[aria-pressed="true"] {
  background: var(--accent-fill);
  border-color: var(--accent-fill);
  color: #fff;
}
#lesson-text {
  margin-top: 0.45rem;
  font-size: 0.84rem;
  line-height: 1.45;
  color: #cbd5e1;
  min-height: 4.35em;
}
#lesson-text b { color: var(--text); }

/* ---- Panels ---- */
.panel {
  min-width: 0;
  min-height: 0;
  padding: 0.6rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-bottom: 1px solid var(--line);
}
#map-panel { grid-area: map; border-right: 1px solid var(--line); }
#trees-panel { grid-area: trees; }
#acc-panel { grid-area: acc; border-right: 1px solid var(--line); }
#controls { grid-area: controls; }

.panel-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.2rem 0.8rem; }
.panel h2 { font-size: 0.88rem; }
.panel .sub { font-size: 0.75rem; color: var(--muted); }

.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 0.15rem 0.7rem; font-size: 0.75rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 0.3rem; }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.sw.c0 { background: var(--c0); }
.sw.c1 { background: var(--c1); }
.sw.ring { border: 1.5px solid var(--muted); }
.sw.truth { width: 16px; height: 0; border-radius: 0; border-top: 2px dashed #f1f5f9; }
.sw.ln-train { width: 16px; height: 0; border-radius: 0; border-top: 2px solid var(--train); }
.sw.ln-test { width: 16px; height: 0; border-radius: 0; border-top: 2px dashed var(--test); }
.sw.ln-oob { width: 16px; height: 0; border-radius: 0; border-top: 2px solid var(--oob); }
.sw.ln-one { width: 16px; height: 0; border-radius: 0; border-top: 2px dotted var(--one); }

#map {
  display: block;
  width: 100%;
  flex: 1 1 0;
  min-height: 0;
  touch-action: none;
  cursor: crosshair;
}
#acc { display: block; width: 100%; height: auto; }

/* ---- Map marks ---- */
.truth { fill: none; stroke: #f1f5f9; stroke-width: 1.5; stroke-dasharray: 6 5; opacity: 0.85; }
.train-pt { stroke: #f8fafc; stroke-width: 1; }
.test-pt { fill: none; stroke-width: 1.6; }
.hover-ring { fill: none; stroke: #fff; stroke-width: 2.5; }
.mini-ring { stroke-width: 9; }
.mini-ring.unseen { stroke-dasharray: 14 12; }
.mini .train-pt { stroke-width: 2; }
.tick { fill: var(--muted); font-size: 11px; }
.axis { fill: var(--muted); font-size: 11px; }

/* ---- Mini maps ---- */
#minis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  width: 100%;
  max-width: 240px;
}
.mini {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 3px 4px;
  background: #0e1626;
  cursor: crosshair;
  outline: none;
  transition: opacity 0.15s, border-color 0.15s;
}
.mini svg image { image-rendering: pixelated; }
.mini svg { display: block; width: 100%; height: auto; aspect-ratio: 1; touch-action: none; border-radius: 4px; }
.mini figcaption { font-size: 0.75rem; line-height: 1.3; color: var(--muted); padding: 3px 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini figcaption b { color: var(--text); }
.mini.active, .mini:focus-visible { border-color: #fff; }
.mini.out { opacity: 0.6; }

/* Scrolls rather than squeezing the mini maps when the frame is short. */
#detail {
  flex: 1 1 0;
  min-height: 5em;
  overflow-y: auto;
  padding: 0.55rem 0.7rem;
  background: #0e1626;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: #cbd5e1;
}
#detail h3 { font-size: 0.82rem; color: var(--text); margin-bottom: 0.25rem; }
#detail p + p, #detail .strip + p { margin-top: 0.3rem; }
#detail b { color: #fff; }
#detail .hint { color: var(--muted); font-style: italic; }
.k0 { color: var(--c0); font-weight: 650; }
.k1 { color: var(--c1); font-weight: 650; }

/* One square per tree, in order; the first six are the mini maps. */
.strip { display: grid; grid-template-columns: repeat(50, minmax(0, 1fr)); gap: 1px; margin-top: 0.35rem; }
.strip i { display: block; aspect-ratio: 1; border-radius: 2px; }
.strip i.v0 { background: var(--c0); }
.strip i.v1 { background: var(--c1); }
.strip i.dim { background: transparent; }
.strip i.dim.v0 { box-shadow: inset 0 0 0 1.5px var(--c0); }
.strip i.dim.v1 { box-shadow: inset 0 0 0 1.5px var(--c1); }

/* ---- Accuracy ---- */
.gridline { stroke: var(--line); stroke-width: 1; }
.ln-train, .ln-test, .ln-oob { fill: none; stroke-width: 2; }
.ln-train { stroke: var(--train); }
.ln-test { stroke: var(--test); stroke-dasharray: 5 3; }
.ln-oob { stroke: var(--oob); }
.ln-one { stroke: var(--one); stroke-width: 1.5; stroke-dasharray: 2 3; }
.n-marker { stroke: #f1f5f9; stroke-width: 1; stroke-dasharray: 2 3; }
.dot-train { fill: var(--train); }
.dot-test { fill: var(--test); }
.dot-oob { fill: var(--oob); }
#stats { min-height: 2.9em; font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
#stats b { color: var(--text); }

/* ---- Controls ---- */
#controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-content: start;
  gap: 0.55rem 0.9rem;
  background: var(--panel);
}
#controls .wide { grid-column: 1 / -1; }
.control { display: flex; flex-direction: column; gap: 0.2rem; }
.control label, .control .label { display: flex; justify-content: space-between; gap: 0.4rem; font-size: 0.76rem; color: var(--muted); }
.control label span { color: var(--text); font-variant-numeric: tabular-nums; }
.control input[type=range] { width: 100%; accent-color: var(--accent); }
.seg { display: flex; }
.seg button { flex: 1; min-height: 30px; padding: 0.25rem 0.4rem; font-size: 0.76rem; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.check { display: flex; align-items: flex-start; gap: 0.45rem; font-size: 0.76rem; color: var(--muted); cursor: pointer; }
.check input { margin-top: 0.1rem; accent-color: var(--accent); }
.button-row { display: grid; grid-template-columns: 0.6fr 1.4fr 1fr; gap: 0.4rem; }
.note { font-size: 0.75rem; color: var(--muted); }

button {
  padding: 0.4rem 0.7rem;
  font: inherit;
  font-size: 0.8rem;
  background: #1e293b;
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 6px;
  cursor: pointer;
  min-height: 34px;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #334155; border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

footer {
  grid-area: footer;
  padding: 0.45rem 1rem;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}

/* ---- Narrow frames (phones): one column that grows to its content ---- */
@media (max-width: 701px) {
  html, body { height: auto; }
  #app {
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "header" "lessons" "map" "trees" "controls" "acc" "footer";
  }
  .panel { border-right: none !important; }
  #map { flex: none; height: auto; max-height: 420px; }
  #detail { flex: none; min-height: 11em; overflow: visible; }
  #lesson-text { min-height: 0; }
  .strip { grid-template-columns: repeat(25, minmax(0, 1fr)); gap: 2px; }
  #minis { max-width: 420px; }
}

/* SVG text is in viewBox units, so it shrinks with the frame: enlarge it on
   phones to keep it readable. */
@media (max-width: 480px) {
  .tick { font-size: 17px; }
  .axis { font-size: 17px; }
}

/* The narrowest two-column frames (702–900px) also shrink the charts. */
@media (min-width: 702px) and (max-width: 900px) {
  .tick, .axis { font-size: 14.5px; }
  .strip { grid-template-columns: repeat(34, minmax(0, 1fr)); }
  #minis { max-width: 200px; }
}
