/* NOCTARA — древня ельфійська пуща. Мох і ніч, різьблена бронза, кров і нефрит. */
@font-face { font-family: "Forum"; font-weight: 400; font-display: swap;
  src: url(fonts/forum-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: "Forum"; font-weight: 400; font-display: swap;
  src: url(fonts/forum-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: "Alegreya Sans"; font-weight: 400; font-display: swap;
  src: url(fonts/alegreya-sans-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: "Alegreya Sans"; font-weight: 400; font-display: swap;
  src: url(fonts/alegreya-sans-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212, U+2190-21FF; }
@font-face { font-family: "Alegreya Sans"; font-weight: 400; font-style: italic; font-display: swap;
  src: url(fonts/alegreya-sans-cyrillic-400-italic.woff2) format("woff2"); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Alegreya Sans"; font-weight: 400; font-style: italic; font-display: swap;
  src: url(fonts/alegreya-sans-latin-400-italic.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F; }
@font-face { font-family: "Alegreya Sans"; font-weight: 500; font-display: swap;
  src: url(fonts/alegreya-sans-cyrillic-500-normal.woff2) format("woff2"); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Alegreya Sans"; font-weight: 500; font-display: swap;
  src: url(fonts/alegreya-sans-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: "Alegreya Sans"; font-weight: 700; font-display: swap;
  src: url(fonts/alegreya-sans-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: "Alegreya Sans"; font-weight: 700; font-display: swap;
  src: url(fonts/alegreya-sans-latin-700-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }

:root {
  --night: #0a120d;        /* пуща вночі */
  --dusk: #121c15;         /* мох */
  --dusk-2: #1a271d;       /* мох на камені */
  --ink: #e7dfc6;          /* пергамент */
  --ink-quiet: #9aa58c;    /* лишайник */
  --gold: #c9a464;         /* різьблена бронза */
  --gold-hi: #e9cc8e;
  --gold-soft: rgba(201, 164, 100, .32);
  --bronze-dark: #6b5530;
  --blood: #b3261e;        /* кров: діаманти, небезпека, головна дія */
  --ember: #e0513f;
  --jade: #5ecf93;         /* нефрит: магія, досвід */
  --moon: #e4ecd4;
  --good: #7fc88f;
  --bad: #e0513f;
  --r-card: 4px;
  --r-ctrl: 3px;
  --display: "Forum", "Palatino Linotype", Georgia, serif;
  --text: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
  --rarity-0: #cfc8b3;
  --rarity-1: #5ecf93;
  --rarity-2: #e8d36a;
  --rarity-3: #e08a34;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--night); color: var(--ink); }
body {
  font: 400 17px/1.45 var(--text);
  font-variant-numeric: lining-nums;
  min-height: 100dvh;
  background:
    radial-gradient(900px 520px at 50% -8%, rgba(94, 207, 147, .10), transparent 65%),
    radial-gradient(1200px 900px at 50% 120%, rgba(0, 0, 0, .7), transparent 60%),
    var(--grain),
    var(--night);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }
:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; letter-spacing: .03em; color: var(--gold-hi);
  text-shadow: 0 1px 0 #000, 0 0 14px rgba(201, 164, 100, .18); }
h2 { font-size: 1.6rem; line-height: 1.15; }
h3 { font-size: 1.22rem; line-height: 1.2; }
p { margin: .35em 0; }
.quiet { color: var(--ink-quiet); }
.small { font-size: .88rem; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.ember { color: var(--ember); }
.gold { color: var(--gold); }
.jade { color: var(--jade); }
.hidden { display: none !important; }

#app { max-width: 760px; margin: 0 auto; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }

/* ---------- шапка: сфера Відлуння ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 8px 14px; background: linear-gradient(#141f17, #0d1610);
  border-bottom: 2px solid var(--bronze-dark); box-shadow: 0 1px 0 var(--gold-soft), 0 8px 20px rgba(0, 0, 0, .55);
}
.orb { --p: 0%; width: 58px; height: 58px; border-radius: 50%; position: relative; flex: none;
  background: radial-gradient(circle at 50% 60%, #0b1a11 0%, #050906 75%);
  box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--bronze-dark), 0 0 0 5px var(--gold), 0 0 18px rgba(94, 207, 147, .25);
  overflow: hidden; }
.orb::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: var(--p);
  background: linear-gradient(#7fe3ad, #2f9e66 55%, #11552f); box-shadow: 0 -2px 6px rgba(127, 227, 173, .6); }
.orb::after { content: ""; position: absolute; inset: 6% 18% 52% 18%; border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, rgba(255, 255, 255, .35), transparent 70%); }
.orb b { position: absolute; inset: 0; display: grid; place-items: center; z-index: 1;
  font-family: var(--display); font-size: 1.35rem; color: #fff; text-shadow: 0 1px 3px #000, 0 0 8px #000; }
.who { min-width: 0; }
.who .name { font-family: var(--display); font-size: 1.25rem; color: var(--gold-hi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 0 #000; }
.moon { display: inline-block; width: 13px; height: 13px; border-radius: 50%; position: relative; overflow: hidden; vertical-align: -1px;
  background: #24301f; margin-right: 6px; }
.moon::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: var(--moon); clip-path: var(--phase); }
.purse { text-align: right; font-size: .98rem; line-height: 1.25; white-space: nowrap; }
.purse .dia { color: var(--ember); }
.coin::before { content: ""; display: inline-block; width: .62em; height: .62em; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--gold-hi), #8a6a33); margin-right: .32em; vertical-align: .02em; }
.gem::before { content: ""; display: inline-block; width: .58em; height: .58em; background: linear-gradient(135deg, #ff7b68, var(--blood));
  transform: rotate(45deg); margin-right: .38em; vertical-align: .05em; box-shadow: 0 0 6px rgba(224, 81, 63, .5); }
.banner { margin: 10px 14px 0; padding: 10px 14px; border-left: 3px solid var(--blood); background: rgba(18, 28, 21, .9); }

/* ---------- нижня «панель поясу» ---------- */
.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: center;
  background: linear-gradient(#18241b, #0b130e); border-top: 2px solid var(--bronze-dark);
  box-shadow: 0 -1px 0 var(--gold-soft), 0 -10px 24px rgba(0, 0, 0, .6); padding-bottom: env(safe-area-inset-bottom); }
.nav-inner { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; max-width: 760px; }
.nav button { background: none; border: 0; padding: 10px 2px 12px; color: var(--ink-quiet); font-size: .82rem; cursor: pointer; }
.nav button svg { display: block; margin: 0 auto 3px; width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.5; }
.nav button[aria-current="page"] { color: var(--gold-hi); text-shadow: 0 0 10px rgba(233, 204, 142, .35); }
.nav button[aria-current="page"] svg { filter: drop-shadow(0 0 4px rgba(233, 204, 142, .45)); }

/* ---------- розкладка й рамки ---------- */
.view { padding: 14px; display: grid; gap: 14px; }
.panel { position: relative; background: linear-gradient(rgba(26, 39, 29, .92), rgba(15, 24, 18, .95)), var(--grain);
  border: 1px solid #000; border-radius: var(--r-card); padding: 14px;
  box-shadow: inset 0 0 0 1px rgba(201, 164, 100, .22), inset 0 0 26px rgba(0, 0, 0, .55), 0 4px 14px rgba(0, 0, 0, .45); }
.panel.framed { padding: 16px; box-shadow: inset 0 0 0 1px var(--bronze-dark), inset 0 0 0 3px #0a120d, inset 0 0 0 4px var(--gold-soft),
  inset 0 0 30px rgba(0, 0, 0, .6), 0 6px 18px rgba(0, 0, 0, .55); }
.panel.framed::before, .panel.framed::after { content: ""; position: absolute; width: 10px; height: 10px; transform: rotate(45deg);
  background: linear-gradient(135deg, var(--gold-hi), var(--bronze-dark)); box-shadow: 0 0 0 1px #000; }
.panel.framed::before { top: -5px; left: calc(50% - 5px); }
.panel.framed::after { bottom: -5px; left: calc(50% - 5px); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.list { display: grid; gap: 8px; }
.item { padding: 10px 12px; background: rgba(6, 11, 8, .55); border: 1px solid rgba(201, 164, 100, .14); border-radius: var(--r-ctrl); }
.item.disabled { opacity: .5; }

/* ---------- кнопки-камені ---------- */
.btn { border: 1px solid var(--bronze-dark); background: linear-gradient(#2b3a2d, #172219); color: var(--gold-hi); border-radius: var(--r-ctrl);
  padding: 8px 14px; cursor: pointer; font-weight: 500; min-height: 40px; white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(233, 204, 142, .18), inset 0 -2px 0 rgba(0, 0, 0, .45), 0 1px 0 #000; text-shadow: 0 1px 0 #000; }
.btn:hover:not(:disabled) { border-color: var(--gold); color: #fff3d6; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: linear-gradient(#8a2219, #4f100c); border-color: #c0573f; color: #ffeedd;
  box-shadow: inset 0 1px 0 rgba(255, 190, 170, .25), inset 0 -2px 0 rgba(0, 0, 0, .5), 0 0 12px rgba(179, 38, 30, .25), 0 1px 0 #000; }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: .9rem; }
.btn.ghost { background: transparent; box-shadow: none; border-color: rgba(154, 165, 140, .35); color: var(--ink-quiet); }
.btn.ember { border-color: var(--ember); color: var(--ember); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.seg { display: flex; border: 1px solid var(--bronze-dark); border-radius: var(--r-ctrl); overflow: hidden; background: rgba(0, 0, 0, .35); }
.seg button { flex: 1; background: none; border: 0; padding: 8px 6px; color: var(--ink-quiet); cursor: pointer; }
.seg button + button { border-left: 1px solid rgba(201, 164, 100, .18); }
.seg button[aria-pressed="true"] { background: linear-gradient(#2b3a2d, #172219); color: var(--gold-hi); }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; background: #070c09; border: 1px solid rgba(201, 164, 100, .28); border-radius: var(--r-ctrl);
  padding: 9px 11px; box-shadow: inset 0 2px 6px rgba(0, 0, 0, .6); }
label { display: grid; gap: 4px; font-size: .92rem; color: var(--ink-quiet); }

/* ---------- вхід: ліс ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px 18px 180px; position: relative; overflow: hidden; }
.gate-inner { width: 100%; max-width: 400px; display: grid; gap: 18px; text-align: center; position: relative; z-index: 2; }
.forest { position: fixed; left: 0; right: 0; bottom: 0; height: 46vh; z-index: 0; pointer-events: none; }
.forest svg { width: 100%; height: 100%; display: block; }
.firefly { position: fixed; width: 4px; height: 4px; border-radius: 50%; background: #c9ffd9; box-shadow: 0 0 10px 3px rgba(94, 207, 147, .7);
  z-index: 1; pointer-events: none; animation: drift 9s ease-in-out infinite alternate; opacity: .8; }
@keyframes drift { 0% { transform: translate(0, 0); opacity: .2; } 50% { opacity: .9; } 100% { transform: translate(26px, -34px); opacity: .3; } }
.wordmark { font-family: var(--display); font-size: clamp(3rem, 15vw, 4.8rem); letter-spacing: .18em; line-height: 1; margin-right: -.18em;
  background: linear-gradient(#f6e5b8 10%, #c9a464 55%, #7a5a2a 90%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 0 #000) drop-shadow(0 0 18px rgba(201, 164, 100, .25)); }
.wordmark-sub { font-family: var(--display); font-size: 1.3rem; color: var(--jade); margin-top: -2px; letter-spacing: .06em; }
.gate form { text-align: left; display: grid; gap: 12px; }

/* ---------- заняття ---------- */
.activity-title { font-family: var(--display); font-size: 1.45rem; line-height: 1.2; color: var(--gold-hi); }
.progress { height: 8px; border-radius: 1px; background: #050906; border: 1px solid #000; box-shadow: 0 0 0 1px rgba(201, 164, 100, .2); overflow: hidden; margin: 8px 0 4px; }
.progress i { display: block; height: 100%; background: linear-gradient(#7fe3ad, #2f9e66); }
.warn { color: var(--ember); }
.zone summary { cursor: pointer; list-style: none; }
.zone summary::-webkit-details-marker { display: none; }
.zone[open] summary { margin-bottom: 10px; }
.tier { display: inline-grid; place-items: center; min-width: 34px; height: 22px; padding: 0 4px; border: 1px solid var(--bronze-dark); border-radius: 2px;
  font-size: .8rem; color: var(--gold); margin-right: 8px; background: #070c09; }
.mon-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .88rem; color: var(--ink-quiet); }
.chronicle { display: grid; gap: 6px; }
.chronicle p { margin: 0; padding-left: 12px; border-left: 2px solid rgba(154, 165, 140, .25); font-size: .95rem; }
.chronicle p.loot { border-color: var(--rarity-2); }
.chronicle p.level { border-color: var(--jade); }
.chronicle p.warn { border-color: var(--blood); color: var(--ink); }
.chronicle time { color: var(--ink-quiet); font-size: .8rem; margin-right: 6px; }

/* ---------- герой ---------- */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.slot { padding: 10px; border: 1px dashed rgba(154, 165, 140, .3); border-radius: var(--r-ctrl); min-height: 64px; cursor: pointer; background: rgba(0, 0, 0, .3); text-align: left; }
.slot.filled { border: 1px solid var(--bronze-dark); background: rgba(6, 11, 8, .7); box-shadow: inset 0 0 14px rgba(0, 0, 0, .6); }
.slot .k { font-size: .8rem; color: var(--ink-quiet); }
.r0 { color: var(--rarity-0); } .r1 { color: var(--rarity-1); } .r2 { color: var(--rarity-2); } .r3 { color: var(--rarity-3); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px 14px; font-size: .95rem; }
.stat-grid div { display: flex; justify-content: space-between; border-bottom: 1px dotted rgba(201, 164, 100, .18); padding: 2px 0; }
.xpbar { height: 4px; background: #050906; border-radius: 1px; margin-top: 3px; overflow: hidden; }
.xpbar i { display: block; height: 100%; background: var(--jade); }

/* ---------- Атлас ---------- */
.atlas-wrap { position: relative; height: min(70vh, 620px); border-radius: var(--r-card); overflow: hidden; touch-action: none;
  background: radial-gradient(circle at 50% 50%, #15261a 0%, #070c09 72%); border: 1px solid #000;
  box-shadow: inset 0 0 0 1px var(--bronze-dark), inset 0 0 40px rgba(0, 0, 0, .8); }
.atlas-wrap svg { width: 100%; height: 100%; cursor: grab; }
.atlas-tools { position: absolute; right: 10px; top: 10px; display: grid; gap: 6px; }
.atlas-tools button { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--bronze-dark); background: rgba(10, 18, 13, .85); color: var(--gold-hi); font-size: 1.2rem; cursor: pointer; }
.atlas-points { position: absolute; left: 12px; top: 10px; font-family: var(--display); font-size: 1.15rem; color: var(--gold-hi); text-shadow: 0 1px 2px #000; }

/* ---------- аркуш ---------- */
.sheet-back { position: fixed; inset: 0; background: rgba(2, 5, 3, .7); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 760px; max-height: 86dvh; overflow: auto; background: linear-gradient(#18241b, #0d1610);
  border-top: 2px solid var(--gold); box-shadow: 0 -1px 0 #000, 0 -12px 30px rgba(0, 0, 0, .7);
  border-radius: 6px 6px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 12px; animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: linear-gradient(#1f2e22, #121c15); border: 1px solid var(--bronze-dark); padding: 10px 16px; border-radius: var(--r-ctrl); max-width: calc(100% - 32px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .7); }
.toast.err { border-color: var(--blood); }

/* ---------- створення персонажа ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.card { text-align: left; background: linear-gradient(rgba(26, 39, 29, .9), rgba(12, 20, 15, .95)); border: 1px solid #000; border-radius: var(--r-card); padding: 12px; cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(201, 164, 100, .2), 0 3px 10px rgba(0, 0, 0, .45); }
.card[aria-pressed="true"] { box-shadow: inset 0 0 0 1px var(--gold), inset 0 0 18px rgba(201, 164, 100, .15), 0 0 14px rgba(201, 164, 100, .2); }
.card h3 { margin-bottom: 4px; }

/* ---------- чат ---------- */
.chat-log { height: 52vh; overflow: auto; display: grid; gap: 6px; align-content: start; padding-right: 4px; }
.chat-log .m b { color: var(--gold); font-weight: 500; }
.chat-log .m.sys { color: var(--ember); }

@media (min-width: 700px) {
  .view { padding: 20px 24px; }
  h2 { font-size: 1.85rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
