/* Look and feel: chunky ink outlines, hard drop shadows, pastel fills, and a
   slight hand-made tilt. Every color is a variable set in both themes. */

/* Nunito, hosted with the site (fonts/, SIL Open Font License in fonts/OFL.txt). */
@font-face {
  font-family: "Nunito Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url("../fonts/nunito-latin-ext-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Nunito Variable";
  font-style: normal;
  font-display: swap;
  font-weight: 200 1000;
  src: url("../fonts/nunito-latin-wght-normal.woff2") format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: dark;
  --bg: #17212c;
  --dot: rgba(255, 255, 255, .07);
  --surface: #22303f;
  --surface-2: #1c2835;
  --ink: #05090e; /* outlines and hard shadows */
  --text: #f5efe4;
  --muted: #a9b6c3;
  --accent: #ff8fab; /* headline highlight */
  --pill-ink: #22303d; /* text on a pastel fill */
  --teal: #22e2cc;
  --purple: #c49bff;
  --yellow: #ffd75e;
  --pink: #ff9bb5;
  --blue: #9ccfff;
  --green: #8de8a8;
  --orange: #ffb978;
  --overlay: rgba(23, 33, 44, .85);
  --info-bg: rgba(34, 48, 63, .97);
  --stage-bg: #0b2233; /* read by js/scene.js */
  --dough: #e8c387;
  --radius: 22px;
  --line: 3px;
  font-family: "Nunito Variable", Nunito, "Trebuchet MS", system-ui, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.5px, transparent 1.6px);
  background-size: 22px 22px;
}

/* js/theme.js sets data-theme from the saved choice, or else the OS setting. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fff4e3;
  --dot: rgba(58, 74, 90, .16);
  --surface: #ffffff;
  --surface-2: #fffaf2;
  --ink: #3a4a5a;
  --text: #33424f;
  --muted: #627384;
  --accent: #e8336a;
  --overlay: rgba(255, 250, 242, .9);
  --info-bg: rgba(255, 255, 255, .97);
  --stage-bg: #cfe8f2;
  --dough: #f6dca8;
}

* { box-sizing: border-box; }

body { margin: 0; min-height: 100vh; }

a { color: var(--accent); }

button, input, select { font: inherit; }

h1, h2, h3 { font-weight: 900; letter-spacing: .2px; }

/* ---------- Shared pieces ---------- */

.chunky {
  background: var(--surface);
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 5px 0 var(--ink);
}

.press {
  border: var(--line) solid var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.press:active { transform: translateY(4px); box-shadow: 0 0 0 var(--ink); }

.theme-toggle, .back {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 48px; min-height: 48px; padding: 0 16px;
  border-radius: 999px;
  background: var(--surface); color: var(--text);
  font-size: 1.05rem; font-weight: 800; text-decoration: none;
  white-space: nowrap;
}

.pill {
  display: inline-block;
  padding: 4px 12px; border-radius: 999px;
  border: 2px solid var(--ink); box-shadow: 0 2px 0 var(--ink);
  background: var(--surface-2); color: var(--text);
  font-size: .85rem; font-weight: 800;
  transform: rotate(-3deg);
}

.wavy {
  text-decoration: underline wavy var(--wave, var(--purple));
  text-decoration-thickness: 3px;
  text-underline-offset: 8px;
}

/* ---------- Home ---------- */

.home { max-width: 1100px; margin: 0 auto; padding: 28px 20px 70px; }

.hero {
  position: relative;
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 20px;
  padding: 24px 0 8px;
}
.hero .theme-toggle { position: absolute; top: 0; right: 0; }
.hero h1 { margin: 0; font-size: clamp(3.4rem, 10vw, 6rem); line-height: .95; color: var(--text); }
.hero h1 .l1 { color: var(--teal); }
.hero h1 .l2 { color: var(--accent); }
.hero h1 .l3 { color: var(--purple); }
.hero h1 .l4 { color: var(--yellow); }
.hero .tagline { margin: 10px 0 0; font-size: clamp(1.4rem, 3.5vw, 2rem); font-weight: 900; color: var(--accent); }
.hero p { font-size: 1.25rem; color: var(--muted); margin: 10px 0 0; }

.hero-mascot { display: flex; align-items: flex-end; gap: 10px; padding-top: 40px; }
.hero-mascot .mascot { width: 130px; }

.confetti-dot {
  position: absolute; width: 12px; height: 12px; border-radius: 50%;
  pointer-events: none;
}
.confetti-dot.diamond { border-radius: 2px; transform: rotate(45deg); }

.topic { margin-top: 26px; }
.topic h2 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin: 44px 0 8px; }
.topic .kicker { margin: 40px 0 0; font-size: 1rem; font-weight: 900; letter-spacing: 2px; text-transform: uppercase; }
.topic > p { color: var(--muted); font-size: 1.2rem; margin: 0 0 22px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 26px;
}

