:root {
  --ink: #1f2a44;
  --muted: #5b6b86;
  --card: #ffffff;
  --soft: #f3f7fd;
  --line: #dbe4f0;
  --accent: #ff3d71;
  --blue: #4c6ef5;
  --good: #2f9e44;
  --bad: #e03131;
  --warn: #f59f00;
  --font: ui-rounded, "Nunito", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, sans-serif;
  --shadow: 0 6px 22px rgba(31, 42, 68, .10), 0 1px 3px rgba(31, 42, 68, .08);
  --topbar: 56px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); font-size: 16px; line-height: 1.4;
  background: linear-gradient(180deg, #d9ecff 0%, #f4f9ff 45%, #fff6ea 100%) fixed;
  display: flex; flex-direction: column; min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------------- top bar */
.topbar {
  height: var(--topbar); flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; background: rgba(255, 255, 255, .82); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; border: 0; background: none; font-weight: 900; font-size: 20px; letter-spacing: -.01em; padding: 6px 4px; }
.brand .logo { font-size: 26px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.seg { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; font-weight: 800; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--blue); color: #fff; box-shadow: 0 2px 6px rgba(76, 110, 245, .35); }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 20px; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen { flex: 1; min-height: 0; }
.loading { text-align: center; padding: 4rem; color: var(--muted); }

/* ---------------- menu */
#menu { max-width: 1120px; width: 100%; margin: 0 auto; padding: 22px 16px 48px; }
.hero { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 16px; margin: 6px 0 22px; }
.hero h1 { font-size: clamp(30px, 5vw, 50px); line-height: 1.05; margin: 0 0 6px; letter-spacing: -.02em; font-weight: 900; }
.hero h1 span { color: var(--accent); }
.hero p { margin: 0; color: var(--muted); font-size: 18px; font-weight: 600; }
.hero-cast { display: flex; gap: 2px; }
.hero-cast canvas { width: 46px; height: 64px; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.mode-card {
  text-align: left; border: 0; border-radius: 22px; padding: 18px 18px 20px; background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; transition: transform .15s ease, box-shadow .15s ease;
}
.mode-card:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(31, 42, 68, .16); }
.mode-card .mi { font-size: 40px; line-height: 1; }
.mode-card h2 { margin: 4px 0 0; font-size: 21px; font-weight: 900; }
.mode-card p { margin: 0; color: var(--muted); font-weight: 600; }
.mode-card::after { content: ""; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; opacity: .14; background: var(--c, var(--blue)); }
.step-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 16px; }
.step-head h2 { margin: 0; font-size: 26px; }
.back-btn { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 7px 12px; font-weight: 800; }
.section-title { font-size: 14px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.maps { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.map-card { border: 3px solid transparent; background: #fff; border-radius: 18px; padding: 8px; box-shadow: var(--shadow); text-align: left; }
.map-card.on { border-color: var(--blue); }
.map-card .thumb { width: 100%; aspect-ratio: 16 / 10; border-radius: 12px; overflow: hidden; background: #cfe3c0; display: block; }
.map-card .thumb > * { width: 100%; height: 100%; object-fit: cover; display: block; }
.map-card b { display: block; margin: 8px 4px 2px; font-size: 17px; }
.map-card small { display: block; margin: 0 4px 2px; color: var(--muted); font-weight: 600; }
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.level-btn { border: 3px solid transparent; background: #fff; border-radius: 16px; padding: 12px 14px; text-align: left; box-shadow: var(--shadow); }
.level-btn.on { border-color: var(--blue); }
.level-btn b { display: block; font-size: 17px; }
.level-btn small { color: var(--muted); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.start-row { margin-top: 22px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.btn { border: 0; border-radius: 14px; padding: 12px 20px; font-weight: 900; font-size: 17px; background: var(--soft); border: 1px solid var(--line); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; box-shadow: 0 6px 16px rgba(255, 61, 113, .35); }
.btn.blue { background: var(--blue); color: #fff; border-color: transparent; }
.btn.big { font-size: 20px; padding: 14px 28px; }
select.pill { font: inherit; font-weight: 800; border-radius: 12px; border: 1px solid var(--line); padding: 8px 10px; background: #fff; }
.stories { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.story-card { display: grid; grid-template-columns: 74px 1fr; gap: 12px; text-align: left; border: 0; border-radius: 20px; padding: 14px; background: #fff; box-shadow: var(--shadow); transition: transform .15s; }
.story-card:hover { transform: translateY(-3px); }
.story-card canvas { width: 74px; height: 96px; background: linear-gradient(180deg, #e7f1ff, #fdf2ff); border-radius: 14px; }
.story-card h3 { margin: 0; font-size: 19px; }
.story-card .who { font-weight: 900; color: var(--accent); font-size: 14px; }
.story-card p { margin: 4px 0 8px; color: var(--muted); font-size: 14px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 12px; font-weight: 800; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }

/* ---------------- game */
#game { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); gap: 12px; padding: 12px; height: calc(100vh - var(--topbar)); height: calc(100dvh - var(--topbar)); }
.stage { position: relative; border-radius: 20px; overflow: hidden; background: #24324a; box-shadow: var(--shadow); min-height: 0; }
.stage > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }
.hud-top { position: absolute; left: 10px; right: 10px; top: 10px; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; pointer-events: none; }
.task-card { pointer-events: auto; background: rgba(255, 255, 255, .95); border-radius: 16px; padding: 8px 12px 8px 8px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center; max-width: min(560px, 75%); }
.task-card canvas { width: 38px; height: 50px; flex: none; }
.task-card .tc-main { min-width: 0; }
.task-card .say { font-weight: 800; font-size: 15px; }
.task-card .say small, .tr-line { display: block; font-weight: 600; color: var(--muted); font-size: 12.5px; }
.task-card .meta { font-size: 12.5px; font-weight: 800; color: var(--muted); margin-top: 2px; }
.task-card .dest { display: inline-flex; align-items: center; gap: 4px; background: #ffe3ea; color: #c2255c; border-radius: 999px; padding: 1px 8px; font-weight: 900; }
.timer { pointer-events: auto; background: rgba(255, 255, 255, .95); border-radius: 16px; box-shadow: var(--shadow); padding: 6px 12px; text-align: center; min-width: 84px; }
.timer .num { font-size: 28px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.05; }
.timer .lbl { font-size: 11px; font-weight: 900; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.timer.warn .num { color: var(--warn); }
.timer.danger .num { color: var(--bad); animation: throb .5s infinite alternate; }
.timer .bar { height: 5px; border-radius: 3px; background: var(--line); margin-top: 3px; overflow: hidden; }
.timer .bar i { display: block; height: 100%; background: var(--good); transition: width .2s linear; }
.timer.warn .bar i { background: var(--warn); }
.timer.danger .bar i { background: var(--bad); }
@keyframes throb { to { transform: scale(1.08); } }
.checklist { position: absolute; left: 10px; bottom: 10px; background: rgba(255, 255, 255, .94); border-radius: 14px; box-shadow: var(--shadow); padding: 8px 12px; font-size: 14px; font-weight: 700; max-width: 260px; }
.checklist h5 { margin: 0 0 2px; font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.checklist ul { list-style: none; padding: 0; margin: 0 0 4px; }
.checklist li { display: flex; gap: 6px; align-items: center; padding: 1px 0; }
.checklist li.done { color: var(--good); text-decoration: line-through; }
.go-overlay { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; pointer-events: none; }
.go-box { pointer-events: auto; background: rgba(255, 255, 255, .95); border-radius: 20px; box-shadow: 0 10px 30px rgba(0, 0, 0, .28); padding: 8px 10px 8px 16px; display: flex; align-items: center; gap: 14px; max-width: min(560px, 94%); flex-wrap: wrap; justify-content: center; }
.go-box p { margin: 0; font-weight: 700; font-size: 14.5px; flex: 1 1 200px; }
.go-box .keys { flex-basis: 100%; margin: 0; font-size: 11.5px; color: var(--muted); font-weight: 600; text-align: center; }
.go-btn { border: 0; border-radius: 999px; padding: 10px 34px; font-size: 24px; flex: none; font-weight: 1000; color: #fff; background: linear-gradient(180deg, #ff5c8a, #ff2e63); box-shadow: 0 8px 20px rgba(255, 46, 99, .45), inset 0 -4px 0 rgba(0, 0, 0, .15); letter-spacing: .02em; animation: pulse 1.4s infinite; }
.go-btn.nudge { animation: shake .4s; }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.zoom-btn { position: absolute; right: 10px; bottom: 10px; width: 42px; height: 42px; border-radius: 12px; border: 0; background: rgba(255, 255, 255, .92); box-shadow: var(--shadow); font-size: 18px; }
.zoom-btn.on { background: var(--blue); }

.panel { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.queue-box { background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 10px 12px; display: flex; flex-direction: column; max-height: 34%; min-height: 120px; }
.queue-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.queue-head h3 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.queue-actions { display: flex; gap: 6px; }
.queue-actions button { width: 36px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--soft); font-weight: 900; font-size: 16px; }
.queue { list-style: none; margin: 8px 0 0; padding: 0; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.queue li { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 10px; background: var(--soft); font-weight: 700; font-size: 14.5px; }
.queue li .qi { width: 18px; text-align: center; flex: none; }
.queue li.empty { background: none; color: var(--muted); font-weight: 600; justify-content: center; }
.queue li.q-active { background: #e7edff; color: var(--blue); box-shadow: inset 3px 0 0 var(--blue); }
.queue li.q-done { color: var(--good); }
.queue li.q-failed { color: var(--bad); background: #fff0f0; }
.queue li.q-pending { opacity: .8; }
.board { background: #fff; border-radius: 18px; box-shadow: var(--shadow); padding: 4px 12px 12px; overflow: auto; flex: 1; min-height: 0; }
.board.locked .phrase { opacity: .55; }
.group h4 { margin: 10px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.phrases { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.phrase {
  display: flex; align-items: center; gap: 8px; text-align: left; border: 2px solid var(--line); background: var(--soft);
  border-radius: 12px; padding: 7px 9px; min-height: 46px; transition: transform .08s, background .15s, border-color .15s;
}
.phrase:hover { border-color: var(--blue); background: #eef2ff; }
.phrase:active { transform: scale(.97); }
.phrase .ico { font-size: 19px; flex: none; width: 24px; text-align: center; }
.phrase b { display: block; font-size: 14px; line-height: 1.2; }
.phrase small { display: block; font-size: 11.5px; color: var(--muted); font-weight: 600; line-height: 1.2; margin-top: 1px; }
.phrase.g-walk .ico { color: var(--good); }
.phrase.g-arrive { background: #fff4e6; }
.phrase.g-car, .phrase.g-bus { background: #f3f0ff; }
.phrase.flash { animation: flash 0.6s 3; border-color: var(--warn); }
@keyframes flash { 50% { background: #fff3bf; } }

/* ---------------- dialogs */
dialog { border: 0; padding: 0; border-radius: 24px; box-shadow: 0 24px 60px rgba(0, 0, 0, .35); max-width: min(640px, 94vw); width: 100%; color: var(--ink); }
dialog::backdrop { background: rgba(20, 28, 48, .55); backdrop-filter: blur(2px); }
.dlg-inner { padding: 20px 22px 18px; max-height: 88vh; overflow: auto; }
.dlg-inner h2 { margin: 0 0 6px; font-size: 26px; }
.dlg-inner .muted { color: var(--muted); font-weight: 600; margin: 0; }
.dlg-head { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; }
.dlg-head canvas { width: 70px; height: 92px; flex: none; background: linear-gradient(180deg, #e7f1ff, #fdf2ff); border-radius: 16px; }
.big-icon { font-size: 46px; line-height: 1; }
.result-score { font-size: 40px; font-weight: 1000; color: var(--accent); margin: 4px 0; }
.stars { font-size: 30px; letter-spacing: 4px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.cols h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.dir-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.dir-list li { background: var(--soft); border-radius: 10px; padding: 5px 8px; font-weight: 700; font-size: 14px; display: flex; gap: 6px; align-items: center; }
.dir-list li.bad { color: var(--bad); background: #fff0f0; }
.dir-list li button { margin-left: auto; border: 0; background: none; font-size: 15px; padding: 0 2px; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.intro-text { font-size: 17px; font-weight: 600; }
.errands { background: var(--soft); border-radius: 14px; padding: 10px 14px; margin: 12px 0; }
.errands h4 { margin: 4px 0; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .06em; }
.errands ul { margin: 0 0 6px; padding-left: 0; list-style: none; }
.errands li { font-weight: 800; padding: 2px 0; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.act-btn { text-align: left; border: 2px solid var(--line); background: var(--soft); border-radius: 14px; padding: 11px 14px; font-weight: 800; font-size: 16px; }
.act-btn small { display: block; color: var(--muted); font-weight: 600; font-size: 13px; }
.act-btn:hover:not(:disabled) { border-color: var(--blue); background: #eef2ff; }
.act-btn:disabled { opacity: .45; text-decoration: line-through; cursor: default; }
.act-result { margin-top: 12px; border-radius: 14px; padding: 12px 14px; font-weight: 700; font-size: 16px; }
.act-result.good { background: #ebfbee; color: #2b8a3e; }
.act-result.bad { background: #fff0f0; color: #c92a2a; }
.act-result .pen { font-weight: 1000; margin-left: 6px; }
.settings-form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.settings-form label { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 700; }
.settings-form input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--blue); }
.settings-form input[type=number] { width: 90px; font: inherit; font-weight: 800; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; }
.end-text { font-size: 18px; font-weight: 700; background: var(--soft); border-radius: 14px; padding: 12px 14px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.facts span { background: var(--soft); border-radius: 999px; padding: 4px 10px; font-weight: 800; font-size: 14px; }

@media (max-width: 860px) {
  #game { grid-template-columns: 1fr; height: auto; padding: 8px; gap: 8px; }
  .stage { height: 54vh; height: 54dvh; min-height: 300px; border-radius: 16px; }
  .panel { min-height: 0; }
  .queue-box { max-height: 180px; }
  .board { overflow: visible; }
  .task-card { max-width: 74%; padding: 6px 10px; }
  .task-card .say { font-size: 13px; line-height: 1.25; }
  .task-card .say small { display: none; }
  .task-card canvas { display: none; }
  .task-card .meta { font-size: 11.5px; }
  .timer .num { font-size: 22px; }
  .timer { min-width: 70px; padding: 5px 8px; }
  .checklist { top: auto; bottom: 10px; left: 10px; font-size: 12.5px; padding: 6px 10px; }
  .go-box .keys { display: none; }
  .hero { grid-template-columns: 1fr; }
  .hero-cast { display: none; }
  .phrases { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .cols { grid-template-columns: 1fr; }
  .brand { font-size: 17px; }
}
@media (prefers-reduced-motion: reduce) {
  .go-btn, .timer.danger .num { animation: none; }
}

.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 26px; }
.how div { background: rgba(255, 255, 255, .7); border: 1px dashed var(--line); border-radius: 18px; padding: 12px 14px; font-weight: 700; color: var(--muted); }
.how b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 2px; }
.how .n { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--blue); color: #fff; font-weight: 900; margin-right: 6px; font-size: 14px; }
