/* Пряничный след — сумеречная рамка цвета Таниной шляпки вокруг книжных иллюстраций.
   Ночь-индиго, морозные панели-«открытки», медовые акценты пряников. Один осознанный тёмный образ. */
:root {
  --night: #131736;
  --night-2: #1b2150;
  --night-3: #2a3270;
  --frost: #eef2ff;
  --frost-2: #dde5fb;
  --frost-3: #c5d1f4;
  --ink: #221e4a;
  --ink-soft: #5a5884;
  --cap: #5b8ee0;
  --cap-deep: #3a63b8;
  --gem: #6d4bd2;
  --gem-soft: #b8a5f4;
  --honey: #d98a3d;
  --honey-deep: #a35d27;
  --honey-soft: #f7ddb6;
  --moss: #3f9460;
  --berry: #c9475f;
  --paper: #fffaf0;
  --font-display: 'Kurale', Georgia, 'Times New Roman', serif;
  --font-body: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-hand: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(120% 90% at 50% -20%, var(--night-3), var(--night) 62%) var(--night);
  color: var(--frost);
  font: 500 16px/1.45 var(--font-body);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--honey); outline-offset: 2px; }
.muted { color: var(--ink-soft); }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 8px 18px; border-radius: 999px; border: 0;
  background: var(--cap); color: #fff; font-weight: 800; letter-spacing: .01em;
  cursor: pointer; box-shadow: 0 3px 0 var(--cap-deep);
  transition: transform .12s, box-shadow .12s, background .2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--cap-deep); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.honey { background: var(--honey); box-shadow: 0 3px 0 var(--honey-deep); }
.btn.ghost { background: transparent; color: var(--cap-deep); box-shadow: inset 0 0 0 2px var(--frost-3); }
.btn.ghost:hover { background: rgba(91, 142, 224, .1); }
.btn.danger { background: var(--berry); box-shadow: 0 3px 0 #8f2b3e; }
.btn.small { min-height: 34px; padding: 5px 14px; font-size: 14px; }
.btn.big { min-height: 52px; padding: 10px 28px; font-size: 18px; }
.btn.round { width: 46px; padding: 0; font-size: 22px; }

/* ---------- каркас ---------- */
#game {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
#hud {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-block: 8px 6px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.hud-loc { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
#loc-chapter { font: 700 12px/1 var(--font-body); letter-spacing: .14em; text-transform: uppercase; color: var(--gem-soft); white-space: nowrap; }
#loc-name { font: 400 22px/1.1 var(--font-display); color: var(--frost); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-btns { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
.hbtn {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px;
  border: 0; border-radius: 12px; background: rgba(238, 242, 255, .08); color: var(--frost);
  font-weight: 700; font-size: 14px; cursor: pointer; transition: background .2s, transform .12s;
}
.hbtn:hover { background: rgba(238, 242, 255, .16); }
.hbtn svg { width: 20px; height: 20px; flex: none; }
.hbtn.icon-only { width: 38px; padding: 0; justify-content: center; }
.hbtn.off { color: #8c92b8; }
.hbtn.off .slash { display: block; }
.hbtn .slash { display: none; }
.hcount { display: inline-flex; align-items: center; gap: 4px; height: 38px; padding: 0 10px; border-radius: 12px; background: rgba(224, 72, 72, .14); font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; }
.hcount svg { width: 22px; height: 22px; }
.pulse { animation: pulse .6s ease; }
@keyframes pulse { 40% { transform: scale(1.18); } }

#viewport {
  flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center;
  padding-block: 4px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
#stage {
  position: relative; border-radius: 18px; overflow: hidden; background: #0d1028;
  box-shadow: 0 22px 60px rgba(4, 6, 24, .55), 0 0 0 1px rgba(255, 255, 255, .07);
}
#scene, .scene-svg { display: block; width: 100%; height: 100%; }
#fade { position: absolute; inset: 0; background: #0d1028; opacity: 0; pointer-events: none; transition: opacity .3s; }
#fade.on { opacity: 1; }
#tip {
  position: absolute; transform: translate(-50%, calc(-100% - 16px)); pointer-events: none;
  padding: 5px 12px; border-radius: 10px; background: rgba(19, 23, 54, .88); color: #fff;
  font-weight: 700; font-size: 14px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
}

