:root {
  --bg: #0a0807;
  --bg-soft: #0f0c0a;
  --bg-panel: #120e0b;
  --text: #e6dfd3;
  --text-soft: #968b7c;
  --dim: #574f45;
  --line: #1c1713;
  --line-soft: #14100d;
  --accent: #ff9a3c;
  --accent-dim: #b96f2c;
  --glow: 0 0 12px rgba(255,154,60,0.45);
  --glow-soft: 0 0 20px rgba(255,154,60,0.18);
  --overlay: rgba(5,3,2,0.7);
  --fs: 19px;

  --c-iris:   #ff8ec4;
  --c-amir:   #7cc0ff;
  --c-toma:   #ff9a3c;
  --c-shadow: #9a9a9a;
  --c-vait:   #e63946;
  --c-lara:   #4fd6c9;
  --c-miau:   #7ed17e;
  --c-nikita: #ffd93d;
  --c-pavel:  #c17eff;
  --c-danya:  #d4a574;
  --c-other:  #9db3ff;

  --font-serif: 'Crimson Pro', georgia, 'times new roman', serif;
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
}

:root[data-theme="light"] {
  --bg: #f7f1e7;
  --bg-soft: #efe7d9;
  --bg-panel: #fffaf1;
  --text: #241a10;
  --text-soft: #6f6152;
  --dim: #a89a88;
  --line: #e2d8c7;
  --line-soft: #eae1d1;
  --accent: #cc7620;
  --accent-dim: #9a5a18;
  --glow: 0 0 12px rgba(204,118,32,0.35);
  --glow-soft: 0 0 20px rgba(204,118,32,0.15);
  --overlay: rgba(30,20,10,0.4);

  --c-iris:   #d8578c;
  --c-amir:   #3d7fc4;
  --c-toma:   #cc7620;
  --c-shadow: #6b6b6b;
  --c-vait:   #b32a35;
  --c-lara:   #1a9c92;
  --c-miau:   #4a9e4a;
  --c-nikita: #b89500;
  --c-pavel:  #9257d1;
  --c-danya:  #a17545;
  --c-other:  #5c76c4;
}

* { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: var(--fs);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100%;
  transition: background 0.35s ease, color 0.35s ease;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse 55% 40% at 20% 0%,
    rgba(255,154,60,0.05), transparent 65%);
  pointer-events: none;
  z-index: 0;
}

#ash { position: fixed; inset: 0; z-index: 1; pointer-events: none; }

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.55) 100%);
}
:root[data-theme="light"] .vignette {
  background: radial-gradient(ellipse at center, transparent 60%, rgba(120,90,50,0.12) 100%);
}

/* ---------- topbar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 54px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-bottom: 1px solid var(--line-soft);
  z-index: 20;
  font-family: var(--font-ui);
}
.topbar-title {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: lowercase;
  color: var(--text-soft);
  margin-left: 4px;
}
.topbar-spacer { flex: 1; }

.topbar button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-soft);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-ui);
}
.topbar button:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow-soft), inset 0 0 12px rgba(255,154,60,0.06);
}
.topbar button.icon-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.topbar button.text-btn {
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: lowercase;
  flex-shrink: 0;
}
.topbar button.text-btn .btn-icon { display: none; }
.topbar button.text-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow-soft);
}

.lang-switch {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}
.lang-btn {
  background: transparent;
  border: none;
  color: var(--text-soft);
  padding: 0 11px;
  height: 34px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-ui);
}
.lang-btn:hover { color: var(--accent); }
.lang-btn.active {
  background: var(--accent);
  color: var(--bg);
}

.theme-icon-light { display: none; }
:root[data-theme="light"] .theme-icon-dark { display: none; }
:root[data-theme="light"] .theme-icon-light { display: inline; }

/* ---------- progress ---------- */
.progress {
  position: fixed;
  top: 54px; left: 0; right: 0;
  height: 1px;
  background: var(--line-soft);
  z-index: 21;
  pointer-events: none;
}
#progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.5s cubic-bezier(.22,.61,.36,1);
  box-shadow: var(--glow);
}

/* ---------- reader ---------- */
.reader {
  position: relative;
  z-index: 5;
  max-width: 700px;
  margin: 0 auto;
  padding: 130px 32px 180px;
}
.chapter-label {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.4em;
  text-transform: lowercase;
  color: var(--dim);
  margin-bottom: 14px;
  text-align: center;
}

.song-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 34px;
  min-height: 26px;
  padding: 0 4px;
}
.song-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-soft);
  padding: 7px 14px;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: all 0.2s ease;
  max-width: 100%;
}
.song-pill > span { min-width: 0; }
.song-pill > span:not(.song-note):not(.song-label) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.song-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow-soft);
}
.song-pill .song-note {
  color: var(--accent);
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
}
.song-pill .song-label {
  opacity: 0.55;
  letter-spacing: 0.18em;
  text-transform: lowercase;
  flex-shrink: 0;
}
.song-pill.playing {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow-soft);
}
.song-pill.playing .song-note {
  animation: notePulse 1.4s ease-in-out infinite;
}
@keyframes notePulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

