:root {
  color-scheme: light;
  --bg: #f5f8fc; --glow: #d9eafc; --card: #fff; --ink: #1b1a19; --muted: #56606b; --line: #c9d3de; --slot: #e6ebf1;
  --brand: #0f6cbd; --brand-hover: #115ea3; --on-brand: #fff; --soft: #ebf3fc;
  --ok: #0e700e; --ok-bg: #e7f5e7; --bad: #b10e1c; --bad-bg: #fdeeef; --field: #616161;
  --shadow: 0 1px 2px rgb(0 0 0 / .08), 0 12px 32px rgb(15 60 110 / .12);
}
:root[data-theme=dark] {
  color-scheme: dark;
  --bg: #16191d; --glow: #17314c; --card: #24282d; --ink: #f5f5f5; --muted: #b3bcc6; --line: #4b545e; --slot: #3a4149;
  --brand: #2886de; --brand-hover: #479ef5; --on-brand: #fff; --soft: #16304a;
  --ok: #7ad07a; --ok-bg: #16301a; --bad: #ff99a4; --bad-bg: #43171c; --field: #adadad;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 12px 32px rgb(0 0 0 / .4);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    color-scheme: dark;
    --bg: #16191d; --glow: #17314c; --card: #24282d; --ink: #f5f5f5; --muted: #b3bcc6; --line: #4b545e; --slot: #3a4149;
    --brand: #2886de; --brand-hover: #479ef5; --on-brand: #fff; --soft: #16304a;
    --ok: #7ad07a; --ok-bg: #16301a; --bad: #ff99a4; --bad-bg: #43171c; --field: #adadad;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 12px 32px rgb(0 0 0 / .4);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); background: var(--bg);
  background-image: radial-gradient(900px 480px at 12% -8%, var(--glow), transparent 70%);
  background-repeat: no-repeat;
  font: 16px/1.5 "Segoe UI", system-ui, sans-serif;
}
h1, h2, p { margin: 0; }
button, input { font: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 16px; z-index: 2; padding: 8px 12px; background: var(--card); color: var(--ink); }

.top { display: flex; align-items: center; gap: 12px; max-width: 1280px; margin: 0 auto; padding: 20px 32px; font-weight: 600; }
.logo { width: 32px; height: 32px; fill: none; stroke: #fff; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.logo rect { fill: #0f6cbd; stroke: none; }

.page {
  display: grid; max-width: 1280px; margin: 0 auto; padding: 12px 32px 40px; column-gap: 48px; row-gap: 20px;
  grid-template: "intro login" auto "story login" 1fr / minmax(0, 1fr) 360px;
}
.intro { grid-area: intro; }
.login { grid-area: login; align-self: start; position: sticky; top: 24px; }
.story { grid-area: story; min-width: 0; }

h1 { max-width: 30ch; font-size: clamp(1.75rem, 3vw, 2.5rem); line-height: 1.15; font-weight: 600; text-wrap: balance; }
.lead { max-width: 62ch; margin-top: 12px; color: var(--muted); font-size: 1.0625rem; }

.login { padding: 28px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow); outline: none; }
.login h2 { margin-bottom: 16px; font-size: 1.5rem; font-weight: 600; }
.login label { display: block; margin: 14px 0 4px; font-weight: 600; }
.login input:not([type=hidden]) {
  width: 100%; min-height: 44px; padding: 8px 12px; color: inherit; background: transparent;
  border: 1px solid var(--line); border-bottom-color: var(--field); border-radius: 6px;
}
.login input[aria-invalid=true] { border-color: var(--bad); }
.password { display: flex; gap: 8px; }
.password button, .ghost {
  flex-shrink: 0; min-height: 44px; padding: 0 12px; color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
}
.ghost { min-height: 36px; min-width: 112px; }
.primary {
  width: 100%; min-height: 44px; margin-top: 24px; color: #fff; background: #0f6cbd; border: 0; border-radius: 6px;
  font-weight: 600; cursor: pointer;
}
.primary:hover { background: #115ea3; }
.password button:hover, .ghost:hover { background: var(--soft); }
.help { margin-top: 16px; color: var(--muted); font-size: .875rem; }
.alert { padding: 10px 12px; color: var(--bad); background: var(--bad-bg); border-radius: 6px; }

.story-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; min-height: 36px; }
.story-head h2 { font-size: 1.25rem; font-weight: 600; }
.stage { position: relative; aspect-ratio: 640 / 400; max-height: 410px; width: 100%; }
.scene { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; visibility: hidden; transition: opacity .35s, visibility .35s; }
.scene.on { opacity: 1; visibility: visible; }

