/* ───────── Токены ───────── */
:root {
  --paper: #f3e7cd;
  --paper-2: #eadab7;
  --paper-3: #dcc79c;
  --ink: #1d1914;
  --ink-2: #3d352b;
  --ink-3: #6a5d4b;
  --forge: #c9431b;
  --forge-2: #e2622a;
  --ember: #f29233;
  --frost: #9fcfe8;
  --frost-2: #4b93bd;
  --frost-d: #1f5a80;
  --gold: #b88a2c;
  --gold-2: #d9ae4f;
  --night: #121821;
  --night-2: #1a2330;
  --night-3: #253244;
  --cream-on-night: #f1e6cf;
  --btn-forge: #c9431b;
  --muted-on-night: #b8ad99;

  --f-display: 'Gorn Display', 'Oswald', 'Arial Black', sans-serif;
  --f-label: 'Oswald', 'Arial Narrow', sans-serif;
  --f-body: 'Literata', Georgia, 'Times New Roman', serif;
  --f-hand: 'Caveat', 'Comic Sans MS', cursive;

  --r: 6px;
  --shadow: 0 1px 0 rgba(0,0,0,.25), 0 10px 24px -10px rgba(0,0,0,.55);
  --shadow-lg: 0 2px 0 rgba(0,0,0,.2), 0 26px 50px -18px rgba(0,0,0,.7);
  --gutter: clamp(12px, 3vw, 28px);
  --bar-h: 0px;           /* шапки нет: липкой остаётся только строка табов (~48px), её учитывают сами отступы */
  --nav-h: 0px;

  /* шум бумаги и тушь */
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .27 0 0 0 0 .16 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --fibers: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='turbulence' baseFrequency='.012 .09' numOctaves='2' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .38 0 0 0 0 .2 0 0 0 .22 -.04'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  --grit: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.6' numOctaves='1' seed='9'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.5 1.42'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  --grit-soft: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' seed='3'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.25 1.55'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  --torn: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='10' preserveAspectRatio='none'%3E%3Cpath d='M0 0h60v4l-4 3-5-4-6 5-4-3-6 4-5-5-5 4-4-2-6 4-5-4-5 3-5-3V0z'/%3E%3C/svg%3E");
  --torn-top: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='10' preserveAspectRatio='none'%3E%3Cpath d='M0 10h60V6l-4-3-5 4-6-5-4 3-6-4-5 5-5-4-4 2-6-4-5 4-5-3-5 3v6z'/%3E%3C/svg%3E");
  color-scheme: dark;
}

@media (max-width: 899px) { :root { --nav-h: 64px; } }

