@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../assets/fonts/atkinson-400.woff2") format("woff2");
}

@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../assets/fonts/atkinson-700.woff2") format("woff2");
}

@font-face {
  font-family: Fraunces;
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../assets/fonts/fraunces-560.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../assets/fonts/plex-mono-400.woff2") format("woff2");
}

:root,
html[data-theme="ink"] {
  color-scheme: dark;
  --bg: #12161c;
  --bg-elev: #1b222c;
  --ink: #f4f0e6;
  --muted: #c5ced6;
  --line: #3c4a5c;
  --accent: #e2a13a;
  --accent-2: #7ec8c3;
  --btn-ink: #1a1206;
  --danger: #ffb4a8;
  --ok: #b6e3a8;
  --code-bg: #0e1318;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  --header: rgba(18, 22, 28, 0.92);
  --room-floor: #243140;
  --room-wall: #18222e;
}

html[data-theme="paper"] {
  color-scheme: light;
  --bg: #f6f1e7;
  --bg-elev: #fffaf2;
  --ink: #1c1915;
  --muted: #4a433a;
  --line: #d4c8b4;
  --accent: #8f2d22;
  --accent-2: #1f6f78;
  --btn-ink: #fffaf2;
  --danger: #8f2d22;
  --ok: #1d6b32;
  --code-bg: #fff;
  --shadow: 0 12px 28px rgba(60, 40, 20, 0.08);
  --header: rgba(246, 241, 231, 0.94);
  --room-floor: #e7dcc8;
  --room-wall: #f8f3ea;
}

html[data-theme="terminal"] {
  color-scheme: dark;
  --bg: #0c1210;
  --bg-elev: #121a17;
  --ink: #d7ffe4;
  --muted: #9dccb0;
  --line: #1f6b45;
  --accent: #39d98a;
  --accent-2: #9dff6a;
  --btn-ink: #04140c;
  --danger: #ffb4a8;
  --ok: #9dff6a;
  --code-bg: #08110d;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  --header: rgba(12, 18, 16, 0.94);
  --room-floor: #163028;
  --room-wall: #0e1c16;
}

html[data-theme="contrast"] {
  color-scheme: dark;
  --bg: #000;
  --bg-elev: #000;
  --ink: #fff;
  --muted: #fff;
  --line: #fff;
  --accent: #ffe14a;
  --accent-2: #fff;
  --btn-ink: #000;
  --danger: #fff;
  --ok: #ffe14a;
  --code-bg: #000;
  --shadow: none;
  --header: #000;
  --room-floor: #000;
  --room-wall: #000;
}

* { box-sizing: border-box; }

html {
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 10% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: "Atkinson Hyperlegible", "Segoe UI", sans-serif;
  font-size: 1.05rem;
  line-height: 1.55;
  overflow-x: clip;
  overflow-wrap: break-word;
  padding-bottom: 128px;
}

img, video, canvas, svg, pre { max-width: 100%; }

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

a:hover { color: var(--ink); }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--accent);
  color: var(--btn-ink);
  padding: 8px 12px;
  z-index: 50;
}

.skip:focus { top: 12px; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  padding: 12px 16px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  margin-right: auto;
  color: var(--ink);
  text-decoration: none;
  font-family: Fraunces, Georgia, serif;
  font-weight: 600;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.theme-btn,
.text-btn,
.choice,
.dir-pad button,
button,
.menu-card,
.lesson-row,
.download-card {
  font: inherit;
}

.theme-btn,
.text-btn,
.primary,
.choice,
.dir-pad button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--ink);
  padding: 8px 12px;
  cursor: pointer;
}

.theme-btn[aria-pressed="true"],
.primary {
  background: var(--accent);
  color: var(--btn-ink);
  border-color: var(--accent);
}

.primary:disabled {
  opacity: 0.7;
  cursor: progress;
}

.wrap {
  width: min(1120px, calc(100% - 32px));
  margin: 24px auto 0;
}

h1, h2, h3 {
  font-family: Fraunces, Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.12;
}

h1 {
  font-size: clamp(2.1rem, 10vw, 3.6rem);
  margin: 0 0 12px;
}

h2 { font-size: 1.7rem; margin: 1.4em 0 0.4em; }

