/* ══════════════════════════════════════════════
   Либреттино v2 — 2026 Spatial Layout
   ══════════════════════════════════════════════ */

:root {
  --bg: #050508;
  --bg2: #0a0a14;
  --panel: rgba(18, 18, 36, 0.7);
  --panel-solid: #141428;
  --accent: #7c5cfc;
  --accent2: #4ea8ff;
  --accent3: #22d3b0;
  --accent-glow: rgba(124, 92, 252, 0.25);
  --text: #f0edf8;
  --muted: #807b96;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-bg: rgba(255, 255, 255, 0.03);
  --topbar-bg: rgba(5, 5, 8, 0.8);
  --read-scale: 1;
  --font-ui: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-it: "Lora", "Georgia", serif;
  --bn-h: 64px;
  color-scheme: dark;
  --gold: var(--accent);
  --gold-dim: var(--accent3);
  --op-accent: var(--accent);
}

html[data-theme="light"] {
  --bg: #f5f5f8;
  --bg2: #ebebf0;
  --panel: rgba(255, 255, 255, 0.8);
  --panel-solid: #ffffff;
  --accent: #6c4cf0;
  --accent2: #3a8af0;
  --accent3: #18a886;
  --accent-glow: rgba(108, 76, 240, 0.15);
  --text: #1a1a28;
  --muted: #6b6880;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.1);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-bg: rgba(0, 0, 0, 0.02);
  --topbar-bg: rgba(245, 245, 248, 0.8);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, a, [role="button"] {
  font-family: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.02em; }

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent2); outline-offset: 2px;
}

/* ── Ambient orbs ───────────────────────── */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(600px 400px at 15% 20%, rgba(124, 92, 252, 0.06), transparent 60%),
    radial-gradient(500px 350px at 80% 60%, rgba(78, 168, 255, 0.05), transparent 55%),
    radial-gradient(450px 300px at 50% 90%, rgba(34, 211, 176, 0.04), transparent 55%);
  pointer-events: none;
}

/* ── Topbar ─────────────────────────────── */
.topbar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 20px; height: 52px;
  background: var(--topbar-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid var(--glass-border);
  z-index: 30;
}
@media (max-width: 720px) { .topbar { padding: 6px 14px; height: 48px; } }

/* ── Progress bar ───────────────────────── */
#progress-bar {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent2), var(--accent3));
  z-index: 60; transition: width .15s ease;
  box-shadow: 0 0 12px var(--accent-glow);
}

/* ── Brand ──────────────────────────────── */
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 1.05rem;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  color: var(--accent);
}
@supports not (-webkit-background-clip: text) {
  .brand { -webkit-text-fill-color: var(--accent); background: none; }
  .hero h1 { -webkit-text-fill-color: var(--text); background: none; }
  .opera-head h1 { -webkit-text-fill-color: var(--accent); background: none; }
}
.brand-mark { -webkit-text-fill-color: var(--accent); }

/* ── Icon buttons ───────────────────────── */
.icon-btn {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: var(--radius-sm);
  min-width: 44px; min-height: 44px;
  font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: all .2s ease;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--panel); border-color: var(--accent); color: var(--accent);
  transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow);
}
.icon-btn:active { transform: scale(.94); }
/* ── Settings dropdown ──────────────────── */
.settings-dropdown {
  position: fixed; top: 52px; right: 16px; z-index: 35;
  background: var(--panel-solid);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 240px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex; flex-direction: column; gap: 14px;
}
.settings-dropdown.hidden { display: none; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-row > span { font-size: .85rem; color: var(--muted); font-weight: 500; }
.settings-btns { display: flex; gap: 6px; }
@media (max-width: 720px) { .settings-dropdown { top: 48px; right: 8px; min-width: 200px; } }

.top-tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.fsbtn { font-size: .78rem; font-weight: 700; }
.scenes-toggle { display: none; }
@media (min-width: 721px) {
  .scenes-toggle { display: inline-flex; }
}
.theme-select {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 5px 8px; font-size: .74rem; font-family: inherit; cursor: pointer;
  max-width: 120px; outline: none;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: all .2s ease;
}
.theme-select:hover, .theme-select:focus { border-color: var(--accent); }

/* ── Search bar ─────────────────────────── */
.search-bar {
  flex-shrink: 0; display: flex; gap: 10px; padding: 10px 20px;
  background: var(--bg2); border-bottom: 1px solid var(--glass-border);
}
.search-bar.hidden { display: none; }
.search-bar input {
  flex: 1;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill); color: var(--text);
  padding: 10px 18px; font-size: .95rem; font-family: inherit; outline: none;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: all .2s ease;
}
.search-bar input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