/* ───────── База ───────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + 56px); }
body {
  margin: 0; min-height: 100vh; overflow-x: hidden;
  font: 400 16px/1.55 var(--f-body);
  color: var(--cream-on-night);
  background:
    radial-gradient(1200px 520px at 50% 115%, rgba(226, 98, 42, .28), transparent 70%),
    radial-gradient(900px 500px at 8% -10%, rgba(75, 147, 189, .22), transparent 65%),
    var(--noise),
    linear-gradient(180deg, #141c27 0%, #10151d 60%, #17130f 100%);
  background-attachment: fixed;
  padding-bottom: var(--nav-h);
}
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 400; line-height: 1.1; }
p { margin: 0; }
[hidden] { display: none !important; }

.skip { position: fixed; left: 8px; top: -60px; z-index: 999; background: var(--ember); color: var(--ink); padding: 8px 14px; border-radius: 4px; font-family: var(--f-label); text-decoration: none; }
.skip:focus-visible { top: 8px; }

:focus-visible { outline: 3px solid var(--frost); outline-offset: 2px; border-radius: 3px; }
.paper :focus-visible, .modal-card :focus-visible { outline-color: var(--frost-d); }

.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ───────── Бумага ───────── */
/* на бумаге текстовые акценты — «чернильные» тёмные версии (WCAG AA ≥ 4.5:1 даже на тёмной бумаге) */
.paper, .modal-card:not(.chest-modal):not(.reveal-modal), .cal-cell, .toast, .lore, .chat {
  --forge: #8c2a0c; --gold: #6a4c0f; --frost-2: #1b4f72; --frost-d: #1b4f72; --ink-3: #54483a;
}
.paper {
  position: relative;
  color: var(--ink);
  background-color: var(--paper);
  background-image: var(--fibers), var(--noise), radial-gradient(120% 90% at 30% 20%, #f8eed8 0%, transparent 60%), radial-gradient(90% 80% at 90% 100%, rgba(150, 110, 50, .18), transparent 70%);
  box-shadow: var(--shadow);
}
.paper--dark { background-color: var(--paper-2); }
.torn-b { -webkit-mask: linear-gradient(#000 0 0) top / 100% calc(100% - 9px) no-repeat, var(--torn) bottom / 60px 10px repeat-x; mask: linear-gradient(#000 0 0) top / 100% calc(100% - 9px) no-repeat, var(--torn) bottom / 60px 10px repeat-x; }
.torn-t { -webkit-mask: linear-gradient(#000 0 0) bottom / 100% calc(100% - 9px) no-repeat, var(--torn-top) top / 60px 10px repeat-x; mask: linear-gradient(#000 0 0) bottom / 100% calc(100% - 9px) no-repeat, var(--torn-top) top / 60px 10px repeat-x; }
.torn-tb { -webkit-mask: linear-gradient(#000 0 0) center / 100% calc(100% - 18px) no-repeat, var(--torn-top) top / 60px 10px repeat-x, var(--torn) bottom / 60px 10px repeat-x; mask: linear-gradient(#000 0 0) center / 100% calc(100% - 18px) no-repeat, var(--torn-top) top / 60px 10px repeat-x, var(--torn) bottom / 60px 10px repeat-x; }

.tape::before {
  content: ''; position: absolute; z-index: 2; top: -12px; left: 50%; width: 110px; height: 26px; translate: -50% 0; rotate: -3deg;
  background: linear-gradient(90deg, rgba(255,255,255,.0), rgba(255,255,255,.12) 10%, rgba(255,255,255,.12) 90%, rgba(255,255,255,0)), rgba(236, 222, 180, .62);
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
  -webkit-mask: var(--torn) left / 10px 26px, linear-gradient(#000 0 0); mask: linear-gradient(90deg, transparent 0 3px, #000 3px calc(100% - 3px), transparent 0);
}

/* штамп */
.stamp {
  display: inline-block; font-family: var(--f-display); text-transform: uppercase; letter-spacing: .04em; line-height: 1;
  color: var(--forge); border: 3px double currentColor; padding: .32em .55em .26em; border-radius: 4px; rotate: -6deg;
  mix-blend-mode: multiply; opacity: .9;
  -webkit-mask: var(--grit); mask: var(--grit);
}
.stamp--frost { color: var(--frost-d); }
.stamp--gold { color: #6a4c0f; }
.stamp--ink { color: var(--ink); }

/* рукописная пометка */
.hand { font-family: var(--f-hand); font-weight: 600; line-height: 1.15; }

/* ───────── Кнопки ───────── */
.btn {
  --bg: var(--btn-forge); --fg: #fff6e6; --bd: #6e2108;
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 44px; padding: .5em 1.15em .5em; border: 2px solid var(--bd); border-radius: 5px;
  background: var(--bg); color: var(--fg);
  font: 600 15px/1.1 var(--f-label); letter-spacing: .06em; text-transform: uppercase;
  box-shadow: 0 3px 0 var(--bd), inset 0 1px 0 rgba(255,255,255,.25);
  transition: transform .12s, box-shadow .12s, filter .15s; position: relative; text-decoration: none; text-align: center; max-width: 100%;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--bd), inset 0 1px 0 rgba(255,255,255,.2); }
.btn[disabled], .btn[aria-disabled="true"] { cursor: not-allowed; filter: grayscale(.85) brightness(.95); opacity: .62; transform: none; }
.btn--ink { --bg: var(--ink); --fg: var(--paper); --bd: #000; }
.btn--frost { --bg: var(--frost-d); --fg: #f2fbff; --bd: #0c2f47; }
.btn--gold { --bg: #d9ae4f; --fg: #1b1408; --bd: #5e430e; }
.btn--ghost { --bg: transparent; --fg: currentColor; --bd: currentColor; box-shadow: none; }
.btn--ghost:active { transform: translateY(1px); box-shadow: none; }
.btn--paper { --bg: var(--paper); --fg: var(--ink); --bd: var(--ink); }
.btn--sm { min-height: 36px; padding: .35em .8em; font-size: 13px; }
.btn--lg { min-height: 54px; font-size: 17px; padding: .6em 1.6em; }
.btn--block { width: 100%; }
.btn .ic { flex: none; }

.chip {
  display: inline-flex; align-items: center; gap: .35em; padding: .15em .6em; border-radius: 999px;
  font: 500 12.5px/1.6 var(--f-label); letter-spacing: .05em; text-transform: uppercase;
  border: 1.5px solid currentColor;
}

/* ───────── Картинки ───────── */
.art { margin: 0; position: relative; overflow: hidden; background: var(--paper-3); }
.art img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .5s; }
.art.is-loaded img { opacity: 1; }
.art.is-missing { background: none; }
.art-fb {
  position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 6px; text-align: center; padding: 14px;
  color: rgba(29, 25, 20, .62);
  background-color: var(--paper-2);
  background-image:
    var(--noise),
    repeating-linear-gradient(45deg, rgba(201, 67, 27, .10) 0 2px, transparent 2px 14px),
    repeating-linear-gradient(-45deg, rgba(31, 90, 128, .10) 0 2px, transparent 2px 14px),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.35), transparent 60%);
}
.art-fb::after { content: ''; position: absolute; inset: 10px; border: 1.5px dashed rgba(29,25,20,.28); border-radius: 3px; pointer-events: none; }
.art-fb-mark { font-size: 30px; color: var(--forge); line-height: 1; }
.art-fb-label { font: 600 12px/1.3 var(--f-label); letter-spacing: .08em; text-transform: uppercase; max-width: 26ch; }

.th { display: inline-grid; place-items: center; overflow: hidden; flex: none; line-height: 1; }
.th img { width: 100%; height: 100%; object-fit: cover; }

/* ───────── Тосты ───────── */
.toasts { position: fixed; z-index: 80; right: 16px; top: calc(var(--bar-h) + 60px); display: grid; gap: 10px; width: min(380px, calc(100vw - 24px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center;
  padding: 12px 10px 12px 14px; color: var(--ink); border-left: 5px solid var(--forge);
  background: var(--paper) var(--noise); box-shadow: var(--shadow-lg); border-radius: 3px;
  animation: toast-in .35s cubic-bezier(.2,1.4,.4,1) both; font-size: 14.5px; line-height: 1.35;
}
.toast--frost { border-left-color: var(--frost-2); }
.toast--gold { border-left-color: var(--gold); }
.toast strong { display: block; font: 600 13px/1.2 var(--f-label); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 2px; }
.toast-ic { font-size: 22px; }
.toast-x { border: 0; background: none; font-size: 22px; line-height: 1; padding: 4px 6px; color: var(--ink-3); border-radius: 3px; }
.toast.is-out { animation: toast-out .3s forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px) rotate(2deg); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(30px); } }
@media (max-width: 899px) { .toasts { top: auto; bottom: calc(var(--nav-h) + 10px); left: 12px; right: 12px; width: auto; } }

/* ───────── Модалка ───────── */
/* StoryForge: без backdrop-filter — под подложкой идёт снег, и размытие пересчитывалось бы каждый кадр; фон плотнее */ .modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px; background: rgba(8, 10, 14, .82); animation: fade .2s both; overflow-y: auto; }
.modal.is-out { animation: fade .2s reverse forwards; }
.modal-card { position: relative; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto; color: var(--ink); background: var(--paper) var(--noise); box-shadow: var(--shadow-lg); padding: 28px 24px 24px; border-radius: 4px; animation: pop .35s cubic-bezier(.2,1.3,.4,1) both; }
.modal-card:focus { outline: none; }
.modal-x { position: absolute; right: 8px; top: 6px; width: 40px; height: 40px; border: 0; background: none; font-size: 30px; line-height: 1; color: var(--ink-2); border-radius: 4px; z-index: 3; }
.modal-x:hover { background: rgba(0,0,0,.06); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.94) rotate(-1deg); } }

/* ───────── Снег ───────── */
#snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; opacity: .75; }

.noscript { padding: 40px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  #snow { display: none; }
}

/* заголовки «ручной печати»: плотный гротеск + неровный оттиск краски */
.view-head h1, .leaf-title, .dc-titles h2, .toc-body h3, .ct-head h2, .ch-title, .reveal-cap-big h2, .lore h3, .event-banner h2,
.questionnaire h1, .q-h, .mini-head h2, .chat-head h2, .reader-t b, .tav-card h3, .freemaster h3, .ending-card h3, .leaf--end h2,
.gift-modal h2, .confirm h2, .brand-text i, .dc-date b, .reader-locked h2, .bc-row b, .reveal-cap {
  -webkit-mask: var(--grit-soft); mask: var(--grit-soft); letter-spacing: -.005em;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
