/* «Стекло»: иллюстрация главы правит экраном, разворот книги в центре,
   HUD — полупрозрачные панели. Ночная палитра, тёплое золото, бумага страниц.
   Мобильный экран — основной; широкий — расширение. */

* { box-sizing: border-box; margin: 0; }
:root {
  --night: #080a0c;
  --light: #F5F0E7;
  --dim: rgba(243, 238, 226, 0.62);
  --gold: #E8BB70;
  --gold-bright: #FFD992;
  --teal: #6EAAA2;
  --glass: rgba(13, 15, 18, 0.62);
  --glass-strong: rgba(10, 12, 15, 0.86);
  --glass-line: rgba(245, 240, 231, 0.17);
  --paper: rgba(244, 240, 229, 0.97);
  --paper-ink: #26221B;
  --paper-dim: #6E6455;
  --good: #7FC79A;
  --good-paper: #3E8E58;
  --bad: #D2705C;
  --serif: "Iowan Old Style", Palatino, Georgia, "Times New Roman", serif;
  --display: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

html, body { height: 100%; }
body {
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--night);
  color: var(--light);
  overflow: hidden;
}

/* ——— фон-иллюстрация ——— */
.backdrop {
  position: fixed; inset: 0; z-index: 0;
  background: var(--night) center/cover no-repeat;
  filter: blur(14px) brightness(0.55) saturate(0.9);
  transform: scale(1.08);
  transition: background-image 1.2s ease;
}
.backdrop.is-setup {
  background-position: center 57%;
  filter: brightness(0.64) saturate(0.82) contrast(1.04);
  transform: scale(1.015);
}
.backdrop-veil {
  position: fixed; inset: 0; z-index: 1;
  background: radial-gradient(ellipse at center 32%, rgba(12,13,16,0.12), rgba(12,13,16,0.66) 82%);
  pointer-events: none;
}
.backdrop.is-setup + .backdrop-veil {
  background:
    linear-gradient(180deg, rgba(7,9,11,0.1) 0%, rgba(7,9,11,0.2) 38%, rgba(7,9,11,0.86) 100%),
    radial-gradient(ellipse at 50% 58%, rgba(232,187,112,0.08), rgba(8,10,12,0.58) 78%);
}

/* visualViewport из app.js учитывает и высоту клавиатуры iOS, и панорамирование
   layout viewport к активному полю. Без --vv-top экран обрывается над клавиатурой. */
.screen {
  position: relative;
  top: var(--vv-top, 0px);
  z-index: 2;
  width: 100%;
  height: var(--vvh, 100dvh);
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

.glass {
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.08);
  -webkit-backdrop-filter: blur(18px) saturate(1.08);
  border: 1px solid var(--glass-line);
  border-radius: 12px;
}
.hud-label {
  font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 6px;
}
.serif, .page-text { font-family: var(--serif); }

/* ——— экран новой книги ——— */
#setupScreen {
  align-items: center;
  justify-content: flex-start;
  gap: clamp(24px, 5vh, 52px);
  padding: calc(30px + env(safe-area-inset-top)) 20px calc(42px + env(safe-area-inset-bottom));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.brand { width: min(100%, 620px); text-align: left; text-shadow: 0 2px 22px rgba(0,0,0,0.72); }
.brand-lockup { display: flex; align-items: center; gap: 10px; font-family: var(--display); letter-spacing: 0.16em; }
.brand-lockup strong { font-size: 0.92rem; letter-spacing: 0.22em; }
.brand-symbol {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 1px solid rgba(232,187,112,0.74); border-radius: 50%;
  color: var(--gold-bright); font-family: var(--serif); font-size: 1rem;
  box-shadow: inset 0 0 0 4px rgba(232,187,112,0.08), 0 0 24px rgba(232,187,112,0.13);
}
.alpha-chip {
  margin-left: 3px; padding: 5px 8px; border: 1px solid rgba(110,170,162,0.42); border-radius: 999px;
  color: #A9D1CA; background: rgba(35,72,68,0.26); font-size: 0.58rem; letter-spacing: 0.09em; text-transform: uppercase;
}
.brand h1 {
  margin-top: 22px; font-family: var(--display); font-size: clamp(2.8rem, 9vw, 5.3rem);
  line-height: 0.93; letter-spacing: -0.055em; font-weight: 780;
}
.brand h1 em { color: var(--gold-bright); font-style: normal; font-weight: 600; }
.brand > p { max-width: 570px; margin-top: 18px; color: rgba(245,240,231,0.76); line-height: 1.55; font-size: 1rem; }
.brand-traits { display: flex; flex-wrap: wrap; gap: 9px 16px; margin-top: 20px; color: rgba(245,240,231,0.78); font-size: 0.76rem; }
.brand-traits span { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.brand-traits span::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 10px rgba(232,187,112,0.7); }
.locale-toggle {
  min-width: 42px; min-height: 34px; padding: 5px 9px;
  border: 1px solid var(--glass-line); border-radius: 999px;
  background: rgba(12,13,16,0.5); color: var(--light);
  font: 650 0.68rem/1 var(--display); letter-spacing: 0.08em; cursor: pointer;
}
.locale-toggle:hover, .locale-toggle:focus-visible { border-color: var(--gold); color: var(--gold-bright); outline: none; }
.brand-lockup .locale-toggle { margin-inline-start: auto; }
.topbar .topbar-locale { flex: none; width: 44px; min-width: 44px; padding: 7px; }
.account-trigger {
  min-height: 34px; max-width: 180px; padding: 6px 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border: 1px solid rgba(232,187,112,0.34); border-radius: 999px;
  background: rgba(12,13,16,0.54); color: var(--gold-bright);
  font: 600 0.7rem/1 var(--display); cursor: pointer;
}
.account-trigger:hover, .account-trigger:focus-visible { border-color: var(--gold); outline: none; }
.auth-screen { align-items: center; justify-content: center; padding: 24px; }
.auth-card, .account-card {
  position: relative; width: min(100%, 430px); padding: 30px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 14px;
  background: linear-gradient(155deg, rgba(23,25,29,0.94), rgba(9,11,14,0.91));
  border-radius: 24px; box-shadow: 0 28px 90px rgba(0,0,0,0.58);
}
.account-card { max-height: min(680px, calc(100dvh - 40px)); overflow-y: auto; }
.auth-symbol { width: 46px; height: 46px; font-size: 1.25rem; }
.auth-card h1, .auth-card h2, .account-card h2 { font-family: var(--display); line-height: 1.08; letter-spacing: -0.03em; }
.auth-card h1 { font-size: clamp(1.8rem, 7vw, 2.5rem); }
.auth-card h2, .account-card h2 { padding-right: 38px; font-size: 1.45rem; }
.auth-card > p, .auth-card small, .account-card > p, .account-user p { color: var(--dim); line-height: 1.5; }
.auth-card small { font-size: 0.7rem; }
.google-button-host { width: 100%; min-height: 44px; display: flex; align-items: center; justify-content: flex-start; }
.auth-error { color: #F0A08F; font-size: 0.8rem; line-height: 1.4; }
.account-panel {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  padding: 20px; background: rgba(4,5,7,0.68); backdrop-filter: blur(10px);
}
.account-close { position: absolute; top: 14px; right: 14px; }
.account-user { width: 100%; display: grid; gap: 7px; }
.account-user strong { font-family: var(--display); font-size: 1.05rem; }
.account-user > span { color: var(--dim); font-size: 0.8rem; overflow-wrap: anywhere; }
.account-summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.account-summary > div { min-width: 0; display: grid; }
.account-summary strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-footer {
  width: min(100%, 1180px); display: flex; justify-content: space-between; gap: 14px;
  color: rgba(245,240,231,0.42); font-size: 0.7rem; letter-spacing: 0.04em;
}

.setup-card {
  width: min(100%, 570px); min-width: 0; padding: 24px;
  display: flex; flex-direction: column; gap: 14px;
  background: linear-gradient(155deg, rgba(23,25,29,0.84), rgba(9,11,14,0.76));
  border-color: rgba(245,240,231,0.2); border-radius: 24px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.48), inset 0 1px 0 rgba(255,255,255,0.04);
}
.setup-step { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--dim); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; }
.setup-step strong { color: var(--gold); font-weight: 650; }
.setup-title { font-family: var(--display); font-size: clamp(1.45rem, 5vw, 1.9rem); line-height: 1.1; letter-spacing: -0.025em; }
.setup-hint { color: var(--dim); font-size: 0.88rem; line-height: 1.5; }