/* ── Content area (full-width, scrollable) ─ */
.content-area {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(20px + var(--bn-h));
}

.screen { padding: 24px 40px; max-width: 1100px; margin: 0 auto; }
.hidden { display: none !important; }
.screen.hidden { display: none; }
@media (max-width: 720px) { .screen { padding: 16px 16px 0; } }

/* ── Hero ────────────────────────────────── */
.hero { padding: 32px 0 12px; }
.hero h1 {
  margin: 0 0 14px;
  font-size: clamp(1.8rem, 5vw, 3.4rem);
  font-weight: 900; letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--text) 30%, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.15;
}
.subtitle { color: var(--muted); margin: 0; font-size: 1.05rem; line-height: 1.5; max-width: 500px; }
.home-actions { display: flex; gap: 10px; margin: 20px 0 28px; flex-wrap: wrap; }
.meta { color: var(--muted); font-size: .9rem; }
@media (max-width: 720px) { .hero { padding: 16px 0 8px; } }

/* ── Opera cards (bento grid) ────────────── */
.op-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-top: 8px;
}
.op-list > :first-child {
  grid-column: span 2;
}
@media (max-width: 900px) { .op-list > :first-child { grid-column: span 1; } }
@media (max-width: 720px) { .op-list { grid-template-columns: 1fr; gap: 14px; } }

.op-card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; width: 100%; padding: 0;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  text-align: left; color: var(--text);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: all .3s cubic-bezier(.4,0,.2,1);
  cursor: pointer;
}
.op-card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--op-accent, var(--accent)), var(--accent2));
  opacity: .9; z-index: 2;
}
.op-card .op-cover {
  display: block; width: 100%;
  aspect-ratio: 16 / 9; object-fit: cover;
}
.op-card .op-body { padding: 18px 22px 22px; }
.op-card:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(124, 92, 252, 0.15);
  background: var(--panel);
}
.op-card h3 {
  margin: 0 0 6px;
  font-size: 1.35rem; font-weight: 800;
  letter-spacing: -0.02em; color: var(--text);
}
.op-card p { margin: 0; color: var(--muted); font-size: .88rem; }
.result-card { padding: 16px 20px; }

/* ── Opera view ──────────────────────────── */
.opera-view { padding: 0; }

/* ── Opera head ──────────────────────────── */
.opera-head { margin-bottom: 8px; }
.opera-head-top {
  display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap;
}
.opera-title-wrap { flex: 1; min-width: 0; }
.opera-head h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-weight: 900; letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--op-accent, var(--accent)), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.scene-context {
  margin: 4px 0 0;
  font-size: .88rem; color: var(--muted); font-weight: 600;
}
.opera-switcher {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 6px 10px; font-size: .82rem; font-family: inherit; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  outline: none; transition: all .2s ease;
  align-self: center; max-width: 140px;
}
.opera-switcher:hover, .opera-switcher:focus { border-color: var(--accent); }
.opera-meta { margin: 4px 0; }
.opera-tools { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }

.back-btn, .cast-toggle {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--text); border-radius: var(--radius-pill);
  padding: 9px 18px; font-size: .85rem; font-weight: 600;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
}
.back-btn:hover, .cast-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--panel); }
.back-btn { min-width: 130px; text-align: center; }
@media (max-width: 720px) {
  .back-btn { min-width: auto; padding: 10px 14px; }
  .opera-head-top { flex-direction: column; align-items: stretch; }
  .opera-title-wrap { order: -1; }
  .opera-switcher { order: -1; align-self: flex-end; margin-bottom: 8px; }
}
.cast-toggle.active { background: rgba(124, 92, 252, 0.14); border-color: var(--accent); color: var(--accent); }
@media (max-width: 720px) { .back-btn, .cast-toggle { padding: 10px 16px; min-height: 44px; } }