.scene text { fill: var(--ink); font-size: 16px; text-anchor: middle; }
.scene .small { fill: var(--muted); font-size: 14px; }
.scene .label { font-size: 15px; }
.scene .strong { fill: var(--ink); font-weight: 600; }
.scene .big { font-size: 24px; font-weight: 600; }
.scene .huge { font-size: 52px; font-weight: 600; }
.scene .start { text-anchor: start; }
.scene .on-brand { fill: #fff; }
.card, .node { fill: var(--card); stroke: var(--line); stroke-width: 1.5; }
.slot { fill: var(--slot); }
.hub, .button { fill: #0f6cbd; }
.fill { fill: var(--brand); }
.late { fill: var(--bad); }
.wire { stroke: var(--line); stroke-width: 2.5; }
.ghostline { fill: none; stroke: none; }
.back { fill: none; stroke: var(--muted); stroke-width: 2; stroke-dasharray: 6 6; }
.mark, .arrow { fill: none; stroke: var(--muted); stroke-width: 2; }
.outline { fill: none; stroke: var(--bad); stroke-width: 2.5; }
.pill.ok { fill: var(--ok-bg); stroke: var(--ok); }
.pill.bad { fill: var(--bad-bg); stroke: var(--bad); }
.done circle { fill: var(--ok-bg); stroke: var(--ok); stroke-width: 2; }
.done path { fill: none; stroke: var(--ok); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.miss circle { fill: var(--bad-bg); stroke: var(--bad); stroke-width: 2; }
.miss path { fill: none; stroke: var(--bad); stroke-width: 3; stroke-linecap: round; }
.lock path { fill: none; stroke: var(--brand); stroke-width: 7; stroke-linecap: round; }
.lock rect { fill: var(--brand); }
.lock circle { fill: var(--card); }
.ring, .press { fill: none; stroke: var(--brand); stroke-width: 4; }
.token { fill: var(--brand); stroke: var(--card); stroke-width: 3; }
.token.late { fill: var(--bad); }
/* Тимчасові елементи: видно лише під час їхнього руху. */
.token, .ring, .press, [data-a=show] { opacity: 0; }
[data-a=pop], [data-a=pulse] { transform-box: fill-box; transform-origin: center; }
[data-a=wide] { transform-box: fill-box; transform-origin: left center; }

.steps { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin: 16px 0 0; padding: 0; list-style: none; }
.steps button {
  display: flex; flex-direction: column; gap: 6px; width: 100%; height: 100%; padding: 0 0 8px; color: var(--ink);
  background: transparent; border: 0; border-radius: 4px; text-align: left; line-height: 1.35; cursor: pointer;
}
.steps b { font-weight: 600; }
.steps span:not(.bar) { color: var(--muted); font-size: .875rem; }
.steps [aria-current] b { color: var(--brand); }
.steps button:hover b { text-decoration: underline; }
.bar { position: relative; display: block; width: 100%; height: 4px; border-radius: 2px; background: transparent; transform-origin: left; }
.bar.full { background: var(--brand); }
.steps li { position: relative; }
.steps li::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; border-radius: 2px; background: var(--slot); }
.steps button { position: relative; }
:root[data-theme=dark] .steps [aria-current] b { color: #62abf5; }
@media (prefers-color-scheme: dark) { :root:not([data-theme=light]) .steps [aria-current] b { color: #62abf5; } }

@media (max-width: 1099px) {
  .page { grid-template-columns: minmax(0, 1fr) 320px; column-gap: 32px; }
  .steps { grid-template-columns: 1fr; gap: 8px; }
}
@media (max-width: 859px) {
  .top { padding: 16px; }
  .page { grid-template: "intro" "login" "story" / minmax(0, 1fr); padding: 4px 16px 32px; }
  .login { position: static; padding: 20px; }
  .lead { font-size: 1rem; }
}
@media (max-width: 479px) {
  /* На вузькому екрані дрібні підписи сцени збільшуємо, щоб їх можна було прочитати. */
  .scene text { font-size: 18px; }
  .scene .small { font-size: 16px; }
  .scene .label { font-size: 17px; }
  .scene .big { font-size: 26px; }
  .scene .huge { font-size: 52px; }
}
@media (prefers-reduced-motion: reduce) { .scene { transition: none; } }
@media (forced-colors: active) { .bar.full { background: Highlight; } }
