/* «Два ключа»: тёмное дерево и латунь у Мастера, бумага наставления у Хранителя. Сначала телефон. */
:root {
  --bg: #1d1712;
  --bg2: #2a2119;
  --panel: #33281e;
  --brass: #c9a24a;
  --brass2: #e6c675;
  --ink: #f4ead6;
  --muted: #b8a68a;
  --paper: #f3e7cf;
  --paper2: #e8d8b8;
  --pink: #3a2a1a;
  --red: #d4463b;
  --green: #4fae61;
  --r: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, #2e241b 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; margin: 0; }
button { font: inherit; color: inherit; }
#app { min-height: 100%; }
main { max-width: 520px; margin: 0 auto; padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); }

.ic { width: 24px; height: 24px; flex: none; vertical-align: middle; }
.ic.big { width: 34px; height: 34px; }
.ic.huge { width: 64px; height: 64px; }
.ic.inl { width: 1.25em; height: 1.25em; margin: 0 .1em; vertical-align: -.25em; }
.ic.flip { transform: scaleX(-1); margin-left: -14px; }
.cdot { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(0,0,0,.35); vertical-align: middle; }
.cdot.inl { width: .95em; height: .95em; vertical-align: -.1em; margin: 0 .12em; }
.cdot.big { width: 22px; height: 22px; }
.pulses { display: inline-flex; gap: 4px; align-items: center; vertical-align: middle; }
.pulses i { display: block; height: 9px; border-radius: 5px; background: currentColor; }
.pulses .ps { width: 9px; }
.pulses .pl { width: 26px; }

/* кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border: 0; border-radius: 12px; cursor: pointer;
  background: linear-gradient(#d9b45c, #b48a35); color: #2a1d0c; font-weight: 650;
  box-shadow: 0 3px 0 #7a5a1f, 0 6px 14px rgba(0,0,0,.35);
  transition: transform .08s, box-shadow .08s, filter .2s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #7a5a1f, 0 3px 8px rgba(0,0,0,.35); }
.btn:disabled { filter: grayscale(.8) brightness(.6); cursor: default; }
.btn.ghost { background: transparent; color: var(--brass2); box-shadow: inset 0 0 0 1.5px var(--brass); }
.btn.big { width: 100%; min-height: 56px; font-size: 18px; }
.btn.on { background: linear-gradient(#6cc47b, #3f8f4e); box-shadow: 0 3px 0 #2a5f34; color: #08210e; }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: 14px; }
.btn.round { width: 64px; height: 64px; border-radius: 50%; font-size: 22px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.row > .btn { flex: 1 1 0; min-width: 120px; }

/* главная */
.home { text-align: center; display: flex; flex-direction: column; gap: 16px; padding-top: 48px; }
.emblem { color: var(--brass); }
.home h1 { font-size: 40px; color: var(--brass2); }
.tag { color: var(--muted); margin: -6px 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; color: var(--muted); font-size: 14px; }
input {
  font: inherit; color: var(--ink); background: var(--bg2); border: 1.5px solid #5a4630; border-radius: 12px;
  min-height: 50px; padding: 10px 14px; width: 100%;
}
input:focus { outline: none; border-color: var(--brass); }
.joinrow { display: flex; gap: 10px; }
.joinrow input { text-transform: uppercase; letter-spacing: .25em; font-weight: 700; text-align: center; }
.joinrow .btn { flex: none; }
.err { color: #ff9b8f; margin: 0; }
.back { color: var(--muted); text-decoration: none; margin-top: 24px; }

/* комната */
.lobby { display: flex; flex-direction: column; gap: 14px; }
.codebox { text-align: center; padding: 8px 0 0; }
.codebox span { display: block; color: var(--muted); font-size: 14px; }
.codebox b { font-size: 52px; letter-spacing: .18em; color: var(--brass2); font-family: Georgia, serif; }
.hint { color: var(--muted); text-align: center; margin: 0; font-size: 15px; }
.tg { text-align: center; color: var(--brass2); }
.chapter-card { background: var(--panel); border-radius: var(--r); padding: 14px 16px; border: 1px solid #4a3a2a; }
.chapter-card h2 { color: var(--brass2); font-size: 22px; }
.chapter-card p { margin: 6px 0 0; color: var(--muted); }
.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rolecard {
  background: var(--bg2); border-radius: var(--r); padding: 14px 12px; display: flex; flex-direction: column; gap: 4px;
  border: 1.5px solid #4a3a2a; color: var(--brass);
}
.rolecard b { color: var(--ink); font-size: 18px; }
.rolecard small { color: var(--muted); line-height: 1.3; }
.rolecard .who { color: var(--ink); margin-top: 6px; font-size: 15px; word-break: break-word; }
.rolecard.mine { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass) inset; }
.rolecard .ok { color: var(--green); font-style: normal; white-space: nowrap; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #000c; padding: 10px 18px; border-radius: 10px; max-width: 90vw; word-break: break-all; }

/* игра */
.play { padding: 0 0 calc(80px + env(safe-area-inset-bottom)); max-width: none; }
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; background: #15100ce6; backdrop-filter: blur(6px); border-bottom: 1px solid #3a2c1f;
}
.bar .role { display: flex; align-items: center; gap: 6px; color: var(--brass2); font-weight: 600; }
.timer { font: 700 26px/1 ui-monospace, "Cascadia Mono", Menlo, monospace; letter-spacing: .04em; }
.timer.low { color: #ff8a7a; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .45; } }
.sparks { display: flex; gap: 2px; color: #5a4a3a; }
.spk.on { color: #ffcf4a; filter: drop-shadow(0 0 4px #ff8a00); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: #15100cf2; border-top: 1px solid #3a2c1f; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.tab { position: relative; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border-radius: 10px; color: var(--muted); cursor: pointer; }
.tab .tl { font-size: 12px; }
.tab.cur { background: #2f241a; color: var(--brass2); }
.tab .mlamp { position: absolute; top: 5px; right: calc(50% - 22px); width: 9px; height: 9px; border-radius: 50%; background: #4a3b2c; }
.tab.done .mlamp { background: var(--green); box-shadow: 0 0 6px var(--green); }

.panels { padding: 14px 16px; max-width: 560px; margin: 0 auto; }
.panel { display: none; }
.panel.cur { display: block; }
.panel h3 { display: flex; align-items: center; gap: 8px; font-size: 20px; color: var(--brass2); margin-bottom: 12px; }
.okb { font: 600 14px system-ui, sans-serif; color: var(--green); margin-left: auto; }
.pbody { background: var(--panel); border: 1px solid #4a3a2a; border-radius: var(--r); padding: 18px 14px; box-shadow: inset 0 1px 0 #ffffff10, 0 8px 22px #0006; }
.panel.done .pbody { box-shadow: 0 0 0 2px var(--green) inset, 0 8px 22px #0006; }

/* Хранитель: бумага */
.as-keeper .pbody { padding: 16px 12px; background: linear-gradient(var(--paper), var(--paper2)); color: var(--pink); border-color: #c9b48a; }
.as-keeper .pbody p { margin: 0 0 12px; }
.as-keeper .lead { font-weight: 600; }
.rules { margin: 0 0 12px; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; }
.rules li { padding-left: 4px; }
.legend { display: flex; gap: 8px; }
.tbl { width: 100%; border-collapse: collapse; margin: 6px 0 14px; }
.tbl th, .tbl td { border: 1px solid #b59d72; padding: 8px 6px; text-align: center; }
.tbl th { background: #e2cfa8; font-weight: 600; font-size: 14px; }
.tbl .num { font: 700 22px Georgia, serif; }
.tbl.bells td, .tbl.bells th { padding: 9px 3px; }
.tbl.bells .pulses { gap: 3px; }
.tbl.bells .pulses i { height: 7px; }
.tbl.bells .ps { width: 7px; }
.tbl.bells .pl { width: 16px; }
.tbl.arrows td { white-space: nowrap; }
.flag .ic { width: 28px; height: 28px; }
.flag.big .ic { width: 44px; height: 44px; }
.myflag { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 10px 12px; margin-bottom: 12px; background: #fff7e6; border: 2px dashed #b59d72; border-radius: 12px; }

/* отсчёт и окна */
.countdown { position: fixed; inset: 0; display: none; place-items: center; z-index: 20; font: 700 120px Georgia, serif; color: var(--brass2); background: #000a; }
.countdown.on { display: grid; }
.overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: #000b; overflow-y: auto; }
.overlay.soft { background: #0008; }
.card { background: var(--panel); border: 1px solid var(--brass); border-radius: 18px; padding: 22px 18px; max-width: 460px; width: 100%; text-align: center; }
.card.end h2 { font-size: 28px; color: var(--brass2); margin-bottom: 10px; }
.card.lost h2 { color: #ff9b8f; }
.lamps { display: flex; justify-content: center; gap: 10px; margin: 6px 0 10px; }
.biglamp { color: #5a4a3a; }
.biglamp .ic { width: 52px; height: 52px; }
.biglamp.on { color: #ffcf4a; filter: drop-shadow(0 0 10px #ffa500); }
.meta { color: var(--muted); }
.story { text-align: left; line-height: 1.55; }

body.sparked .play { animation: shake .4s; }
body.sparked::after { content: ""; position: fixed; inset: 0; pointer-events: none; background: #ff6a0055; animation: flash .45s forwards; z-index: 40; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
@keyframes flash { to { opacity: 0; } }

/* компьютер: все модули сразу, без вкладок */
@media (min-width: 900px) {
  .tabs { display: none; }
  .play { padding-bottom: 24px; }
  .panels { max-width: 1180px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 22px; padding: 22px; }
  .panel { display: block; }
  .bar { padding: 12px 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::after { animation-duration: .01s !important; transition-duration: .01s !important; }
}

/* ---------- этап 2: главы, режимы, голос, чат ---------- */
.emblem { display: flex; justify-content: center; }
.emblem .k1 { transform: rotate(-35deg) translateX(8px); }
.emblem .k2 { transform: rotate(35deg) scaleX(-1) translateX(8px); margin-left: -18px; color: var(--brass2); }
.sect { font-size: 18px; color: var(--muted); margin: 6px 0 -4px; }
.chlist { display: flex; flex-direction: column; gap: 8px; }
.chitem { display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 12px; border-radius: 12px; border: 1.5px solid #4a3a2a; background: var(--bg2); cursor: pointer; min-height: 56px; }
.chitem.cur { border-color: var(--brass); background: #3a2d1f; box-shadow: 0 0 0 1px var(--brass) inset; }
.chitem.shut { opacity: .5; cursor: default; }
.chn { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: #4a3a2a; color: var(--brass2); font: 700 16px Georgia, serif; }
.chitem.cur .chn { background: var(--brass); color: #2a1d0c; }
.cht { flex: 1; display: flex; flex-direction: column; }
.cht small { color: var(--muted); font-size: 13px; }
.chl { display: flex; gap: 3px; }
.chl i { width: 10px; height: 10px; border-radius: 50%; background: #4a3b2c; }
.chl i.on { background: #ffcf4a; box-shadow: 0 0 6px #ffa500; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left; padding: 12px; border-radius: var(--r); border: 1.5px solid #4a3a2a; background: var(--bg2); color: var(--brass); cursor: pointer; }
.mode b { color: var(--ink); }
.mode small { color: var(--muted); line-height: 1.3; }
.mode.cur { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass) inset; }
.lobby-tools { display: flex; justify-content: center; gap: 10px; }
.ibtn { position: relative; width: 42px; height: 42px; border-radius: 50%; border: 0; display: grid; place-items: center; background: #2f241a; color: var(--brass2); cursor: pointer; font-size: 22px; flex: none; }
.ibtn.mic.on { background: #2f6a3a; color: #dfffe4; }
.ibtn.mic.busy { opacity: .6; }
.ibtn .badge { position: absolute; top: -3px; right: -3px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--red); color: #fff; font: 700 11px/18px system-ui; font-style: normal; padding: 0 4px; }
.ibtn .pdot { position: absolute; bottom: 1px; right: 1px; width: 11px; height: 11px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 2px #15100c; }
.bar .tools { display: flex; gap: 6px; }
.bar .timer.notimer { font: 600 16px Georgia, serif; color: var(--brass2); letter-spacing: 0; }
.tab .mlamp { display: grid; place-items: center; font: 700 9px/1 system-ui; font-style: normal; color: #0b2410; }
.tab.done .mlamp { width: 14px; height: 14px; top: 3px; right: calc(50% - 24px); }
.endbtns { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.prog { text-align: left; background: var(--bg2); border-radius: 12px; padding: 10px 14px; color: var(--muted); }
.prog summary { cursor: pointer; color: var(--brass2); }
.prog p { margin: 8px 0; font-size: 14px; }
.pcode { display: block; font: 700 26px Georgia, serif; letter-spacing: .2em; color: var(--ink); margin-bottom: 10px; }
.toast { z-index: 60; }
.panel.fx-spark .pbody { animation: modshake .45s; }
.panel.fx-solved .pbody { animation: modglow .9s; }
@keyframes modshake { 15% { transform: translateX(-10px) rotate(-1deg); } 35% { transform: translateX(9px) rotate(1deg); } 55% { transform: translateX(-6px); } 75% { transform: translateX(3px); } }
@keyframes modglow { 30% { box-shadow: 0 0 0 3px var(--green) inset, 0 0 40px #4fae6199; } }
/* чат: снизу на телефоне, справа на компьютере */
.chat { position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; max-height: 70vh; display: flex; flex-direction: column; background: #1a130ef7; border-top: 1px solid var(--brass); border-radius: 16px 16px 0 0; padding: 10px 14px calc(12px + env(safe-area-inset-bottom)); transform: translateY(105%); transition: transform .25s; }
.chat.open { transform: none; }
.chat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; color: var(--brass2); }
.chat-log { flex: 1; overflow-y: auto; min-height: 80px; max-height: 34vh; display: flex; flex-direction: column; gap: 6px; }
.chat-log p { margin: 0; padding: 6px 10px; border-radius: 10px; background: #2f241a; max-width: 85%; word-break: break-word; }
.chat-log p.mine { align-self: flex-end; background: #4a3a22; }
.chat-log b { color: var(--brass2); font-size: 13px; display: block; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.qbtn { border: 1px solid #5a4630; background: none; color: var(--ink); border-radius: 16px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { min-height: 44px; }
.chat-form .btn { min-height: 44px; }
@media (min-width: 900px) {
  .chat { left: auto; right: 18px; bottom: 18px; width: 360px; border: 1px solid var(--brass); border-radius: 16px; transform: translateX(120%); }
}
@media (max-width: 380px) {
  .bar { padding: 8px 10px; gap: 6px; }
  .bar .rl { display: none; }
  .timer { font-size: 22px; }
  .ibtn { width: 36px; height: 36px; }
}

/* картинки мест */
.home { padding-top: 16px; }
.cover { width: 100%; height: auto; aspect-ratio: 800 / 446; border-radius: 16px; display: block; box-shadow: 0 10px 30px #0008; background: var(--bg2); }
.chapter-card { padding: 0; overflow: hidden; }
.chimg { width: 100%; height: auto; aspect-ratio: 480 / 268; display: block; object-fit: cover; background: var(--bg2); }
.cc-text { padding: 12px 16px 14px; }
.card.end .chimg { border-radius: 12px; margin-bottom: 12px; }
.card.end { max-height: calc(100vh - 32px); overflow-y: auto; }
.story-h { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); text-align: left; margin: 14px 0 4px; font-family: system-ui, sans-serif; }

/* лента глав */
.chstrip { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: 16px; margin: 0 -16px; padding: 4px 16px 8px; scrollbar-width: none; }
.chstrip::-webkit-scrollbar { display: none; }
.chtile { position: relative; flex: 0 0 62%; max-width: 240px; scroll-snap-align: start; border: 2px solid #4a3a2a; border-radius: 14px; overflow: hidden; padding: 0; background: var(--bg2); cursor: pointer; text-align: left; }
.chtile img { display: block; width: 100%; height: auto; aspect-ratio: 480 / 268; object-fit: cover; }
.chtile.cur { border-color: var(--brass2); box-shadow: 0 0 0 2px var(--brass) inset, 0 6px 18px #0008; }
.chtile.shut { cursor: default; }
.chtile.shut img { filter: grayscale(1) brightness(.45); }
.chtile .chn { position: absolute; top: 8px; left: 8px; }
.chtile .chl { position: absolute; top: 12px; right: 10px; }
.chtile .cht { display: flex; flex-direction: column; padding: 8px 10px 10px; }
.chtile .cht b { font-size: 15px; line-height: 1.2; }
@media (min-width: 560px) { .chtile { flex-basis: 40%; } }
.langs { display: flex; justify-content: center; gap: 6px; }
.langs a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.langs a.cur { color: #2a1d0c; background: var(--brass); }
/* сцена победы не должна раздвигать страницу; длинная карточка прокручивается целиком */
.scene { overflow: hidden; border-radius: 12px; max-width: 100%; }
.overlay { overflow-x: hidden; place-items: start center; }
.overlay > .card { margin: auto 0; }
.card.end { max-height: none; overflow: visible; }
html, body { overflow-x: hidden; }
.privacy { color: var(--muted); font-size: 13px; text-align: center; margin-top: -6px; }
.home .back { margin-top: 8px; }
.cmark { width: 64%; height: 64%; display: block; pointer-events: none; }
.cdot .cmark { width: 66%; height: 66%; }
.chtile .noimg { display: grid; place-items: center; aspect-ratio: 480 / 268; background: radial-gradient(#3a2d20, #1d1712); color: #5a4630; }
.finale { font-family: Georgia, serif; font-size: 18px; color: var(--brass2); }

/* цифры в таблицах наставления одной высоты (Georgia по умолчанию рисует «старые» цифры) */
.as-keeper .pbody, .tbl, .tbl .num { font-variant-numeric: lining-nums tabular-nums; }