.page p { margin: 0 0 1.15em 0; color: var(--text); }

.chapter-title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-style: italic;
  font-size: 2em;
  line-height: 1.3;
  text-align: center;
  color: var(--accent);
  margin: 0 0 1.8em 0;
  text-shadow: 0 0 30px rgba(255,154,60,0.35);
}
:root[data-theme="light"] .chapter-title { text-shadow: none; }

.page.fade-in { animation: fadeUp 0.5s cubic-bezier(.22,.61,.36,1); }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- pager ---------- */
.pager {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 15;
  padding: 22px 32px 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 65%, transparent);
  pointer-events: none;
}
.pager-inner {
  max-width: 700px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: auto;
  font-family: var(--font-ui);
}
.pager-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-soft);
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: lowercase;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.pager-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow-soft), inset 0 0 14px rgba(255,154,60,0.06);
}
.pager-btn:disabled { opacity: 0.2; cursor: not-allowed; }
.counter {
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.24em;
  font-weight: 500;
  white-space: nowrap;
}

/* ---------- panel chrome ---------- */
.panel-header,
.gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.3em;
  text-transform: lowercase;
  color: var(--dim);
  font-family: var(--font-ui);
  position: relative;
}
.panel-header::after,
.gallery-header::after {
  content: '';
  position: absolute;
  left: 20px; right: 20px; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, var(--accent), transparent 70%);
  opacity: 0.5;
}
.panel-close {
  background: none;
  border: none;
  color: var(--text-soft);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}
.panel-close:hover { color: var(--accent); }

/* ---------- table of contents ---------- */
.toc {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 280px;
  background: var(--bg-panel);
  border-right: 1px solid var(--line-soft);
  z-index: 40;
  transform: translateX(-100%);
  transition: transform 0.4s cubic-bezier(.22,.61,.36,1);
  display: flex;
  flex-direction: column;
  font-family: var(--font-ui);
  box-shadow: 24px 0 80px rgba(0,0,0,0.5);
}
.toc.open { transform: translateX(0); }
#toc-list { overflow-y: auto; padding: 10px 0; flex: 1; }
.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-soft);
  padding: 14px 22px;
  cursor: pointer;
  font-size: 12.5px;
  font-family: inherit;
  letter-spacing: 0.14em;
  line-height: 1.4;
  transition: all 0.18s ease;
  text-transform: lowercase;
  position: relative;
}
.toc-item:hover { color: var(--text); background: rgba(255,154,60,0.03); }
.toc-item.active {
  color: var(--accent);
  background: linear-gradient(90deg, rgba(255,154,60,0.08), transparent 80%);
}
.toc-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 2px;
  background: var(--accent);
  box-shadow: var(--glow);
}

/* ---------- characters dropdown ---------- */
.chars {
  position: fixed;
  top: 68px;
  right: 20px;
  width: 220px;
  background: var(--bg-panel);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  z-index: 25;
  display: none;
  font-family: var(--font-ui);
  box-shadow: 0 24px 70px rgba(0,0,0,0.5);
  overflow: hidden;
}
.chars.open { display: block; animation: panelIn 0.22s ease; }

@keyframes panelIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.char-list {
  list-style: none;
  margin: 0;
  padding: 14px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  font-size: 13.5px;
}
.char-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.char-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor, 0 0 3px currentColor;
}

/* ---------- gallery viewer ---------- */
.gallery-modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
  padding-bottom: calc(30px + env(safe-area-inset-bottom));
}
.gallery-modal.open { display: flex; animation: fadeIn 0.25s ease; }

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.gallery-inner {
  background: var(--bg-panel);
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  width: 100%;
  max-width: 900px;
  height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 90px rgba(0,0,0,0.7);
  animation: panelIn 0.3s ease;
}
.gallery-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 16px;
  min-height: 0;
}
.gallery-frame {
  flex: 1;
  height: 100%;
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  overflow: hidden;
}
.gallery-frame img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}
.gallery-fallback {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 8em;
  font-weight: 600;
  text-transform: lowercase;
  color: var(--bg);
}
.gallery-fallback.show { display: flex; }
.gallery-nav {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-soft);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
}
.gallery-nav:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow-soft);
  transform: scale(1.05);
}
.gallery-nav:disabled { opacity: 0.15; cursor: not-allowed; }
.gallery-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--font-ui);
}
.gallery-name {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: lowercase;
}
.gallery-counter {
  font-size: 11.5px;
  letter-spacing: 0.24em;
  color: var(--dim);
  font-weight: 500;
}

