:root {
  color-scheme: dark;
  --bg: #090c0e;
  --panel: #11171a;
  --panel-2: #161e22;
  --text: #edf1f2;
  --muted: #91a0a8;
  --yellow: #fcee0a;
  --cyan: #00f0ff;
  --pink: #ff2a6d;
  --orange: #ff9f1c;
  --line: #263238;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    linear-gradient(rgba(0, 240, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 240, 255, 0.025) 1px, transparent 1px),
    var(--bg);
  background-size: 34px 34px;
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
}
a { color: inherit; }
button { font: inherit; }

.site-header {
  min-height: 72px;
  padding: 14px clamp(20px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 12, 14, 0.93);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}
.brand { display: inline-flex; flex-direction: column; text-decoration: none; line-height: 1; }
.brand span { color: var(--yellow); font-weight: 900; letter-spacing: 0.11em; }
.brand strong { margin-top: 5px; color: var(--muted); font-size: 0.73rem; letter-spacing: 0.2em; text-transform: uppercase; }
.site-nav { display: flex; gap: 8px; }
.site-nav a { padding: 10px 13px; color: var(--muted); text-decoration: none; border: 1px solid transparent; border-radius: 3px; }
.site-nav a:hover, .site-nav a.active { color: var(--text); border-color: #3c4b52; background: var(--panel); }

.home-shell, .reader-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.reader-shell.narrow { width: min(920px, calc(100% - 40px)); }
.home-hero { padding: clamp(70px, 12vw, 150px) 0 80px; max-width: 900px; }
.home-hero h1, .chapter-hero h1 { margin: 8px 0 18px; line-height: 0.98; letter-spacing: -0.045em; }
.home-hero h1 { max-width: 800px; font-size: clamp(3.2rem, 8vw, 7rem); }
.home-hero > p:last-child, .chapter-intro { max-width: 700px; color: var(--muted); font-size: 1.08rem; line-height: 1.7; }
.eyebrow { margin: 0; color: var(--cyan); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase; }
.section-heading h2 { margin: 5px 0 24px; font-size: 2rem; }
.library { padding-bottom: 90px; }
.library-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.chapter-card { min-height: 310px; padding: 30px; display: flex; flex-direction: column; border: 1px solid var(--line); background: linear-gradient(145deg, rgba(22,30,34,.98), rgba(12,16,18,.98)); text-decoration: none; transition: transform .18s, border-color .18s; }
.chapter-card:hover { transform: translateY(-4px); border-color: var(--cyan); }
.chapter-card.featured { border-top: 4px solid var(--yellow); }
.card-kicker { color: var(--muted); font-size: .77rem; letter-spacing: .12em; text-transform: uppercase; }
.chapter-card h3 { margin: 25px 0 10px; font-size: clamp(2rem, 4vw, 3.6rem); }
.chapter-card p { color: var(--muted); line-height: 1.6; }
.card-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; }
.card-meta span { padding: 5px 8px; border: 1px solid #334148; color: #c6d1d5; font-size: .76rem; }
.card-action { margin-top: 20px; color: var(--yellow); font-weight: 800; }

.chapter-hero { padding: 54px 0 34px; display: flex; align-items: end; justify-content: space-between; gap: 35px; }
.chapter-hero.compact { padding-bottom: 24px; }
.chapter-hero h1 { font-size: clamp(3rem, 7vw, 6rem); }
.chapter-stats { margin: 0; display: grid; grid-template-columns: repeat(3, 88px); gap: 8px; }
.chapter-stats div { padding: 14px; border: 1px solid var(--line); background: var(--panel); }
.chapter-stats dt { color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.chapter-stats dd { margin: 4px 0 0; color: var(--yellow); font-size: 1.35rem; font-weight: 800; }

.player-bar { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto; align-items: center; gap: 22px; padding: 16px 18px; background: #131a1e; border: 1px solid #334148; position: sticky; top: 87px; z-index: 15; box-shadow: 0 12px 30px rgba(0,0,0,.34); }
.control-label { display: block; color: var(--muted); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; }
.now-playing strong { display: block; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.speed-control { display: flex; align-items: center; gap: 6px; }
.speed-control .control-label { margin-right: 4px; }
.speed-control button, .repeat-button, .play-button { border: 1px solid #3a4b53; background: #0c1113; color: var(--text); cursor: pointer; }
.speed-control button { min-width: 50px; padding: 8px; }
.speed-control button.active { color: #071013; border-color: var(--cyan); background: var(--cyan); font-weight: 800; }
.repeat-button { padding: 10px 14px; }
.repeat-button:disabled { opacity: .4; cursor: not-allowed; }

.part-nav { display: flex; gap: 8px; margin: 22px 0 12px; padding-bottom: 8px; overflow-x: auto; }
.part-nav a { min-width: max-content; padding: 9px 11px; color: var(--muted); background: #0d1214; border: 1px solid var(--line); text-decoration: none; font-size: .8rem; }
.part-nav a:hover { color: var(--text); border-color: var(--cyan); }
.part-nav small { margin-left: 6px; color: var(--orange); font-size: .65rem; text-transform: uppercase; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 38px; color: var(--muted); font-size: .78rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 8px; height: 8px; display: inline-block; border-radius: 50%; background: #68747a; }
.legend-dot.branch { background: var(--pink); }
.legend-dot.optional { background: var(--orange); }
.legend-dot.unknown { background: #9b7cff; }
.line-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 0 0 26px; }
.line-filters .control-label { margin-right: 5px; }
.line-filters button { padding: 8px 12px; color: var(--muted); background: #0d1214; border: 1px solid var(--line); cursor: pointer; }
.line-filters button:hover { color: var(--text); border-color: var(--cyan); }
.line-filters button.active { color: #071013; border-color: var(--cyan); background: var(--cyan); font-weight: 800; }

.part { margin: 0 0 54px; scroll-margin-top: 185px; }
.part-header { padding: 20px 0 14px; border-bottom: 1px solid var(--line); }
.part-title-row { display: flex; align-items: center; gap: 12px; }
.part-index { color: var(--muted); font-family: Consolas, monospace; }
.part h2 { margin: 0; font-size: clamp(1.65rem, 4vw, 2.5rem); }
.part-note { max-width: 760px; margin: 10px 0 0; color: var(--muted); line-height: 1.55; }
.badge { padding: 4px 8px; color: #081013; background: #78868d; font-size: .66rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.badge.branch { background: var(--pink); color: white; }
.badge.unknown-order { background: #9b7cff; color: white; }
.badge.optional { background: var(--orange); }
.scene { margin-top: 24px; border: 1px solid var(--line); background: rgba(14,19,22,.86); }
.scene-header { padding: 16px 18px; display: flex; justify-content: space-between; gap: 15px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.scene-header h3 { margin: 0; font-size: 1rem; letter-spacing: .02em; }
.scene-count { color: var(--muted); font-size: .75rem; }
.scene-lines.standalone { margin-bottom: 70px; border: 1px solid var(--line); }
.line { display: grid; grid-template-columns: 44px 42px 105px minmax(0, 1fr) auto; gap: 11px; align-items: start; min-height: 82px; padding: 13px 16px; border-left: 3px solid transparent; border-bottom: 1px solid #1d272c; transition: background .15s, border-color .15s; }
.line:last-child { border-bottom: 0; }
.line.has-audio { cursor: pointer; }
.line.has-audio:hover { background: #172126; border-left-color: var(--yellow); }
.line.playing { background: #13272b; border-left-color: var(--cyan); }
.line-number { padding-top: 7px; color: #65747b; font-family: Consolas, monospace; font-size: .75rem; }
.play-button { width: 36px; height: 36px; border-radius: 50%; color: var(--yellow); }
.play-button:hover { border-color: var(--yellow); }
.play-button:disabled { color: #536067; border-color: #29343a; cursor: not-allowed; }
.line-speaker { padding-top: 6px; color: var(--yellow); font-size: .82rem; line-height: 1.25; }
.line-speaker strong, .line-speaker small { display: block; }
.line-speaker small { margin-top: 5px; color: var(--muted); font-size: .65rem; font-weight: 400; text-transform: uppercase; }
.line-text { padding: 2px 0; font-size: 1.02rem; line-height: 1.5; user-select: text; }
.bilingual-copy p { margin: 0; }
.bilingual-copy .translation { margin-top: 5px; color: #9fb1b8; font-size: .9rem; line-height: 1.5; }
.line.playing .line-text { color: var(--cyan); }
.audio-state { padding-top: 8px; color: #68747a; font-size: .7rem; text-transform: uppercase; }
.loading, .error { padding: 30px; color: var(--muted); border: 1px solid var(--line); }
.error { color: #ff8fa8; }

.library-tools { display: grid; grid-template-columns: minmax(240px, 1fr) auto; gap: 18px; align-items: end; margin: 6px 0 18px; padding: 18px; border: 1px solid var(--line); background: var(--panel); }
.library-tools .line-filters { margin: 0; }
.search-field span { display: block; margin-bottom: 7px; color: var(--muted); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; }
.search-field input { width: 100%; padding: 11px 12px; color: var(--text); background: #090d0f; border: 1px solid #3a4b53; outline: none; }
.search-field input:focus { border-color: var(--cyan); }
.result-count { margin: 0 0 16px; color: var(--muted); font-size: .82rem; }
.text-library { display: grid; gap: 22px; padding-bottom: 80px; }
.text-card { border: 1px solid var(--line); background: rgba(14,19,22,.9); }
.text-card-header { display: flex; justify-content: space-between; gap: 24px; padding: 22px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.text-card-header h2 { margin: 7px 0 0; font-size: 1.45rem; }
.text-card-header .translation { margin: 7px 0 0; color: #b2c1c7; }
.text-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; color: var(--muted); font-family: Consolas, monospace; font-size: .72rem; }
.text-entry { display: grid; grid-template-columns: 110px minmax(0,1fr) auto; gap: 18px; padding: 15px 20px; border-bottom: 1px solid #1d272c; }
.text-entry:last-child { border-bottom: 0; }
.text-source strong, .text-source small { display: block; }
.text-source strong { color: var(--yellow); font-size: .8rem; }
.text-source small { margin-top: 5px; color: var(--muted); font-size: .67rem; }
.text-entry .english { line-height: 1.5; }
.entry-flags { display: flex; align-items: flex-start; gap: 6px; color: var(--muted); font-family: Consolas, monospace; font-size: .7rem; }
.optional-flag { padding: 3px 6px; color: #111; background: var(--orange); font-family: "Segoe UI", sans-serif; font-weight: 800; text-transform: uppercase; }
.empty-note { margin: 0; padding: 18px 20px; color: var(--muted); }
.to-top { position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 50; display: flex; align-items: center; gap: 7px; min-width: 62px; padding: 11px 14px; border: 1px solid #43545c; color: #d9e2e5; background: rgba(14,19,22,.94); box-shadow: 0 8px 24px rgba(0,0,0,.35); font: 700 .78rem/1 "Segoe UI", sans-serif; text-transform: uppercase; letter-spacing: .06em; cursor: pointer; opacity: 0; visibility: hidden; transform: translateY(10px); transition: opacity .18s ease, transform .18s ease, visibility .18s; }
.to-top:hover, .to-top:focus-visible { border-color: var(--yellow); color: var(--yellow); outline: none; }
.to-top.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.to-top span[aria-hidden] { font-size: 1.15rem; line-height: .7; }

@media (max-width: 760px) {
  .site-header { position: static; align-items: flex-start; flex-direction: column; }
  .site-nav { width: 100%; overflow-x: auto; }
  .library-grid { grid-template-columns: 1fr; }
  .chapter-hero { align-items: flex-start; flex-direction: column; }
  .player-bar { position: static; grid-template-columns: 1fr; gap: 13px; }
  .part { scroll-margin-top: 20px; }
  .line { grid-template-columns: 32px 38px minmax(0,1fr); padding: 12px 10px; }
  .line-speaker { grid-column: 3; }
  .line-text { grid-column: 1 / -1; padding-left: 70px; }
  .audio-state { grid-column: 3; padding-top: 0; }
  .chapter-stats { width: 100%; grid-template-columns: repeat(3, 1fr); }
  .library-tools { grid-template-columns: 1fr; }
  .text-card-header { flex-direction: column; }
  .text-meta { align-items: flex-start; }
  .text-entry { grid-template-columns: 1fr; gap: 9px; }
  .entry-flags { grid-row: 1; justify-content: flex-end; }
  .to-top { right: 14px; bottom: 14px; min-width: 48px; padding: 11px; }
  .to-top span:last-child { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