.option-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.option-card {
  font: inherit; color: var(--light); text-align: left; cursor: pointer;
  background: rgba(245,240,231,0.055);
  border: 1px solid var(--glass-line); border-radius: 10px;
  padding: 12px 13px; min-width: 0;
}
.option-card:hover { border-color: rgba(232,187,112,0.56); }
.option-card.selected { border-color: var(--gold); background: rgba(232,187,112,0.13); box-shadow: inset 3px 0 0 var(--gold); }
.option-card b { display: block; font-size: 0.95rem; }
.option-card small { color: var(--dim); font-size: 0.8rem; line-height: 1.35; display: block; margin-top: 2px; }

.option-row { display: flex; gap: 8px; flex-wrap: nowrap; }
.option-chip {
  flex: 1 1 0; min-width: 0; font: inherit; cursor: pointer; font-size: 0.84rem;
  background: rgba(245,240,231,0.055); color: var(--light);
  border: 1px solid var(--glass-line); border-radius: 999px;
  padding: 11px 9px;
}
.option-chip:hover { border-color: rgba(232,187,112,0.56); }
.option-chip.selected { border-color: var(--gold); color: #201A0E; background: var(--gold); font-weight: 700; }
.genre-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.genre-list .option-chip { border-radius: 12px; min-height: 44px; }
.genre-hint { min-height: 2.7em; margin-top: -6px; color: var(--dim); font-size: 0.78rem; line-height: 1.35; }

.premise-toggle {
  width: 100%; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 13px; font: inherit; color: var(--light); text-align: left; cursor: pointer;
  border: 1px solid var(--glass-line); border-radius: 14px; background: rgba(4,6,8,0.22);
}
.premise-toggle:hover { border-color: rgba(232,187,112,0.5); }
.premise-toggle > span { min-width: 0; display: grid; gap: 3px; }
.premise-toggle b { font-size: 0.88rem; line-height: 1.25; }
.premise-toggle em { color: var(--dim); font-size: 0.72rem; font-style: normal; line-height: 1.35; }
.premise-toggle > strong {
  flex: 0 0 auto; min-width: 48px; padding: 6px 8px; border-radius: 999px;
  color: var(--dim); background: rgba(245,240,231,0.06); font-size: 0.7rem; text-align: center;
}
.premise-toggle[aria-pressed="true"] { border-color: var(--gold); background: rgba(232,187,112,0.13); }
.premise-toggle[aria-pressed="true"] > strong { color: #201a0e; background: var(--gold); }

.setup-advanced { border: 1px solid var(--glass-line); border-radius: 14px; background: rgba(4,6,8,0.2); overflow: hidden; }
.setup-advanced summary { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 13px; cursor: pointer; list-style: none; color: var(--dim); font-size: 0.82rem; }
.setup-advanced summary::-webkit-details-marker { display: none; }
.setup-advanced summary::after { content: '+'; color: var(--gold); font-size: 1.05rem; }
.setup-advanced[open] summary::after { content: '−'; }
.setup-advanced summary strong { margin-left: auto; color: var(--light); font-weight: 600; }
.setup-advanced > .setup-hint { padding: 0 13px 10px; }
.setup-advanced .option-list { padding: 0 10px 10px; grid-template-columns: 1fr; }

.primary-button {
  min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font: inherit; cursor: pointer; margin-top: 4px;
  background: linear-gradient(100deg, var(--gold), var(--gold-bright)); color: #201A0E; font-weight: 760;
  border: none; border-radius: 14px; padding: 13px 17px; font-size: 1rem;
  box-shadow: 0 10px 30px rgba(232,187,112,0.16);
}
.primary-button:hover { filter: brightness(1.05); transform: translateY(-1px); }
.primary-button:active { transform: translateY(0); }
.ghost-button {
  background: rgba(243,238,226,0.08); color: var(--light);
  border: 1px solid var(--glass-line); border-radius: 10px;
  min-width: 44px; height: 44px; font-size: 1.05rem; cursor: pointer;
}
.ghost-button.wide { width: auto; padding: 0 16px; height: auto; min-height: 44px; }

#introInput {
  width: 100%; max-width: 100%;
  font: inherit; font-size: 1rem; line-height: 1.5;
  background: rgba(3,5,7,0.42); color: var(--light);
  border: 1px solid rgba(245,240,231,0.23); border-radius: 14px;
  padding: 14px; resize: vertical; min-height: 9em;
}
#introInput:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(232,187,112,0.12); }
#introInput::placeholder, #moveInput::placeholder { color: rgba(243,238,226,0.4); }
.timeline-picker {
  min-width: 0; border: 1px solid var(--glass-line); border-radius: 15px;
  background: rgba(4,6,8,0.24); overflow: hidden;
}
.timeline-picker > summary {
  min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 10px 13px; cursor: pointer; list-style: none;
}
.timeline-picker > summary::-webkit-details-marker { display: none; }
.timeline-picker > summary > span { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.timeline-picker > summary .hud-label { margin: 0; }
.timeline-picker > summary b { color: var(--light); font-size: 0.9rem; }
.timeline-picker > summary strong {
  min-width: 0; color: var(--gold-bright); font-size: 0.72rem; line-height: 1.3; font-weight: 600;
  text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.timeline-picker > summary::after { content: '+'; flex: none; color: var(--gold); font-size: 1.05rem; }
.timeline-picker[open] > summary::after { content: '−'; }
.timeline-body {
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
  padding: 0 13px 13px; border-top: 1px solid rgba(245,240,231,0.07);
}
.timeline-body > p { padding-top: 11px; color: var(--dim); font-size: 0.76rem; line-height: 1.42; }
.timeline-preview {
  min-width: 0; display: flex; flex-direction: column; gap: 4px; padding: 11px 12px;
  border: 1px solid var(--glass-line); border-radius: 12px; background: rgba(245,240,231,0.045);
}
.timeline-preview.selected { border-color: var(--gold); background: rgba(232,187,112,0.13); }
.timeline-preview span { color: var(--gold-bright); font-size: 0.67rem; line-height: 1.3; }
.timeline-preview strong { font-family: var(--display); font-size: 0.94rem; line-height: 1.28; }
.timeline-preview small { color: var(--dim); font-size: 0.72rem; line-height: 1.35; }
#timelineRange {
  width: 100%; height: 28px; margin: 0; accent-color: var(--gold); cursor: ew-resize;
}
#timelineRange:disabled { cursor: default; opacity: 0.45; }
.timeline-limits { display: grid; grid-template-columns: 1fr 1fr 1fr; margin-top: -5px; color: var(--dim); font-size: 0.61rem; }
.timeline-limits span:nth-child(2) { text-align: center; }
.timeline-limits span:last-child { text-align: right; }
.timeline-actions { display: flex; gap: 8px; min-width: 0; }
.timeline-actions > * { min-width: 0; }
.timeline-actions .ghost-button { flex: 0 1 auto; font-size: 0.74rem; }
.timeline-select {
  flex: 1; min-height: 44px; padding: 9px 12px; border: 1px solid var(--gold); border-radius: 11px;
  background: rgba(232,187,112,0.13); color: var(--gold-bright); font: inherit; font-size: 0.82rem; font-weight: 680; cursor: pointer;
}
.timeline-select:hover, .timeline-select:focus-visible { background: rgba(232,187,112,0.22); outline: none; }
.timeline-select:disabled { opacity: 0.48; cursor: default; }
.historical-choice {
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
  padding: 13px; border: 1px solid rgba(232,187,112,0.38); border-radius: 15px;
  background: linear-gradient(145deg, rgba(66,48,24,0.3), rgba(5,8,10,0.46));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.035);
}
.historical-choice-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.historical-choice-head h3 { margin-top: 3px; font-family: var(--display); font-size: 1rem; line-height: 1.2; }
.historical-choice > p { color: var(--dim); font-size: 0.78rem; line-height: 1.4; }
.historical-candidates { display: grid; grid-template-columns: 1fr; gap: 7px; min-width: 0; }
.historical-candidate {
  width: 100%; min-width: 0; display: grid; grid-template-columns: minmax(0,1fr);
  gap: 3px; padding: 11px 12px; text-align: left; cursor: pointer; font: inherit; color: var(--light);
  border: 1px solid var(--glass-line); border-radius: 11px; background: rgba(245,240,231,0.045);
}
.historical-candidate:hover { border-color: rgba(232,187,112,0.58); }
.historical-candidate.selected {
  border-color: var(--gold); background: rgba(232,187,112,0.15); box-shadow: inset 3px 0 0 var(--gold);
}
.historical-candidate strong { min-width: 0; font-size: 0.88rem; line-height: 1.3; }
.historical-candidate span { color: var(--gold-bright); font-size: 0.68rem; line-height: 1.3; }
.historical-candidate small { color: var(--dim); font-size: 0.73rem; line-height: 1.35; }
.setup-examples { display: flex; flex-direction: column; gap: 6px; }
.example-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.example-chip {
  font: inherit; cursor: pointer; font-size: 0.84rem;
  background: rgba(232,187,112,0.09); color: var(--light);
  border: 1px solid rgba(232,187,112,0.32); border-radius: 999px;
  padding: 11px 14px;
}
.example-chip.selected {
  border-color: var(--gold);
  background: rgba(242,200,121,0.24);
  color: #fff8e8;
}
.setup-actions { display: flex; gap: 10px; align-items: stretch; min-width: 0; }
.setup-actions > * { min-width: 0; }
.setup-actions .primary-button { flex: 1; margin-top: 0; }

.continue-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--glass-line); }
.continue-list:empty { display: none; }
.continue-list:not(:empty)::before { content: 'Мои книги'; font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); }
.continue-item {
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
  background: transparent; color: var(--light);
  border: 1px solid var(--glass-line); border-radius: 10px;
  padding: 11px 14px; cursor: pointer; font: inherit; width: 100%; text-align: left;
}
.continue-item small { color: var(--dim); }
.continue-item:hover { border-color: var(--gold); }

