/* TeachSimAI play page. Tokens = the in-game UI (TeachSimSelectStyle / TeachSimSettings): ink, paper, accent ring, badge.
   "TSAI Sans" = page-text subset of Pretendard 1.3.9 (SIL OFL 1.1, Reserved Font Name "Pretendard" -> renamed; made by
   web/tools/subset_fonts.sh, license text in fonts/Pretendard-OFL.txt). */
@font-face {
  font-family: "TSAI Sans";
  src: url("fonts/TSAISans-Medium.subset.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "TSAI Sans";
  src: url("fonts/TSAISans-Bold.subset.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --ink: #24344D;
  --ink-soft: #3C4C66;
  --on-ink: #FFFFFF;
  --on-ink-soft: #D9E0EA;
  --paper: #FFFAF2;
  --row: #F2EADC;
  --track: #CFC3AE;
  --accent: #E67A2A;
  --badge: #FFE2C4;
  --fade: #101621;
  --sand: #E2CCAA;          /* the studio floor around the aerial capture */
  --muted: #56617A;         /* 6.1:1 on paper */
  --radius-card: 20px;
  --radius-plate: 16px;
  --ring: 0 0 0 4px var(--paper), 0 0 0 8px var(--accent);
  --shadow-card: 0 18px 48px -12px rgba(16, 22, 33, 0.28), 0 2px 6px rgba(16, 22, 33, 0.08);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font: "TSAI Sans", "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--sand);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  word-break: keep-all;
  overflow: hidden;
}
::selection { background: var(--badge); color: var(--ink); }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 6px; }
h1, h2 { font-weight: 700; margin: 0; }
h1:focus { outline: none; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ stage */
.stage { position: fixed; inset: 0; overflow: hidden; background: var(--sand); }

/* the whole diorama, floating on the same sand floor it was captured on (no crop of the school) */
.poster { position: absolute; inset: 0 0 0 clamp(400px, 36vw, 600px); }
.poster__img {
  position: absolute; left: 0; top: 50%; width: 100%; height: auto; aspect-ratio: 16 / 9;
  transform: translateY(-50%) scale(1.14);
  transform-origin: 40% 40%;            /* the main entrance of the school */
  -webkit-mask-image: radial-gradient(ellipse 50% 50% at 50% 50%, #000 70%, transparent 100%);
          mask-image: radial-gradient(ellipse 50% 50% at 50% 50%, #000 70%, transparent 100%);
  transition: transform 2.4s var(--ease-out), opacity .45s var(--ease-out);
}
.is-loading .poster__img { transform: translateY(-50%) scale(1.32); transition: transform 60s cubic-bezier(.2, .1, .2, 1); }
.is-playing .poster { opacity: 0; transition: opacity .45s var(--ease-out); }

.game { position: absolute; inset: 0; opacity: 0; pointer-events: none; transition: opacity .45s var(--ease-out); background: var(--fade); }
.game canvas { display: block; width: 100%; height: 100%; outline: none; }
.is-playing .game { opacity: 1; pointer-events: auto; }

/* ------------------------------------------------------------------ panel (paper card, like the ESC settings card) */
.panel {
  position: absolute; top: 50%; left: clamp(20px, 6vw, 96px);
  transform: translateY(-50%);
  width: min(480px, calc(100vw - 40px));
  max-height: calc(100vh - 40px); overflow: auto;
  padding: 36px 40px 28px;
  background: var(--paper); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  transition: opacity .3s var(--ease-out), transform .3s var(--ease-out);
  scrollbar-width: thin; scrollbar-color: var(--track) transparent;
}
.is-playing .panel { opacity: 0; pointer-events: none; transform: translateY(-50%) scale(.98); visibility: hidden; transition: opacity .3s var(--ease-out), transform .3s var(--ease-out), visibility 0s .3s; }

.wordmark { margin: 0 0 28px; font-weight: 700; font-size: 22px; letter-spacing: -0.01em; color: var(--ink); }
.view h1 { font-size: clamp(28px, 2.4vw + 8px, 40px); line-height: 1.22; letter-spacing: -0.025em; text-wrap: balance; }
.lede { margin: 14px 0 0; font-size: 18px; color: var(--ink-soft); }
.note { margin: 18px 0 0; font-size: 15px; color: var(--ink-soft); }
.note strong { font-weight: 700; color: var(--ink); }
.note--soft { margin-top: 6px; color: var(--muted); }

/* plate = the in-game focused name plate: ink fill, white label, orange ring on focus/hover */
.plate {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 28px; min-height: 64px; padding: 0 36px; min-width: 220px;
  font: inherit; font-weight: 700; font-size: 22px; letter-spacing: -0.01em;
  color: var(--on-ink); background: var(--ink);
  border-radius: var(--radius-plate);
  box-shadow: 0 6px 16px -6px rgba(16, 22, 33, .45);
  transition: transform .18s var(--ease-out), box-shadow .18s var(--ease-out), background-color .18s var(--ease-out);
}
.plate:hover { box-shadow: 0 0 0 4px var(--paper), 0 0 0 8px var(--accent), 0 6px 16px -6px rgba(16, 22, 33, .45); }
.plate:focus-visible { outline: none; box-shadow: var(--ring); }
.plate:active { transform: scale(.97); }
.plate:disabled { cursor: progress; opacity: .6; }
.plate--quiet { background: var(--row); color: var(--ink); box-shadow: none; min-width: 0; font-size: 19px; padding: 0 24px; min-height: 56px; }
.plate--quiet:hover { background: #EADFCC; box-shadow: none; }
.plate--quiet:focus-visible { box-shadow: var(--ring); }
.plate--small { min-height: 44px; font-size: 16px; padding: 0 18px; margin-top: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.actions .plate { margin-top: 0; }

/* error mark: drawn, badge fill */
.mark { width: 48px; height: 48px; margin-bottom: 18px; display: block; }
.mark circle:first-child { fill: var(--badge); }
.mark path { stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; fill: none; }
.mark .dot { fill: var(--ink); }
#error-detail { font-size: 13px; word-break: break-all; }
.steps { margin: 18px 0 0; padding: 0; list-style: none; counter-reset: step; display: grid; gap: 10px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; font-size: 15px; color: var(--ink-soft); }
.steps li::before {
  content: counter(step); display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 7px; background: var(--ink); color: var(--on-ink);
  font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 1px;
}
.steps code { font: 700 14px/1 ui-monospace, Menlo, monospace; padding: 2px 6px; border-radius: 6px; background: var(--row); color: var(--ink); white-space: nowrap; }

/* progress = the in-game volume slider: track + ink fill + orange knob */
.progress { position: relative; margin-top: 30px; height: 12px; border-radius: 999px; background: var(--row); box-shadow: inset 0 0 0 1px rgba(36, 52, 77, .08); }
.progress__fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  border-radius: inherit; background: var(--ink);
  transition: width .25s linear;
}
.progress__fill::after {
  content: ""; position: absolute; right: -11px; top: 50%; width: 22px; height: 22px; margin-top: -11px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--paper);
}
.progress.is-finishing .progress__fill::after { animation: knob 1.1s ease-in-out infinite; }
@keyframes knob { 50% { box-shadow: 0 0 0 4px var(--paper), 0 0 0 9px rgba(230, 122, 42, .28); } }
.progress__text { display: flex; justify-content: space-between; gap: 16px; margin: 14px 0 0; font-size: 16px; color: var(--ink-soft); }
.progress__text .num { color: var(--ink); font-weight: 700; white-space: nowrap; }

/* ------------------------------------------------------------------ controls (keycaps = the in-game hint bar) */
.controls { margin-top: 30px; padding-top: 22px; border-top: 1px solid var(--row); }
.is-error .controls, .is-ended .controls { display: none; }
.controls h2, .help-pop h2 { font-size: 15px; color: var(--muted); letter-spacing: 0; }
.keys { margin: 12px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 9px 16px; align-items: center; }
.keys > div { display: contents; }
.keys dt { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.keys dd { margin: 0; font-size: 15px; color: var(--ink-soft); }
kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; padding: 0 8px;
  font: inherit; font-weight: 700; font-size: 14px; line-height: 1;
  color: var(--on-ink); background: var(--ink); border-radius: 7px;
  box-shadow: 0 2px 0 rgba(16, 22, 33, .35);
}
kbd.arrows svg { width: 18px; height: 18px; stroke: var(--on-ink); stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.or { font-size: 13px; color: var(--muted); margin: 0 4px; }
.device { display: inline-flex; align-items: center; height: 30px; padding: 0 10px; border-radius: 7px; background: var(--row); font-size: 14px; font-weight: 700; color: var(--ink); }

.foot { margin-top: 26px; font-size: 13px; color: var(--muted); }

/* ------------------------------------------------------------------ in-game toolbar + help (only while the pointer is free) */
.toolbar {
  position: absolute; top: 16px; right: 16px; display: none; gap: 8px; z-index: 5;
}
.is-playing .toolbar { display: flex; }
.is-playing.is-locked .toolbar { display: none; }
.tool {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 16px 0 12px;
  font: inherit; font-weight: 700; font-size: 15px; color: var(--ink);
  background: var(--paper); border-radius: 12px;
  box-shadow: 0 6px 18px -6px rgba(16, 22, 33, .35);
  transition: box-shadow .18s var(--ease-out), transform .18s var(--ease-out);
}
.tool:hover { box-shadow: 0 0 0 3px var(--accent), 0 6px 18px -6px rgba(16, 22, 33, .35); }
.tool:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--accent); }
.tool:active { transform: scale(.97); }
.tool svg { width: 22px; height: 22px; stroke: var(--ink); stroke-width: 1.9; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.tool .fs-out { display: none; }
.tool[aria-pressed="true"] .fs-in { display: none; }
.tool[aria-pressed="true"] .fs-out { display: inline; }

.help-pop {
  position: absolute; top: 72px; right: 16px; z-index: 6; width: min(400px, calc(100vw - 32px));
  padding: 22px 24px; background: var(--paper); border-radius: 16px; box-shadow: var(--shadow-card);
}
.is-locked .help-pop { display: none; }

.stats {
  position: absolute; left: 12px; bottom: 12px; z-index: 7; padding: 6px 10px; border-radius: 8px;
  background: rgba(16, 22, 33, .72); color: #fff; font: 12px/1.45 ui-monospace, Menlo, monospace; white-space: pre; pointer-events: none;
}
.qa-clean .toolbar, .qa-clean .stats { display: none !important; }   /* ?qa=1&clean=1: comparison captures */
.noscript { position: fixed; inset: auto 0 0 0; margin: 0; padding: 16px; background: var(--paper); text-align: center; }

/* ------------------------------------------------------------------ responsive: stacked below 900 px (mobile = notice only) */
@media (max-width: 900px) {
  body { overflow: auto; }
  .stage { position: relative; min-height: 100%; overflow: visible; }
  .poster { position: relative; inset: auto; height: 40vh; min-height: 220px; }
  .poster__img { transform: translateY(-50%) scale(1.04); }
  .panel { position: relative; top: auto; left: auto; transform: none; margin: -32px auto 24px; width: calc(100vw - 32px); max-height: none; padding: 28px 24px 22px; }
  .is-playing .panel { transform: none; }
  .is-playing .stage { position: fixed; }
  .plate { width: 100%; }
  .actions .plate { width: auto; flex: 1 1 auto; }
}
@media (max-height: 860px) and (min-width: 901px) {   /* 1280x720-class windows: the whole card without scrolling */
  .panel { padding: 24px 32px 18px; }
  .wordmark { margin-bottom: 14px; font-size: 20px; }
  .view h1 { font-size: 30px; }
  .lede { margin-top: 10px; font-size: 17px; }
  .plate { margin-top: 20px; min-height: 56px; font-size: 20px; }
  .note { margin-top: 12px; font-size: 14px; }
  .note--soft { margin-top: 4px; }
  .progress { margin-top: 22px; }
  .controls { margin-top: 16px; padding-top: 14px; }
  .keys { margin-top: 8px; gap: 5px 14px; }
  kbd, .device { height: 26px; min-width: 26px; font-size: 13px; }
  .keys dd { font-size: 14px; }
  .foot { margin-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .poster__img, .is-loading .poster__img { transition: opacity .2s linear; transform: translateY(-50%) scale(1.14) !important; }
  .panel, .plate, .tool, .game { transition-duration: .01s; }
  .progress.is-finishing .progress__fill::after { animation: none; }
}
