@font-face {
  font-family: "Noto Sans";
  src: url("assets/fonts/NotoSans-Regular-subset.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Noto Sans";
  src: url("assets/fonts/NotoSans-Bold-subset.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* The arrow face joins each weight separately: a ranged weight would win the match for 600 and leave
   every other letter to the system font. */
@font-face {
  font-family: "Noto Sans";
  src: url("assets/fonts/NotoSansSymbols-arrow.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+2192;
}
@font-face {
  font-family: "Noto Sans";
  src: url("assets/fonts/NotoSansSymbols-arrow.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+2192;
}
@font-face {
  font-family: "HRSim Pixel";
  src: url("assets/fonts/HRSimPixel-subset.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #25334F;
  --cream: #F8F4EB;
  --cream-deep: #EDE4D0;
  --frame: #6178B3;
  --navy: #263C70;
  --success: #72B59B;
  --caution: #C17F59;
  --fade-bg: 180ms;
  --fade-panel: 160ms;
  --font: "Noto Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Pixel face (Press Start 2P, renamed) only for short labels: titles, names, buttons, letters.
     Its pixel grid is 8 units, so it is only ever set at 8, 16 or 24 px to stay crisp. */
  --font-pixel: "HRSim Pixel", var(--font);
  --body-size: clamp(17px, 1.6vw, 24px);
  --gap: clamp(8px, 1.2vw, 16px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-reduced-motion: reduce) {
  :root { --fade-bg: 0ms; --fade-panel: 0ms; }
}

/* Per-character accent: speaker names (panel, feedback, cast) and the avatar frame. */
[data-speaker="maria"] { --who: #A3306E; }
[data-speaker="gennady"] { --who: #1E7040; }
[data-speaker="pavel"] { --who: #1D5BB0; }
[data-speaker="elena"] { --who: #B23A1E; }
[data-speaker="oleg"] { --who: #8A5A00; }
[data-speaker="darya"] { --who: #6A3FB5; }

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #1b2440;
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--body-size);
  font-weight: 400;
  line-height: 1.45;
  font-synthesis: none;
  -webkit-text-size-adjust: 100%;
}

button { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

/* ---------- stage, backgrounds, speakers ---------- */

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.bg-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity var(--fade-bg) ease;
}
.bg-layer.is-active { opacity: 1; }
.bg-layer picture, .bg-layer img {
  display: block;
  width: 100%;
  height: 100%;
}
.bg-layer img {
  object-fit: cover;
  object-position: 50% 40%;
  image-rendering: auto;
}

.speaker-layer {
  position: absolute;
  display: none;
  opacity: 0;
  transition: opacity var(--fade-bg) ease;
  pointer-events: none;
  object-fit: contain;
  object-position: 50% 100%;
}
.speaker-layer.is-active { opacity: 1; }

.is-booting, .is-booting * { transition: none !important; }

/* ---------- top bar ---------- */

.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 3;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top, 0px)) max(10px, env(safe-area-inset-right, 0px)) 0 max(10px, env(safe-area-inset-left, 0px));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar-info {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  padding: 4px 12px;
  background: rgba(248, 244, 235, 0.94);
  border: 3px solid var(--navy);
  font-size: 0.78em;
  color: var(--ink);
}
.topbar-info:empty, .topbar-info.is-empty { visibility: hidden; }
.topbar-phase { font-weight: 700; }

.fullscreen-btn {
  min-height: 44px;
  padding: 6px 12px;
  background: var(--cream);
  border: 3px solid var(--navy);
  font-size: 0.78em;
  cursor: pointer;
}
.fullscreen-btn[aria-pressed="true"] { background: var(--cream-deep); }

/* ---------- panel frame ---------- */

.panel {
  --o: -8px;
  position: absolute;
  z-index: 2;
  left: 8px;
  right: 8px;
  bottom: calc(8px + var(--safe-b));
  height: calc(66vh - 8px);
  height: calc(66dvh - 8px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: clamp(14px, 2vw, 26px) clamp(14px, 2.4vw, 32px) clamp(14px, 2vw, 22px);
  background: var(--cream);
  border: 4px solid var(--navy);
  box-shadow: 0 0 0 4px var(--frame), 0 0 0 8px var(--navy), inset 0 0 0 3px var(--cream-deep);
  clip-path: polygon(
    var(--o) calc(var(--o) + 8px), calc(var(--o) + 4px) calc(var(--o) + 8px), calc(var(--o) + 4px) calc(var(--o) + 4px), calc(var(--o) + 8px) calc(var(--o) + 4px), calc(var(--o) + 8px) var(--o),
    calc(100% - var(--o) - 8px) var(--o), calc(100% - var(--o) - 8px) calc(var(--o) + 4px), calc(100% - var(--o) - 4px) calc(var(--o) + 4px), calc(100% - var(--o) - 4px) calc(var(--o) + 8px), calc(100% - var(--o)) calc(var(--o) + 8px),
    calc(100% - var(--o)) calc(100% - var(--o) - 8px), calc(100% - var(--o) - 4px) calc(100% - var(--o) - 8px), calc(100% - var(--o) - 4px) calc(100% - var(--o) - 4px), calc(100% - var(--o) - 8px) calc(100% - var(--o) - 4px), calc(100% - var(--o) - 8px) calc(100% - var(--o)),
    calc(var(--o) + 8px) calc(100% - var(--o)), calc(var(--o) + 8px) calc(100% - var(--o) - 4px), calc(var(--o) + 4px) calc(100% - var(--o) - 4px), calc(var(--o) + 4px) calc(100% - var(--o) - 8px), var(--o) calc(100% - var(--o) - 8px)
  );
  transition: opacity var(--fade-panel) ease;
}
.panel.is-swapping { opacity: 0.35; }

.panel > * + * { margin-top: var(--gap); }

.speaker-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 56px;
  height: 56px;
  flex: none;
  background: var(--cream-deep);
  border: 3px solid var(--who, var(--navy));
  object-fit: cover;
}
.speaker-name, #panel-title { color: var(--navy); }
.speaker-name { color: var(--who, var(--navy)); }
#panel-title { margin: 0; }
#panel-title:focus { outline: none; }
#panel-title.is-quiet {
  position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.speaker-row + #panel-title.is-quiet + * { margin-top: var(--gap); }

.subtitle { margin: 0; color: var(--navy); font-weight: 600; }

.dialogue {
  margin: 0;
  white-space: pre-line;
}
.dialogue:empty { display: none; }
.dialogue .rest { visibility: hidden; }
.dialogue.is-narration { font-style: normal; color: #3a4766; }

.prompt {
  margin: 0;
  font-weight: 700;
  color: var(--navy);
}

/* ---------- buttons ---------- */

.btn {
  min-height: 48px;
  padding: 10px 18px;
  background: var(--navy);
  color: var(--cream);
  border: 0;
  box-shadow: 0 0 0 3px var(--frame);
  cursor: pointer;
  touch-action: manipulation;
}
.btn.secondary { background: var(--cream); color: var(--navy); box-shadow: inset 0 0 0 3px var(--navy); }
.btn:hover { filter: brightness(1.12); }

.btn.primary { position: relative; padding-right: 40px; }
.btn.primary::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 12px;
  height: 8px;
  margin-top: -3px;
  background: var(--cream);
  clip-path: polygon(0 0, 100% 0, 100% 25%, 83% 25%, 83% 50%, 67% 50%, 67% 75%, 50% 75%, 50% 100%, 50% 100%, 33% 75%, 33% 50%, 17% 50%, 17% 25%, 0 25%);
  animation: nudge 900ms steps(2, end) infinite;
}
@keyframes nudge { 50% { transform: translateY(3px); } }
@media (prefers-reduced-motion: reduce) { .btn.primary::after { animation: none; } }

:focus-visible {
  outline: 3px solid var(--navy);
  outline-offset: 2px;
  box-shadow: 0 0 0 2px var(--cream), 0 0 0 7px var(--navy);
}
.btn:focus-visible { outline: 3px solid var(--navy); outline-offset: 3px; box-shadow: 0 0 0 3px var(--cream); }

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}
.actions:not(:has(> :not([hidden]))) { display: none; }

.choices {
  display: grid;
  gap: 10px;
}
.choice {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  text-align: left;
  background: #fffdf8;
  color: var(--ink);
  border: 3px solid var(--frame);
  cursor: pointer;
  font-weight: 400;
  touch-action: manipulation;
}
.choice:hover:not(:disabled) { border-color: var(--navy); background: #fff; }
.choice-letter {
  display: inline-grid;
  place-items: center;
  min-width: 1.8em;
  height: 1.8em;
  background: var(--navy);
  color: var(--cream);
}
.choice:disabled { cursor: default; opacity: 0.55; }
.choices.is-arming .choice:disabled { opacity: 1; } /* brief input guard after reveal: no visual flash */
.choice[aria-current="true"] { opacity: 1; border-color: var(--navy); background: #fff; box-shadow: inset 6px 0 0 var(--navy); }

/* ---------- feedback ---------- */

.feedback {
  padding: 12px 14px;
  background: #fffdf8;
  border: 3px solid var(--navy);
  box-shadow: inset 8px 0 0 var(--caution);
  padding-left: 22px;
  scroll-margin: 12px;
}
.feedback[data-kind="good"] { box-shadow: inset 8px 0 0 var(--success); }
.feedback h3 { margin: 0 0 6px; font-size: 1em; color: var(--navy); }
.reaction p { margin: 0 0 6px; }
.reaction b { color: var(--who, var(--navy)); }
.explanation { margin: 0; }
/* The explanation is scrolled to its top; its button stays pinned to the panel bottom so focus is visible. */
.feedback-actions {
  position: sticky;
  bottom: calc(-1 * clamp(14px, 2vw, 22px));
  display: flex;
  justify-content: flex-end;
  margin: 0 -8px -8px;
  padding: 10px 8px 8px;
  background: #fffdf8;
}

/* ---------- cards ---------- */

.content:empty { display: none; }
.content p { margin: 0; }
.content > * + * { margin-top: var(--gap); }

.card-list {
  margin: 0;
  padding: 10px 14px;
  list-style: none;
  background: #fffdf8;
  border: 3px solid var(--frame);
}
.card-list li { padding: 4px 0; }
.card-list li + li { border-top: 2px dashed var(--cream-deep); }
.card-list .label { color: var(--navy); font-weight: 700; }

.notice {
  padding: 10px 14px;
  background: #fffdf8;
  border: 3px solid var(--frame);
}

.cast {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.cast figure {
  margin: 0;
  height: 100%;
  padding: 8px;
  background: #fffdf8;
  border: 3px solid var(--frame);
  text-align: center;
}
.cast img {
  display: block;
  width: 100%;
  height: clamp(96px, 16vh, 150px);
  object-fit: contain;
  object-position: 50% 100%;
}
.cast figcaption h3 { margin: 6px 0 2px; font-size: 1em; color: var(--who, var(--navy)); }
.cast figcaption p { margin: 0; font-size: 0.85em; }

.noscript { position: absolute; inset: auto 16px 16px; padding: 16px; background: var(--cream); }

/* ---------- pixel labels ---------- */

#panel-title, .speaker-name, .feedback h3, .cast figcaption h3, .choice-letter, .btn {
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
}
.cast figcaption h3 { line-height: 1.4; }
.choice-letter { line-height: 1; padding-top: 2px; } /* the face keeps descender room below its capitals */

/* ---------- wide layout ---------- */

@media (min-width: 900px) and (min-height: 600px) {
  /* Two columns that never overlap: the speaker cut-out on the left, the panel on the right.
     The pair is centred once the panel reaches its maximum width. */
  .stage {
    --fig-w: min(58.5vh, 570px, 36vw);
    --col-gap: clamp(16px, 2vw, 40px);
    --panel-max: 1040px;
    --side: max(20px, 2.5vw, calc((100vw - var(--fig-w) - var(--col-gap) - var(--panel-max)) / 2));
  }
  .speaker-row .avatar { display: none; }
  #panel-title, .speaker-name { font-size: 24px; line-height: 1.4; }
  .speaker-layer {
    display: block;
    left: var(--side);
    bottom: 0;
    width: var(--fig-w);
    height: auto;
    aspect-ratio: 543 / 724;
  }
  .stage[data-speaker=""] .speaker-layer { display: none; }
  .panel {
    left: calc(var(--side) + var(--fig-w) + var(--col-gap));
    right: auto;
    bottom: calc(24px + var(--safe-b));
    width: min(var(--panel-max), calc(100vw - 2 * var(--side) - var(--fig-w) - var(--col-gap)));
    height: auto;
    max-height: calc(100vh - 96px);
    max-height: calc(100dvh - 96px);
  }
  /* Cards without a speaker (cast gallery, offer) use the full width. */
  .stage[data-panel="card"][data-speaker=""] .panel {
    left: 50%;
    transform: translateX(-50%);
    width: min(1180px, calc(100vw - 64px));
    max-height: 82vh;
  }
  .cast { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .cast img { height: min(22vh, 230px); }
  .choices { grid-template-columns: 1fr; }
}

/* ---------- short landscape (phones on their side) ---------- */

@media (orientation: landscape) and (max-height: 500px) {
  .topbar { padding-top: 4px; }
  .topbar-info { padding: 2px 8px; font-size: 0.7em; }
  .fullscreen-btn { font-size: 0.7em; }
  .panel {
    left: max(8px, env(safe-area-inset-left, 0px));
    right: max(8px, env(safe-area-inset-right, 0px));
    height: calc(100vh - 3.25rem - 8px);
    height: calc(100dvh - 3.25rem - 8px);
  }
  .cast { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cast img { height: 80px; }
}