/* ── Language toggle ─────────────────────── */
.seg {
  display: inline-flex; gap: 0; margin: 10px 0;
  background: var(--glass-bg); padding: 4px;
  border-radius: var(--radius-pill); border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.seg-btn {
  background: none; border: none; color: var(--muted);
  padding: 9px 18px; border-radius: var(--radius-pill);
  font-size: .88rem; font-weight: 600; transition: all .2s ease;
}
.seg-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; box-shadow: 0 4px 16px rgba(124, 92, 252, 0.3);
}
@media (max-width: 720px) { .seg-btn { padding: 11px 16px; min-height: 44px; } }

/* ── Scene location label ────────────────── */
.scene-location {
  font-size: .8rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
  padding: 0 0 16px;
}
/* ── Scene body (libretto lines) ─────────── */
#scene-body { padding-bottom: 20px; }

.scene-title {
  color: var(--accent2); font-size: 1.3rem; font-weight: 800;
  margin: 24px 0 14px; letter-spacing: -0.02em;
}
.scene-plain { color: var(--muted); margin: 28px 0 14px; font-size: 1.15rem; font-weight: 700; }

/* ── Line card ───────────────────────────── */
.line {
  display: flex; flex-direction: column; gap: 6px;
  padding: 16px 20px; margin-bottom: 8px;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
}
.line:hover { background: var(--panel); border-color: var(--accent); }
.line.playing {
  background: rgba(124, 92, 252, 0.15);
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(124, 92, 252, 0.15);
  animation: pulse-play 2s ease-in-out infinite;
}
@keyframes pulse-play {
  0%, 100% { box-shadow: 0 0 20px rgba(124, 92, 252, 0.15); }
  50% { box-shadow: 0 0 35px rgba(124, 92, 252, 0.3); }
}
.line .who {
  display: inline-flex; align-self: flex-start;
  color: var(--accent); font-size: calc(.7rem * var(--read-scale));
  font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  background: rgba(124, 92, 252, 0.08); border: 1px solid rgba(124, 92, 252, 0.2);
  border-radius: var(--radius-pill); padding: 4px 12px; white-space: nowrap;
}
.line .who-it { color: var(--accent); font-weight: 700; }
.line .who-sep { color: var(--muted); }
.line .who-ru { color: var(--muted); text-transform: none; font-weight: 500; }
.line .it {
  font-family: var(--font-it); font-weight: 500;
  font-size: calc(1.15rem * var(--read-scale)); line-height: 1.6;
  overflow-wrap: break-word; color: var(--text);
}
.line .ru {
  color: var(--muted); font-size: calc(.9rem * var(--read-scale));
  line-height: 1.5; overflow-wrap: break-word;
}
.line.matched { background: rgba(78, 168, 255, 0.08); border-color: var(--accent2); }
.line.matched .it { color: var(--accent2); }
.line.mine {
  border-left: 3px solid var(--accent);
  background: linear-gradient(90deg, rgba(124, 92, 252, 0.1), rgba(124, 92, 252, 0.02) 70%);
}
.line.mine .who { border-color: var(--accent); background: rgba(124, 92, 252, 0.14); }
.line.other { opacity: .35; }
@media (max-width: 720px) { .line { padding: 14px 16px; } }

