:root {
  --bg: #1b1033;
  --card: #fff8ec;
  --ink: #2b1a3d;
  --muted: #7a6a85;
  --orange: #f28c28;
  --orange-d: #c9661a;
  --purple: #6b3fa0;
  --green: #3f8f3a;
  --red: #c0392b;
  --console: #17111f;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
#app { position: fixed; inset: 0; }
#game { display: block; width: 100%; height: 100%; touch-action: none; }

#hud { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
.hud-pill { background: rgba(20, 10, 40, .72); color: #fff3d6; padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 15px; border: 1px solid rgba(255,255,255,.15); }
.hud-py { font-weight: 500; font-size: 13px; }
.hud-py.ok { color: #b8f5a8; }
.hud-py.bad { color: #ffb4a8; }
.hud-btn { pointer-events: auto; margin-left: auto; background: rgba(20, 10, 40, .72); border: 1px solid rgba(255,255,255,.2); color: #fff; border-radius: 999px; font-size: 18px; padding: 4px 12px; cursor: pointer; }
.hud-btn + .hud-btn { margin-left: 0; }

#touch { position: absolute; left: 0; right: 0; bottom: max(14px, env(safe-area-inset-bottom)); display: none; padding: 0 16px; pointer-events: none; }
#touch.on { display: flex; }
.tbtn { pointer-events: auto; width: 76px; height: 76px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); background: rgba(30, 15, 55, .55); color: #fff; font-size: 30px; margin-right: 12px; touch-action: none; user-select: none; -webkit-user-select: none; }
.tbtn.tjump { margin-left: auto; margin-right: 0; width: 92px; height: 92px; background: rgba(242, 140, 40, .6); }
.tbtn.down { background: rgba(255,255,255,.35); }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(12, 6, 26, .55); overflow-y: auto; }
.overlay[hidden] { display: none; }
.card { width: min(640px, 100%); background: var(--card); border-radius: 18px; padding: 22px 22px 18px; box-shadow: 0 18px 50px rgba(0,0,0,.45); border: 3px solid #f6c77d; max-height: calc(100vh - 32px); overflow-y: auto; }
.card h1 { margin: 0 0 10px; color: var(--purple); font-size: clamp(24px, 5vw, 34px); line-height: 1.1; }
.card h2 { margin: 0 0 10px; color: var(--purple); }
.card p { line-height: 1.5; margin: 8px 0; }
code, pre, textarea { font-family: "Cascadia Code", Consolas, "Fira Code", Menlo, monospace; }
code { background: #f1e3ff; color: #4a237a; padding: 1px 6px; border-radius: 6px; }
.keys { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 14px 0; color: var(--muted); font-size: 14px; }
kbd { display: inline-block; background: #fff; border: 1px solid #ccb; border-bottom-width: 3px; border-radius: 6px; padding: 0 6px; margin-right: 3px; font-size: 13px; color: var(--ink); }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btn { font: inherit; font-weight: 700; border-radius: 12px; padding: 11px 18px; cursor: pointer; border: 2px solid transparent; min-height: 46px; }
.btn.primary { background: var(--orange); color: #fff; border-color: var(--orange-d); }
.btn.primary:hover { background: #ff9d3d; }
.btn.primary:disabled { background: #c9b9a6; border-color: #b0a090; cursor: wait; }
.btn.ghost { background: transparent; color: var(--purple); border-color: #d8c3ee; }
.btn.ghost:hover { background: #f4eaff; }

.gate-head { display: flex; gap: 14px; align-items: center; }
#guard-portrait { width: 84px; height: 84px; flex: none; background: #2c1a4a; border-radius: 14px; }
.guard-name { font-weight: 800; color: var(--purple); font-size: 18px; }
.bubble { background: #fff; border: 2px solid #e5d3f5; border-radius: 14px; padding: 8px 12px; margin-top: 4px; line-height: 1.4; }
.task { margin: 14px 0 8px; background: #fff2d6; border-left: 5px solid var(--orange); padding: 10px 12px; border-radius: 8px; line-height: 1.5; }
.task pre { background: var(--console); color: #ffe9b0; padding: 8px 10px; border-radius: 8px; margin: 6px 0 0; white-space: pre-wrap; }
.code-label { font-weight: 700; font-size: 14px; color: var(--muted); }
#g-code { width: 100%; margin-top: 4px; font-size: 18px; padding: 10px 12px; border-radius: 10px; border: 2px solid #c9b3e3; background: #1f1630; color: #f9f3ff; resize: vertical; min-height: 92px; caret-color: var(--orange); }
#g-code:focus { outline: none; border-color: var(--orange); }
.console-wrap { margin-top: 12px; }
.console-title { font-size: 13px; color: var(--muted); font-weight: 700; }
.console { background: var(--console); color: #b8f5a8; min-height: 38px; padding: 8px 12px; border-radius: 10px; margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; font-size: 16px; }
.console .err { color: #ff9f8f; }
.console .empty { color: #8a7d99; font-style: italic; }
.feedback { margin-top: 10px; line-height: 1.45; min-height: 1em; }
.feedback.ok { color: var(--green); font-weight: 700; }
.feedback.bad { color: var(--red); }
.feedback.info { color: var(--purple); }
.feedback code { font-size: 15px; }

.rule { border-top: 1px dashed #e0cfa9; padding: 10px 0; }
.rule b { color: var(--purple); }
.rule pre { background: var(--console); color: #ffe9b0; padding: 8px 10px; border-radius: 8px; margin: 6px 0 0; white-space: pre-wrap; font-size: 15px; }
.muted { color: var(--muted); }

.newspaper { background: #f4ecd8; border-color: #3b2b1a; font-family: Georgia, "Times New Roman", serif; }
.np-title { font-size: clamp(26px, 6vw, 40px); font-weight: 900; text-align: center; letter-spacing: 2px; border-bottom: 3px double #3b2b1a; padding-bottom: 4px; }
.np-date { text-align: center; font-size: 13px; color: #6b5a44; margin: 4px 0 12px; }
.name-label { display: block; font-weight: 800; color: var(--purple); margin-top: 6px; }
.name-input { width: 100%; margin-top: 6px; font: inherit; font-size: 20px; padding: 10px 14px; border-radius: 12px; border: 2px solid #c9b3e3; background: #fff; color: var(--ink); }
.name-input:focus { outline: none; border-color: var(--orange); }
.name-hint { min-height: 1.3em; margin-top: 6px; font-size: 14px; color: var(--muted); }
.btn.primary:disabled { cursor: not-allowed; }
.np-by { text-align: center; font-style: italic; }
#hud-player[hidden] { display: none; }
#np-photo { display: block; width: 100%; max-width: 360px; margin: 0 auto 10px; border: 3px solid #3b2b1a; border-radius: 6px; filter: sepia(.25); }
.newspaper h2 { color: #8a2d0c; text-align: center; font-size: clamp(20px, 4.5vw, 28px); }
.newspaper h3 { margin: 16px 0 4px; }

#toast { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); background: rgba(20,10,40,.88); color: #fff3d6; padding: 10px 18px; border-radius: 12px; font-weight: 700; opacity: 0; transition: opacity .25s; pointer-events: none; text-align: center; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }

@media (max-width: 520px) {
  .card { padding: 16px 14px 14px; }
  #guard-portrait { width: 64px; height: 64px; }
  #g-code { font-size: 16px; }
  .btn { padding: 10px 14px; }
}

.example { margin: 10px 0; background: #eef7ff; border: 2px dashed #8cb8e6; border-radius: 10px; padding: 8px 10px; }
.ex-label, .ex-arrow { font-size: 13px; font-weight: 700; color: #2f5d8a; }
.ex-arrow { margin-top: 6px; }
.task .example pre.ex-code { background: #1f1630; color: #f9f3ff; margin: 4px 0 0; }
.task .example pre.ex-out { background: #17111f; color: #b8f5a8; margin: 4px 0 0; }

/* Кнопка «до вибору рівнів» у HUD */
.hud-btn.hud-home { margin-left: 0; text-decoration: none; line-height: 1.45; }
.hud-home + .hud-pill { margin-left: 0; }

/* Урок (рівень kind: "quiz"): слайди, питання, брейншторм */
.slide { text-align: center; }
.slide-n { font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); text-align: left; }
.slide-icon { font-size: 52px; line-height: 1.1; margin: 6px 0 2px; }
.slide h3 { margin: 4px 0 6px; color: var(--purple); font-size: 20px; }
.slide p { margin: 0 auto; max-width: 520px; font-size: 17px; }
.terms { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; }
.terms span { background: #efe3ff; color: #4a237a; border-radius: 999px; padding: 2px 10px; font-size: 13px; font-family: "Cascadia Code", Consolas, monospace; }
.quiz .q { font-size: 18px; font-weight: 700; margin: 8px 0 10px; }
.opts { display: grid; gap: 8px; }
.opt { font: inherit; font-size: 16px; text-align: left; padding: 11px 14px; border-radius: 12px; border: 2px solid #d8c3ee; background: #fff; color: var(--ink); cursor: pointer; min-height: 46px; }
.opt:hover:not(:disabled) { border-color: var(--orange); background: #fff7ec; }
.opt:disabled { cursor: default; }
.opt.wrong { border-color: var(--red); background: #ffecea; color: #8e2a1f; text-decoration: line-through; }
.opt.right { border-color: var(--green); background: #e9f8e7; color: #24622a; font-weight: 700; }
.opt.right::before { content: "✓ "; }
.quiz.storm .slide-n { color: var(--orange-d); }
.task:has(.slide), .task:has(.quiz) { background: #fff7ea; }

/* Оцінка: 12 відьомських капелюхів */
.grade { text-align: center; margin: 10px 0 6px; }
.grade-hats { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; margin: 6px 0; }
.grade-hats .hat { width: 40px; height: 48px; }
.grade-hats .hat.on { animation: hat-pop .45s ease-out both; }
.grade-hats .hat.off { filter: grayscale(1); opacity: .25; }
@keyframes hat-pop { from { transform: translateY(-14px) scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }
.grade-big { font-size: 22px; font-weight: 900; color: #8a2d0c; }
.grade-big b { font-size: 34px; }
@media (prefers-reduced-motion: reduce) { .grade-hats .hat.on { animation: none; } }
