:root {
  --paper: #f4f7f5;
  --white: #fff;
  --ink: #172e28;
  --muted: #4f635a;
  --line: #dbe4de;
  --green: #17604a;
  --deep: #143d32;
  --mint: #e3efe7;
  --radius: 26px;
  --body: 1.125rem;
  color: var(--ink);
  background: var(--paper);
  font-family: system-ui, -apple-system, "PingFang HK", "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.55;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: var(--body); }
a { color: inherit; }
img { display: block; max-width: 100%; }
button, input, summary { font: inherit; }
button, a, input, summary { touch-action: manipulation; }
button { cursor: pointer; color: inherit; border: 0; }
button:disabled { cursor: default; opacity: .65; }
:focus-visible { outline: 3px solid #307e88; outline-offset: 4px; }
main:focus, [tabindex="-1"]:focus { outline: none; }
h1, h2, h3, p, figure { margin: 0; }
h1, h2, h3 { line-height: 1.2; overflow-wrap: anywhere; }
h1 { font-size: clamp(2.2rem, 4.7vw, 3.75rem); font-weight: 760; }
h2 { font-size: clamp(1.65rem, 3.5vw, 2.25rem); font-weight: 730; }
h3 { font-size: 1.15rem; }
p { overflow-wrap: break-word; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.micro { color: var(--muted); font-size: .9375rem; }
.lead { color: var(--muted); font-size: clamp(1.125rem, 2.3vw, 1.375rem); }
.topbar, main, .footer { width: min(100% - 64px, 1340px); margin-inline: auto; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  font-size: 1.125rem;
  font-weight: 750;
}
.brand img { flex: none; width: 34px; height: auto; }
.header-actions, .action-row, .result-tools {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
}
.header-actions { justify-content: flex-end; }
.primary, .secondary, .text-button, .dialog-close {
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 100px;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.35;
}
.primary { background: var(--green); color: #fff; }
a.primary { display: inline-grid; place-items: center; text-decoration: none; }
a[aria-disabled="true"] { opacity: .65; }
.primary:hover { background: #104e3c; }
.secondary { background: #e8efea; }
.secondary:hover, .text-button:hover { background: #dce9e0; }
.text-button { background: transparent; color: var(--green); }
main { padding-block: 32px 40px; min-height: calc(100svh - 155px); }
.footer {
  display: flex; justify-content: flex-end; border-top: 1px solid var(--line);
  padding-block: 8px;
}
.footer .text-button { color: var(--muted); font-size: .875rem; }
.hero {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 8fr);
  min-height: 450px;
  background: var(--deep);
  border-radius: 32px;
  overflow: hidden;
}
.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(28px, 4.2vw, 66px);
  color: #fff;
}
.hero h1 { font-size: clamp(3rem, 5.8vw, 5.9rem); line-height: 1.05; letter-spacing: -.06em; }
.hero p { margin-top: 26px; max-width: 16em; color: #e1f0e7; font-size: clamp(1.125rem, 2vw, 1.35rem); }
.hero .primary {
  margin-top: 32px;
  padding: 17px 28px;
  background: #eff8f0;
  color: var(--deep);
  font-size: 1.15rem;
}
.hero .primary:hover { background: #fff; }
.hero-photo { position: relative; min-width: 0; background: #b9d4e4; }
.hero-photo img { height: 100%; width: 100%; min-height: 450px; object-fit: cover; object-position: center 20%; }
.hero-photo figcaption {
  position: absolute;
  right: 12px;
  bottom: 12px;
  max-width: calc(100% - 24px);
  padding: 5px 10px;
  background: #102a23e8;
  color: #fff;
  border-radius: 100px;
  font-size: .75rem;
}
.home-links { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.home-tile {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  text-align: start; font-size: clamp(1.125rem, 2vw, 1.5rem); font-weight: 720;
  padding: 17px clamp(16px, 2.2vw, 32px); border-radius: var(--radius); min-height: 97px;
}
.home-tile:hover { filter: brightness(.975); }
.home-tile-catalog { background: #e3efe7; }
.home-tile-arcade { background: #f7ead8; }
.tile-avatars, .tile-glyphs { display: flex; align-items: center; gap: 5px; }
.tile-glyphs i {
  display: grid; place-items: center;
  width: 42px; aspect-ratio: 1; border-radius: 14px;
  font: inherit; font-size: 1.35rem; color: #744315; background: #f2d7ad;
}
.tile-glyphs i:nth-child(2) { color: #174b4c; background: #d7eae5; }
.tile-glyphs i:nth-child(3) { color: #51387a; background: #e8dcf3; }
.pixel-avatar {
  display: inline-block; flex: none; width: 144px; height: 144px;
  background-image: url('assets/player-pixels.svg'); background-size: 400% 200%;
  background-position: var(--avatar-x) var(--avatar-y); background-repeat: no-repeat;
  image-rendering: pixelated; vertical-align: middle;
}
.pixel-avatar.small { width: 52px; height: 52px; }
.intro, .outcome {
  margin: clamp(10px, 4vh, 44px) auto;
  max-width: 790px;
  padding: clamp(24px, 5vw, 64px);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 32px;
  text-align: center;
}
.intro h1 { font-size: clamp(2rem, 4.5vw, 3.25rem); }
.passport {
  display: grid; grid-template-columns: auto 1fr; align-items: center;
  gap: clamp(12px, 4vw, 34px); text-align: start;
  max-width: 490px; background: var(--mint); border-radius: 24px;
  margin: 28px auto 23px; padding: 18px clamp(16px, 3vw, 30px);
}
.passport-avatar .pixel-avatar { width: 144px; height: 144px; }
.house-tag { display: inline-flex; align-items: center; gap: 9px; font-size: 1.125rem; font-weight: 730; }
.house-dot { width: 13px; height: 13px; border-radius: 50%; background: var(--house); flex: none; }
.traits, .effect-pills, .card-badges { display: flex; flex-wrap: wrap; gap: 8px; }
.traits { margin-top: 12px; }
.pill {
  display: inline-block; border-radius: 100px; padding: 5px 12px; color: var(--deep);
  background: #fff9; font-size: .9375rem; font-weight: 600;
}
.intro .action-row, .outcome .action-row { justify-content: center; }
.journey-screen { max-width: 1120px; margin-inline: auto; }
.journey {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 20px; padding: 8px; border-radius: 19px; background: #e6ede8;
}
.grade-list { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 0; margin: 0; list-style: none; flex: 1; }
.grade-list li { text-align: center; border-radius: 12px; padding: 9px 3px; font-weight: 650; font-size: 1rem; color: #4c6157; }
.grade-list li[aria-current] { background: var(--green); color: #fff; }
.grade-list .done { background: #d4e5da; color: #234e3b; }
.chapter-label { padding: 0 10px; color: var(--muted); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.event-card {
  display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 7fr); min-height: 440px;
  border: 1px solid var(--line); border-radius: 30px; overflow: hidden; background: var(--white);
}
.event-content { padding: clamp(22px, 3.8vw, 52px); min-width: 0; }
.context-label { color: var(--green); font-weight: 720; font-size: 1rem; margin-bottom: 9px; }
.event-heading .context-label::before {
  content: ''; display: inline-block; vertical-align: .09em; width: .56em; height: .56em;
  margin-right: .55em; border-radius: 50%; background: var(--context, var(--green));
}
.event-heading h1 { font-size: clamp(2rem, 3.8vw, 3rem); }
.story { margin-top: 14px; font-size: clamp(1.125rem, 1.7vw, 1.3125rem); }
.choices { display: grid; gap: 9px; margin: 22px 0 8px; }
.choice {
  min-height: 58px; width: 100%; display: flex; align-items: center; gap: 12px;
  background: #eff5f0; border: 1px solid #e0ebe3; border-radius: 16px;
  padding: 11px 14px; text-align: start;
  font-size: clamp(1.125rem, 1.65vw, 1.25rem); font-weight: 650;
}
.choice:hover { background: #dfefe4; border-color: #b9d6c3; }
.mini-prepare-actions > .primary {
  min-height: 58px;
  padding-inline: 15px;
  border-radius: 16px;
  text-align: start;
  font-size: clamp(1.125rem, 1.65vw, 1.25rem);
}
.key {
  display: inline-grid; place-items: center; flex: none; min-width: 31px; height: 31px;
  border-radius: 9px; background: #d7eadc; color: #194b38; font-size: .9375rem;
}
.source-button { margin-left: -12px; color: var(--muted); font-size: .9375rem; }
.outcome h1 { max-width: 20em; margin-inline: auto; font-size: clamp(1.65rem, 3.7vw, 2.65rem); }
.outcome-avatar { margin: 0 auto 18px; border-radius: 50%; background: var(--mint); width: max-content; }
.effect-pills { justify-content: center; margin-top: 19px; }
.effect-pills .pill { background: var(--mint); }
[data-screen="outcome"] .outcome {
  display: grid;
  justify-items: center;
  gap: clamp(14px, 4vw, 24px);
  max-width: 620px;
  margin-block: clamp(10px, 2vh, 22px);
  padding: clamp(22px, 5vw, 42px);
}
[data-screen="outcome"] .outcome-avatar { margin: 0; }
[data-screen="outcome"] .outcome-avatar .pixel-avatar {
  width: clamp(96px, 26vw, 132px);
  height: auto;
  aspect-ratio: 1;
}
[data-screen="outcome"] .outcome h1 {
  font-size: clamp(1.5rem, 5.6vw, 2.44rem);
  line-height: 1.36;
  text-wrap: balance;
}
[data-screen="outcome"] .effect-pills { margin: 0; }
[data-screen="outcome"] .action-row { margin-top: 4px; }
[data-screen="outcome"] #next { min-width: 132px; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.arcade-hub { max-width: 1140px; margin-inline: auto; }
.arcade-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.arcade-option {
  display: grid; grid-template-rows: auto 1fr auto; justify-items: start; gap: 13px;
  border-radius: var(--radius); padding: clamp(18px, 3vw, 32px); min-height: 205px;
  text-align: start;
}
.arcade-option:hover { filter: brightness(.96); }
.arcade-lights { background: #eee6fa; color: #533680; }
.arcade-volley { background: #e1eef8; color: #244d68; }
.arcade-fair { background: #f8e8d2; color: #773f17; }
.arcade-circuit { background: #e2f0e7; color: #195a45; }
.arcade-option-icon { font-size: 2.4rem; line-height: 1; }
.arcade-option-name { font-size: 1.3rem; font-weight: 760; }
.arcade-duration { font-size: .9375rem; font-weight: 650; }
.mini-preview {
  display: grid; place-items: center; width: 90px; aspect-ratio: 1; margin: 0 auto 18px;
  border-radius: 26px; font-size: 2.75rem; line-height: 1;
}
.outcome .lead { margin: 12px auto 20px; }
.arcade-play { width: min(100%, 760px); margin-inline: auto; }
.arcade-play h1 { font-size: clamp(1.9rem, 4vw, 2.65rem); }
.arcade-stats {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px;
  margin: 12px 0 10px; color: var(--ink); font-variant-numeric: tabular-nums;
}
.arcade-stats strong { font-weight: 760; }
.timer-bar { height: 7px; background: #dce8e0; border-radius: 10px; overflow: hidden; margin-bottom: 10px; }
.timer-bar span { display: block; height: 100%; width: 100%; background: var(--green); }
#play-canvas { display: block; width: 100%; height: auto; border-radius: 20px; touch-action: none; background: var(--deep); }
.mini-prompt { margin: 10px 0 4px; font-size: 1.125rem; font-weight: 740; }
.arcade-feedback { color: var(--muted); min-height: 1.6em; margin-bottom: 10px; }
.arcade-feedback.good { color: var(--green); font-weight: 700; }
.arcade-feedback.bad { color: #932d28; }
.arcade-actions { display: flex; gap: 8px; }
.arcade-actions:empty { display: none; }
.arcade-actions button {
  flex: 1; min-width: 0; min-height: 64px; padding: 9px 6px;
  display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 5px;
  border-radius: 16px; background: var(--button-color, #dcece2); font-weight: 700;
  touch-action: none;
}
.arcade-actions button b { font-size: 1.35rem; }
.arcade-bottom { display: flex; justify-content: space-between; margin-top: 10px; gap: 8px; }
.circuit-stage {
  display: flex; gap: clamp(5px, 2vw, 20px); align-items: center; justify-content: center;
  background: var(--deep); border-radius: 20px; padding: clamp(10px, 3vw, 24px); color: #fff;
}
.circuit-board { display: grid; grid-template-columns: repeat(3, minmax(52px, 77px)); gap: 5px; }
.circuit-board button { display: grid; place-items: center; position: relative; aspect-ratio: 1; border-radius: 12px; color: #fff; background: #285448; }
.circuit-board button.powered { background: #48664c; }
.circuit-board svg { width: 100%; }
.circuit-board small { position: absolute; left: 4px; bottom: 1px; font-size: .75rem; }
.battery, .star-lamp { font-size: clamp(1.4rem, 4vw, 2.5rem); text-align: center; font-weight: 750; }
.battery small, .star-lamp small { display: block; font-size: .875rem; }
.star-lamp.powered { color: #f7dc7e; }
.result-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(20px, 5vw, 68px); max-width: 1150px; margin-inline: auto;
}
.souvenir { position: relative; background: var(--mint); padding: clamp(24px, 4vw, 50px); border-radius: 32px; }
.souvenir h1 { font-size: clamp(2rem, 4.5vw, 3.4rem); margin: 14px 0; }
.result-avatar { float: right; margin: 0 -2px 0 10px; }
.result-avatar .pixel-avatar { width: clamp(94px, 11vw, 144px); height: clamp(94px, 11vw, 144px); }
.card-badges { clear: both; padding-top: 23px; }
.result-tools { margin-top: 16px; }
.result-layout .micro { margin-top: 10px; }
.result-memories h2 { margin-bottom: 12px; }
.timeline { padding: 0; margin: 0; list-style: none; }
.timeline li { display: grid; grid-template-columns: 3.35em 1fr; gap: 12px; border-top: 1px solid var(--line); padding: 11px 0; }
.timeline-grade { color: var(--green); font-weight: 740; }
.timeline p { margin-top: 2px; color: var(--muted); }
dialog {
  border: 1px solid var(--line); border-radius: 26px; width: min(660px, calc(100% - 24px));
  max-width: none; max-height: 91dvh; padding: clamp(20px, 4vw, 34px);
  color: var(--ink); background: var(--white); overscroll-behavior: contain;
  box-shadow: 0 14px 55px #152a2424;
}
dialog::backdrop { background: #10251e72; backdrop-filter: blur(4px); }
dialog h2 { margin: 0 48px 14px 0; }
dialog h3, dialog p, dialog li { margin-bottom: 10px; }
dialog a { color: var(--green); }
dialog .action-row, dialog > button { margin-top: 14px; }
.dialog-close {
  position: absolute; top: 10px; right: 10px; min-width: 48px; margin: 0;
  padding: 0; color: var(--deep); background: #e8efea; font-size: 1.75rem;
}
dialog > .dialog-close { margin: 0; }
dialog input {
  display: block; width: 100%; color: var(--ink); background: #f1f6f2; border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px; min-height: 50px; font-size: 1.0625rem;
}
.catalog-dialog { width: min(920px, calc(100% - 24px)); }
.catalog-tabs, .catalog-filters { display: flex; gap: 7px; flex-wrap: wrap; }
.catalog-tabs { margin: 18px 0; }
.catalog-filters { margin: 11px 0; }
.catalog-tabs button, .catalog-filters button {
  min-height: 44px; padding: 7px 13px; border-radius: 14px;
  color: var(--ink); background: #edf3ef; font-size: 1rem; font-weight: 650;
}
.catalog-tabs .selected, .catalog-filters .selected { background: var(--green); color: #fff; }
.catalog-search { display: block; color: var(--muted); font-size: .9375rem; }
.catalog-search input { margin-top: 4px; }
.catalog-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-content: start;
  overflow: auto; max-height: 43dvh; padding: 4px; margin: -4px; overscroll-behavior: contain;
}
.catalog-entry {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 15px;
}
.catalog-entry h3 { font-size: 1.125rem; margin: 0; }
.catalog-entry .catalog-play { flex: none; min-height: 44px; padding: 7px 13px; }
.catalog-seen { font-size: .875rem; color: var(--green); }
.story-preview details { margin: 12px 0 4px; }
.story-preview summary { display: list-item; min-height: 44px; width: fit-content; padding-block: 8px; cursor: pointer; color: var(--muted); }
.story-preview #preview-back.text-button { margin-inline-start: -12px; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  max-width: calc(100% - 36px); width: max-content; opacity: 0; pointer-events: none;
  color: #fff; background: #153d33; padding: 11px 17px; border-radius: 16px;
}
.toast.show { opacity: 1; }
@media (max-width: 960px) {
  .arcade-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { min-height: 390px; }
  .hero-photo img { min-height: 390px; }
}
@media (max-width: 700px) {
  .topbar, main, .footer { width: min(100% - 32px, 1340px); }
  .topbar { min-height: 68px; }
  main { padding-block: 18px 28px; }
  .brand { gap: 7px; }
  .brand img { width: 28px; }
  .header-actions { gap: 4px; }
  .header-actions button { padding: 7px 10px; min-height: 44px; }
  .hero { grid-template-columns: 1fr; }
  .hero h1 { font-size: clamp(2.85rem, 9vw, 4rem); }
  .hero h1 br { display: none; }
  .hero p { margin-top: 10px; max-width: none; }
  .hero .primary { margin-top: 18px; }
  .hero-photo img { min-height: unset; height: auto; aspect-ratio: 1.86; }
  .home-links { gap: 8px; margin-top: 8px; }
  .home-tile { min-height: 76px; padding: 10px 13px; border-radius: 19px; }
  .tile-glyphs i { width: 30px; border-radius: 9px; }
  .tile-avatars .small { width: 38px; height: 38px; }
  .tile-avatars .small:first-child, .tile-glyphs i:not(:first-child) { display: none; }
  .passport-avatar .pixel-avatar { width: 112px; height: 112px; }
  .event-card, .result-layout { grid-template-columns: 1fr; }
  .journey { margin-bottom: 12px; }
  .journey .chapter-label { padding: 0 1px; }
  .grade-list li, .chapter-label { font-size: .875rem; }
  .catalog-grid { grid-template-columns: 1fr; }
  .arcade-option { min-height: 156px; }
}
@media (max-width: 410px) {
  .topbar { flex-wrap: wrap; padding-top: 6px; }
  .topbar:has(#restart:not([hidden])) .header-actions { flex: 1 0 100%; justify-content: flex-start; }
  .tile-avatars, .tile-glyphs { display: none; }
}
@media (max-width: 360px) {
  .brand { font-size: 1rem; }
  .header-actions button { font-size: .875rem; }
  .passport-avatar .pixel-avatar { width: 90px; height: 90px; }
}

.hero .primary {
  display: inline-grid;
  place-items: center;
  min-width: min(100%, 285px);
  min-height: 88px;
  padding: 14px 28px;
  font-size: clamp(1.75rem, 3.25vw, 2.8rem);
  font-weight: 780;
}
.home-links { grid-template-columns: minmax(0, 360px); }
.home-tile { min-height: 68px; }
.student-avatar { background-image: url('assets/student-atlas.svg?v=10'); background-size: 1000% 1000%; }
.student-heading {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 18px;
}
.student-heading h1 { font-size: clamp(1.9rem, 4.5vw, 3.4rem); }
.student-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.student-filters button {
  border-radius: 30px; min-height: 44px; padding: 6px 14px; font-weight: 650;
  background: #e8efea; font-size: 1rem;
}
.student-filters button[aria-pressed="true"] { background: var(--green); color: #fff; }
.student-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 175px), 1fr)); gap: 12px; }
.student-card {
  display: flex; flex-direction: column; align-items: start; padding: 9px 9px 12px;
  width: 100%; text-align: start; background: #fff; border: 1px solid var(--line);
  border-radius: 19px; line-height: 1.45; overflow-wrap: anywhere;
}
.student-card:hover { border-color: var(--green); background: #f9fdf9; }
.student-portrait { width: 100%; display: grid; place-items: center; border-radius: 13px; }
.student-portrait .pixel-avatar { width: 102px; height: 102px; }
.theme-sports { background: #e4effb; }
.theme-arts { background: #f6e5da; }
.theme-academic { background: #eee7fa; }
.theme-service { background: #dcefe4; }
.theme-leadership { background: #f7edcf; }
.student-interest { font-size: 1.06rem; font-weight: 750; margin: 7px 3px 1px; }
.student-persona { font-size: .92rem; color: var(--muted); margin-inline: 3px; }
.result-interest { color: var(--muted); font-size: 1rem; margin-top: 5px; }
@media (max-width: 520px) {
  .hero .primary { min-height: 74px; min-width: min(100%, 225px); }
  .student-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .student-portrait .pixel-avatar { width: 84px; height: 84px; }
  .student-filters { gap: 5px; }
  .student-filters button { padding-inline: 11px; }
}

/* The viewport stays fixed while the students move in two dimensions. */
body.picking-student { overflow: hidden; }
.picking-student .topbar { display: none; }
.picking-student main { width: 100%; padding: 0; min-height: 0; }
.student-screen {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  position: relative;
  isolation: isolate;
  background: radial-gradient(ellipse at center, #f7faf7 0%, #e1eee5 88%);
}
.wall-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  overflow: clip;
  overscroll-behavior: contain;
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
}
.wall-viewport:focus { outline: none; }
.wall-viewport.dragging, .wall-viewport.dragging .student-card { cursor: grabbing; }
.student-grid {
  --card-width: clamp(155px, 17vw, 220px);
  --card-height: clamp(164px, 24dvh, 214px);
  --card-gap: 16px;
  position: absolute;
  inset: 0;
}
.student-grid .student-card {
  position: absolute;
  inset: 0 auto auto 0;
  width: var(--card-width);
  height: var(--card-height);
  cursor: inherit;
  touch-action: none;
  min-width: 0;
  border: 2px solid #bfcec3;
  border-radius: 20px;
  box-shadow: 0 5px 14px #193b2110;
}
.student-card[aria-current="true"] {
  cursor: pointer;
  z-index: 2;
  border-color: var(--green);
  background: #fff;
  outline: 4px solid #17604a40;
  box-shadow: 0 12px 22px #17342c35;
}
/* Keep the sprite inside the space left after the two text lines. */
.student-card .student-portrait {
  flex: 1 1 0;
  min-height: 0;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  overflow: hidden;
}
.student-card .student-portrait .pixel-avatar {
  height: 100%;
  width: auto;
  aspect-ratio: 1;
  max-width: 100%;
}
.student-interest { margin-top: 5px; font-size: 1rem; }
.student-persona { font-size: .875rem; }
.wall-controls {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid #b7cdc0;
  border-radius: 20px;
  background: #f7fbf8;
  box-shadow: 0 4px 20px #17342c19;
}
.wall-controls {
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 24px);
  justify-content: space-between;
  flex-wrap: wrap;
}
.wall-current { padding-inline: 10px; color: var(--green); font-weight: 720; font-size: 1rem; }
.wall-hint {
  position: absolute;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f7fbf8b8;
  color: #164a3cb8;
  pointer-events: none;
  transition: opacity 140ms ease-out;
}
.wall-hint::before {
  content: '';
  width: 10px;
  height: 10px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: rotate(var(--hint-angle));
}
.wall-hint-up {
  --hint-angle: 225deg;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
}
.wall-hint-left, .wall-hint-right {
  top: 50%;
  transform: translateY(-50%);
}
.wall-hint-left { --hint-angle: 135deg; left: max(8px, env(safe-area-inset-left)); }
.wall-hint-right { --hint-angle: -45deg; right: max(8px, env(safe-area-inset-right)); }
.wall-hint-down {
  --hint-angle: 45deg;
  top: -6px;
  left: 50%;
  transform: translate(-50%, -100%);
}
.wall-viewport.is-moving .wall-hint,
.wall-viewport.is-moving ~ .wall-controls .wall-hint {
  opacity: 0;
  transition: none;
}
@media (prefers-reduced-motion: reduce) {
  .wall-hint { transition: none; }
}
@media (max-width: 600px) {
  .student-grid { --card-width: 150px; --card-height: 165px; --card-gap: 12px; }
  .wall-controls { gap: 6px; padding: 7px; }
  .wall-controls .primary { padding-inline: 12px; font-size: .95rem; }
}
@media (max-width: 340px) {
  .wall-controls { justify-content: center; }
  .wall-current { padding-inline: 4px; font-size: .875rem; }
}

.hero h1 { white-space: nowrap; font-size: clamp(1.65rem, 4.1vw, 4.6rem); }
.hero-photo { background: #dcecf0; }
.hero-photo img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.home-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 700px) {
  .hero h1 { font-size: clamp(1.85rem, 9vw, 3.7rem); }
  .hero-photo img { height: auto; aspect-ratio: auto; }
}

.scene {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 12px;
  padding: clamp(12px, 2.25vw, 26px);
  background: #edf4ef;
}
.scene-player { display: grid; place-items: center; }
.scene-player .pixel-avatar {
  width: clamp(112px, 14vw, 176px);
  height: auto;
  aspect-ratio: 1;
}
.photo-frame {
  width: min(100%, 310px);
  margin: 0;
  text-align: center;
}
/* Let the uncropped image set its own frame height. */
.photo-matte { display: grid; justify-items: center; }
.photo-frame .event-photo {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(390px, 48svh);
  border-radius: 14px;
  object-fit: contain;
}
.photo-frame figcaption {
  position: static;
  margin-top: 6px;
  padding: 0;
  background: transparent;
  color: #36584b;
  font-size: .75rem;
}
.catalog-photo { width: 134px; margin: 12px 0; }
@media (max-width: 700px) {
  .scene-player .pixel-avatar { width: clamp(90px, 23vw, 124px); }
}

.hero.hero-no-photo { grid-template-columns: 1fr; }

/* The programme map is a visit suggestion alongside the fictional story. */
.visit-card {
  display: grid;
  gap: 3px;
  padding: 11px 14px;
  margin-top: 15px;
  text-align: start;
  background: #f3f1e2;
  border-inline-start: 3px solid #ab8032;
  border-radius: 10px;
  color: #3f3829;
  line-height: 1.4;
}
.visit-label { color: #736039; font-size: .875rem; font-weight: 650; }
.visit-card strong, .result-visits strong { display: block; font-size: 1.05rem; }
.visit-card div > span, .result-visits li > span { font-size: .975rem; }
.result-visits { margin-top: 24px; }
.result-visits h2 { font-size: 1.45rem; }
.result-visits ul { display: grid; gap: 7px; margin: 10px 0 0; padding: 0; list-style: none; }
.result-visits li { padding: 9px 12px; border-radius: 12px; background: #fff; line-height: 1.45; }
.preview-layout { display: grid; align-items: start; gap: 16px; }
.preview-layout .catalog-photo { width: min(112px, 35vw); margin: 0 auto; }

.arcade-play { display: grid; gap: 10px; }
.arcade-stats { margin: 8px 0; }
.timer-bar { margin-bottom: 0; }
.timer-bar span { transform-origin: left; }
.arcade-feedback { margin-block: 11px 0; }
.arcade-actions button { touch-action: manipulation; }
.arcade-actions [data-direction] { touch-action: none; -webkit-user-select: none; user-select: none; }
.circuit-board button { touch-action: manipulation; }

@media (min-width: 701px) {
  .preview-layout:has(.catalog-photo) { grid-template-columns: minmax(105px, .36fr) minmax(0, 1fr); }
  .preview-layout .catalog-photo { width: min(100%, 144px); }
  .preview-layout .choices { margin-top: 15px; }

}

/* These proportions leave the next action within reach in both iPad orientations. */
@media (min-width: 701px) and (max-width: 1366px) {
  .topbar, main {
    width: calc(100% - max(24px, env(safe-area-inset-left)) - max(24px, env(safe-area-inset-right)));
  }
  .topbar { min-height: calc(60px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
  main { padding-block: 18px max(20px, env(safe-area-inset-bottom)); }
  .hero { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); min-height: 360px; }
  .hero.hero-no-photo { grid-template-columns: 1fr; }
  .hero h1 { font-size: clamp(2.25rem, 4.8vw, 4.1rem); }
  .hero-copy { padding: clamp(24px, 4vw, 44px); }
  .hero .primary { min-height: 72px; min-width: min(245px, 100%); margin-top: 22px; }
  .home-tile { min-height: 78px; }
  .journey { padding: 6px; margin-bottom: 12px; }
  .grade-list li { padding-block: 7px; }
  .event-card { grid-template-columns: minmax(0, 32fr) minmax(0, 68fr); min-height: 0; }
  .event-content { padding: clamp(19px, 2.7vw, 32px); }
  .event-heading h1 { font-size: clamp(1.875rem, 3.55vw, 2.95rem); }
  .story { margin-top: 10px; font-size: 1.1875rem; line-height: 1.5; }
  .choices { gap: 8px; margin: 14px 0 0; }
  .choice { min-height: 56px; padding-block: 8px; }
  .outcome { margin-block: 12px; padding: clamp(22px, 4vw, 42px); }
  .result-layout { gap: 20px; }
  .souvenir { padding: clamp(19px, 3vw, 35px); }
  .result-tools :is(.primary, button) { min-height: 52px; }
  .arcade-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .arcade-option { min-height: 150px; }
  .circuit-board { grid-template-columns: repeat(3, minmax(68px, 98px)); }
  .arcade-console .arcade-actions button { min-height: 64px; }
}

@media (min-width: 701px) and (max-width: 1366px) and (orientation: landscape) {
  .arcade-play {
    width: min(100%, 1120px);
    grid-template-columns: minmax(0, 1.85fr) minmax(0, 1fr);
    gap: 12px 20px;
    align-items: start;
  }
  .arcade-play > header { grid-column: 1 / -1; }
  .arcade-console { padding: 12px 16px; background: #e6efe8; border-radius: 18px; }
  .arcade-console .mini-prompt { margin: 0 0 12px; }
  .arcade-actions { display: grid; }
  .arcade-bottom { justify-content: flex-start; flex-wrap: wrap; }
}

@media (min-width: 701px) and (max-width: 1024px) and (orientation: portrait) {
  .hero { grid-template-columns: 1fr; }
  .hero-photo img { height: min(40dvh, 400px); }
  .hero-copy { align-items: center; text-align: center; }
  .hero-copy p { max-width: none; margin-top: 14px; }
  .arcade-play { width: min(100%, 720px); }
  .arcade-actions button { min-height: 70px; }
}

@media (pointer: coarse) {
  .wall-controls .primary { min-height: 54px; }
  .arcade-bottom button, .catalog-tabs button, .catalog-filters button { min-height: 48px; }
  #play-canvas:focus { outline: none; }
}

.event-card.event-no-scene { grid-template-columns: 1fr; }

.event-card, .mini-with-backdrop {
  position: relative;
  isolation: isolate;
}
.mini-with-backdrop { overflow: hidden; }
.mini-with-backdrop .lead {
  color: var(--ink);
  text-shadow: 0 1px 6px #fff;
}
.event-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: .65;
  pointer-events: none;
  z-index: -2;
}
.event-with-backdrop {
  background: linear-gradient(135deg, #f7f9f5, #f2f7f2);
}
.event-with-backdrop::before, .mini-with-backdrop::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(90deg, transparent 15%, #ffffff60 34%, #ffffff91 77%);
}
.event-with-backdrop .scene {
  justify-content: center;
  align-content: end;
  background: transparent;
}
.event-with-backdrop.event-no-scene::before { background: #fff8; }
.event-with-backdrop .choice {
  background: #f5f9f540;
  border-color: #234e3b38;
}
.event-with-backdrop .choice:is(:hover, :active) {
  background: #e4f0e57a;
  border-color: #234e3b66;
}
.event-with-backdrop .key { background: #d7eadc59; }
.event-card .visit-card { background: transparent; border-radius: 0; }
.event-with-backdrop :is(.context-label, .visit-label) { color: var(--ink); }
.event-with-backdrop :is(.event-heading h1, .event-content p, .event-content .choice, .event-content .visit-card) {
  text-shadow: 0 1px 5px #fffc;
}
.mini-with-backdrop::before { background: radial-gradient(ellipse at center, #fff9 25%, #fff2 100%); }
.arcade-with-photo {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border-radius: 20px;
  background: var(--deep);
}
.arcade-photo {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.arcade-with-photo #play-canvas { background: transparent; }
.arcade-with-photo .circuit-stage { background: #143d32a6; }

.souvenir-page {
  text-align: center;
  padding-top: 18px;
}
.souvenir-page h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); }
.souvenir-page img {
  display: block;
  width: min(100%, 430px);
  height: auto;
  margin: 16px auto;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.souvenir-page [hidden] { display: none; }
.title-reason { margin-top: 14px; color: var(--muted); }

.pathway-choices {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.pathway-choices .choice small {
  display: block;
  margin-top: 2px;
  font-size: .875rem;
  line-height: 1.4;
  font-weight: 550;
}
@media (max-width: 550px) {
  .pathway-choices { grid-template-columns: 1fr; }
}

/* Keep the phone story and photo together, with a separate row for choices. */
@media (max-width: 700px), (max-height: 520px) and (max-width: 1000px) {
  .topbar, main, .footer {
    width: auto;
    margin-left: max(12px, env(safe-area-inset-left));
    margin-right: max(12px, env(safe-area-inset-right));
  }
  .topbar {
    min-height: calc(58px + env(safe-area-inset-top));
    padding-block: env(safe-area-inset-top) 0;
    flex-wrap: nowrap;
  }
  .topbar:has(#restart:not([hidden])) .header-actions { flex: 0 0 auto; }
  .brand { min-width: 0; font-size: clamp(.92rem, 4vw, 1.125rem); }
  main { padding-block: 12px max(24px, env(safe-area-inset-bottom)); }
  .picking-student main { margin: 0; }
  .toast { bottom: max(14px, env(safe-area-inset-bottom)); }
  .hero { min-height: 0; }
  .hero .hero-copy { padding: clamp(18px, 5vw, 28px); }
  .hero h1 { font-size: clamp(1.75rem, 8.6vw, 3rem); }
  .hero .primary { min-height: 58px; }
  .arcade-grid, .result-layout { gap: 12px; }

  .event-card,
  .event-card.event-no-scene {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "summary avatar" "choices choices";
    min-height: 0;
    border-radius: 20px;
    background: var(--white);
  }
  .event-with-backdrop::before, .mini-with-backdrop::before { content: none; }
  .event-card > .event-backdrop,
  .mini-with-backdrop > .event-backdrop {
    position: static;
    display: block;
    width: 100%;
    height: auto;
    max-height: min(45svh, 300px);
    object-fit: contain;
    opacity: 1;
    background: var(--mint);
  }
  .event-card.event-with-backdrop { --photo-opening: clamp(68px, 25vw, 134px); }
  .event-card > .event-backdrop {
    grid-area: summary-start / summary-start / summary-end / avatar-end;
    align-self: start;
    max-height: min(56svh, 380px);
    background: transparent;
    object-position: center top;
    mask-image: linear-gradient(#000 24%, #0008 40%, #0005 58%, #0002 80%, transparent);
  }
  .event-content { display: contents; }
  .event-summary {
    grid-area: summary;
    grid-column: 1 / -1;
    min-width: 0;
    padding: 16px;
  }
  .event-with-backdrop .event-summary { padding-block-start: var(--photo-opening); }
  .event-card:not(.event-no-scene) .event-heading {
    padding-inline-end: clamp(54px, 15vw, 78px);
  }
  .event-heading h1 { font-size: clamp(1.55rem, 4.9vw, 2.25rem); }
  .event-card > .scene {
    grid-area: avatar;
    z-index: 1;
    align-self: start;
    padding: 12px 14px 0 8px;
    background: transparent;
  }
  .event-with-backdrop > .scene { padding-block-start: calc(var(--photo-opening) - 3px); }
  .scene-player .pixel-avatar { width: clamp(48px, 15vw, 72px); }
  .event-summary .story { margin-top: 10px; font-size: 1.08rem; }
  .event-content > .choices {
    grid-area: choices;
    min-width: 0;
    margin: 0;
    padding: 14px 16px 16px;
    background: var(--white);
  }
  .event-with-backdrop .choice { background: #eef5f0; border-color: #d5e3da; }
  .event-with-backdrop .key { background: #d7eadc; }
  .event-with-backdrop .event-content :is(p, .choice, .visit-card),
  .event-with-backdrop .event-heading h1 { text-shadow: none; }
  .choice { min-height: 52px; padding-inline: 9px; gap: 8px; }
  .choice > span:last-child { min-width: 0; overflow-wrap: anywhere; }

  .mini-with-backdrop > .event-backdrop {
    max-height: min(34svh, 220px);
    margin-bottom: 12px;
    border-radius: 14px;
  }
  .arcade-with-photo .arcade-photo { object-fit: contain; }
  .circuit-stage {
    display: grid;
    grid-template-columns: minmax(26px, auto) minmax(0, 241px) minmax(26px, auto);
    padding: 8px;
    gap: 5px;
  }
  .circuit-board { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .circuit-board button { padding: 0; min-height: 44px; min-width: 0; }
  .battery small, .star-lamp small { font-size: .72rem; }

  .souvenir {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px 10px;
  }
  .souvenir .context-label { margin: 0; }
  .souvenir .result-avatar { float: none; margin: 0; justify-self: end; }
  .result-avatar .pixel-avatar { width: 74px; height: 74px; }
  .souvenir > :not(.context-label, .result-avatar) { grid-column: 1 / -1; }
  .souvenir h1 { font-size: clamp(1.75rem, 5.7vw, 2.5rem); margin: 0; }
  .souvenir .card-badges { padding-top: 7px; }
  .result-tools { display: flex; flex-wrap: wrap; gap: 8px; }

  .wall-controls {
    max-width: calc(100% - max(12px, env(safe-area-inset-left)) - max(12px, env(safe-area-inset-right)));
  }
}
@media (max-width: 430px) {
  .journey { gap: 6px; padding: 5px; }
  .grade-list { min-width: 0; gap: 2px; }
  .grade-list li, .chapter-label { font-size: clamp(.73rem, 3.4vw, .875rem); }
  .grade-list li { padding-inline: 1px; white-space: nowrap; }
  .home-tile { font-size: clamp(.94rem, 4vw, 1.125rem); }
  .wall-controls { width: min(96%, 280px); justify-content: center; }
  .wall-current { flex: 1 0 100%; text-align: center; }
  .wall-controls .primary { width: 100%; }
  .catalog-entry > div { min-width: 0; }
  .catalog-entry .catalog-play { padding-inline: 8px; }
}
@media (max-height: 520px) and (orientation: landscape) and (max-width: 1000px) {
  .student-grid { --card-height: 152px; --card-width: 148px; }
  .wall-hint-down { top: -3px; }
  .arcade-play { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); }
  .arcade-play > header { grid-column: 1 / -1; }
}

.souvenir-download-preview {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(62svh, 550px);
  margin-inline: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