.build-mark {
  position: fixed; right: 8px; bottom: calc(4px + env(safe-area-inset-bottom)); z-index: 40;
  color: rgba(245,240,231,0.38); font-size: 0.58rem; letter-spacing: 0.08em;
  pointer-events: none; text-shadow: 0 1px 4px rgba(0,0,0,0.9);
}

/* ——— книга: шапка ——— */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  border-radius: 0; border-left: none; border-right: none; border-top: none;
}
.glass-bar {
  background: rgba(12,13,16,0.42);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  border-bottom: 1px solid var(--glass-line);
}
.book-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.book-title strong { font-family: var(--serif); font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-title span { font-size: 0.75rem; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tariff { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.tariff .hud-label { margin: 0; }
.tariff select {
  font: inherit; font-size: 0.82rem;
  background: rgba(243,238,226,0.08); color: var(--light);
  border: 1px solid var(--glass-line); border-radius: 8px; padding: 5px 8px;
}
.tariff select option { background: #1a1c21; color: var(--light); }
.reader-open {
  min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 7px 11px; border: 1px solid var(--glass-line); border-radius: 10px;
  background: rgba(243,238,226,0.08); color: var(--light); font: inherit; font-size: 0.82rem; cursor: pointer;
}
.reader-open:hover, .reader-open:focus-visible { border-color: var(--gold); color: var(--gold-bright); outline: none; }
.reader-open-icon { font-size: 1.15rem; line-height: 1; }

/* Полноценная читалка: половина экрана на компьютере, весь экран на телефоне. */
.reader-panel {
  --reader-surface: #F4F0E5;
  --reader-head: rgba(234,226,209,0.92);
  --reader-ink: #26221B;
  --reader-dim: #6E6455;
  --reader-accent: #8A5A2B;
  --reader-line: rgba(86,69,44,0.22);
  position: fixed; top: var(--vv-top, 0px); right: 0; z-index: 35;
  width: clamp(520px, 50vw, 760px); height: var(--vvh, 100dvh);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--reader-surface); color: var(--reader-ink);
  border-left: 1px solid var(--reader-line);
  box-shadow: -28px 0 70px rgba(0,0,0,0.58);
  transform: translateX(102%); visibility: hidden;
  transition: transform 0.24s ease, visibility 0s linear 0.24s;
}
.reader-panel.is-open {
  transform: translateX(0); visibility: visible;
  transition: transform 0.24s ease, visibility 0s;
}
.reader-head {
  flex: none; display: flex; align-items: center; gap: 18px; justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 24px 14px;
  border-bottom: 1px solid var(--reader-line);
  background: var(--reader-head);
}
.reader-heading { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.reader-heading .hud-label { margin: 0 0 2px; color: var(--reader-accent); }
.reader-heading strong {
  font-family: var(--serif); font-size: 1.08rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reader-clock {
  color: var(--reader-dim); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.reader-head-actions { flex: none; display: flex; align-items: center; gap: 10px; }
.reader-material {
  max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 5px 9px; border: 1px solid var(--reader-line); border-radius: 999px;
  color: var(--reader-accent); background: rgba(255,255,255,0.16);
  font-family: var(--display); font-size: 0.62rem; font-weight: 650; letter-spacing: 0.055em; text-transform: uppercase;
}
.reader-close {
  flex: none; width: 44px; height: 44px; border: 1px solid var(--reader-line); border-radius: 50%;
  background: rgba(255,255,255,0.22); color: var(--reader-ink); font: inherit; font-size: 1.45rem; cursor: pointer;
}
.reader-close:hover, .reader-close:focus-visible { border-color: var(--reader-accent); color: var(--reader-accent); outline: none; }

.illustrating {
  position: absolute; top: calc(60px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 4;
  font-size: 0.78rem; letter-spacing: 0.04em; color: var(--dim);
  background: var(--glass); border: 1px solid var(--glass-line);
  border-radius: 999px; padding: 4px 12px;
}

/* ——— сцена: разворот + HUD ——— */
.stage {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) 248px;
  gap: 14px; padding: 14px;
  align-items: start;
}
.spread { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.m-tabs { display: none; gap: 4px; }
.m-tabs button {
  font: inherit; font-size: 0.78rem; cursor: pointer;
  color: var(--dim); background: transparent; border: 1px solid transparent;
  padding: 7px 14px; border-radius: 9px 9px 0 0;
}
.m-tabs button.on { background: var(--paper); color: var(--paper-ink); }

.spread-pages {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr);
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}
.page-text {
  position: relative; isolation: isolate;
  flex: 1; min-height: 0; background: var(--reader-surface); color: var(--reader-ink);
  overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; padding: 34px clamp(28px, 5vw, 62px) 42px;
}
.page-text::before {
  content: '';
  position: absolute; z-index: -1; inset: 0; overflow: hidden; pointer-events: none;
  opacity: 0.46;
}
.page-art {
  position: relative; min-height: 0;
  background: #101114 center/cover no-repeat;
}
.page-art .caption, .page-art figcaption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 26px 16px 10px;
  background: linear-gradient(0deg, rgba(10,10,12,0.72), transparent);
  color: var(--light); font-size: 0.78rem; letter-spacing: 0.05em;
}

.chronicle { position: relative; z-index: 1; width: min(100%, 680px); margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.entry-world { font-size: 1.08rem; line-height: 1.7; white-space: pre-wrap; }
/* Буквица — только на первом абзаце главы. */
.entry-world.first-entry::first-letter { font-size: 1.6em; color: var(--reader-accent); }
.entry-player {
  align-self: flex-end; max-width: 88%;
  font-style: italic; color: var(--reader-dim);
  border-inline-end: 3px solid var(--reader-accent); padding-inline-end: 10px;
  font-size: 0.93rem; line-height: 1.5; white-space: pre-wrap;
}
.entry-meta { font-size: 0.74rem; letter-spacing: 0.05em; color: var(--reader-accent); }
.entry-development { padding-inline-start: 12px; border-inline-start: 2px solid var(--reader-line); margin-top: 4px; font-size: 0.93rem; line-height: 1.5; }
.entry-development b { display: block; font-size: 0.78rem; letter-spacing: 0.03em; color: var(--reader-accent); }
.entry-development span { display: block; }
.entry-world[dir="rtl"], .entry-player[dir="rtl"], .entry-development[dir="rtl"],
.suggestion[dir="rtl"], .hud-row[dir="rtl"], .concern[dir="rtl"],
.person-copy[dir="rtl"], .history-item [dir="rtl"] {
  direction: rtl; text-align: right; unicode-bidi: plaintext;
}
.entry-world.first-entry[dir="rtl"]::first-letter { font-size: inherit; color: inherit; }
.thinking { position: relative; z-index: 1; margin-top: 14px; color: var(--reader-dim); font-style: italic; font-family: var(--serif); }
.quill { display: inline-block; animation: quill 1.1s ease-in-out infinite; }
@keyframes quill { 0%,100% { transform: rotate(-4deg); } 50% { transform: rotate(7deg) translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .quill { animation: none; } }

/* ——— разбор хода ——— */
.verdict {
  flex: none; margin: 0; padding: 12px clamp(28px, 5vw, 62px) calc(14px + env(safe-area-inset-bottom));
  border: 0; border-top: 1px solid var(--reader-line); border-radius: 0;
  background: var(--reader-head); color: var(--reader-ink); font-size: 0.86rem; line-height: 1.45;
}
.verdict summary { cursor: pointer; list-style: none; }
.verdict summary::-webkit-details-marker { display: none; }
.verdict .roll { color: var(--reader-dim); font-size: 0.79rem; margin-top: 6px; }
.verdict .up { color: var(--good-paper); font-weight: 600; }
.verdict .down { color: var(--bad); font-weight: 600; }

/* Материал страницы выбирается из культуры и даты кампании. Все фактуры
   построены CSS-градиентами: они бесплатны, работают офлайн и не ждут ИИ. */
.reader-panel[data-material="stone"] {
  --reader-surface:
    radial-gradient(circle at 18% 12%, rgba(255,255,255,0.14) 0 1px, transparent 2px),
    radial-gradient(circle at 76% 64%, rgba(0,0,0,0.12) 0 1px, transparent 3px),
    linear-gradient(135deg, #85857B, #B0ADA0 44%, #74766F);
  --reader-head: rgba(70,72,68,0.94); --reader-ink: #1C1D1A; --reader-dim: #393C37;
  --reader-accent: #EEE3C4; --reader-line: rgba(28,29,26,0.3);
}
.reader-panel[data-material="stone"] .page-text { text-shadow: 0 1px rgba(255,255,255,0.24); }
.reader-panel[data-material="stone"] .page-text::before {
  content: '⋮  △  ◯  ╱╲     ✣  ⋮';
  padding: 10vh 7vw; color: rgba(24,25,22,0.2); font: 700 clamp(2rem, 7vw, 5rem)/2 Georgia, serif;
  letter-spacing: 0.35em;
}

.reader-panel[data-material="clay"] {
  --reader-surface:
    radial-gradient(ellipse at 20% 16%, rgba(255,229,179,0.24), transparent 28%),
    repeating-linear-gradient(8deg, rgba(90,46,23,0.045) 0 1px, transparent 1px 9px),
    #C88757;
  --reader-head: rgba(139,78,43,0.95); --reader-ink: #2B170F; --reader-dim: #5C3020;
  --reader-accent: #FFE0A9; --reader-line: rgba(63,31,16,0.3);
}
.reader-panel[data-material="clay"] .page-text::before {
  content: '𒀭 𒂗 𒆠 𒌋  𒀭 𒂗'; right: 8%; left: auto; width: 36%; padding-top: 9vh;
  color: rgba(65,32,16,0.18); font-size: clamp(2.2rem, 6vw, 4.6rem); line-height: 1.8; word-break: break-all;
}

.reader-panel[data-material="runic"] {
  --reader-surface:
    repeating-linear-gradient(92deg, rgba(255,223,170,0.025) 0 2px, rgba(0,0,0,0.045) 3px 13px),
    linear-gradient(105deg, #4B3528, #72513B 48%, #3D2E26);
  --reader-head: rgba(42,31,27,0.96); --reader-ink: #F1DFC0; --reader-dim: #C2AD8E;
  --reader-accent: #F0B96E; --reader-line: rgba(240,185,110,0.25);
}
.reader-panel[data-material="runic"] .page-text::before {
  content: 'ᚠ ᚢ ᚦ ᚨ ᚱ ᚲ  ·  ᚺ ᚾ ᛁ ᛃ ᛇ';
  padding: 7vh 2vw; color: rgba(246,213,165,0.12); font-size: clamp(2rem, 5vw, 4rem); letter-spacing: 0.24em;
  writing-mode: vertical-rl;
}

.reader-panel[data-material="papyrus"] {
  --reader-surface:
    repeating-linear-gradient(0deg, rgba(118,78,26,0.055) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.08) 0 2px, transparent 2px 18px),
    #D8B86F;
  --reader-head: rgba(184,143,69,0.94); --reader-ink: #302313; --reader-dim: #6E5128;
  --reader-accent: #7A261B; --reader-line: rgba(82,51,17,0.27);
}
.reader-panel[data-material="papyrus"] .page-text { box-shadow: inset 18px 0 28px rgba(91,52,16,0.12), inset -18px 0 28px rgba(91,52,16,0.12); }
.reader-panel[data-material="papyrus"] .page-text::before {
  content: '☥   𓂀   𓆣'; left: auto; width: 28%; padding-top: 12vh;
  color: rgba(95,45,22,0.13); font-size: clamp(2.5rem, 7vw, 5.5rem); line-height: 2.2;
}

.reader-panel[data-material="parchment"] {
  --reader-surface:
    radial-gradient(ellipse at 12% 18%, rgba(122,76,30,0.09), transparent 25%),
    radial-gradient(ellipse at 90% 75%, rgba(122,76,30,0.08), transparent 28%),
    #E4D2A8;
  --reader-head: rgba(199,174,124,0.95); --reader-ink: #2D251A; --reader-dim: #716047;
  --reader-accent: #812E25; --reader-line: rgba(91,60,31,0.25);
}
.reader-panel[data-material="parchment"] .page-text { box-shadow: inset 14px 0 20px rgba(73,45,18,0.12), inset -14px 0 20px rgba(73,45,18,0.12); }
.reader-panel[data-material="parchment"] .page-text::before {
  content: '✥'; display: grid; place-items: center; color: rgba(117,52,35,0.08); font-size: min(38vw, 18rem);
}

.reader-panel[data-material="print"] {
  --reader-surface:
    radial-gradient(circle, rgba(45,38,28,0.045) 0 0.7px, transparent 0.8px) 0 0 / 5px 5px,
    #F2EEE2;
  --reader-head: rgba(226,219,202,0.96); --reader-ink: #26221B; --reader-dim: #6E6455;
  --reader-accent: #7C4F24; --reader-line: rgba(86,69,44,0.22);
}
.reader-panel[data-material="print"] .page-text::before {
  content: 'ODNA'; right: 5%; bottom: 3%; left: auto; top: auto; min-height: 0;
  color: rgba(56,43,28,0.055); font: 800 clamp(3rem, 9vw, 7rem)/1 Georgia, serif; letter-spacing: 0.08em;
}

.reader-panel[data-material="notebook"] {
  --reader-surface:
    linear-gradient(rgba(67,128,164,0.14) 1px, transparent 1px),
    linear-gradient(90deg, rgba(67,128,164,0.14) 1px, transparent 1px),
    #F5F2E8;
  --reader-head: rgba(225,225,216,0.96); --reader-ink: #1E2D39; --reader-dim: #566977;
  --reader-accent: #A64B43; --reader-line: rgba(65,102,126,0.25);
}
.reader-panel[data-material="notebook"] .page-text { background-size: 24px 24px; }
.reader-panel[data-material="notebook"] .page-text::before {
  content: ''; left: clamp(15px, 4vw, 42px); right: auto; width: 2px; background: rgba(190,67,61,0.25);
}

.reader-panel[data-material="screen"] {
  --reader-surface:
    radial-gradient(ellipse at center, rgba(28,78,66,0.17), transparent 72%),
    #07100F;
  --reader-head: rgba(5,17,16,0.97); --reader-ink: #BDE8D4; --reader-dim: #70A690;
  --reader-accent: #70E0B3; --reader-line: rgba(112,224,179,0.22);
  font-family: "Cascadia Mono", Consolas, monospace;
}
.reader-panel[data-material="screen"] .reader-heading strong,
.reader-panel[data-material="screen"] .page-text { font-family: "Cascadia Mono", Consolas, monospace; }
.reader-panel[data-material="screen"] .page-text { text-shadow: 0 0 12px rgba(112,224,179,0.16); }
.reader-panel[data-material="screen"] .page-text::before {
  content: ''; opacity: 0.42;
  background: repeating-linear-gradient(0deg, transparent 0 3px, rgba(112,224,179,0.045) 3px 4px);
}

/* ——— HUD-панели ——— */
.hudstack { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; max-height: 100%; }
.hud-panel { padding: 11px 13px; }
.hud-row { font-size: 0.86rem; line-height: 1.4; }
.hud-dim { color: var(--dim); font-size: 0.76rem; margin-top: 2px; }
.concern { cursor: pointer; padding: 6px 0; font-size: 0.85rem; line-height: 1.35; border-bottom: 1px dashed var(--glass-line); }
.concern:last-child { border-bottom: none; }
.concern:hover strong { color: var(--gold); }
.concern strong { display: block; font-weight: 500; }
.concern small { color: var(--dim); font-size: 0.74rem; }
.concern.urgent strong::before { content: '⚑ '; color: var(--bad); }
.person {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 4px 8px;
  font-size: 0.84rem; padding: 7px 0; border-bottom: 1px dashed var(--glass-line);
}
.person:last-child { border-bottom: none; }
.person-copy { min-width: 0; }
.person-copy b { display: block; overflow: hidden; text-overflow: ellipsis; }
.person span { display: block; color: var(--dim); font-size: 0.72rem; margin-top: 1px; }
.person-role {
  max-width: 132px; padding: 5px 7px; border: 1px solid var(--glass-line); border-radius: 8px;
  background: rgba(12,13,16,0.72); color: var(--light); font: inherit; font-size: 0.72rem;
  cursor: pointer;
}
.person-role:hover, .person-role:focus-visible { border-color: var(--gold); outline: none; }
.resource { display: flex; justify-content: space-between; font-size: 0.84rem; padding: 4px 0; font-variant-numeric: tabular-nums; }
.resource .up { color: var(--good); font-weight: 600; }
.resource .down { color: var(--bad); font-weight: 600; }
.bar-track { height: 5px; border-radius: 4px; overflow: hidden; background: rgba(243,238,226,0.18); margin-top: 6px; }
.bar-fill { display: block; height: 100%; width: 0; background: var(--gold); transition: width 0.5s ease; }

/* ——— композер ——— */
.composer {
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(12,13,16,0.88), rgba(12,13,16,0.25));
}
.suggestions { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.suggestions:empty { display: none; }
.suggestion {
  flex-shrink: 0; font: inherit; font-size: 0.84rem;
  background: var(--glass); color: var(--light);
  border: 1px solid var(--glass-line); border-radius: 999px;
  padding: 11px 14px; cursor: pointer; max-width: 78vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.suggestion:hover { border-color: var(--gold); color: var(--gold); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#moveInput {
  flex: 1; font: inherit; font-size: 1rem; line-height: 1.4;
  background: rgba(18,19,23,0.65); color: var(--light);
  border: 1px solid rgba(243,238,226,0.25); border-radius: 12px;
  padding: 11px 13px; resize: none; max-height: 30dvh; text-align: start;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.live-on, .send {
  font: inherit; cursor: pointer; border-radius: 12px; border: none;
  padding: 11px 13px; font-size: 0.9rem;
}
.live-on { background: transparent; border: 1px solid var(--gold); color: var(--gold); white-space: nowrap; }
.send { background: var(--gold); color: #201A0E; min-width: 48px; font-size: 1rem; font-weight: 700; }
button:disabled { opacity: 0.45; cursor: default; }

/* ——— Скрип: оригинальный советник-хранитель страниц ——— */
.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;
}
.advisor {
  position: fixed; right: 18px; bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 20; display: flex; align-items: flex-end; gap: 7px;
  pointer-events: none;
}
.advisor > * { pointer-events: auto; }
.advisor-character {
  position: relative; flex: none; width: 76px; height: 94px; padding: 0;
  border: 0; border-radius: 48%; background: transparent; cursor: pointer;
  filter: drop-shadow(0 8px 10px rgba(0,0,0,0.45));
  animation: advisor-float 4.2s ease-in-out infinite;
  transform-origin: 50% 88%;
}
.advisor-character:hover { filter: drop-shadow(0 8px 12px rgba(242,200,121,0.34)); }
.advisor-character:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.advisor-character.is-speaking { animation: advisor-greet 0.7s ease-in-out, advisor-float 4.2s 0.7s ease-in-out infinite; }
.advisor-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.advisor-shadow { fill: rgba(0,0,0,0.34); }
.advisor-ribbon { fill: #854C38; stroke: #E6B967; stroke-width: 2; stroke-linejoin: round; }
.advisor-wire {
  fill: none; stroke: #C9933E; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round;
}
.advisor-face { fill: #F2D99C; stroke: #8B5B27; stroke-width: 2.5; stroke-linejoin: round; }
.advisor-eyes { fill: #FFF9E9; transform-box: fill-box; transform-origin: center; animation: advisor-blink 5.6s infinite; }
.advisor-pupil { fill: #2A2118; }
.advisor-brow, .advisor-mouth {
  fill: none; stroke: #5D3A21; stroke-width: 2.5; stroke-linecap: round;
}
.advisor-bubble {
  position: relative; width: min(310px, calc(100vw - 112px)); padding: 13px 38px 13px 15px;
  border: 1px solid #BE9653; border-radius: 15px 15px 4px 15px;
  background: linear-gradient(150deg, #FFF8E8, #EADAB8); color: #332719;
  box-shadow: 0 10px 30px rgba(0,0,0,0.38);
  font-size: 0.86rem; line-height: 1.42;
  animation: advisor-bubble-in 0.2s ease-out;
}
.advisor-bubble::after {
  content: ''; position: absolute; right: -9px; bottom: 13px; width: 17px; height: 17px;
  background: #EADAB8; border-right: 1px solid #BE9653; border-bottom: 1px solid #BE9653;
  transform: rotate(-45deg);
}
.advisor-bubble strong { display: block; margin-bottom: 4px; font-family: var(--serif); color: #6D431F; }
.advisor-bubble p { margin: 0; }
.advisor-close {
  position: absolute; top: 5px; right: 5px; z-index: 1; width: 30px; height: 30px;
  border: 0; border-radius: 50%; background: transparent; color: #6D5A43;
  font: inherit; font-size: 1.15rem; cursor: pointer;
}
.advisor-close:hover, .advisor-close:focus-visible { background: rgba(109,67,31,0.1); color: #3D2816; }
@keyframes advisor-float {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-6px) rotate(1.5deg); }
}
@keyframes advisor-greet {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-8deg) scale(1.04); }
  55% { transform: rotate(7deg) scale(1.04); }
  78% { transform: rotate(-3deg); }
}
@keyframes advisor-blink {
  0%, 43%, 47%, 76%, 80%, 100% { transform: scaleY(1); }
  45%, 78% { transform: scaleY(0.08); }
}
@keyframes advisor-bubble-in {
  from { opacity: 0; transform: translateY(5px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ——— ошибки ——— */
.error-banner {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: rgba(122, 46, 29, 0.92); color: var(--light);
  border: 1px solid rgba(210,112,92,0.5);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  font-size: 0.9rem; line-height: 1.4;
}
.error-banner button {
  font: inherit; background: transparent; border: none; color: inherit;
  font-size: 1rem; cursor: pointer; min-width: 44px; min-height: 32px;
}

@media (min-width: 901px) {
  #setupScreen {
    display: grid; grid-template-columns: minmax(420px, 620px) minmax(420px, 570px);
    grid-template-rows: auto auto; align-content: center; justify-content: center;
    column-gap: clamp(42px, 7vw, 110px); row-gap: 36px;
  }
  #setupScreen .brand-footer { grid-column: 1 / -1; }
  .backdrop.is-setup { background-position: center 61%; }
}

/* ——— телефон: разворот складывается, HUD — лента карточек ——— */
@media (max-width: 900px) {
  #setupScreen {
    align-items: stretch; gap: 20px;
    padding: calc(18px + env(safe-area-inset-top)) 14px calc(34px + env(safe-area-inset-bottom));
  }
  .brand {
    min-height: clamp(245px, 32vh, 285px); padding: 12px 8px 0;
    display: flex; flex-direction: column; justify-content: flex-end;
  }
  .brand h1 { margin-top: 13px; font-size: clamp(2.45rem, 11.8vw, 3.5rem); }
  .brand > p { margin-top: 10px; font-size: 0.84rem; line-height: 1.42; }
  .brand-traits { margin-top: 10px; gap: 6px 11px; font-size: 0.66rem; }
  .setup-card { padding: 18px; gap: 11px; border-radius: 22px; }
  .genre-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .genre-hint { min-height: 0; }
  .setup-detail { gap: 8px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .setup-detail .brand, .setup-detail .brand-footer { display: none; }
  .setup-detail .setup-card { margin: 0 auto; }
  #introInput { resize: none; min-height: clamp(130px, 25vh, 210px); }
  .brand-footer { padding: 0 5px; }

  .stage { display: flex; flex-direction: column; gap: 10px; padding: 10px; overflow: hidden; }
  .hudstack {
    order: -1; flex-direction: row; overflow-x: auto; overflow-y: hidden;
    max-height: none; flex: none; padding-bottom: 2px;
  }
  .hud-panel { min-width: 208px; flex-shrink: 0; }
  .spread { flex: 1; min-height: 0; }
  .m-tabs { display: flex; }
  .spread-pages { grid-template-columns: 1fr; border-radius: 0 10px 10px 10px; }
  .page-art { display: block; min-height: 100%; }
  .verdict { margin-top: 8px; }
  .reader-open-label { display: none; }
  .reader-open { padding: 7px; }
  .reader-panel { width: 100vw; border-left: 0; box-shadow: none; }
  .reader-head { padding: calc(11px + env(safe-area-inset-top)) 18px 10px; }
  .reader-heading strong { font-size: 1rem; }
  .reader-material { max-width: 118px; padding: 4px 7px; font-size: 0.56rem; }
  .reader-head-actions { gap: 7px; }
  .page-text { padding: 24px 22px 34px; }
  .chronicle { gap: 16px; }
  .entry-world { font-size: 1.02rem; line-height: 1.66; }
  .verdict {
    margin: 0; padding: 11px 22px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(86,69,44,0.2);
  }
  .advisor { right: 8px; bottom: calc(88px + env(safe-area-inset-bottom)); }
  .advisor-character { width: 66px; height: 82px; }
  .advisor-bubble { width: min(280px, calc(100vw - 90px)); font-size: 0.82rem; }
}

@media (prefers-reduced-motion: reduce) {
  .advisor-character, .advisor-character.is-speaking, .advisor-eyes, .advisor-bubble { animation: none; }
  .primary-button { transition: none; }
}

/* ——— «Живая книга» 0.2: основной игровой экран ———
   Текст и ход всегда на одной поверхности. Вторичные сведения открываются
   поверх книги, а на широком экране иллюстрация остаётся рядом по умолчанию. */
#bookScreen { overflow: hidden; }
#bookScreen .advisor { bottom: calc(168px + env(safe-area-inset-bottom)); }

.living-book-shell {
  flex: 1; min-height: 0; min-width: 0;
  display: grid; grid-template-columns: minmax(0, 68fr) minmax(270px, 32fr);
  gap: 0; padding: 12px;
  transition: grid-template-columns 0.24s ease;
}

.living-book-shell .reader-panel {
  position: relative; inset: auto; z-index: 2;
  width: auto; height: auto; min-width: 0; min-height: 0;
  transform: none; visibility: visible;
  transition: border-radius 0.24s ease;
  border: 1px solid var(--reader-line); border-right: 0;
  border-radius: 18px 0 0 18px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.52);
}

.living-book-shell .page-text { padding-top: 25px; }
.page-material {
  position: relative; z-index: 1; display: table;
  margin: 0 0 20px auto; max-width: min(70%, 240px);
}

.scene-column {
  position: relative; min-width: 0; min-height: 0; overflow: hidden;
  border: 1px solid rgba(245,240,231,0.13); border-left: 0;
  border-radius: 0 18px 18px 0;
  background: #101114;
  box-shadow: 16px 24px 70px rgba(0,0,0,0.42);
  transition: opacity 0.18s ease, transform 0.24s ease, visibility 0s linear;
}

.scene-column .page-art {
  position: absolute; inset: 0; min-height: 0;
  background-color: #111218; background-position: center; background-size: cover;
}
.scene-column .page-art::before,
.art-overlay-image::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 33% 26%, rgba(244,190,92,0.92) 0 7%, rgba(244,190,92,0.22) 8%, transparent 18%),
    linear-gradient(180deg, #25263A 0 42%, #B16D3E 43%, #182530 45% 100%),
    repeating-linear-gradient(174deg, transparent 0 18px, rgba(232,187,112,0.12) 19px 20px);
  opacity: 0.78;
}
.scene-column .page-art.has-art::before { display: none; }
.art-overlay-image.has-art::before { display: none; }
.scene-column .caption { padding-bottom: 92px; }

.art-expand {
  position: absolute; top: 14px; right: 14px; z-index: 3;
  min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--glass-line); border-radius: 10px;
  background: rgba(8,10,12,0.7); color: var(--light);
  font: inherit; font-size: 0.78rem; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.art-expand:hover, .art-expand:focus-visible { border-color: var(--gold); color: var(--gold); outline: none; }

.scene-card {
  position: absolute; z-index: 3; left: 18px; right: 18px; bottom: 18px;
  padding: 13px 15px; background: rgba(7,9,11,0.82);
}
.scene-card .hud-label { display: block; margin-bottom: 4px; }
.scene-card strong { display: block; line-height: 1.35; }
.scene-card > span:last-child { display: block; margin-top: 4px; color: var(--dim); font-size: 0.76rem; }

#bookScreen.book-wide .living-book-shell { grid-template-columns: minmax(0, 1fr) 0fr; }
#bookScreen.book-wide .reader-panel { border-right: 1px solid var(--reader-line); border-radius: 18px; }
#bookScreen.book-wide .scene-column { opacity: 0; visibility: hidden; transform: translateX(24px); }

.topbar-action-icon { font-size: 1.1rem; line-height: 1; }
.topbar-action-label { white-space: nowrap; }

/* Композер теперь физически является нижней частью книги. */
.reader-panel > .composer {
  flex: none; position: relative; z-index: 4;
  border-top: 1px solid rgba(245,240,231,0.14);
  background: #0E1014; color: var(--light);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
}
.reader-panel .suggestions { scrollbar-width: thin; }
.reader-panel #moveInput { min-height: 46px; }
.reader-panel .living-book-live-on {
  display: block; width: 100%; min-height: 34px; margin-top: 5px; padding: 5px 10px;
  border: 0; color: var(--gold-bright); text-align: center; font-size: 0.82rem;
}
.reader-panel .living-book-live-on:hover,
.reader-panel .living-book-live-on:focus-visible { color: #fff; outline: 1px solid rgba(232,187,112,0.36); }

/* Вторичные сведения не уменьшают книгу и не требуют смены экрана. */
.world-panel,
.art-overlay {
  position: fixed; top: var(--vv-top, 0px); right: 0; z-index: 48;
  width: min(440px, 100vw); height: var(--vvh, 100dvh);
  display: flex; flex-direction: column; overflow: hidden;
  background: rgba(10,12,15,0.97); color: var(--light);
  border-left: 1px solid var(--glass-line);
  box-shadow: -26px 0 76px rgba(0,0,0,0.68);
}
.art-overlay { width: min(920px, 100vw); background: #08090C; }
.overlay-head {
  flex: none; min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  border-bottom: 1px solid var(--glass-line);
}
.overlay-head .hud-label { display: block; margin-bottom: 3px; }
.overlay-head strong { font-family: var(--serif); font-size: 1.05rem; }
.overlay-close {
  flex: none; width: 44px; height: 44px; border: 1px solid var(--glass-line); border-radius: 50%;
  background: rgba(245,240,231,0.06); color: var(--light); font: inherit; font-size: 1.35rem; cursor: pointer;
}
.overlay-close:hover, .overlay-close:focus-visible { border-color: var(--gold); color: var(--gold); outline: none; }
.world-panel-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; }
.world-tariff {
  display: flex; flex-direction: row; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding: 12px 13px;
  border: 1px solid var(--glass-line); border-radius: 12px; background: rgba(245,240,231,0.04);
}
.world-tariff .hud-label { margin: 0; }
.world-panel .hudstack {
  display: flex; flex-direction: column; gap: 10px;
  max-height: none; overflow: visible;
}
.world-panel .hud-panel { min-width: 0; flex: none; background: rgba(245,240,231,0.045); }
.history-panel { border-color: rgba(232,187,112,0.24); }
.history-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.history-head .hud-label { margin: 0 0 3px; }
.history-context { color: var(--dim); font-size: 0.75rem; line-height: 1.35; }
.history-status {
  flex: none; max-width: 46%; padding: 4px 7px; border: 1px solid rgba(245,240,231,0.13); border-radius: 999px;
  color: var(--dim); font-size: 0.65rem; line-height: 1.2; text-align: center;
}
.history-status.changed { border-color: rgba(232,187,112,0.44); color: var(--gold-bright); }
.history-empty { margin: 10px 0 0; color: var(--dim); font-size: 0.76rem; line-height: 1.45; }
.history-section { margin-top: 12px; }
.history-section h4 { margin: 0 0 7px; color: var(--gold-bright); font-size: 0.67rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }
.history-list { display: grid; gap: 7px; }
.history-item { min-width: 0; padding: 9px 10px; border-left: 2px solid rgba(245,240,231,0.18); background: rgba(0,0,0,0.16); }
.history-item.rumor { border-left-style: dashed; }
.history-item.known { border-left-color: rgba(112,224,179,0.55); }
.history-item.divergence { border-left-color: var(--gold); background: rgba(232,187,112,0.055); }
.history-item-meta { display: block; margin-bottom: 3px; color: var(--dim); font-size: 0.64rem; line-height: 1.3; }
.history-item strong { display: block; overflow-wrap: anywhere; font-family: var(--serif); font-size: 0.86rem; line-height: 1.3; }
.history-item p { margin: 4px 0 0; color: rgba(245,240,231,0.88); font-size: 0.75rem; line-height: 1.42; }
.history-item small { display: block; margin-top: 5px; color: var(--dim); font-size: 0.68rem; line-height: 1.4; overflow-wrap: anywhere; }
.art-overlay-image {
  position: relative; flex: 1; min-height: 0;
  background: #111218 center/contain no-repeat;
}

@media (max-width: 900px) {
  #bookScreen .topbar {
    flex: none; gap: 6px; min-height: 64px;
    padding: calc(7px + env(safe-area-inset-top)) 10px 7px;
  }
  #bookScreen .book-title strong { font-size: 0.9rem; }
  #bookScreen .book-title span { font-size: 0.68rem; }
  #readerOpenBtn { display: none; }
  .topbar-action { width: 44px; min-width: 44px; padding: 7px; }
  .topbar-action-label { display: none; }
  .living-book-shell { grid-template-columns: minmax(0, 1fr); padding: 0; }
  .living-book-shell .reader-panel {
    border: 0; border-radius: 0; box-shadow: none;
  }
  .living-book-shell .scene-column { display: none; }
  .living-book-shell .page-text { padding: 20px 18px 28px; }
  .page-material { margin-bottom: 16px; max-width: 68%; }
  .chronicle { gap: 15px; }
  .entry-world { font-size: 1rem; line-height: 1.62; }
  .reader-panel > .composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .reader-panel .suggestions { padding-bottom: 7px; }
  .reader-panel .suggestion { max-width: calc(100vw - 54px); padding: 9px 12px; font-size: 0.8rem; }
  .reader-panel #moveInput { min-height: 44px; padding: 10px 11px; font-size: 0.95rem; }
  .reader-panel .send { min-height: 44px; }
  .reader-panel .living-book-live-on { min-height: 31px; margin-top: 3px; font-size: 0.78rem; }
  .world-panel, .art-overlay {
    inset: var(--vv-top, 0px) 0 auto 0; width: 100vw; height: var(--vvh, 100dvh);
    border-left: 0; box-shadow: none;
  }
  .world-panel-scroll { padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .world-panel .hudstack { flex-direction: column; overflow: visible; }
  .world-panel .hud-panel { min-width: 0; }
  .art-overlay-image { background-size: contain; }
  .advisor { right: 5px; bottom: calc(128px + env(safe-area-inset-bottom)); }
  .advisor-character { width: 58px; height: 72px; }
  .advisor-bubble { width: min(270px, calc(100vw - 76px)); }
  .illustrating { top: calc(67px + env(safe-area-inset-top)); }
}

@media (max-width: 390px) {
  .auth-screen, .account-panel { padding: 12px; }
  .auth-card, .account-card { padding: 24px 20px; border-radius: 20px; }
  .account-trigger { max-width: 118px; }
  #bookScreen .topbar { padding-left: 7px; padding-right: 7px; }
  #bookScreen .ghost-button { min-width: 42px; }
  #bookScreen .book-title strong { font-size: 0.82rem; }
  #bookScreen .book-title span { font-size: 0.62rem; }
  .topbar-action { width: 42px; min-width: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .living-book-shell, .scene-column { transition: none; }
}