.card {
  position: relative;
  display: block;
  padding: 22px;
  color: var(--text);
  text-decoration: none;
  transform: rotate(-1.2deg);
  transition: transform .15s, box-shadow .15s;
}
.card:nth-child(2n) { transform: rotate(1deg); }
.card:nth-child(3n) { transform: rotate(-.6deg); }
a.card:hover, a.card:focus-visible {
  transform: rotate(0) translateY(-4px);
  box-shadow: 0 10px 0 var(--ink);
  outline: none;
}

.tile {
  display: inline-grid; place-items: center;
  width: 64px; height: 64px;
  border: var(--line) solid var(--ink); border-radius: 16px;
  box-shadow: 0 3px 0 var(--ink);
  background: var(--tile, var(--teal));
  font-size: 2.1rem; line-height: 1;
}
.card h3 { font-size: 1.5rem; margin: 14px 0 6px; }
.card p { margin: 0; color: var(--muted); font-size: 1.05rem; line-height: 1.4; }

.card.soon { border-style: dashed; box-shadow: none; background: var(--surface-2); }
.card.soon .tile { box-shadow: none; }

.card .pill { position: absolute; top: -14px; right: 16px; }
.pill.live { background: var(--teal); color: var(--pill-ink); }
.pill.stars { background: var(--yellow); color: var(--pill-ink); top: auto; bottom: -14px; transform: rotate(2deg); }
.pill.stars[hidden] { display: none; }

/* ---------- Explorer page ---------- */

.explorer {
  display: grid;
  grid-template-columns: 1fr 350px;
  grid-template-rows: auto 1fr;
  gap: 16px;
  padding: 0 16px 20px;
  height: 100vh;
  height: 100dvh; /* keeps the panel above iPad Safari's toolbar */
  overflow: hidden;
}

.topbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 0 0;
}
.topbar h1 { margin: 0; min-width: 0; font-size: clamp(1.3rem, 4vw, 2.1rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .theme-toggle { margin-left: auto; }

.stage { position: relative; min-height: 0; overflow: hidden; }
.stage canvas { display: block; touch-action: none; }

.label {
  padding: 3px 10px; border-radius: 999px;
  background: var(--overlay); border: 2px solid var(--ink);
  color: var(--text); font-size: 13px; font-weight: 800;
  white-space: nowrap; pointer-events: none;
}

.hint {
  position: absolute; top: 14px; left: 14px; right: 14px; width: fit-content;
  padding: 6px 14px; border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--overlay); color: var(--text);
  font-size: .95rem; font-weight: 700; pointer-events: none;
}

.counter {
  position: absolute; top: 14px; right: 14px;
  padding: 6px 14px; border-radius: 999px;
  border: 2px solid var(--ink); box-shadow: 0 3px 0 var(--ink);
  background: var(--yellow); color: var(--pill-ink);
  font-size: 1.15rem; font-weight: 900; pointer-events: none;
}
.has-counter .hint { max-width: calc(100% - 150px); }

.info {
  position: absolute; left: 14px; bottom: 14px;
  max-width: min(400px, calc(100% - 190px));
  padding: 16px 18px;
  background: var(--info-bg);
  font-size: 1.1rem; line-height: 1.4;
  transform: rotate(-1deg);
}
.info[hidden] { display: none; }
.info h3 { margin: 0 44px 6px 0; color: var(--accent); font-size: 1.35rem; }
.info p { margin: 0; }
.info .found { margin-top: 8px; font-weight: 800; color: var(--muted); font-size: .95rem; }
.info .close {
  position: absolute; top: 6px; right: 6px;
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: transparent; color: var(--muted); font-size: 1.6rem; cursor: pointer;
}

.panel {
  overflow-y: auto;
  padding: 4px 6px 10px 2px;
  display: flex; flex-direction: column; gap: 18px;
}

.panel section { padding: 16px; }
.panel h2 { margin: 0 0 14px; font-size: 1.25rem; display: flex; justify-content: space-between; align-items: baseline; }
.panel h2 .count { font-size: .95rem; color: var(--muted); }

.control { display: block; margin-bottom: 14px; }
.control:last-child { margin-bottom: 0; }
.control .name { display: flex; justify-content: space-between; font-size: 1.05rem; font-weight: 700; margin-bottom: 4px; }
.control .name output { color: var(--accent); font-weight: 900; }
.control .ends { display: flex; justify-content: space-between; font-size: .9rem; color: var(--muted); }

input[type="range"] { width: 100%; height: 44px; accent-color: var(--accent); cursor: pointer; }

.buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  min-height: 52px; padding: 8px 12px;
  border-radius: 16px;
  background: var(--surface-2); color: var(--text);
  font-size: 1.05rem; font-weight: 800;
}
.btn.big { grid-column: 1 / -1; background: var(--teal); color: var(--pill-ink); font-size: 1.25rem; }
.btn[aria-pressed="true"] { background: var(--yellow); color: var(--pill-ink); }
.buttons.three { grid-template-columns: repeat(3, 1fr); }
.buttons.three .btn { padding: 6px 4px; font-size: .95rem; }

