:root {
  --bg: #0c0918;
  --bg2: #151027;
  --panel: rgba(22, 16, 42, 0.94);
  --panel2: #1e1638;
  --line: rgba(196, 170, 255, 0.18);
  --text: #efe9ff;
  --muted: #b3a8d6;
  --orange: #ff8b2b;
  --orange2: #ffb35c;
  --gold: #f2c55c;
  --violet: #8f6cff;
  --blood: #e8394f;
  --green: #5fd39a;
  --radius: 14px;
  --font-ui: 'Rubik', system-ui, sans-serif;
  --font-story: 'Kurale', Georgia, serif;
  --font-logo: 'Rubik Wet Paint', 'Rubik', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg) radial-gradient(ellipse at top, #241a48 0%, var(--bg) 60%) fixed;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--orange2); }
button { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 999px; cursor: pointer;
  padding: 12px 22px; font-size: 16px; font-weight: 500;
  background: linear-gradient(180deg, var(--orange2), var(--orange));
  color: #2a1203; box-shadow: 0 4px 18px rgba(255, 139, 43, 0.35);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
a.btn { text-decoration: none; }
.btn.ghost {
  background: transparent; color: var(--text); box-shadow: none;
  border: 1px solid var(--line);
}
.btn.ghost:hover { border-color: var(--orange2); }
.btn.small { padding: 8px 14px; font-size: 14px; }
.btn.violet { background: linear-gradient(180deg, #a58bff, #7653f2); color: #fff; box-shadow: 0 4px 18px rgba(143,108,255,.35); }

label.field { display: block; margin: 0 0 14px; }
label.field span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
input.inp {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: #0f0b20; color: var(--text);
  font-size: 16px; font-family: inherit; outline: none;
}
input.inp:focus { border-color: var(--orange2); box-shadow: 0 0 0 3px rgba(255,179,92,.18); }
.err { color: #ff8a98; font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

/* ---------- экран входа ---------- */
#auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
  background: linear-gradient(180deg, rgba(12,9,24,.35), rgba(12,9,24,.92)), url('../img/throne.jpg') center/cover no-repeat;
}
.auth-card {
  width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 26px; box-shadow: 0 20px 60px rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
}
.logo {
  font-family: var(--font-logo); font-weight: 400; color: var(--orange);
  font-size: clamp(38px, 9vw, 54px); line-height: 1.05; margin: 0 0 6px; text-align: center;
  text-shadow: 0 0 24px rgba(255, 139, 43, .45);
}
.logo-sub { text-align: center; color: var(--muted); margin: 0 0 22px; font-family: var(--font-story); font-size: 18px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; background: #0f0b20; padding: 4px; border-radius: 999px; }
.auth-tabs button {
  flex: 1; border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 999px;
  cursor: pointer; font-size: 15px;
}
.auth-tabs button.on { background: var(--panel2); color: var(--text); }
.auth-note { font-size: 13px; color: var(--muted); margin-top: 14px; text-align: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- полноэкранные сцены (пролог, финалы) ---------- */
.scene-screen {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center;
  background: #000 center/cover no-repeat; padding: 16px;
  animation: fadein .6s ease;
}
.scene-screen::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 30%, rgba(8,5,18,.92) 75%);
}
.scene-box {
  position: relative; max-width: 760px; width: 100%; margin-bottom: 4vh;
  background: rgba(18, 12, 36, .78); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px 24px; backdrop-filter: blur(4px);
}
.scene-box h2 { font-family: var(--font-logo); font-weight: 400; color: var(--orange); margin: 0 0 8px; font-size: 34px; }
.scene-text { font-family: var(--font-story); font-size: 20px; line-height: 1.6; margin: 0 0 16px; }
.scene-actions { display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.dots { display: flex; gap: 6px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); display: block; }
.dots i.on { background: var(--orange2); }
.tokens { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 16px; }
.tokens button {
  font-size: 34px; width: 64px; height: 64px; border-radius: 16px; cursor: pointer;
  background: #0f0b20; border: 2px solid var(--line);
}
.tokens button.on { border-color: var(--orange2); box-shadow: 0 0 18px rgba(255,179,92,.5); }

/* ---------- игровой экран ---------- */
#game { min-height: 100vh; }
.hud {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: rgba(12, 9, 24, .9); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.hud .brand { font-family: var(--font-logo); color: var(--orange); font-size: 24px; white-space: nowrap; }
.hud .stat { display: flex; align-items: center; gap: 6px; font-size: 15px; white-space: nowrap; }
.hud .lives span { font-size: 20px; transition: transform .3s, opacity .3s, filter .3s; }
.hud .lives span.lost { filter: grayscale(1); opacity: .3; }
.hud .score b { color: var(--gold); font-size: 18px; }
.hud .relics span { font-size: 18px; opacity: .25; filter: grayscale(1); }
.hud .relics span.got { opacity: 1; filter: none; }
.hud .relics span.used { opacity: .45; filter: grayscale(.8); }
.hud .spacer { flex: 1; }
.hud .menu { display: flex; gap: 6px; flex-wrap: wrap; }
.hud .who { color: var(--muted); font-size: 13px; }

.board-wrap { max-width: 860px; margin: 0 auto; padding: 14px 12px 40px; }
.chapter-banner {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 12px; display: flex; gap: 12px; align-items: flex-start;
}
.chapter-banner .jack { font-size: 30px; line-height: 1; }
.chapter-banner b { color: var(--orange2); display: block; }
.chapter-banner p { margin: 2px 0 0; color: var(--muted); font-size: 15px; }

.board {
  position: relative; width: 100%; border-radius: 18px; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.6), 0 0 0 1px var(--line);
}
.board svg { display: block; width: 100%; height: auto; }

/* узлы карты */
.node { cursor: pointer; }
.node .ring { fill: none; stroke: rgba(255,255,255,.25); stroke-width: 3; }
.node .glow { fill: none; stroke: var(--orange2); stroke-width: 4; opacity: 0; }
.node.available .glow { animation: pulse 1.8s ease-in-out infinite; }
.node.available .ring { stroke: var(--orange2); }
.node.solved .ring { stroke: var(--gold); stroke-width: 5; }
.node.bonus .ring { stroke: #c9a8ff; stroke-dasharray: 8 6; }
.node.locked { cursor: not-allowed; }
.node.locked image { filter: grayscale(1) brightness(.45); }
.node .lbl-bg { fill: rgba(10, 7, 22, .82); stroke: rgba(255,255,255,.12); }
.node .lbl { fill: #fff; font: 600 15px var(--font-ui); text-anchor: middle; }
.node .lbl2 { fill: var(--orange2); font: 500 12.5px var(--font-ui); text-anchor: middle; }
.node.solved .lbl2 { fill: var(--gold); }
.node.locked .lbl, .node.locked .lbl2 { fill: #8d84ad; }
.node .badge-bg { fill: #2a1203; stroke: var(--orange2); stroke-width: 2; }
.node .badge { fill: var(--orange2); font: 700 15px var(--font-ui); text-anchor: middle; dominant-baseline: central; }
.node.solved .badge-bg { fill: var(--gold); stroke: #fff6d6; }
.node.solved .badge { fill: #2a1203; }
.node:hover:not(.locked) .ring { stroke: #fff; }
.trail { fill: none; stroke: rgba(255, 220, 170, .35); stroke-width: 4; stroke-dasharray: 2 12; stroke-linecap: round; }
.trail.open { stroke: var(--orange2); stroke-opacity: .9; animation: march 1.2s linear infinite; }
.trail.done { stroke: var(--gold); stroke-opacity: .85; }
.gate { fill: #1a1230; stroke: rgba(255,255,255,.4); stroke-width: 2; }
.gate.open { stroke: var(--orange2); fill: #3a1d08; }
.token { font-size: 44px; text-anchor: middle; dominant-baseline: central; filter: drop-shadow(0 4px 6px rgba(0,0,0,.8)); pointer-events: none; }
.token-g { transition: transform 1.1s cubic-bezier(.5,0,.3,1); }
.cat-sprite { cursor: pointer; animation: catblink 4s infinite; }
.secret-hint { fill: none; stroke: #c9a8ff; stroke-width: 2; stroke-dasharray: 4 6; opacity: .0; }

@keyframes pulse { 0%, 100% { opacity: .15; stroke-width: 3; } 50% { opacity: .95; stroke-width: 9; } }
@keyframes march { to { stroke-dashoffset: -28; } }
@keyframes catblink { 0%, 92%, 100% { opacity: 1; } 95% { opacity: .2; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-10px); } 40% { transform: translateX(10px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }
@keyframes floatup { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-60px); opacity: 0; } }

/* легенда под картой */
.board-hint { display: none; color: var(--muted); font-size: 13px; margin: 0 4px 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 12px 4px 0; color: var(--muted); font-size: 13px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

/* ---------- модальные окна ---------- */
.modal {
  position: fixed; inset: 0; z-index: 40; background: rgba(5, 3, 12, .78);
  display: flex; align-items: flex-start; justify-content: center; overflow-y: auto;
  padding: 24px 12px; animation: fadein .25s ease;
}
.modal-card {
  width: 100%; max-width: 860px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.7);
  animation: pop .3s ease;
}
.modal-card.narrow { max-width: 560px; }
.modal-head {
  position: relative; min-height: 200px; background: #000 center/cover no-repeat;
  display: flex; align-items: flex-end; padding: 18px 22px;
}
.modal-head::before { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0) 20%, rgba(18,12,36,.97) 100%); }
.modal-head > * { position: relative; }
.modal-head h2 { margin: 0; font-family: var(--font-story); font-size: 30px; line-height: 1.15; }
.modal-head .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.tag { display: inline-block; font-size: 12.5px; padding: 3px 10px; border-radius: 999px; background: rgba(255,139,43,.18); color: var(--orange2); border: 1px solid rgba(255,139,43,.35); }
.tag.gold { background: rgba(242,197,92,.15); color: var(--gold); border-color: rgba(242,197,92,.4); }
.tag.violet { background: rgba(143,108,255,.18); color: #cdbdff; border-color: rgba(143,108,255,.4); }
.tag.green { background: rgba(95,211,154,.15); color: var(--green); border-color: rgba(95,211,154,.4); }
.close-x {
  position: absolute; top: 12px; right: 12px; z-index: 2; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(10,7,22,.7); color: var(--text); font-size: 20px; cursor: pointer;
}
.modal-body { padding: 18px 22px 22px; }
.story { font-family: var(--font-story); font-size: 18px; line-height: 1.6; color: #e6dcff; margin: 0 0 16px;
  padding-left: 14px; border-left: 3px solid var(--orange); }

/* текст задания */
.task { background: #120d24; border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.task p { margin: 0 0 10px; }
.task p:last-child { margin-bottom: 0; }
.task .note { color: var(--muted); font-size: 14px; }
.task details { background: #0d0a1b; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; margin: 0 0 12px; }
.task details summary { cursor: pointer; color: var(--orange2); }
.task details p { font-size: 14.5px; color: #d9d0f5; margin-top: 8px; }
.ege-table { border-collapse: collapse; margin: 8px 0 12px; font-size: 14.5px; background: #0d0a1b; }
.ege-table th, .ege-table td { border: 1px solid rgba(196,170,255,.35); padding: 5px 9px; text-align: center; }
.ege-table th { background: #241a44; font-weight: 500; }
.ege-table td.diag { background: #4a4166; }
.ege-table.hdr { width: 100%; font-size: 13px; }
.ege-table.weights td, .ege-table.weights th { min-width: 34px; padding: 5px 4px; }
.ege-table th.vert { writing-mode: vertical-rl; transform: rotate(180deg); padding: 6px 4px; }
.tbl-scroll { overflow-x: auto; }
.ege-graph-wrap { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin: 6px 0 12px; }
.ege-graph-wrap .ege-table { margin: 0; }
.ege-graph { width: 330px; max-width: 100%; background: #f5efe0; border-radius: 10px; }
.ege-graph .g-edge { stroke: #2b2238; stroke-width: 2.4; }
.ege-graph .g-node { fill: #2b2238; }
.ege-graph .g-label { fill: #2b2238; font: 600 17px 'Rubik', sans-serif; }
.cipher { font-family: 'Courier New', monospace; font-size: 20px; letter-spacing: 2px; background: #0d0a1b;
  padding: 10px 14px; border-radius: 10px; word-break: break-all; color: var(--gold); }

.files { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 0; }
.answer-box { margin-top: 16px; background: #171030; border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.answer-box .ans-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.answer-box label.field { flex: 1; min-width: 160px; margin: 0; }
.answer-box .warn { font-size: 13.5px; color: var(--muted); margin: 8px 0 0; }
.solved-box { margin-top: 16px; padding: 14px 16px; border-radius: 14px; background: rgba(242,197,92,.1);
  border: 1px solid rgba(242,197,92,.35); color: var(--gold); }
.jack-says { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; color: var(--muted); font-size: 14.5px; }
.jack-says .face { font-size: 26px; line-height: 1; }

/* финал: печати */
.seals { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin: 6px 0 0; }
.seal {
  text-align: left; border-radius: 14px; padding: 12px 14px; cursor: pointer; color: var(--text);
  background: radial-gradient(circle at 20% 20%, rgba(255,139,43,.25), rgba(30,20,56,.9) 70%);
  border: 1px solid rgba(255,139,43,.35); font-size: 15px;
}
.seal b { display: block; font-family: var(--font-story); font-size: 17px; margin-bottom: 2px; }
.seal small { color: var(--orange2); }
.seal.broken { background: rgba(242,197,92,.08); border-color: rgba(242,197,92,.4); }
.seal.broken small { color: var(--gold); }
.seal:hover:not(.broken) { border-color: var(--orange2); box-shadow: 0 0 20px rgba(255,139,43,.3); }
.boss-bar { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin: 4px 0 14px; color: var(--muted); }
.boss-bar .hp span { font-size: 22px; }
.boss-bar .hp span.gone { filter: grayscale(1); opacity: .3; }

/* дневник, рейтинг, правила */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { border: 1px solid var(--line); background: transparent; color: var(--muted); padding: 8px 14px; border-radius: 999px; cursor: pointer; }
.tabs button.on { background: var(--panel2); color: var(--text); border-color: var(--orange2); }
.diary-card { background: #f2e8d0; color: #2b1d0e; border-radius: 12px; padding: 14px 16px; margin-bottom: 10px;
  font-family: var(--font-story); font-size: 17px; box-shadow: inset 0 0 30px rgba(120, 80, 30, .25); }
.diary-card b { display: block; font-size: 18px; margin-bottom: 4px; color: #6b2a0a; }
.diary-card .ege-table { background: #fff8e8; color: #2b1d0e; }
.diary-card .ege-table th { background: #e9d9b5; }
.diary-card .ege-table th, .diary-card .ege-table td { border-color: #b59a6a; }
.diary-card .cipher { background: #fff8e8; color: #6b2a0a; }
.diary-card ol { margin: 6px 0 0; padding-left: 22px; }
.diary-card li { margin-bottom: 4px; }
.diary-card .method { margin-top: 8px; padding: 8px 10px; border-left: 3px solid #2f6b2a; border-radius: 8px;
  background: rgba(47, 107, 42, .1); }
.diary-card .method b { font-size: 16px; color: #2f6b2a; }
.diary-card .example { margin: 6px 0 0; font-style: italic; }
.diary-card .trap { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: rgba(140, 30, 10, .1); color: #7a1d08; }
.relic-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.relic { background: #120d24; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.relic .ic { font-size: 30px; }
.relic.off { opacity: .4; filter: grayscale(1); }
.lb { width: 100%; border-collapse: collapse; font-size: 15px; }
.lb th { text-align: left; color: var(--muted); font-weight: 500; font-size: 13px; padding: 8px; border-bottom: 1px solid var(--line); }
.lb td { padding: 9px 8px; border-bottom: 1px solid rgba(196,170,255,.08); }
.lb tr.me td { background: rgba(255,139,43,.12); }
.lb .pl { width: 42px; text-align: center; font-weight: 700; color: var(--muted); }
.lb tr:nth-child(2) .pl { color: var(--gold); } .lb tr:nth-child(3) .pl { color: #d9dce6; } .lb tr:nth-child(4) .pl { color: #d79b61; }
.lb .sc { font-weight: 700; color: var(--gold); text-align: right; }
.rules-list { display: grid; gap: 10px; }
.rules-list div { background: #120d24; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.rules-list b { color: var(--orange2); }

/* всплывающие события */
.toast-wrap { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 70; display: grid; gap: 8px; width: min(92vw, 520px); }
.toast { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: pop .3s ease; }
.toast.good { border-color: rgba(242,197,92,.6); }
.toast.bad { border-color: rgba(232,57,79,.6); }
.flash { position: fixed; inset: 0; z-index: 60; pointer-events: none; animation: fadein .1s ease reverse forwards; }
.flash.bad { background: radial-gradient(circle, rgba(232,57,79,0) 30%, rgba(232,57,79,.45)); }
.flash.good { background: radial-gradient(circle, rgba(242,197,92,0) 30%, rgba(242,197,92,.35)); }
.shake { animation: shake .45s ease; }
.result-card { text-align: center; padding: 26px 22px; }
.result-card .big { font-size: 64px; line-height: 1; margin-bottom: 8px; animation: pop .5s ease; }
.result-card h3 { font-family: var(--font-story); font-size: 26px; margin: 0 0 8px; }
.result-card p { color: #ddd3fa; margin: 0 0 14px; font-family: var(--font-story); font-size: 18px; }
.pts-float { color: var(--gold); font-weight: 700; font-size: 28px; animation: floatup 1.6s ease forwards; }
.score-table { margin: 0 auto 16px; border-collapse: collapse; font-size: 16px; }
.score-table td { padding: 4px 12px; text-align: left; }
.score-table td:last-child { text-align: right; color: var(--gold); font-weight: 700; }

.loading { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 980px) {
  .hud .menu .t { display: none; }
}
@media (max-width: 640px) {
  .hud { gap: 8px; padding: 8px 10px; }
  .hud .brand { font-size: 19px; }
  .hud .who { display: none; }
  .modal { padding: 0; }
  .modal-card { border-radius: 0; min-height: 100vh; }
  .modal-head { min-height: 150px; }
  .modal-head h2 { font-size: 24px; }
  .modal-body { padding: 14px 14px 20px; }
  .story { font-size: 16.5px; }
  .task { padding: 12px; font-size: 15px; }
  .scene-text { font-size: 17px; }
  .row2 { grid-template-columns: 1fr; gap: 0; }
  .board-wrap { padding-left: 8px; padding-right: 8px; }
  .board { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .board svg { width: 720px; max-width: none; }
  .board-hint { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
