/* Загадкин — основа: шрифты, токены, шапка, кнопки, окна, шторка. Мир: библиотека на дереве, ночь, светлячки. */
@font-face { font-family: 'Ruslan Display'; font-display: swap; src: url(/fonts/ruslan-display-cyrillic-400-normal.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Ruslan Display'; font-display: swap; src: url(/fonts/ruslan-display-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215; }
@font-face { font-family: 'Marck Script'; font-display: swap; src: url(/fonts/marck-script-cyrillic-400-normal.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Marck Script'; font-display: swap; src: url(/fonts/marck-script-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215; }
@font-face { font-family: 'Podkova'; font-weight: 700; font-display: swap; src: url(/fonts/podkova-cyrillic-700-normal.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Podkova'; font-weight: 700; font-display: swap; src: url(/fonts/podkova-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215; }
@font-face { font-family: 'Nunito'; font-weight: 200 1000; font-display: swap; src: url(/fonts/nunito-cyrillic-wght-normal.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Nunito'; font-weight: 200 1000; font-display: swap; src: url(/fonts/nunito-latin-wght-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215; }

:root {
  --night-950: #0b0824; --night-900: #120d36; --night-800: #1b1446; --night-700: #2a1f66; --night-600: #3b2d87; --night-500: #5443b3;
  --amber-200: #ffe3b0; --amber-300: #ffd58a; --amber-400: #ffc66a; --amber: #ffb84d; --amber-600: #f09a1f; --amber-700: #c97a0b;
  --cream: #fff4de; --parch: #f6e7c7; --parch-2: #ecd7a8; --ink: #2a1b3d; --ink-soft: #5a4670;
  --good: #7ee0a2; --good-d: #2f9d62; --bad: #ff8585; --bad-d: #c9473f; --info: #7cc7ff;
  --glass: rgba(27, 20, 70, .62); --glass-2: rgba(42, 31, 102, .7); --line: rgba(255, 213, 138, .22);
  --font-display: 'Ruslan Display', 'Marck Script', Georgia, serif;
  --font-script: 'Marck Script', 'Ruslan Display', Georgia, cursive;
  --font-num: 'Podkova', 'Nunito', Georgia, serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --r-s: 10px; --r-m: 16px; --r-l: 24px; --r-xl: 32px;
  --spring: cubic-bezier(.34, 1.56, .64, 1); --ease: cubic-bezier(.22, 1, .36, 1);
  --shadow-1: 0 6px 18px rgba(8, 5, 30, .35); --shadow-2: 0 18px 48px rgba(8, 5, 30, .55);
  --glow: 0 0 22px rgba(255, 184, 77, .45);
  --maxw: 1180px; --top-h: 64px;
  color-scheme: dark;
}
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
html[data-bigtext="on"] { font-size: 112.5%; }
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; background: var(--night-900); color: var(--cream); font: 400 1rem/1.55 var(--font-body); overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
body.noscroll { overflow: hidden; }
img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 400; line-height: 1.1; margin: 0; letter-spacing: .01em; }
p { margin: 0; }
a { color: var(--amber-300); text-underline-offset: 3px; }
a:hover { color: var(--amber); }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; border-radius: 6px; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--amber); color: var(--ink); padding: 10px 16px; border-radius: var(--r-s); font-weight: 800; transition: top .2s; }
.skip:focus { top: 10px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.boot { padding: 30vh 24px; text-align: center; font: 1.6rem var(--font-script); color: var(--amber-300); }

/* фон: библиотека на дереве */
#bg { position: fixed; inset: 0; z-index: -3; background: var(--night-900) url(/img/bg-library.webp) center 30% / cover no-repeat; }
#bg::after { content: ''; position: absolute; inset: 0; background: radial-gradient(120% 90% at 50% 20%, rgba(11, 8, 36, .15), rgba(11, 8, 36, .78) 70%), linear-gradient(180deg, rgba(11, 8, 36, .55), rgba(11, 8, 36, .25) 35%, rgba(11, 8, 36, .85)); }
#fireflies { position: fixed; inset: 0; z-index: -2; width: 100%; height: 100%; pointer-events: none; }
html[data-motion="off"] #fireflies { display: none; }

/* шапка */
.top { position: sticky; top: 0; z-index: 40; height: var(--top-h); display: flex; align-items: center; gap: 14px; padding: 0 max(16px, calc((100vw - var(--maxw)) / 2)); border-bottom: 1px solid var(--line); }
/* стекло шапки — на псевдоэлементе: backdrop-filter у самой шапки запер бы в ней position:fixed нижнего меню */
.top::before { content: ''; position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, rgba(11, 8, 36, .86), rgba(11, 8, 36, .5)); backdrop-filter: blur(10px) saturate(1.2); -webkit-backdrop-filter: blur(10px) saturate(1.2); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--amber-300); text-decoration: none; font: 1.9rem/1 var(--font-display); white-space: nowrap; }
.brand img { width: 40px; height: 40px; filter: drop-shadow(0 2px 8px rgba(255, 184, 77, .45)); }
.brand span { text-shadow: 0 0 18px rgba(255, 184, 77, .4); }
.nav { display: flex; gap: 4px; margin-left: 14px; }
.nav a { padding: 9px 14px; border-radius: 999px; color: var(--cream); text-decoration: none; font-weight: 700; font-size: .95rem; transition: background .2s, color .2s; white-space: nowrap; }
.nav a:hover { background: rgba(255, 213, 138, .12); }
.nav a[aria-current="page"] { background: rgba(255, 184, 77, .18); color: var(--amber-300); box-shadow: inset 0 0 0 1px var(--line); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); font-weight: 800; white-space: nowrap; }
.pill .e { font-size: 1.1rem; }
.pill.coins b { color: var(--amber-300); font-family: var(--font-num); }
.icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); transition: transform .25s var(--spring), background .2s; }
.icon-btn:hover { background: var(--glass-2); transform: translateY(-1px); }
.icon-btn:active { transform: scale(.92); }
.burger { display: none; }
@media (max-width: 880px) {
  .nav { position: fixed; left: 0; right: 0; bottom: 0; top: auto; margin: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; background: rgba(11, 8, 36, .94); backdrop-filter: blur(14px); border-top: 1px solid var(--line); z-index: 45; gap: 0; }
  .nav a { flex: 1; text-align: center; padding: 10px 2px; font-size: .78rem; min-height: 44px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
  .nav a .ni { font-size: 1.25rem; line-height: 1; }
  .pill.lvl { display: none; }
  body { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
}
@media (min-width: 881px) { .nav a .ni { display: none; } }
@media (max-width: 560px) { .brand { font-size: 1.45rem; } .brand img { width: 34px; height: 34px; } .pill { padding: 0 10px; height: 38px; } .top-right { gap: 6px; } .top .icon-btn { display: none; } .top { gap: 8px; } .top .btn-sm { min-height: 38px; padding: 0 14px; } }
@media (max-width: 380px) { .brand span { font-size: 1.2rem; } .pill.me .nick { max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } }

/* кнопки */
.btn { --b: var(--amber); display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 24px; border: 0; border-radius: 999px; font-weight: 900; font-size: 1.02rem; letter-spacing: .01em; text-decoration: none; position: relative; transition: transform .3s var(--spring), box-shadow .25s, filter .2s; user-select: none; }
.btn:active { transform: scale(.95); transition-duration: .08s; }
.btn-primary { color: var(--ink); background: linear-gradient(180deg, var(--amber-300), var(--amber) 55%, var(--amber-600)); box-shadow: 0 4px 0 var(--amber-700), 0 10px 26px rgba(240, 154, 31, .35), inset 0 1px 0 rgba(255, 255, 255, .55); }
.btn-primary:hover { transform: translateY(-2px); filter: brightness(1.05); box-shadow: 0 6px 0 var(--amber-700), 0 14px 30px rgba(240, 154, 31, .45), inset 0 1px 0 rgba(255, 255, 255, .55); color: var(--ink); }
.btn-primary:active { transform: translateY(2px) scale(.98); box-shadow: 0 1px 0 var(--amber-700), 0 4px 12px rgba(240, 154, 31, .3), inset 0 1px 0 rgba(255, 255, 255, .45); }
.btn-ghost { color: var(--cream); background: rgba(255, 244, 222, .08); box-shadow: inset 0 0 0 1.5px rgba(255, 213, 138, .35); }
.btn-ghost:hover { background: rgba(255, 244, 222, .15); color: var(--cream); transform: translateY(-1px); }
.btn-danger { color: #fff; background: linear-gradient(180deg, #ff9a8a, #e5574a); box-shadow: 0 4px 0 #a23a31; }
.btn-sm { min-height: 40px; padding: 0 16px; font-size: .92rem; }
.btn-lg { min-height: 58px; padding: 0 34px; font-size: 1.18rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; filter: grayscale(.4); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: rgba(255, 244, 222, .1); border: 1px solid var(--line); font-weight: 700; font-size: .85rem; }

/* окна */
#modal-root:empty { display: none; }
.modal-back { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px; background: rgba(8, 5, 28, .72); backdrop-filter: blur(6px); animation: fade .25s var(--ease); }
.modal { width: min(480px, 100%); max-height: calc(100dvh - 32px); overflow: auto; border-radius: var(--r-xl); padding: 28px 26px 24px; background: linear-gradient(180deg, #2c2170, #1b1446); border: 1px solid var(--line); box-shadow: var(--shadow-2), var(--glow); animation: pop .4s var(--spring); position: relative; }
.modal h2 { font-size: 2rem; color: var(--amber-300); margin-bottom: 6px; }
.modal .x { position: absolute; right: 12px; top: 12px; }
.modal-lead { color: rgba(255, 244, 222, .75); margin-bottom: 16px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 800; font-size: .88rem; color: var(--amber-200); }
.field input, .field select { height: 50px; padding: 0 16px; border-radius: 14px; border: 1.5px solid rgba(255, 213, 138, .3); background: rgba(8, 5, 30, .55); transition: border-color .2s, box-shadow .2s; width: 100%; }
.field input:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 4px rgba(255, 184, 77, .2); }
.form-err { min-height: 1.4em; color: var(--bad); font-weight: 700; margin: 2px 0 8px; }
.tabs { display: inline-flex; padding: 4px; border-radius: 999px; background: rgba(8, 5, 30, .5); border: 1px solid var(--line); gap: 2px; margin-bottom: 16px; }
.tabs button { border: 0; background: transparent; padding: 8px 18px; border-radius: 999px; font-weight: 800; color: rgba(255, 244, 222, .75); min-height: 40px; }
.tabs button[aria-selected="true"] { background: linear-gradient(180deg, var(--amber-300), var(--amber)); color: var(--ink); }

/* тосты */
#toasts { position: fixed; z-index: 90; top: calc(var(--top-h) + 10px); right: 12px; display: grid; gap: 10px; width: min(360px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-radius: var(--r-m); background: linear-gradient(180deg, #33267a, #231a5a); border: 1px solid var(--line); box-shadow: var(--shadow-1); animation: toast-in .5s var(--spring); font-weight: 700; }
.toast.out { animation: toast-out .3s ease forwards; }
.toast .t-ic { font-size: 1.6rem; flex: none; }
.toast small { display: block; font-weight: 600; color: rgba(255, 244, 222, .7); }
.toast.good { border-color: rgba(126, 224, 162, .5); } .toast.bad { border-color: rgba(255, 133, 133, .5); } .toast.gold { border-color: rgba(255, 213, 138, .8); box-shadow: var(--shadow-1), var(--glow); }

/* шторка-плащ при переходах */
#curtain { position: fixed; inset: 0; z-index: 95; pointer-events: none; transform: translateX(-105%); background: radial-gradient(circle at 30% 40%, #4a3aa6, #1b1446 55%, #0b0824); }
#curtain::after { content: ''; position: absolute; top: 0; bottom: 0; right: -60px; width: 120px; background: radial-gradient(60px 50px at 0 12%, #1b1446 98%, transparent) 0 0 / 120px 25% repeat-y; }
#curtain.go { animation: curtain .75s var(--ease) both; }
html[data-motion="off"] #curtain { display: none; }

@keyframes curtain { 0% { transform: translateX(-105%); } 45%, 55% { transform: translateX(0); } 100% { transform: translateX(105%); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(24px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(40px); } }

.foot { text-align: center; padding: 34px 16px 40px; color: rgba(255, 244, 222, .5); font-size: .86rem; }
.foot a { color: rgba(255, 213, 138, .8); }
@media (max-width: 880px) { .foot { padding-bottom: 26px; } }

/* режим без анимаций (настройка игрока и prefers-reduced-motion) */
html[data-motion="off"] *, html[data-motion="off"] *::before, html[data-motion="off"] *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
@media (prefers-reduced-motion: reduce) {
  html:not([data-motion="on"]) *, html:not([data-motion="on"]) *::before, html:not([data-motion="on"]) *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  html:not([data-motion="on"]) #fireflies { display: none; }
  html:not([data-motion="on"]) #curtain { display: none; }
}