/* ── Badges ──────────────────────────────── */
.badge {
  display: inline-block; margin-left: .4em; padding: .08em .45em;
  font-size: .6rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  border-radius: var(--radius-pill); vertical-align: .1em;
}
.chorus-tag { color: var(--accent3); border: 1px solid rgba(34, 211, 176, 0.4); }
.ens-tag { color: var(--accent2); border: 1px solid rgba(78, 168, 255, 0.4); }
.offstage-tag { color: #ffa94d; border: 1px solid rgba(255, 169, 77, 0.4); }

/* ── Play button ─────────────────────────── */
.play-wrap { display: inline-flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.play-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--accent2); border-radius: var(--radius-pill);
  padding: 8px 16px; font-size: .8rem; font-weight: 600;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
}
.play-btn:hover { border-color: var(--accent2); background: rgba(78, 168, 255, 0.08); }
.eq { display: none; gap: 2px; align-items: flex-end; height: 12px; }
.eq i { width: 3px; height: 100%; background: currentColor; border-radius: 2px; animation: eqbar .9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: .18s; }
.eq i:nth-child(3) { animation-delay: .36s; }
@keyframes eqbar { 0%, 100% { height: 30%; } 50% { height: 100%; } }
.play-btn.playing { background: rgba(78, 168, 255, 0.12); border-color: var(--accent2); }
.play-btn.playing .eq { display: inline-flex; }
.play-btn.playing .play-ico, .play-btn.playing .play-label { display: none; }
.play-btn.paused { background: rgba(78, 168, 255, 0.04); border-color: rgba(78, 168, 255, 0.3); }
.play-btn.paused .eq { display: none; }
.play-btn.paused .play-ico, .play-btn.paused .play-label { display: inline; }
.speed-sel {
  background: var(--glass-bg); color: var(--accent2); border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill); padding: 6px 10px; font-size: .75rem; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.speed-sel:hover { border-color: var(--accent2); }
.rec-btn, .rec-play-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--muted); border-radius: var(--radius-pill);
  min-width: 36px; min-height: 36px; font-size: .85rem; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
}
.rec-btn:hover { border-color: #ff4757; color: #ff4757; }
.rec-btn.recording { background: #ff4757; border-color: #ff4757; color: #fff; animation: rec-pulse 1s ease-in-out infinite; }
@keyframes rec-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }
.rec-play-btn { color: var(--accent3); }
.rec-play-btn:hover { border-color: var(--accent3); background: rgba(34, 211, 176, 0.1); }
.rec-del-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--muted); border-radius: var(--radius-pill);
  min-width: 36px; min-height: 36px; font-size: .75rem; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
}
.rec-del-btn:hover { border-color: #ff4757; color: #ff4757; }
@media (max-width: 720px) { .play-btn { min-height: 44px; padding: 10px 18px; } }
@media (max-width: 720px) { .rec-btn, .rec-play-btn, .rec-del-btn { min-width: 44px; min-height: 44px; } }

/* ── Floating scenes panel (right side) ──── */
.scenes-backdrop {
  position: fixed; inset: 0; z-index: 35;
  background: rgba(5, 5, 8, 0.5);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.scenes-backdrop.hidden { display: none; }

.scenes-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 40;
  width: 320px; max-width: 90vw;
  background: var(--bg2);
  border-left: 1px solid var(--glass-border);
  padding: 20px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  box-shadow: var(--shadow-lg);
}
.scenes-panel.open { transform: translateX(0); }
#roles-panel {
  right: auto; left: 0;
  transform: translateX(-100%);
}
#roles-panel.open { transform: translateX(0); }
.scenes-panel h3 {
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .15em; color: var(--muted); margin: 0 0 16px;
}
.scenes-panel .act-group { margin-bottom: 18px; }
.scenes-panel .act-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .12em; color: var(--muted); margin-bottom: 8px;
}
.scenes-panel .sp-scene {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--muted);
  padding: 10px 14px; border-radius: 10px; font-size: .88rem;
  transition: all .15s ease; cursor: pointer;
}
.scenes-panel .sp-scene:hover { color: var(--text); background: var(--glass-bg); }
.scenes-panel .sp-scene.active { color: var(--accent2); background: rgba(78, 168, 255, 0.08); font-weight: 600; }
.scenes-panel .sp-scene.has-role { color: var(--accent3); font-weight: 600; }