h3 { font-size: 1.25rem; margin: 1.1em 0 0.3em; }

.lede, .summary {
  font-size: 1.12rem;
  max-width: 68ch;
}

.muted { color: var(--muted); }

.kicker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 18px 0;
}

.filter input,
textarea,
select,
.guess-row input,
.adv-row input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--code-bg);
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
}

textarea {
  min-height: 180px;
  resize: vertical;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.92rem;
  line-height: 1.45;
}

.download-card a[download], .dl-list a { touch-action: manipulation; scroll-margin-bottom: 200px; scroll-margin-top: 90px; }
@media (max-width: 899px) { .download-grid, .dl-list { padding-right: 124px; } }
.menu-grid, .clip-grid, .card-grid, .download-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.menu-card, .lesson-row, .panel, .download-card, .exam-card, .project-card {
  display: block;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  color: inherit;
  text-decoration: none;
  padding: 16px;
  min-width: 0;
}

.menu-card {
  min-height: 112px;
}

.menu-card:hover, .lesson-row:hover, .download-card:hover {
  border-color: var(--accent);
}

.menu-top, .row-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.ico {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--accent);
}

.menu-label, .row-label {
  display: block;
  font-family: Fraunces, Georgia, serif;
  font-size: 1.28rem;
  line-height: 1.15;
}

.menu-desc, .row-desc {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.crumbs a { color: var(--ink); }

pre {
  overflow-x: auto;
  padding: 12px 14px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  line-height: 1.45;
}

code, .mono, textarea {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

:not(pre) > code {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.05em 0.35em;
  background: var(--code-bg);
  overflow-wrap: anywhere;
}

.toolbar, .pager, .guess-row, .adv-row, .quiz-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
}

.output, .log, .check-list {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--code-bg);
  padding: 12px;
  min-height: 72px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.check-list { white-space: normal; }

.pass { color: var(--ok); }

.fail { color: var(--danger); }

.is-reading {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 8px;
}

.diagram-host {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elev);
  padding: 8px;
}

.diagram-host svg { height: auto; }

.room {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--room-wall);
  margin: 16px 0;
  overflow: hidden;
}

.room-stage {
  height: 250px;
  perspective: 680px;
  perspective-origin: 50% 30%;
  position: relative;
  overflow: hidden;
  transform-style: preserve-3d;
}

.room-floor, .room-wallback, .prop, .float-card, .desk {
  position: absolute;
}

.room-floor {
  width: 140%;
  height: 70%;
  left: -20%;
  bottom: -18%;
  background:
    linear-gradient(90deg, transparent 0 46%, color-mix(in srgb, var(--accent) 35%, transparent) 46% 47%, transparent 47%),
    var(--room-floor);
  transform: rotateX(68deg);
  transform-origin: center center;
  border: 1px solid var(--line);
}

.room-wallback {
  inset: 18px 12% auto;
  height: 46%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 70%, var(--room-wall));
  transform: translateZ(-40px);
}

.prop {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  transform-style: preserve-3d;
}

.desk {
  width: 68%;
  height: 42%;
  left: 16%;
  bottom: 6%;
  background: color-mix(in srgb, var(--accent) 18%, var(--room-floor));
  border: 1px solid var(--line);
  transform: rotateX(68deg);
  transform-origin: center bottom;
}

.monitor {
  width: 42%;
  height: 38%;
  left: 29%;
  bottom: 28%;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}

.lamp {
  width: 18px;
  height: 64px;
  right: 18%;
  bottom: 26%;
  background: var(--accent);
}

.book {
  width: 54px;
  height: 18px;
  left: 18%;
  bottom: 24%;
  background: var(--accent-2);
}

.float-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: var(--bg-elev);
  font-size: 0.85rem;
}

.float-a { top: 18px; left: 8%; animation: floaty 7s ease-in-out infinite; }
.float-b { top: 36px; right: 8%; animation: floaty 8s ease-in-out infinite reverse; }
.float-c { top: 78px; left: 22%; animation: floaty 6.5s ease-in-out infinite; }

.room-flat {
  display: none;
  gap: 8px;
  padding: 12px;
}

.room-caption { margin: 0; padding: 10px 12px 12px; color: var(--muted); }

.clips figure { margin: 0; min-width: 0; }