.facts { margin: 0; padding-left: 20px; font-size: 1.05rem; line-height: 1.45; }
.facts li { margin-bottom: 6px; }

/* Multi-cell: the five levels, cell to organism. */
.ladder { display: grid; gap: 8px; margin-bottom: 12px; }
.ladder .btn { display: flex; align-items: center; gap: 12px; text-align: left; min-height: 48px; }
.ladder .num {
  flex: none; display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--ink); background: var(--surface); color: var(--text);
  font-weight: 900;
}
.ladder .level { display: block; font-size: .8rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.ladder .btn[aria-pressed="true"] .level { color: var(--pill-ink); }
.btn:disabled { opacity: .45; cursor: default; transform: none; box-shadow: 0 4px 0 var(--ink); }
.level-card { font-size: 1.05rem; font-weight: 800; background: var(--surface); }

/* Single-cell: riddles and links to each organism. */
.riddle { margin: 0 0 12px; font-size: 1.15rem; font-weight: 800; line-height: 1.35; }
.visit { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.visit a { display: flex; align-items: center; justify-content: space-between; gap: 6px; text-decoration: none; }
.visit .got { font-size: .85rem; color: var(--muted); }

/* Yeast: sugar left and the dough rising. */
.meter {
  height: 18px; margin: 4px 0 14px;
  border: var(--line) solid var(--ink); border-radius: 999px;
  background: var(--surface-2); overflow: hidden;
}
.meter span { display: block; height: 100%; width: 0; background: var(--pink); transition: width .3s; }
.dough-bowl {
  height: 130px; display: flex; align-items: flex-end; justify-content: center;
  border-bottom: var(--line) solid var(--ink);
}
.dough {
  --rise: 1;
  width: 150px; height: 46px;
  background: var(--dough);
  border: var(--line) solid var(--ink);
  border-radius: 50% 50% 14px 14px / 90% 90% 14px 14px;
  transform-origin: bottom center;
  transform: scale(calc(.85 + var(--rise) * .15), var(--rise));
  transition: transform .4s;
}

/* "Try this!" ticks itself off as each experiment is done. */
.try { list-style: none; margin: 0; padding: 0; font-size: 1.05rem; line-height: 1.4; }
.try li { position: relative; padding-left: 38px; margin-bottom: 10px; }
.try li::before {
  content: "";
  position: absolute; left: 0; top: 0;
  width: 26px; height: 26px;
  border: var(--line) solid var(--ink); border-radius: 8px;
  background: var(--surface-2);
}
.try li.done::before {
  content: "★"; display: grid; place-items: center;
  background: var(--yellow); color: var(--pill-ink); font-size: 1rem; line-height: 1;
}
.try li.done { color: var(--muted); }
.link-btn {
  margin-top: 4px; padding: 6px 0; min-height: 44px;
  border: 0; background: none; color: var(--muted);
  font-size: .95rem; font-weight: 700; text-decoration: underline; cursor: pointer;
}

/* ---------- Mascot ---------- */

.mascot-dock {
  position: absolute; right: 12px; bottom: 12px;
  display: flex; align-items: flex-end; gap: 6px;
  pointer-events: none;
}
.mascot { width: 104px; height: auto; display: block; }
.mascot .eye { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
.mascot.talk { animation: bob .5s ease-in-out 2; }

.bubble {
  position: relative;
  max-width: 230px;
  padding: 10px 14px;
  border: var(--line) solid var(--ink); border-radius: 18px;
  box-shadow: 0 4px 0 var(--ink);
  background: var(--surface); color: var(--text);
  font-size: 1.05rem; font-weight: 800; line-height: 1.3;
  margin-bottom: 54px;
  transition: opacity .25s, transform .25s;
}
.bubble.quiet { opacity: 0; transform: translateY(6px); }

@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-3deg); } }

.burst {
  position: absolute; width: 12px; height: 12px; border-radius: 3px;
  pointer-events: none;
  animation: burst 1.6s ease-out forwards;
}
@keyframes burst {
  from { transform: translate(0, 0) rotate(0); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) rotate(540deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .mascot .eye, .mascot.talk, .burst { animation: none; }
  .burst { display: none; }
  .card, a.card:hover { transition: none; }
}

@media (max-width: 480px) {
  .wide-only { display: none; }
  .topbar { gap: 10px; }
}

@media (max-width: 820px) {
  .explorer {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 60vh auto;
    height: auto; overflow: visible;
  }
  .panel { overflow: visible; padding: 4px 2px 10px; }
  .hero { grid-template-columns: 1fr; }
  .hero-mascot { padding-top: 0; }
  .mascot { width: 80px; }
  .bubble { max-width: 180px; font-size: .95rem; margin-bottom: 40px; }
  .info { max-width: calc(100% - 28px); bottom: auto; top: 60px; }
}