/* ── Bottom navigation ──────────────────── */
.bottom-nav {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-around;
  height: var(--bn-h);
  background: var(--panel-solid);
  border-top: 1px solid var(--glass-border);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bn-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; color: var(--muted);
  padding: 6px 10px; font-size: .68rem; font-family: inherit;
  transition: color .2s ease; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bn-item .bn-icon { font-size: 1.2rem; }
.bn-item .bn-label { font-size: .64rem; font-weight: 600; }
.bn-item.active { color: var(--accent); }
.bn-item:disabled { opacity: .3; pointer-events: none; }

@media (min-width: 721px) {
  .bottom-nav { display: none; }
  .content-area { padding-bottom: 20px; }
}

/* ── Cast panel ──────────────────────────── */
.cast-list {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 6px; margin-top: 8px;
}
@media (max-width: 720px) { .cast-list { grid-template-columns: 1fr; } }
.cast-card {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: left; color: var(--text);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
  cursor: pointer;
  user-select: none;
}
.cast-card:hover { border-color: var(--accent); transform: translateY(-1px); background: var(--panel); }
.cast-card.cast-chorus { border-color: rgba(124, 92, 252, 0.3); }
.cast-card:active { border-color: var(--accent); }
.cast-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.cast-name { font-size: .95rem; font-weight: 700; }
.cast-name .who-it { color: var(--accent2); }
.cast-name .who-ru { color: var(--text); }
.cast-role { color: var(--muted); font-size: .78rem; }
.cast-count { color: var(--accent3); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.cast-add-btn.inline {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--muted); border-radius: var(--radius-pill);
  font-size: 1rem; flex-shrink: 0;
  transition: all .2s ease;
}
.cast-add-btn.inline:hover { border-color: var(--accent); color: var(--accent); }
.cast-add-btn.inline.added { background: linear-gradient(135deg, var(--accent), var(--accent2)); border-color: var(--accent); color: #fff; }
.scene-tag {
  color: var(--muted); font-size: .74rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; margin: 18px 0 4px;
}

/* Remove old split-row styles */
.cast-card-row { display: none; }
.cast-add-btn { display: none; }
@media (max-width: 720px) { .cast-list { grid-template-columns: 1fr; } .cast-add-btn { min-width: 48px; } }

/* ── Role bar ────────────────────────────── */
.role-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 8px 0 14px; }
.role-bar.hidden { display: none; }
.learn-btn {
  background: rgba(124, 92, 252, 0.08); border: 1px solid rgba(124, 92, 252, 0.25);
  color: var(--accent); border-radius: var(--radius-pill);
  padding: 10px 20px; font-size: .88rem; font-weight: 600;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
}
.learn-btn:hover { background: rgba(124, 92, 252, 0.16); border-color: var(--accent); }
.learn-btn.ghost { background: none; border-color: var(--glass-border); color: var(--muted); }
.learn-btn.ghost:hover { color: var(--accent); border-color: var(--accent); }
.role-tag { color: var(--accent); font-weight: 800; font-size: 1rem; }
.role-progress-text { color: var(--muted); font-size: .85rem; }
.role-bar-track { width: 120px; height: 6px; border-radius: var(--radius-pill); overflow: hidden; background: var(--glass-bg); border: 1px solid var(--glass-border); }
#role-bar-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: var(--radius-pill); transition: width .3s ease; }

/* ── Know button ─────────────────────────── */
.know-btn {
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: auto; margin-top: 8px;
  width: 36px; height: 36px; border-radius: var(--radius-pill);
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--muted); font-size: 1rem; transition: all .2s ease;
}
.know-btn:hover { border-color: var(--accent); color: var(--accent); }
.know-btn.known { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (max-width: 720px) { .know-btn { width: 44px; height: 44px; font-size: 1.2rem; } }
.streak-display { font-size: .9rem; color: #ffa94d; font-weight: 700; }

/* ── My roles ────────────────────────────── */
/* ── Roles panel (высплывающая) ─────────── */
#roles-panel h2 {
  font-size: 1.2rem; font-weight: 800; color: var(--accent);
  margin: 16px 0 12px;
}
#myroles-roles {
  display: flex; flex-direction: column; gap: 8px;
}