.clips video, .clips img, .clips canvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  display: block;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 12px;
  object-fit: cover;
}

.clips figcaption, .diagram figcaption { color: var(--muted); margin-top: 6px; }

.choice { text-align: left; width: 100%; }

.choice.chosen { border-color: var(--accent); }

.dir-pad {
  display: grid;
  grid-template-columns: 44px 44px 44px;
  gap: 6px;
  width: max-content;
}

.dir-pad .up { grid-column: 2; }
.dir-pad .left { grid-column: 1; }
.dir-pad .down { grid-column: 2; }
.dir-pad .right { grid-column: 3; }

#snake-canvas {
  width: min(100%, 420px);
  height: auto;
  background: #12142b;
  border: 2px solid #7f8cff;
  border-radius: 12px;
  box-shadow: 0 0 22px color-mix(in srgb, #ff5da2 35%, transparent);
  touch-action: none;
}

.site-footer {
  width: min(1120px, calc(100% - 32px));
  margin: 36px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding: 0;
  margin: 0 0 8px;
  list-style: none;
}

.source-list { display: grid; gap: 12px; padding: 0; list-style: none; }

.source-list a { overflow-wrap: anywhere; }

.glossary-item { margin: 0 0 12px; }

.bot {
  position: fixed;
  z-index: 25;
  right: 12px;
  bottom: 12px;
  width: 84px;
  height: 108px;
  touch-action: none;
  cursor: grab;
  user-select: none;
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
}

.bot:focus-visible, button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.bot.is-dragging { cursor: grabbing; }

.bot-stage {
  width: 100%;
  height: 100%;
  perspective: 400px;
}

.bot-figure {
  position: relative;
  width: 72px;
  height: 96px;
  margin: 0 auto;
  transform-style: preserve-3d;
  animation: bot-idle 5s ease-in-out infinite;
}

.antenna {
  position: absolute;
  left: 33px;
  top: 0;
  width: 4px;
  height: 14px;
  background: var(--accent);
  border-radius: 4px;
}

.antenna::after {
  content: "";
  position: absolute;
  left: -4px;
  top: -8px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-2);
  border: 1px solid var(--line);
}

.head, .torso {
  position: absolute;
  left: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 55%, var(--bg-elev)), var(--bg-elev) 45%);
  box-shadow: var(--shadow);
}

.head { top: 16px; width: 56px; height: 36px; }

.face {
  display: flex;
  justify-content: space-between;
  padding: 12px 12px 0;
}

.face i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink);
  display: block;
}

.torso {
  top: 54px;
  width: 56px;
  height: 32px;
  display: grid;
  place-items: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
}

.bot-shadow {
  position: absolute;
  left: 16px;
  bottom: 2px;
  width: 52px;
  height: 8px;
  background: color-mix(in srgb, var(--ink) 25%, transparent);
  border-radius: 50%;
  filter: blur(1px);
}

.bot.bounce .bot-figure { animation: bot-bounce 420ms ease; }

.empty {
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 16px;
}

@keyframes floaty {
  0%, 100% { transform: translateY(0) rotateX(8deg); }
  50% { transform: translateY(-8px) rotateX(8deg) rotateZ(-1deg); }
}

@keyframes bot-idle {
  0%, 100% { transform: rotateY(-18deg) rotateX(8deg); }
  50% { transform: rotateY(18deg) rotateX(4deg); }
}

@keyframes bot-bounce {
  0% { transform: rotateY(0) scale(1, 1); }
  40% { transform: rotateY(-12deg) scale(1.06, 0.92); }
  100% { transform: rotateY(0) scale(1, 1); }
}

@media (min-width: 800px) {
  .menu-grid, .card-grid, .download-grid { grid-template-columns: 1fr 1fr; }
  .clip-grid { grid-template-columns: 1fr 1fr; }
  .room-stage { height: 320px; }
}

@media (min-width: 1100px) {
  .menu-grid { grid-template-columns: 1fr 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .room-stage { display: none; }
  .room-flat { display: flex; flex-wrap: wrap; }
}

@media print {
  #lab-bot, .header-actions, .skip, .toolbar { display: none !important; }
  body { background: #fff; color: #000; padding-bottom: 0; }
}