/* ---------- overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.overlay.show { opacity: 1; pointer-events: auto; }

/* ---------- settings ---------- */
.settings {
  position: fixed;
  top: 68px; right: 20px;
  background: var(--bg-panel);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 16px 18px;
  z-index: 25;
  font-family: var(--font-ui);
  font-size: 12.5px;
  display: none;
  flex-direction: column;
  gap: 14px;
  min-width: 220px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.5);
}
.settings.open { display: flex; animation: panelIn 0.22s ease; }
.settings label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  color: var(--text-soft);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: lowercase;
}
.settings input[type=range] { accent-color: var(--accent); width: 110px; }
.settings input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- character text colors ---------- */
.c-iris   { color: var(--c-iris); }
.c-amir   { color: var(--c-amir); }
.c-toma   { color: var(--c-toma); }
.c-shadow { color: var(--c-shadow); }
.c-vait   { color: var(--c-vait); }
.c-lara   { color: var(--c-lara); }
.c-miau   { color: var(--c-miau); }
.c-nikita { color: var(--c-nikita); }
.c-pavel  { color: var(--c-pavel); }
.c-danya  { color: var(--c-danya); }
.c-other  { color: var(--c-other); }

a { color: var(--accent); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ==================== mobile ==================== */
@media (max-width: 640px) {
  .topbar {
    padding: 0 10px;
    gap: 6px;
    height: 52px;
  }
  .topbar-title { display: none; }

  .topbar button.icon-btn {
    width: 30px; height: 30px;
    font-size: 13px;
    border-radius: 7px;
  }
  .topbar button.text-btn {
    width: 30px; height: 30px;
    padding: 0;
    border-radius: 7px;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0;
  }
  .topbar button.text-btn .btn-text { display: none; }
  .topbar button.text-btn .btn-icon { display: inline; font-size: 15px; }

  .lang-btn {
    padding: 0 8px;
    height: 30px;
    font-size: 10px;
    letter-spacing: 0.12em;
  }

  .progress { top: 52px; }

  .reader {
    padding: 88px 20px 160px;
  }
  .chapter-label {
    font-size: 9px;
    letter-spacing: 0.32em;
    margin-bottom: 12px;
  }
  .chapter-title {
    font-size: 1.6em;
    margin-bottom: 1.4em;
  }
  .song-row {
    margin-bottom: 26px;
  }
  .song-pill {
    font-size: 10.5px;
    padding: 6px 12px;
    gap: 7px;
  }
  .song-pill > span:not(.song-note):not(.song-label) {
    max-width: 150px;
  }

  .pager {
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  }
  .pager-inner { gap: 8px; }
  .pager-btn {
    padding: 9px 12px;
    font-size: 10.5px;
    letter-spacing: 0.12em;
  }
  .counter {
    font-size: 10px;
    letter-spacing: 0.2em;
  }

  .toc {
    width: 86vw;
    max-width: 340px;
  }
  .toc-item {
    padding: 15px 20px;
    font-size: 13px;
  }

  .chars {
    left: 12px;
    right: 12px;
    top: 62px;
    width: auto;
    border-radius: 10px;
  }
  .char-list {
    padding: 12px 20px 16px;
    font-size: 13.5px;
  }

  .settings {
    left: 12px;
    right: 12px;
    top: 62px;
    width: auto;
    min-width: 0;
  }

  .gallery-modal {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .gallery-inner {
    height: 94vh;
    border-radius: 12px;
  }
  .gallery-stage {
    padding: 14px 8px;
    gap: 6px;
  }
  .gallery-nav {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }
  .gallery-footer {
    padding: 12px 16px;
  }
  .gallery-name { font-size: 12.5px; }
  .gallery-counter { font-size: 10.5px; }
}
/* ---------- support / donate button ---------- */
.topbar a.support-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: lowercase;
  text-decoration: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--accent);
  transition: all 0.2s ease;
  flex-shrink: 0;
  cursor: pointer;
}
.topbar a.support-btn:hover {
  border-color: var(--accent);
  background: rgba(255,154,60,0.08);
  box-shadow: var(--glow-soft), inset 0 0 12px rgba(255,154,60,0.06);
  color: var(--accent);
}
.topbar a.support-btn .btn-icon { display: none; }

@media (max-width: 640px) {
  .topbar a.support-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 7px;
    font-size: 15px;
  }
  .topbar a.support-btn .btn-text { display: none; }
  .topbar a.support-btn .btn-icon { display: inline; }
}
/* ---------- side arrow buttons (desktop only) ---------- */
.arrow-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--bg-panel) 85%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  color: var(--text-soft);
  font-size: 30px;
  line-height: 1;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: all 0.2s ease;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 18;
  padding: 0;
  padding-bottom: 4px;
}
.arrow-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255,154,60,0.08);
  box-shadow: var(--glow-soft), inset 0 0 14px rgba(255,154,60,0.06);
  transform: translateY(-50%) scale(1.06);
}
.arrow-btn:active:not(:disabled) {
  transform: translateY(-50%) scale(0.98);
}
.arrow-btn:disabled {
  opacity: 0.15;
  cursor: not-allowed;
}
.arrow-prev { left: 24px; }
.arrow-next { right: 24px; }

/* show the arrows only on screens wide enough to fit them cleanly */
@media (min-width: 1000px) {
  .arrow-btn { display: flex; }
}

/* on very wide screens, push them a bit further out */
@media (min-width: 1400px) {
  .arrow-prev { left: 60px; }
  .arrow-next { right: 60px; }
}