/*
 * Meadow Lab — kid-friendly, tablet-first styling.
 * Touch targets >= 48px, text >= 18px, high contrast (WCAG AA).
 * No external font (system stack) so the page works fully offline.
 */
:root {
  --bg: #f2f8ee;
  --card: #ffffff;
  --ink: #1f2a1c;
  --ink-soft: #4a5745;
  --line: #dce8d5;
  --accent: #2f9e44;
  --accent-ink: #0e4d1c;
  --clover: #2f9e44;
  --rabbit: #b06e2c;
  --fox: #e8590c;
  --focus: #1c6fd0;
  --radius: 16px;
  --shadow: 0 2px 8px rgba(31, 42, 28, .08);
  font-size: 18px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 600px at 50% -10%, #dff3d8, var(--bg)) fixed, var(--bg);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { line-height: 1.2; }
.muted { color: var(--ink-soft); font-weight: 400; }
.small { font-size: 14px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px;
  background: rgba(255,255,255,0.9); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.title { font-size: 1.4rem; margin: 0; font-weight: 800; letter-spacing: .2px; }
.title span { font-size: 1.3rem; }
.topbar-actions { display: flex; gap: 8px; align-items: center; min-height: 48px; }

/* ---------- buttons ---------- */
button, .icon-btn {
  font: inherit; cursor: pointer; border: 0; border-radius: 12px;
  min-height: 48px; min-width: 48px; padding: 10px 14px; font-weight: 700;
  background: #fff; color: var(--ink);
  box-shadow: var(--shadow); transition: transform .08s ease, background .15s ease;
}
button:active { transform: translateY(1px); }
button:hover { background: #f4f9f0; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #268a3a; }
.icon-btn { padding: 8px 12px; }
.mode-btn { display: inline-flex; align-items: center; gap: 6px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- layout ---------- */
.layout {
  max-width: 1200px; margin: 0 auto; padding: 14px;
  display: grid; grid-template-columns: 1fr; gap: 14px;
}
.left-col, .right-col { display: grid; gap: 14px; align-content: start; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.card-title { margin: 0 0 8px; font-size: 1.15rem; }
.card-stack { display: grid; gap: 14px; }

@media (min-width: 900px) {
  .layout { grid-template-columns: 1.25fr 1fr; }
  .title { font-size: 1.5rem; }
}

/* ---------- badges ---------- */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #fff; border: 2px solid var(--line); border-radius: 14px;
  padding: 10px 6px; box-shadow: var(--shadow); text-align: center;
}
.badge .badge-emoji { font-size: 2rem; line-height: 1; }
.badge .badge-num { font-size: 1.6rem; font-weight: 800; min-height: 1.2em; }
.badge .badge-label { font-size: .9rem; font-weight: 600; }
.badge[data-sp="clover"]  { border-color: color-mix(in srgb, var(--clover) 55%, white); }
.badge[data-sp="rabbits"] { border-color: color-mix(in srgb, var(--rabbit) 55%, white); }
.badge[data-sp="foxes"]   { border-color: color-mix(in srgb, var(--fox) 55%, white); }
.badge.bump .badge-emoji { animation: bump .45s ease; }
@keyframes bump { 0%{transform:translateY(0)} 30%{transform:translateY(-7px) scale(1.12)} 60%{transform:translateY(0) scale(.96)} 100%{transform:translateY(0)} }

/* ---------- meadow ---------- */
.meadow-wrap { padding: 8px; }
#meadow { width: 100%; height: auto; display: block; border-radius: 12px; background: linear-gradient(#bfe3ff, #e6f6dc); }
.meadow-legend { font-size: .9rem; color: var(--ink-soft); margin-top: 6px; }
.meadow-event {
  margin-top: 8px; padding: 10px 12px; border-radius: 10px;
  background: #fff4e2; border: 1px solid #f3d9a3; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.meadow-event button { min-height: 40px; }

/* ---------- graph ---------- */
#graph { width: 100%; height: auto; display: block; }

/* ---------- playbar ---------- */
.playbar { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; }
.playbar-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.playbar-meta { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.speed { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.speed-select { font: inherit; padding: 8px 10px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; min-height: 44px; }
.season { font-weight: 700; }

/* ---------- species cards ---------- */
.sp-card { border-left: 8px solid; padding: 12px 14px; }
.sp-card[data-sp="clover"]  { border-left-color: var(--clover); }
.sp-card[data-sp="rabbits"] { border-left-color: var(--rabbit); }
.sp-card[data-sp="foxes"]   { border-left-color: var(--fox); }
.sp-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sp-head .sp-emoji { font-size: 1.8rem; }
.sp-head .sp-name { font-size: 1.2rem; font-weight: 800; }
.sp-head .sp-sub { font-size: .9rem; color: var(--ink-soft); }
.sp-head .sp-count { margin-left: auto; font-weight: 800; font-size: 1.15rem; }

.ctrl { display: block; margin: 12px 0; }
.ctrl-label { display: flex; gap: 6px; font-weight: 700; margin-bottom: 6px; }
.ctrl-label .help, .ctrl-label .concept-q {
  width: 36px; height: 36px; min-width: 36px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: #eef6ea; color: var(--accent-ink); font-size: 1rem; font-weight: 800;
  cursor: help; flex: none; padding: 0; box-shadow: none; border: 0;
}
.ctrl-label .concept-q:hover { background: #c9e3c4; }
.ctrl-label .concept-q:active { transform: none; }
.ctrl-label .ctrl-copy { display: inline; color: inherit; }
.ctrl-controls { display: flex; align-items: center; gap: 10px; }
input[type="range"].slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 30px;
  background: transparent; margin: 0;
}
input[type="range"].slider::-webkit-slider-runnable-track {
  height: 12px; border-radius: 8px; background: #d8e6cf;
}
input[type="range"].slider::-moz-range-track { height: 12px; border-radius: 8px; background: #d8e6cf; }
input[type="range"].slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 30px; height: 30px; margin-top: -9px;
  border-radius: 50%; background: var(--accent); border: 3px solid #fff;
  box-shadow: var(--shadow); cursor: pointer;
}
input[type="range"].slider::-moz-range-thumb {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; cursor: pointer;
}
.sp-card[data-sp="rabbits"] input[type="range"].slider::-webkit-slider-thumb { background: var(--rabbit); }
.sp-card[data-sp="rabbits"] input[type="range"].slider::-moz-range-thumb { background: var(--rabbit); }
.sp-card[data-sp="foxes"]   input[type="range"].slider::-webkit-slider-thumb { background: var(--fox); }
.sp-card[data-sp="foxes"]   input[type="range"].slider::-moz-range-thumb { background: var(--fox); }

.numbox {
  width: 72px; font: inherit; font-weight: 700; text-align: center;
  padding: 8px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff;
}
.ctrl-controls .num-unit { font-size: .9rem; color: var(--ink-soft); min-width: 1.2em; }

/* concept help bubble */
[data-scheme] .concept-pop { }
.help-bubble {
  position: fixed; z-index: 60; max-width: 240px;
  background: #fffdf5; border: 1.5px solid #f0e0a6; border-radius: 12px;
  padding: 10px 12px; box-shadow: 0 6px 20px rgba(0,0,0,.15);
  font-size: .92rem; font-weight: 500;
}
.help-bubble .hb-emoji { font-size: 1.6rem; margin-bottom: 4px; }

/* ---------- toggles ---------- */
.toggles-row { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 44px; cursor: pointer; }
.toggles-check { width: 26px; height: 26px; accent-color: var(--accent); }

/* ---------- presets & challenges ---------- */
.presets .presets-row, .challenges .challenges-list { display: grid; gap: 8px; }
.presets .presets-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.presets-row { display: grid; gap: 8px; }
.presets-row .btn { width: 100%; font-size: .98rem; }
.presets-row .btn small { display: block; font-weight: 500; opacity: .85; }
.btn { min-height: 48px; }
.challenge {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 12px; background: #fbfdf8;
}
.challenge .ck {
  width: 30px; height: 30px; min-width: 30px; border-radius: 50%;
  border: 2px solid var(--line); display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; color: #fff;
}
.challenge.done { border-color: color-mix(in srgb, var(--accent) 55%, white); background: #f2fbf2; }
.challenge.done .ck { background: var(--accent); border-color: var(--accent); }
.challenge .cbody { display: flex; flex-direction: column; gap: 2px; }
.challenge .ctext { font-weight: 700; }
.challenge .chint { font-size: .85rem; color: var(--ink-soft); }

/* ---------- help overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(20,30,16,.5);
  display: none; align-items: center; justify-content: center; padding: 16px;
}
.overlay.is-open { display: flex; }
.help-inner { max-width: 460px; background: #fff; border-radius: 18px; padding: 20px; }
.help-inner .btn { margin-top: 12px; width: 100%; }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 120; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--accent); color: #fff; border-radius: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  max-width: min(92vw, 460px); font-weight: 700; overflow: hidden;
}
.toast[hidden] { display: none; }
.toast .btn { min-height: 40px; background: #fff; color: var(--accent-ink); }

/* ---------- data table (scientist) ---------- */
.data-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: .95rem; }
.data-table th, .data-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.data-table th { font-size: .85rem; color: var(--ink-soft); }
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.data-table tr.sp-clover td:first-child, .data-table tr.sp-rabbits td:first-child, .data-table tr.sp-foxes td:first-child { font-weight: 700; }

/* ---------- prefers-reduced-motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}

/* ---------- mode toggles ----------
 * Explorer (K-2) hides numbers on the graph, the number boxes next to sliders,
 * the "over time" label, and the "What happened?" panel. Scientist mode shows
 * everything (that's the default in the DOM).
 */
/* default: show scientist extras */
html[data-mode="scientist"] .only-scientist { display: initial; }

/* Explorer mode: hide the scientist extras */
html[data-mode="explorer"] .only-scientist { display: none !important; }
html[data-mode="explorer"] .numbox,
html[data-mode="explorer"] .num-unit    { display: none !important; }

/* ---------- species tabs (one panel at a time) ---------- */
.species-tabs {
  display: flex; gap: 6px; padding: 4px;
  background: #eef4ea; border-radius: 14px; margin-bottom: 10px;
  flex-wrap: wrap;
}
.species-tab {
  flex: 1; min-width: 96px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 8px 10px; border-radius: 10px;
  font-weight: 700; background: #fff; color: var(--ink);
}
.species-tab[aria-selected="true"] {
  background: var(--accent); color: #fff;
}
.species-tab .swatch {
  width: 14px; height: 14px; border-radius: 5px; border: 1px solid rgba(0,0,0,.12); flex: none;
}
.species-panel { display: none; }
.species-panel.is-active { display: block; }
.species-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.species-head .swatch {
  width: 16px; height: 16px; border-radius: 6px; border: 1px solid rgba(0,0,0,.12);
}
.species-head .species-emoji { font-size: 1.4rem; line-height: 1; }
.species-head .species-name { font-size: 1.1rem; font-weight: 800; }

/* ---------- scientist notation tag (only-scientist) ---------- */
.science-tag, .sci-tag {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: .82rem; font-weight: 700;
  background: #eef6ea; color: var(--accent-ink);
  border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 6px;
  letter-spacing: .3px;
  margin-left: 6px;
  vertical-align: middle;
}
.science-tag { display: inline-block; }

/* ---------- preset & campaign spacing (denser) ---------- */
.species-card { display: grid; gap: 4px; }
.species-panel .card, .species-panel { border-radius: 14px; }
.challenges .ch-intro { font-size: .92rem; margin: 0 0 10px; }
.challenge { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; }
.challenge .ch-emoji { font-size: 1.4rem; line-height: 1.2; flex: none; }
.challenge .ch-body { display: flex; flex-direction: column; gap: 2px; }
.challenge .ch-title { font-weight: 800; font-size: 1.02rem; }
.challenge .ch-goal { font-size: .92rem; font-weight: 600; }
.challenge .ch-hint { font-size: .85rem; color: var(--ink-soft); }
.challenge .ch-check {
  width: 30px; height: 30px; min-width: 30px; border-radius: 50%;
  border: 2px solid var(--line); background: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900; color: #fff; font-size: 1rem;
}
.challenge.is-done { border-color: color-mix(in srgb, var(--accent) 55%, white); background: #f2fbf2; }
.challenge.is-done .ch-check { background: var(--accent); border-color: var(--accent); }

/* denser right column (feedback #3) */
.right-col { gap: 10px; }
.card { padding: 12px; }
.ctrl { margin: 8px 0; }
.ctrl-head { display: flex; align-items: center; gap: 8px; }
.ctrl-label { flex: 1; min-width: 0; }
.card-stack { display: grid; gap: 10px; }
.presets .presets-row, .challenges .challenges-list { gap: 6px; }

/* ---------- campaigns: collapsible <details> ---------- */
details.challenges {
  display: block;
  padding: 0;
  overflow: visible;
}
details.challenges summary {
  list-style: none;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1rem;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #fbfdf8;
  user-select: none;
}
details.challenges summary::-webkit-details-marker { display: none; }
details.challenges summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
details.challenges .ch-progress { margin-left: auto; font-size: .92rem; }
details.challenges .ch-chevron {
  transition: transform .18s ease;
  font-size: 1rem; color: var(--ink-soft);
}
details.challenges.is-open .ch-chevron,
details.challenges[open] .ch-chevron { transform: rotate(180deg); }
details.challenges .challenges-body { padding: 4px 12px 12px; }
details.challenges .ch-intro { font-size: .88rem; margin: 0 0 8px; }

/* All campaigns done — celebrate */
details.challenges.all-done summary {
  background: linear-gradient(90deg, #f5fbd6, #d8f5b3);
  border: 1px solid #a6d34a;
}