/* активные зоны */
.hs { fill: transparent; stroke: transparent; stroke-width: 4; cursor: pointer; pointer-events: all; transition: stroke .2s, fill .2s; }
.hs:hover, .hs:focus-visible { stroke: rgba(255, 255, 255, .9); stroke-dasharray: 12 9; fill: rgba(255, 255, 255, .08); outline: none; }
.hs-layer.reveal .hs { stroke: #ffe7a0; stroke-dasharray: 12 9; fill: rgba(255, 231, 160, .14); animation: march 1s linear infinite; }
@keyframes march { to { stroke-dashoffset: -42; } }
.exit-badge { cursor: pointer; }
.exit-badge .eb-bg { fill: rgba(19, 23, 54, .62); stroke: #fff; stroke-width: 3; transition: fill .2s; }
.exit-badge .eb-arrow { fill: none; stroke: #fff; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.exit-badge .eb-label { fill: #fff; font: 800 26px var(--font-body); text-anchor: middle; paint-order: stroke; stroke: rgba(19, 23, 54, .75); stroke-width: 7px; stroke-linejoin: round; }
.exit-badge:hover .eb-bg, .exit-badge:focus-visible .eb-bg { fill: var(--honey); }
.exit-badge:focus-visible { outline: none; }
.hm { cursor: pointer; }
.hm-hit { fill: transparent; pointer-events: all; }
.hm.got { animation: got .5s ease forwards; transform-box: fill-box; transform-origin: center; }
@keyframes got { to { transform: translateY(-40px) scale(1.6); opacity: 0; } }

.twinkle { animation: twinkle 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes twinkle { 50% { opacity: .25; transform: scale(.7); } }
.flicker { animation: flicker 3.2s steps(1) infinite; }
@keyframes flicker { 0%, 100% { opacity: .55; } 8% { opacity: 1; } 10% { opacity: .5; } 52% { opacity: .9; } 54% { opacity: .55; } }
.jet { animation: jet 1.2s linear infinite; }
@keyframes jet { to { stroke-dashoffset: -36; } }
.notes-float text { animation: bob 2.6s ease-in-out infinite; }
.notes-float text:nth-child(2) { animation-delay: -.9s; }
.notes-float text:nth-child(3) { animation-delay: -1.7s; }
@keyframes bob { 50% { transform: translateY(-10px); } }
.wave { animation: wave 1s ease-in-out infinite; }
@keyframes wave { 50% { transform: rotate(-28deg); } }

/* ---------- инвентарь ---------- */
#invbar {
  display: flex; align-items: center; gap: 12px; height: 86px; flex: none;
  padding-block: 6px 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
#inv { display: flex; gap: 8px; overflow-x: auto; flex: 1; min-width: 0; padding: 6px 2px; scrollbar-width: thin; }
.inv-empty { color: #9aa1c9; font-size: 14px; padding: 8px 4px; }
.slot {
  position: relative; flex: none; width: 64px; height: 64px; padding: 6px; border-radius: 16px; cursor: pointer;
  border: 2px solid rgba(238, 242, 255, .12); background: linear-gradient(180deg, rgba(238, 242, 255, .14), rgba(238, 242, 255, .05));
  transition: transform .15s, border-color .2s, background .2s;
}
.slot svg { width: 100%; height: 100%; display: block; }
.slot:hover { transform: translateY(-2px); border-color: rgba(238, 242, 255, .35); }
.slot.sel { border-color: var(--honey); background: linear-gradient(180deg, rgba(217, 138, 61, .35), rgba(217, 138, 61, .12)); transform: translateY(-4px); }
.slot.flash { animation: flash .9s ease; }
@keyframes flash { 30% { transform: scale(1.2); box-shadow: 0 0 0 6px rgba(247, 221, 182, .45); } }
.slot-badge { position: absolute; right: -6px; top: -6px; min-width: 30px; padding: 1px 6px; border-radius: 99px; background: var(--honey); color: #fff; font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; }
/* плашка выбранной вещи помещается в высоту панели и не раздвигает её */
#selinfo {
  flex: 0 1 560px; min-width: 0; max-height: 66px; overflow: hidden; display: flex; align-items: center; gap: 12px;
  padding: 7px 10px 7px 14px; border-radius: 16px; background: var(--frost); color: var(--ink);
}
.si-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; font-size: 13.5px; line-height: 1.3; }
.si-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.si-head b { flex: none; font-family: var(--font-display); font-weight: 400; font-size: 17px; line-height: 1.15; }
.si-head small { min-width: 0; color: var(--ink-soft); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.si-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.si-btns { display: flex; gap: 6px; flex: none; }

/* ---------- диалоги ---------- */
#dialog {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: linear-gradient(180deg, transparent 55%, rgba(10, 12, 32, .45));
  cursor: pointer;
}
.dlg-box {
  position: relative; width: min(980px, 100%); display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: end;
  padding: 14px 22px 16px 14px; border-radius: 24px; background: var(--frost); color: var(--ink);
  box-shadow: 0 18px 50px rgba(4, 6, 24, .5), inset 0 0 0 3px var(--who);
  animation: rise .25s ease;
}
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
#dialog.side-right .dlg-box { grid-template-columns: 1fr auto; padding: 14px 14px 16px 22px; }
#dialog.side-right .dlg-portrait { order: 2; }
#dialog.is-narr .dlg-box { grid-template-columns: 1fr; padding: 18px 26px; }
.dlg-portrait {
  width: 150px; height: 162px; margin-top: -64px; border-radius: 22px; overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #fff, var(--frost-2)); box-shadow: 0 0 0 4px var(--who), 0 10px 24px rgba(4, 6, 24, .35);
}
.dlg-portrait svg { width: 100%; height: 100%; display: block; }
.dlg-body { min-width: 0; align-self: center; }
.dlg-name { font: 400 22px/1.1 var(--font-display); color: var(--who); margin-bottom: 4px; }
.dlg-text { margin: 0; min-height: 3em; font-size: 19px; line-height: 1.5; font-weight: 600; text-wrap: pretty; }
#dialog.is-narr .dlg-text { font-style: italic; font-weight: 500; color: var(--ink-soft); }
.dlg-choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.dlg-choices:empty { display: none; }
.dlg-more { position: absolute; right: 22px; bottom: 10px; width: 0; height: 0; border: 8px solid transparent; border-top-color: var(--who); opacity: 0; }
#dialog.done .dlg-more { opacity: 1; animation: nudge 1s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(4px); } }

/* ---------- модальные окна ---------- */
#modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  padding-block: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: rgba(9, 11, 30, .62); backdrop-filter: blur(5px);
}
.mbox {
  width: min(760px, 100%); max-height: calc(100dvh - 24px); overflow: auto;
  background: var(--frost); color: var(--ink); border-radius: 26px; padding: 16px 22px 22px;
  box-shadow: 0 30px 80px rgba(4, 6, 24, .6); animation: rise .22s ease;
}
.mbox.wide { width: min(1040px, 100%); }
.mhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.mtitle { margin: 0; font: 400 26px/1.15 var(--font-display); color: var(--ink); text-wrap: balance; }
.mclose { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--frost-2); color: var(--ink); font-size: 18px; cursor: pointer; }
.mclose:hover { background: var(--frost-3); }
.mbody h3 { margin: 0 0 8px; font: 400 20px var(--font-display); color: var(--cap-deep); }
.pz-done { margin-top: 14px; padding: 12px 16px; border-radius: 16px; background: #e5f4ea; color: #1f5a36; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; animation: rise .25s ease; }
.pz-done p { margin: 0; font-weight: 700; }
.vw-actions { display: flex; justify-content: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.vw-cap { text-align: center; color: var(--ink-soft); margin: 12px auto 0; max-width: 52ch; }

.paper {
  background: var(--paper); border-radius: 6px; padding: 14px 18px;
  box-shadow: 0 1px 0 #e8dcc0, 0 8px 22px rgba(60, 40, 10, .12); color: #3a2f6a;
  background-image: repeating-linear-gradient(180deg, transparent 0 29px, rgba(122, 111, 184, .14) 29px 30px);
}
.paper.big { padding: 20px 24px; }
.paper-label { font: 700 12px/1 var(--font-body); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); margin: 6px 0 6px; }
.paper ol, .paper ul { margin: 6px 0; padding-left: 1.3em; }
.paper .sign, .paper .ps { font-family: var(--font-hand); font-size: 22px; text-align: right; margin: 4px 0 0; }
.paper p, .paper li { font-family: var(--font-hand); font-size: 22px; line-height: 1.3; }
.np-cipher, .np-plain { font-family: var(--font-hand); font-size: 24px; line-height: 1.35; letter-spacing: .03em; margin: 0; word-break: break-word; }
.np-plain { color: var(--ink-soft); min-height: 4em; }
.np-plain.ok { color: #1f5a36; }
.np-doodle { width: 130px; height: 48px; display: block; margin-top: 6px; }

/* шифровальный круг */
.cw { display: grid; grid-template-columns: minmax(240px, 400px) 1fr; gap: 22px; align-items: start; }
.cw-disk { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.cw-svg { width: 100%; max-width: 400px; touch-action: none; cursor: grab; user-select: none; }
.cw-o { fill: #f2e2bf; stroke: #a87e45; stroke-width: 3; }
.cw-i { fill: #dab77d; stroke: #a87e45; stroke-width: 3; }
.cw-hub { fill: #c49a5e; stroke: #a87e45; stroke-width: 2; }
.cw-l { font: 400 24px var(--font-display); fill: #4a3214; }
.cw-l2 { font: 400 22px var(--font-display); fill: #3a2410; }
.cw-btns { display: flex; align-items: center; gap: 12px; }
.cw-side { min-width: 0; display: flex; flex-direction: column; gap: 6px; }

/* часы */
.clk { display: grid; grid-template-columns: minmax(220px, 320px) 1fr; gap: 22px; align-items: center; }
.clk-svg { width: 100%; touch-action: none; cursor: grab; user-select: none; }
.clk-svg.pop { animation: pulse .5s ease; }
.clk-ctrl { display: flex; flex-direction: column; gap: 10px; }
.clk-row { display: flex; gap: 8px; flex-wrap: wrap; }
.clk-read { margin: 6px 0 0; font-size: 18px; }
.clk-read b { font: 400 26px var(--font-display); font-variant-numeric: tabular-nums; }

/* телефон */
.pz-phone { width: min(420px, 100%); }
.phone { margin: 0 auto; width: min(320px, 100%); padding: 12px; border-radius: 40px; background: #1d2140; box-shadow: inset 0 0 0 3px #5a6190; }
.ph-screen { border-radius: 30px; overflow: hidden; background: linear-gradient(180deg, #2b3176, #171a45); color: #eef2ff; padding: 14px 14px 18px; min-height: 520px; display: flex; flex-direction: column; }
.ph-status { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 700; }
.ph-bat { width: 26px; height: 12px; border-radius: 3px; border: 2px solid #eef2ff; position: relative; overflow: hidden; }
.ph-bat i { position: absolute; inset: 0 auto 0 0; background: #ff8a8a; }
.ph-lock { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: 1; }
.ph-time { font: 400 54px/1 var(--font-display); margin-top: 18px; }
.ph-date { font-size: 14px; color: #c9cff5; }
.ph-grid { width: 240px; height: 240px; margin-top: 12px; touch-action: none; user-select: none; }
.ph-dot { fill: rgba(238, 242, 255, .25); stroke: #eef2ff; stroke-width: 2; transition: fill .15s; }
.ph-dot.on { fill: #f6e7a4; }
.ph-line, .ph-live { fill: none; stroke: #f6e7a4; stroke-width: 8; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.ph-grid.bad .ph-line { stroke: #ff8a8a; }
.ph-grid.bad { animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.ph-hint { font-size: 14px; color: #c9cff5; text-align: center; margin-top: 6px; }
.ph-msg { min-height: 1.4em; color: #ffb3b3; font-weight: 700; font-size: 14px; text-align: center; }
.ph-app { flex: 1; display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.ph-apphead { font: 400 22px var(--font-display); }
.ph-note { background: #fffaf0; color: #3a2f6a; border-radius: 14px; padding: 10px 14px; }
.ph-note h4 { margin: 0 0 4px; font-family: var(--font-hand); font-size: 22px; }
.ph-note ul { margin: 0; padding: 0; list-style: none; font-family: var(--font-hand); font-size: 19px; line-height: 1.25; }
.ph-note li::before { content: '☐ '; }
.ph-note li.ok::before { content: '☑ '; color: var(--moss); }
.ph-photo { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #c9cff5; }
.ph-photo svg { width: 90px; height: 88px; border-radius: 10px; flex: none; }
.ph-warn { font-size: 13px; color: #ffb3b3; font-weight: 700; }
.ph-close { margin-top: 10px; }

/* кроссворд */
.cr { display: grid; grid-template-columns: auto 1fr; gap: 22px; align-items: start; }
.cr-grid { display: grid; grid-template-columns: repeat(var(--cols), 40px); gap: 3px; }
.cell { position: relative; width: 40px; height: 40px; border-radius: 6px; background: #fff; box-shadow: inset 0 0 0 2px var(--frost-3); display: grid; place-items: center; cursor: pointer; }
.cell.void { background: transparent; box-shadow: none; cursor: default; }
.cell span { font: 400 24px var(--font-display); color: var(--ink); }
.cell i { position: absolute; left: 3px; top: 1px; font-style: normal; font-size: 10px; font-weight: 800; color: var(--ink-soft); }
.cell.key { background: var(--honey-soft); }
.cell.row { box-shadow: inset 0 0 0 2px var(--cap); }
.cell.cur { box-shadow: inset 0 0 0 3px var(--honey); background: #fff4e3; }
.cell.ok { background: #e2f3e7; }
.cell.key.ok { background: #f4d6a7; }
.cell.glow { animation: glow 1s ease forwards; }
@keyframes glow { 50% { transform: scale(1.18); } to { background: var(--honey); } }
.cell.glow span { color: #fff; }
.cr-clues { margin: 0; padding-left: 1.4em; display: flex; flex-direction: column; gap: 6px; }
.cr-clues li { padding: 4px 8px; border-radius: 10px; cursor: pointer; line-height: 1.35; }
.cr-clues li.on { background: #e8eefc; }
.kb { margin-top: 14px; display: flex; flex-direction: column; gap: 5px; align-items: center; }
.kb-row { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.kb-k { min-width: 36px; height: 40px; padding: 0 6px; border: 0; border-radius: 8px; background: #fff; box-shadow: 0 2px 0 var(--frost-3); font: 400 19px var(--font-display); color: var(--ink); cursor: pointer; }
.kb-k:active { transform: translateY(2px); box-shadow: none; }
.kb-k.wide { padding: 0 18px; font: 700 15px var(--font-body); }
.cr-tip { text-align: center; font-size: 13px; margin: 8px 0 0; }

/* замок */
.pz-lock { width: min(560px, 100%); }
.pz-lock .mbody { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; justify-content: center; }
.lk { display: flex; flex-direction: column; align-items: center; padding-top: 30px; }
.lk-shackle { width: 160px; height: 88px; margin-bottom: -16px; transition: transform .45s cubic-bezier(.3, 1.6, .5, 1); }
.lk.open .lk-shackle { transform: translateY(-26px); }
.lk-body { display: flex; gap: 10px; padding: 18px 18px; border-radius: 22px; background: linear-gradient(180deg, #f0cd6a, #c99a2a); box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .12); }
.dial { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dial-btn { width: 52px; height: 34px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .55); color: #6a4a10; font-size: 16px; cursor: pointer; }
.dial-btn:hover { background: rgba(255, 255, 255, .8); }
.dial-win { width: 52px; height: 62px; border-radius: 10px; background: #2b2b33; display: grid; place-items: center; box-shadow: inset 0 4px 10px rgba(0, 0, 0, .5); }
.dial-win span { font: 400 36px var(--font-display); color: #f6e7a4; font-variant-numeric: tabular-nums; }
.dial-win.roll span { animation: roll .18s ease; }
@keyframes roll { from { transform: translateY(-40%); opacity: .2; } }
.lk-side { flex: 1 1 200px; min-width: 0; }
.lk-clues { margin: 6px 0 0; padding-left: 1.3em; }
.pz-lock .pz-done { flex-basis: 100%; }

/* банки */
.jr { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: center; }
.jr-svg { width: 100%; }
.jar { cursor: pointer; transition: transform .2s; }
.jar.sel rect:first-child { stroke: var(--honey); stroke-width: 4; }
.jar:focus-visible { outline: none; }
.jar:focus-visible > g > rect:first-child { stroke: var(--honey); stroke-width: 4; }
.jr-svg.solved .jar-letter { animation: popin .5s ease both; }
.jr-svg.solved .jar:nth-of-type(2) .jar-letter { animation-delay: .12s; }
.jr-svg.solved .jar:nth-of-type(3) .jar-letter { animation-delay: .24s; }
.jr-svg.solved .jar:nth-of-type(4) .jar-letter { animation-delay: .36s; }
.jr-svg.solved .jar:nth-of-type(5) .jar-letter { animation-delay: .48s; }
@keyframes popin { from { opacity: 0; transform: translateY(10px); } }
.jr-poem ol { padding-left: 1.2em; }
.jr-poem li { font-size: 20px; margin: 2px 0; }
.jr-tip { text-align: center; margin: 10px 0 0; }

/* весы */
.sc { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.sc-svg { width: min(600px, 100%); }
.sc-tray { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ck { width: 64px; padding: 4px 4px 2px; border-radius: 14px; border: 2px solid var(--frost-3); background: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; transition: transform .15s, border-color .2s; }
.ck svg { width: 46px; height: 46px; }
.ck small { font-size: 11px; font-weight: 800; height: 14px; color: var(--ink-soft); }
.ck.l { border-color: var(--cap); background: #e8f0ff; }
.ck.r { border-color: var(--honey); background: #fff2e2; }
.ck.pick { animation: pick 1s ease-in-out infinite; }
@keyframes pick { 50% { transform: translateY(-4px); } }
.sc-ctrl { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
#sc-pick.on { background: var(--berry); box-shadow: 0 3px 0 #8f2b3e; }
.sc-msg { margin: 0; text-align: center; font-weight: 700; min-height: 1.5em; max-width: 60ch; }
.sc-log { margin: 0; padding-left: 1.4em; font-size: 14px; color: var(--ink-soft); align-self: stretch; }

/* поющие грибы */
.ml-svg { width: 100%; display: block; border-radius: 18px; }
.mush { cursor: pointer; }
.mush.bounce { animation: boing .42s ease; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes boing { 30% { transform: scale(1.06, .9); } 60% { transform: scale(.96, 1.06); } }
.mush:focus-visible { outline: none; }
.mush:focus-visible path:last-of-type { stroke: var(--honey); stroke-width: 4; }
.fly-note { font: 400 34px var(--font-display); fill: var(--gem); animation: fly 1.2s ease-out forwards; }
@keyframes fly { to { transform: translate(18px, -70px); opacity: 0; } }
.ml-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.ml-played { display: flex; gap: 6px; }
.ml-played .dot { width: 22px; height: 22px; border-radius: 50%; background: var(--frost-2); box-shadow: inset 0 0 0 2px var(--frost-3); }

/* провода */
.pz-wires { width: min(720px, 100%); }
.wr-svg { width: 100%; display: block; }
.tile { cursor: pointer; }
.tile-bg { fill: #384062; stroke: #4c557d; stroke-width: 2; }
.tile:hover .tile-bg, .tile:focus-visible .tile-bg { fill: #434c75; }
.tile:focus-visible { outline: none; }
.w-line { stroke: #8a93b8; stroke-width: 14; stroke-linecap: round; fill: none; }
.w-node { fill: #8a93b8; }
.tile.on .w-line, .w-line.on { stroke: #ffd25a; }
.tile.on .w-node { fill: #ffd25a; }
#wr-motor.spin .gear { animation: spin 1.2s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* пульт */
.pn { display: grid; grid-template-columns: minmax(250px, 320px) 1fr; gap: 20px; align-items: start; }
.pn-left { padding: 16px; border-radius: 22px; background: #3a4260; box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .2); }
.pn-screen { padding: 10px 12px; border-radius: 12px; background: #0f1a12; box-shadow: inset 0 0 0 3px #26332a; }
.pn-label { font: 800 12px/1 var(--font-body); letter-spacing: .18em; color: #7be07b; opacity: .8; }
.pn-digits { display: flex; gap: 8px; margin-top: 8px; }
.pn-digits span { flex: 1; height: 50px; border-radius: 8px; background: #16261a; display: grid; place-items: center; font: 400 34px var(--font-display); color: #9fffa0; font-variant-numeric: tabular-nums; }
.pn-digits.ok span { background: #2c6b37; color: #fff; }
.pn-digits.bad { animation: shake .4s; }
.pn-digits.bad span { color: #ff8a8a; }
.pn-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.pn-k { height: 52px; border: 0; border-radius: 12px; background: #e8eefc; color: var(--ink); font: 400 24px var(--font-display); cursor: pointer; box-shadow: 0 3px 0 #9aa6cc; }
.pn-k:active { transform: translateY(3px); box-shadow: none; }
.pn-k.go { background: #4fb35f; color: #fff; font: 800 16px var(--font-body); box-shadow: 0 3px 0 #2c6b37; }
.pn-k.cl { background: #f2c94c; box-shadow: 0 3px 0 #a9842e; }
.pn-right { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.sticky { align-self: flex-start; max-width: 340px; padding: 12px 16px; background: #fff59a; color: #4a3d10; font: 600 22px/1.25 var(--font-hand); transform: rotate(-2deg); box-shadow: 0 6px 16px rgba(60, 50, 10, .2); }
.pn-window { border-radius: 16px; overflow: hidden; box-shadow: inset 0 0 0 6px #a9845a; max-width: 360px; }
.pn-window svg { width: 100%; display: block; }
.pn-ginger { display: flex; gap: 10px; flex-wrap: wrap; }
.pn-ginger figure { margin: 0; display: flex; flex-direction: column; align-items: center; }
.pn-ginger svg { width: 64px; height: 64px; }
.pn-ginger figcaption { font: 400 20px/1 var(--font-display); color: var(--honey-deep); }

/* крупные планы */
.flip { perspective: 1200px; max-width: 560px; margin: 0 auto; }
.flip-in { position: relative; transition: transform .7s; transform-style: preserve-3d; }
.flip.flipped .flip-in { transform: rotateY(180deg); }
.flip-face { backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip-face.back { position: absolute; inset: 0; transform: rotateY(180deg); }
.polaroid { background: #fff; padding: 14px 14px 10px; border-radius: 6px; box-shadow: 0 12px 30px rgba(20, 20, 60, .25); height: 100%; }
.polaroid svg { width: 100%; display: block; border-radius: 3px; }
.polaroid > span { display: block; text-align: center; font: 700 26px var(--font-hand); color: #3a2f6a; margin-top: 4px; }
.polaroid.back { display: flex; flex-direction: column; justify-content: center; gap: 6px; padding: 26px; background: #fffaf0; }
.polaroid.back p { margin: 0; font: 600 26px/1.3 var(--font-hand); color: #3a2f6a; }
.polaroid.back .ps { color: var(--berry); }
.mirror { width: min(300px, 80%); margin: 0 auto; padding: 14px; border-radius: 50%; background: linear-gradient(135deg, #e2c27a, #a9843e); }
.mirror-glass { border-radius: 50%; overflow: hidden; aspect-ratio: 3 / 4; max-width: 100%; background: linear-gradient(135deg, #f3f7ff, #b9c9ea); display: grid; place-items: center; }
.mirror-glass svg { width: 120%; transform: scaleX(-1) translateY(4%); }
.mbx svg, .inv-card svg, .wheel-close svg { width: 100%; display: block; }
.mbx { max-width: 560px; margin: 0 auto; }
.mbx .mb-note { transition: transform .2s; transform-box: fill-box; transform-origin: center; }
.mbx .mb-note.on { transform: scale(1.5); }
.mbx .mb-note.on path { fill: #ffe27a; }
.mbx svg.playing .mb-dancer { animation: spin 1.4s linear infinite; transform-box: fill-box; transform-origin: center; }
.inv-card { max-width: 520px; margin: 0 auto; }
.wheel-close { max-width: 480px; margin: 0 auto; border-radius: 18px; overflow: hidden; }
.sign-svg { width: 100%; max-width: 560px; display: block; margin: 0 auto; }
.pc { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.pc-front svg { width: 100%; display: block; border-radius: 10px; box-shadow: 0 10px 26px rgba(20, 20, 60, .2); }
.news { background: #f6f2e8; color: #2b2a2a; padding: 18px 22px; border-radius: 6px; box-shadow: 0 10px 26px rgba(20, 20, 60, .18); }
.news header { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 3px double #2b2a2a; padding-bottom: 6px; gap: 12px; flex-wrap: wrap; }
.news h3 { margin: 0; font: 400 34px var(--font-display); color: #2b2a2a; }
.news header span { font-size: 13px; color: #6b6660; }
.news h4 { margin: 12px 0 6px; font: 400 24px/1.2 var(--font-display); text-wrap: balance; }
.news p { margin: 0 0 8px; max-width: 65ch; }
.news aside { margin-top: 10px; padding: 10px 12px; border: 2px dashed #6b6660; border-radius: 8px; font-size: 15px; }
.poster { max-width: 420px; margin: 0 auto; padding: 24px; border-radius: 12px; background: linear-gradient(160deg, #f08a3c, #d9475f); color: #fff; text-align: center; box-shadow: 0 12px 30px rgba(120, 40, 20, .3); }
.poster h3 { margin: 0; font: 400 32px/1.1 var(--font-display); color: #fff; text-wrap: balance; }
.poster .when { margin: 6px 0 14px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; font-size: 13px; }
.poster ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 17px; }
.poster .small { margin: 14px 0 0; font-size: 13px; opacity: .9; }

/* блокнот */
.journal .mbody { display: flex; flex-direction: column; gap: 18px; }
.j-goal { padding: 12px 16px; border-radius: 16px; background: #fff2e2; box-shadow: inset 0 0 0 2px var(--honey-soft); }
.j-goal p { margin: 0; font-weight: 700; }
.jg-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.jg { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 13px; color: var(--ink-soft); }
.jg svg { width: 64px; height: 64px; }
.jg.got figcaption { color: var(--ink); font-weight: 700; }
.jg figcaption small { display: block; font-weight: 500; color: var(--ink-soft); }
.jg-row.big .jg svg { width: 84px; height: 84px; }
.jn-list { display: flex; flex-direction: column; gap: 10px; }
.jn { padding: 10px 14px; border-radius: 14px; background: #fff; box-shadow: inset 0 0 0 2px var(--frost-2); }
.jn h4 { margin: 0 0 4px; font: 400 18px var(--font-display); color: var(--cap-deep); }
.jn div { line-height: 1.45; }
.jn ol { margin: 4px 0 0; padding-left: 1.4em; }
.jn .hand { font: 600 21px/1.3 var(--font-hand); margin: 0; color: #3a2f6a; }
.j-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--ink-soft); font-size: 14px; }
.j-shroom { display: inline-flex; align-items: center; gap: 6px; }
.j-shroom svg { width: 22px; height: 22px; }

/* меню и справка */
.menu { width: min(420px, 100%); }
.menu-list { display: flex; flex-direction: column; gap: 10px; }
.menu-confirm, .title-confirm { margin-top: 14px; padding: 12px 16px; border-radius: 16px; background: #fde8ec; color: #6b1f30; }
.menu-confirm p, .title-confirm p { margin: 0 0 10px; font-weight: 700; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.help-list { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 10px; max-width: 62ch; line-height: 1.5; }

/* ---------- всплывашки ---------- */
#toasts {
  position: fixed; z-index: 50; left: 50%; top: calc(58px + env(safe-area-inset-top, 0px)); transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(560px, calc(100% - 32px));
}
.toast {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px 8px 10px; border-radius: 16px;
  background: var(--frost); color: var(--ink); font-size: 15px; box-shadow: 0 12px 30px rgba(4, 6, 24, .45);
  opacity: 0; transform: translateY(-10px); transition: opacity .3s, transform .3s;
}
.toast.in { opacity: 1; transform: none; }
.t-ico { flex: none; width: 40px; height: 40px; display: grid; place-items: center; }
.t-ico svg { width: 100%; height: 100%; }
.t-book { color: var(--cap-deep); width: 30px; height: 30px; }

/* ---------- титульный экран и финал ---------- */
#screen {
  position: fixed; inset: 0; z-index: 60; overflow: auto;
  background: radial-gradient(90% 70% at 30% 20%, #2f3a86 0%, var(--night) 60%) var(--night);
  padding-block: max(20px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
#screen.ending { background: radial-gradient(90% 70% at 70% 10%, #6d4f9e 0%, #2a2a62 45%, var(--night) 80%) var(--night); }
.title-wrap, .end-wrap {
  position: relative; z-index: 1; min-height: 100%; max-width: 1100px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(220px, 420px) 1fr; gap: 36px; align-items: center;
}
.end-wrap { grid-template-columns: 1.15fr 1fr; }
.title-art svg { width: 100%; max-height: 82dvh; display: block; filter: drop-shadow(0 30px 40px rgba(4, 6, 24, .5)); animation: float 6s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-10px); } }
.end-art svg { width: 100%; display: block; border-radius: 26px; box-shadow: 0 30px 60px rgba(4, 6, 24, .55); }
.float-heart { animation: bob 3s ease-in-out infinite; }
.eyebrow { margin: 0 0 6px; font: 800 13px/1 var(--font-body); letter-spacing: .22em; text-transform: uppercase; color: var(--honey-soft); }
.title-text h1, .end-text h1 {
  margin: 0; font: 400 clamp(44px, 7vw, 86px)/.98 var(--font-display); color: var(--frost); text-wrap: balance;
  text-shadow: 0 4px 0 var(--cap-deep), 0 10px 30px rgba(91, 142, 224, .45);
}
.lead { font-size: 19px; line-height: 1.55; max-width: 46ch; color: #d4dbf8; margin: 18px 0 24px; }
.title-btns { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.title-btns .btn.ghost { color: var(--frost); box-shadow: inset 0 0 0 2px rgba(238, 242, 255, .35); }
.title-btns .btn.ghost:hover { background: rgba(238, 242, 255, .1); }
.title-foot { margin-top: 26px; color: #8f97c8; font-size: 14px; letter-spacing: .08em; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin: 0 0 14px; }
.stats div { padding: 10px 16px; border-radius: 16px; background: rgba(238, 242, 255, .08); }
.stats dt { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: #9aa1c9; }
.stats dd { margin: 2px 0 0; font: 400 26px var(--font-display); color: var(--frost); font-variant-numeric: tabular-nums; }
.bonus { color: #ffd77a; font-weight: 800; }
#screen .muted { color: #9aa1c9; }
.spores { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.spores i { position: absolute; bottom: -20px; width: 8px; height: 8px; border-radius: 50%; background: #cfe0ff; opacity: .5; box-shadow: 0 0 12px #9fc0ff; animation: rise-spore linear infinite; }
.spores i:nth-child(3n) { width: 5px; height: 5px; background: #ffe7b0; }
@keyframes rise-spore { to { transform: translate(40px, -110vh); opacity: 0; } }

/* ---------- узкие экраны ---------- */
@media (max-width: 860px) {
  .hbtn span { display: none; }
  .hbtn { width: 38px; padding: 0; justify-content: center; }
  #loc-name { font-size: 18px; }
  #loc-chapter { display: none; }
  .cw, .clk, .cr, .jr, .pn, .pc { grid-template-columns: 1fr; }
  .cw-disk, .clk-svg { max-width: 340px; margin: 0 auto; }
  .title-wrap, .end-wrap { grid-template-columns: 1fr; gap: 10px; text-align: left; }
  .title-art { max-width: 300px; margin: 0 auto; }
  .title-art svg { max-height: 46dvh; }
  .dlg-portrait { width: 96px; height: 104px; margin-top: -40px; }
  .dlg-text { font-size: 17px; }
  .cr-grid { grid-template-columns: repeat(var(--cols), minmax(0, 32px)); }
  .cell { width: 32px; height: 32px; }
  .cell span { font-size: 19px; }
  .jg-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 520px) {
  #hud { gap: 6px; }
  .hud-btns { gap: 4px; }
  .hbtn, .hcount { height: 34px; }
  .hbtn.icon-only, .hbtn { width: 34px; }
  #invbar { flex-direction: column-reverse; align-items: stretch; height: auto; }
  #selinfo { flex-basis: auto; max-height: none; }
  .si-head small { display: none; }
  .slot { width: 54px; height: 54px; }
  .dlg-box { grid-template-columns: 1fr; padding: 14px 16px; }
  #dialog.side-right .dlg-box { grid-template-columns: 1fr; padding: 14px 16px; }
  .dlg-portrait { display: none; }
  .mbox { padding: 12px 14px 16px; border-radius: 20px; }
  .kb-k { min-width: 28px; height: 38px; font-size: 16px; padding: 0 4px; }
}
/* телефон боком: инвентарь уходит в колонку справа, сцена занимает почти весь экран */
@media (max-height: 520px) and (orientation: landscape) {
  #game { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); }
  #hud { grid-column: 1 / -1; padding-block: 4px 2px; }
  .hbtn, .hcount { height: 32px; }
  .hbtn span { display: none; }
  .hbtn { width: 32px; padding: 0; justify-content: center; }
  #loc-chapter { display: none; }
  #loc-name { font-size: 17px; }
  #viewport { grid-column: 1; grid-row: 2; padding-block: 2px 8px; padding-right: 8px; }
  #invbar { grid-column: 2; grid-row: 2; flex-direction: column; justify-content: flex-start; height: auto; min-height: 0; padding-block: 2px 8px; padding-left: 0; overflow: hidden; }
  #inv { flex-direction: column; overflow-x: hidden; overflow-y: auto; max-height: 100%; padding: 4px; }
  .slot { width: 48px; height: 48px; padding: 4px; border-radius: 12px; }
  .inv-empty { display: none; }
  #selinfo { position: fixed; z-index: 20; left: 50%; bottom: max(8px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); width: min(520px, calc(100% - 140px)); max-height: 46px; padding: 4px 6px 4px 12px; box-shadow: 0 12px 30px rgba(4, 6, 24, .5); }
  .si-desc { display: none; }
  #selinfo .btn.small { min-height: 30px; padding: 3px 12px; }
  .dlg-portrait { width: 88px; height: 96px; margin-top: -30px; }
  .dlg-text { font-size: 16px; min-height: 2.4em; }
  #toasts { top: calc(40px + env(safe-area-inset-top, 0px)); }
}
/* телефон вертикально: подсказать повернуть экран */
#rotate-tip { display: none; }
@media (orientation: portrait) and (max-width: 600px) {
  #rotate-tip {
    display: flex; align-items: center; gap: 10px; position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); top: 8px;
    padding: 10px 14px; border-radius: 14px; background: rgba(238, 242, 255, .08); color: #c9d1f5; font-size: 14px; line-height: 1.35;
  }
  #rotate-tip svg { flex: none; width: 28px; height: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