.myroles-panel { margin-bottom: 28px; }
.myroles-panel .meta { margin: 10px 0; }
.myrole-card {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); padding: 14px 18px;
  text-align: left; color: var(--text); margin-bottom: 8px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
}
.myrole-card:hover { border-color: var(--accent); transform: translateY(-1px); background: var(--panel); }
.myrole-body { flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.myrole-op { color: var(--muted); font-size: .8rem; }
.myrole-name { color: var(--accent); font-weight: 700; font-size: 1rem; }
.myrole-pct { color: var(--accent3); font-size: .88rem; font-weight: 600; margin-left: auto; }
.myrole-track { width: 100%; height: 4px; border-radius: var(--radius-pill); overflow: hidden; background: var(--glass-bg); }
.myrole-track span { display: block; height: 100%; border-radius: var(--radius-pill); background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s ease; }
.myrole-remove { background: none; border: none; color: var(--muted); font-size: 1.1rem; padding: 6px; transition: color .15s ease; }
.myrole-remove:hover { color: #ff4757; }

/* ── Modal ───────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5, 5, 8, 0.7);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 20px;
}
.modal-card {
  width: 100%; max-width: 400px;
  background: var(--panel-solid); border: 1px solid var(--glass-border);
  border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-lg);
}
.modal-card h2 { margin: 0 0 10px; font-size: 1.2rem; font-weight: 800; color: var(--text); }
.role-list { display: flex; flex-direction: column; gap: 8px; margin: 16px 0 18px; max-height: 44vh; overflow-y: auto; }
.role-opt {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 14px 18px; font-size: .95rem; font-weight: 500; text-align: left;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
}
.role-opt:hover { border-color: var(--accent); background: var(--panel); }
.role-opt .cnt { color: var(--muted); font-size: .82rem; }
.role-opt .who-it { color: var(--accent2); }
.role-opt .who-ru { color: var(--text); }
.role-opt-row { display: none; }
.modal-card-wide { max-width: 480px; }
.rd-title { font-weight: 900; font-size: 1.5rem; margin: 8px 0 4px; color: var(--accent); }
.rd-opera { color: var(--muted); font-size: .88rem; margin: 0 0 12px; }
.rd-summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 16px;
}
.rd-streak { color: #ffa94d; font-size: .9rem; font-weight: 700; }
.rd-pct { color: var(--accent); font-weight: 900; font-size: 1.3rem; margin-left: auto; }
.rd-track { width: 100%; height: 6px; border-radius: var(--radius-pill); overflow: hidden; background: var(--glass-bg); }
.rd-total { width: 100%; color: var(--muted); font-size: .8rem; }
.rd-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.rd-actions .learn-btn { flex: 1; text-align: center; }
.rd-acts { display: flex; flex-direction: column; gap: 10px; max-height: 50vh; overflow-y: auto; }
.rd-act {
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.rd-act-header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.rd-act-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.rd-act-pct { color: var(--muted); font-size: .85rem; margin-left: auto; }
.rd-act-bar { width: 100%; height: 4px; border-radius: var(--radius-pill); overflow: hidden; background: var(--glass-bg); }
.rd-act-bar span { display: block; height: 100%; border-radius: var(--radius-pill); background: var(--accent2); transition: width .3s ease; }
.rd-act-scenes { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.rd-scene {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; transition: background .15s ease;
}
.rd-scene:hover { background: var(--glass-bg); }
.rd-scene.done { opacity: .5; }
.rd-scene.no-role { opacity: .3; }
.rd-scene-title { flex: 1; font-size: .88rem; color: var(--text); }
.rd-scene-cnt { color: var(--muted); font-size: .78rem; }
.rd-scene-cnt.done { color: var(--accent3); font-weight: 600; }
.rd-train { padding: 4px 12px; font-size: .78rem; }

/* ── Video panel ───────────────────────── */
.video-panel {
  position: fixed; top: 60px; right: 16px; z-index: 40;
  width: 280px;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  transition: all .3s ease;
}
.video-panel.hidden { display: none; }
.video-container {
  position: relative; width: 100%; padding-bottom: 56.25%;
}
.video-container iframe {
  position: absolute; inset: 0; width: 100%; height: 100%; border: none;
}
.video-close {
  position: absolute; top: 4px; right: 4px; z-index: 5;
  background: rgba(0,0,0,.7); border: none; color: #fff;
  border-radius: 50%; width: 28px; height: 28px; font-size: .8rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
@media (max-width: 720px) {
  .video-panel { top: 54px; right: 8px; width: 200px; }
}

/* ── Toast ───────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--bn-h) + 16px + env(safe-area-inset-bottom, 0px)); left: 50%;
  transform: translateX(-50%);
  background: var(--panel-solid); border: 1px solid var(--glass-border);
  color: var(--text); padding: 12px 24px; border-radius: var(--radius-pill);
  font-size: .88rem; font-weight: 600; z-index: 50;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
@media (min-width: 721px) { .toast { bottom: 30px; } }

/* ── Scroll to top button ──────────────── */
.scroll-top {
  position: fixed; bottom: calc(var(--bn-h) + 20px); right: 20px; z-index: 45;
  width: 44px; height: 44px;
  background: var(--panel-solid);
  border: 1px solid var(--glass-border);
  color: var(--accent);
  border-radius: var(--radius-pill);
  font-size: 1.2rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg);
  transition: all .3s ease;
  opacity: 0; transform: translateY(10px);
  pointer-events: none;
}
.scroll-top:not(.hidden) {
  opacity: 1; transform: translateY(0);
  pointer-events: auto;
}
.scroll-top:hover { border-color: var(--accent); box-shadow: 0 0 20px var(--accent-glow); }

/* ── Prev/Next scene buttons ──────────── */
.prev-scene-btn {
  display: block; width: 100%;
  margin-bottom: 8px; padding: 10px 20px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: var(--muted);
  border-radius: var(--radius);
  font-size: .9rem; font-weight: 600;
  text-align: left; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
}
.prev-scene-btn:hover { border-color: var(--accent); color: var(--accent); }
.scene-nav { display: flex; gap: 8px; margin-top: 20px; }
.scene-nav .prev-scene-btn, .scene-nav .next-scene-btn { flex: 1; margin: 0; }
.next-scene-btn {
  display: block; width: 100%;
  margin-top: 20px; padding: 16px 24px;
  background: var(--glass-bg);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius);
  font-size: 1rem; font-weight: 700;
  text-align: center; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: all .2s ease;
}
.next-scene-btn:hover {
  background: rgba(124, 92, 252, 0.12);
  box-shadow: 0 0 24px var(--accent-glow);
}

@media (min-width: 721px) { .scroll-top { bottom: 30px; } }

/* ── My role modal cards ────────────────── */
.myrole-modal-card {
  position: relative; background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 8px;
}
.myrole-go { width: 100%; text-align: left; font-size: .95rem; background: none; border: none; color: inherit; }
.myrole-go .myrole-op { display: block; margin-bottom: 4px; }
.myrole-go .myrole-name { font-size: 1.05rem; }
.myrole-modal-remove { position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--muted); font-size: 1rem; padding: 4px; transition: color .15s ease; }
.myrole-modal-remove:hover { color: #ff4757; }

/* ── Mobile modal ────────────────────────── */
@media (max-width: 720px) {
  .modal { padding: 12px; align-items: flex-end; }
  .modal-card { max-width: 100%; border-radius: 22px 22px 8px 8px; padding: 22px 18px; }
  .role-opt { padding: 16px 18px; min-height: 52px; }
}

/* ── Touch ───────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
  .op-card:hover { transform: none; box-shadow: none; background: var(--glass-bg); }
  .op-card:active { transform: scale(.97); border-color: var(--accent); }
  .cast-card:hover { transform: none; }
  .cast-card:active { border-color: var(--accent); }
  .line:active { background: rgba(124, 92, 252, 0.05); }
}

/* ── Reduced motion ─────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ── Search screen ──────────────────────── */
#screen-search h2 {
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 900; color: var(--accent);
  margin: 0 0 8px;
}
#search-results { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
