:root {
    --bg: #100e0c;
    --bg-elevated: #181513;
    --bg-deep: #0a0908;
    --ink: #ece6d9;
    --ink-dim: #b5a998;
    --muted: #7a6f62;
    --accent: hsl(35 50% 65%);
    --accent-soft: hsl(35 58% 72%);
    --accent-deep: hsl(35 38% 48%);
    --line: rgba(236, 230, 218, 0.12);
    --line-gold: hsl(35 50% 65% / 0.28);
    --font-serif: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --radius: 2px;
    --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Атрибут hidden должен побеждать любые display: grid/flex ниже */
[hidden] { display: none !important; }

html, body {
    height: 100%;
    background: var(--bg-deep);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overscroll-behavior: none;
}

/* На телефоне тап по экрану продвигает текст — выделение мешает */
.stage, .chapter-card, .dialogue, .choices, .title-inner {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; }

/* Зерно поверх всего */
.noise {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 60;
    opacity: 0.05;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Кнопки ---------- */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    padding: 0.85rem 1.6rem;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #1a1410;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-decoration: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.25s var(--ease), border-color 0.25s var(--ease), transform 0.15s var(--ease);
}
.button:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.button:active { transform: translateY(1px); }
.button--ghost {
    background: transparent;
    color: var(--ink);
    border-color: var(--line-gold);
}
.button--ghost:hover { background: rgba(236, 230, 218, 0.05); border-color: var(--accent); color: var(--accent-soft); }

.eyebrow {
    display: inline-block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: var(--accent-soft);
}

/* ---------- Титульный экран ---------- */
.title-screen {
    position: fixed;
    inset: 0;
    height: 100dvh;
    z-index: 50;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 6vh 6vw;
    overflow-y: auto;
}
.title-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(120% 90% at 50% 0%, #1b1713 0%, var(--bg-deep) 70%);
}
.title-bg::after {
    content: "";
    position: absolute;
    inset: 0;
    background: url("/images/scene-1-childhood.jpeg") center/cover no-repeat;
    opacity: 0.16;
    filter: sepia(0.4) contrast(1.05);
    mask-image: radial-gradient(120% 80% at 50% 40%, #000 30%, transparent 80%);
}
.title-inner {
    position: relative;
    max-width: 40rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    animation: rise 1s var(--ease) both;
}
.game-name {
    font-family: var(--font-serif);
    font-weight: 600;
    font-size: clamp(3.5rem, 12vw, 7rem);
    line-height: 0.95;
    letter-spacing: 0.02em;
    color: var(--ink);
}
.game-name::after {
    content: "";
    display: block;
    width: 4rem;
    height: 1px;
    margin: 1.2rem auto 0;
    background: var(--accent);
}
.game-sub {
    color: var(--ink-dim);
    font-size: 1.05rem;
    max-width: 34rem;
}
.title-actions { display: flex; gap: 0.8rem; flex-wrap: wrap; justify-content: center; margin-top: 0.6rem; }
.title-note { color: var(--muted); font-size: 0.78rem; margin-top: 0.4rem; }
.title-back { color: var(--ink-dim); font-size: 0.85rem; text-decoration: none; margin-top: 0.6rem; border-bottom: 1px solid transparent; }
.title-back:hover { color: var(--accent-soft); border-color: var(--line-gold); }

/* ---------- Сцена ---------- */
.stage {
    position: fixed;
    inset: 0;
    height: 100dvh;
    z-index: 10;
    overflow: hidden;
    cursor: pointer;
}
.stage-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    opacity: 0;
    transition: opacity 1.1s var(--ease), transform 9s linear;
    filter: sepia(0.32) contrast(1.04) brightness(0.82);
    transform: scale(1.04);
}
.stage-bg.is-active { opacity: 1; transform: scale(1.1); }
.stage-vignette {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(to top, rgba(7,6,5,0.92) 0%, rgba(7,6,5,0.45) 32%, rgba(7,6,5,0.1) 55%, rgba(7,6,5,0.35) 100%),
        radial-gradient(120% 80% at 50% 30%, transparent 50%, rgba(7,6,5,0.55) 100%);
}

/* ---------- HUD ---------- */
.hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: max(1rem, env(safe-area-inset-top)) 1.4rem 1rem;
}
.hud-btn {
    background: rgba(16,14,12,0.55);
    border: 1px solid var(--line-gold);
    color: var(--ink);
    padding: 0.5rem 0.9rem;
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    border-radius: var(--radius);
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.hud-btn:hover { color: var(--accent-soft); border-color: var(--accent); }
.hud-left { display: flex; align-items: center; gap: 0.5rem; }
.hud-btn--icon {
    padding: 0.5rem 0.7rem;
    line-height: 1;
    font-size: 0.95rem;
}
.hud-btn--icon.is-muted { color: var(--muted); }

/* Переключатель языка */
.lang-switch { display: inline-flex; gap: 0.3rem; }
.title-inner .lang-switch { margin-bottom: 1.3rem; }
.lang-switch--menu { margin-top: 0.6rem; justify-content: center; }
.lang-btn {
    background: rgba(16,14,12,0.55);
    border: 1px solid var(--line-gold);
    color: var(--ink-dim);
    padding: 0.32rem 0.7rem;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    border-radius: var(--radius);
    cursor: pointer;
    transition: color 0.2s var(--ease), border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.lang-btn:hover { color: var(--accent-soft); border-color: var(--accent); }
.lang-btn.is-active { color: #0a0807; background: var(--accent); border-color: var(--accent); }

.threads {
    display: flex;
    gap: 0.5rem;
    background: rgba(16,14,12,0.5);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    backdrop-filter: blur(4px);
}
.thread {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    color: var(--muted);
    transition: color 0.3s var(--ease);
}
.thread b { color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.thread i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; transition: background 0.3s var(--ease), box-shadow 0.3s var(--ease); }
.thread--sea i  { background: hsl(200 35% 55%); }
.thread--word i { background: hsl(40 60% 62%); }
.thread--duty i { background: hsl(8 45% 55%); }
.thread.is-bumped { color: var(--accent-soft); }
.thread.is-bumped i { box-shadow: 0 0 10px 1px currentColor; }
@media (max-width: 560px) {
    .thread b { display: none; }
    .thread span { font-size: 0; }
}

/* ---------- Карточка главы ---------- */
.chapter-card {
    position: absolute;
    inset: 0;
    z-index: 25;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.8rem;
    padding: 0 8vw;
    background: rgba(7,6,5,0.55);
}
.chapter-card .place {
    color: var(--muted);
    font-size: 0.85rem;
    letter-spacing: 0.04em;
}
.chapter-card .title {
    font-family: var(--font-serif);
    font-weight: 600;
    font-size: clamp(2.2rem, 7vw, 4rem);
    line-height: 1.05;
}
.chapter-card.is-in { animation: cardIn 0.9s var(--ease) both; }
.chapter-card.is-out { animation: cardOut 0.7s var(--ease) both; }

/* ---------- Диалог ---------- */
.dialogue {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    z-index: 28;
    padding: 0 0 max(1.6rem, env(safe-area-inset-bottom)) 0;
    cursor: pointer;
}
.dialogue-inner {
    max-width: 52rem;
    margin: 0 auto;
    padding: 1.6rem 1.8rem 1.7rem;
    background: linear-gradient(to top, rgba(12,10,9,0.9), rgba(12,10,9,0.72));
    border-top: 1px solid var(--line-gold);
    position: relative;
}
@media (min-width: 720px) {
    .dialogue-inner {
        margin: 0 auto 1rem;
        border: 1px solid var(--line);
        border-top: 1px solid var(--line-gold);
        border-radius: var(--radius);
        backdrop-filter: blur(3px);
    }
}
.speaker {
    display: inline-block;
    font-family: var(--font-serif);
    font-size: 1.1rem;
    color: var(--accent-soft);
    margin-bottom: 0.5rem;
    letter-spacing: 0.01em;
}
.line {
    font-size: clamp(1.05rem, 2.4vw, 1.2rem);
    line-height: 1.7;
    color: var(--ink);
    min-height: 1.7em;
}
.line.narration { color: var(--ink-dim); font-style: italic; }
.advance {
    position: absolute;
    right: 1.4rem;
    bottom: 0.9rem;
    color: var(--accent);
    font-size: 0.9rem;
    animation: blink 1.4s ease-in-out infinite;
}

/* ---------- Выборы ---------- */
.choices {
    position: absolute;
    inset: 0;
    z-index: 32;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    justify-content: safe center;
    gap: 0.75rem;
    padding: 8vh 6vw;
    background: rgba(7,6,5,0.5);
    overflow-y: auto;
}

/* Галерея финала «что осталось» */
.end-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 0.7rem;
    justify-content: center;
    max-width: 48rem;
    margin: 0.2rem 0 1.2rem;
}
.end-card {
    width: 9rem;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.end-card img {
    width: 100%;
    height: 7rem;
    object-fit: cover;
    border: 1px solid var(--line-gold);
    border-radius: var(--radius);
    filter: sepia(0.3) contrast(1.03);
    transition: filter 0.25s var(--ease), border-color 0.25s var(--ease), transform 0.2s var(--ease);
}
.end-card:hover img { filter: none; border-color: var(--accent); transform: translateY(-2px); }
.end-cap {
    font-size: 0.72rem;
    line-height: 1.3;
    color: var(--muted);
    text-align: center;
}
.end-card:hover .end-cap { color: var(--accent-soft); }
@media (max-width: 640px) {
    .end-card { width: 7rem; }
    .end-card img { height: 5.5rem; }
}
.choices .prompt {
    font-family: var(--font-serif);
    font-size: clamp(1.2rem, 3.5vw, 1.7rem);
    color: var(--ink);
    text-align: center;
    max-width: 44rem;
    margin-bottom: 0.8rem;
}
.choice-btn {
    width: min(100%, 40rem);
    text-align: left;
    padding: 1rem 1.3rem;
    background: rgba(20,17,15,0.82);
    border: 1px solid var(--line-gold);
    color: var(--ink);
    font-size: 1rem;
    line-height: 1.45;
    border-radius: var(--radius);
    cursor: pointer;
    backdrop-filter: blur(3px);
    transition: border-color 0.2s var(--ease), background 0.2s var(--ease), transform 0.15s var(--ease), color 0.2s var(--ease);
    animation: rise 0.5s var(--ease) both;
}
.choice-btn:hover { border-color: var(--accent); background: rgba(36,30,25,0.9); color: var(--accent-soft); transform: translateY(-1px); }
.choice-btn .idx { color: var(--accent); font-weight: 600; margin-right: 0.6rem; }

/* ---------- Оверлеи ---------- */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: grid;
    place-items: center;
    background: rgba(5,4,3,0.78);
    backdrop-filter: blur(6px);
    padding: 6vh 6vw;
}
.overlay-panel {
    width: min(100%, 26rem);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    background: var(--bg-elevated);
    border: 1px solid var(--line-gold);
    border-radius: var(--radius);
    padding: 1.8rem;
}
.overlay-panel--wide { width: min(100%, 44rem); }
.overlay-panel h3 {
    font-family: var(--font-serif);
    font-weight: 600;
    font-size: 1.5rem;
    margin-bottom: 0.4rem;
}
.history-log {
    max-height: 55vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    padding-right: 0.5rem;
    margin-bottom: 0.4rem;
}
.history-log .h-row { border-left: 2px solid var(--line-gold); padding-left: 0.9rem; }
.history-log .h-spk { color: var(--accent-soft); font-family: var(--font-serif); font-size: 0.95rem; }
.history-log .h-txt { color: var(--ink-dim); font-size: 0.95rem; }
.history-log .h-choice { color: var(--accent); font-size: 0.85rem; font-style: italic; }

/* ---------- Анимации ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes cardIn { 0% { opacity: 0; transform: translateY(16px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes cardOut { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes blink { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
    .stage-bg, .stage-bg.is-active { transition: opacity 0.4s linear; transform: none; }
    .choice-btn, .title-inner, .chapter-card.is-in { animation: none; }
    .advance { animation: none; }
}

/* ---------- Телефон (портрет) ---------- */
@media (max-width: 640px) {
    .hud { padding: max(0.7rem, env(safe-area-inset-top)) 0.85rem 0.7rem; }
    .hud-btn { padding: 0.45rem 0.7rem; font-size: 0.78rem; }
    .threads { gap: 0.4rem; padding: 0.3rem 0.55rem; }

    .game-sub { font-size: 0.98rem; }
    .title-note { font-size: 0.72rem; }
    .title-actions .button { width: 100%; }
    .title-actions { width: 100%; }

    .chapter-card { padding: 0 7vw; gap: 0.6rem; }
    .chapter-card .place { font-size: 0.78rem; }

    .dialogue { padding-bottom: 0; }
    .dialogue-inner {
        padding: 1.15rem 1.15rem calc(1.3rem + env(safe-area-inset-bottom));
        border-radius: 0;
    }
    .speaker { font-size: 1rem; margin-bottom: 0.35rem; }
    .line { font-size: 1.06rem; line-height: 1.6; }
    .advance { right: 1rem; bottom: calc(0.7rem + env(safe-area-inset-bottom)); }

    .choices { padding: 7vh 5vw calc(7vh + env(safe-area-inset-bottom)); gap: 0.6rem; justify-content: safe flex-end; overflow-y: auto; }
    .choices .prompt { margin-bottom: 0.6rem; }
    .choice-btn { padding: 0.9rem 1.05rem; font-size: 0.98rem; }

    .overlay { padding: 5vh 5vw; }
    .overlay-panel { padding: 1.4rem; }
    .history-log { max-height: 62vh; }
}

/* ---------- Телефон (альбом, низкая высота) ---------- */
@media (max-height: 460px) and (orientation: landscape) {
    .title-inner { gap: 0.6rem; }
    .game-name { font-size: clamp(2.4rem, 9vh, 3.4rem); }
    .game-name::after { margin-top: 0.6rem; }
    .chapter-card .title { font-size: clamp(1.8rem, 8vh, 2.8rem); }
    .dialogue-inner { padding: 0.8rem 1.4rem calc(0.9rem + env(safe-area-inset-bottom)); }
    .line { font-size: 1rem; line-height: 1.5; }
    .choices { padding: 2vh 8vw; justify-content: center; }
    .choice-btn { padding: 0.7rem 1rem; }
}
