:root {
  --bg: #f3efe6;
  --bg-deep: #e7e0d2;
  --ink: #1c1914;
  --muted: #6b6458;
  --line: #d4ccbc;
  --accent: #0f6b5c;
  --accent-ink: #f7faf9;
  --danger: #9b3b2e;
  --card: #fffdf8;
  --shadow: 0 10px 30px rgba(28, 25, 20, 0.08);
  --radius: 18px;
  --font: "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #fff8e8 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, #d9efe8 0%, transparent 50%),
    var(--bg);
}

button,
input,
summary {
  font: inherit;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

button.ghost {
  background: transparent;
}

button.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
}

.app-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 1rem 5.5rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: 0.02em;
}

.brand p,
.muted,
.cap {
  color: var(--muted);
}

.cap {
  font-size: 0.85rem;
  margin: 0.25rem 0 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.root-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: var(--bg-deep);
  font-size: 0.9rem;
}

.hero-empty {
  padding: 2rem 1.25rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--card) 80%, transparent);
  text-align: center;
}

.hero-empty h2 {
  margin: 0 0 0.5rem;
}

.scan-status {
  margin: 0.75rem 0 1rem;
  font-size: 0.92rem;
  color: var(--muted);
}

.series {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.series > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1rem;
  font-weight: 600;
}

.series > summary::-webkit-details-marker {
  display: none;
}

.series-count {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
}

.episode-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}

.episode {
  display: grid;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.episode:first-child {
  border-top: 0;
}

.episode-title {
  font-weight: 600;
}

.episode-meta {
  margin-top: 0.2rem;
  font-size: 0.82rem;
  color: var(--muted);
  word-break: break-all;
}

.episode-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  padding: 0.55rem 0.75rem calc(0.55rem + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}

.nav-btn {
  border-radius: 14px;
  padding: 0.7rem 0.4rem;
  border: 0;
  background: transparent;
}

.nav-btn.is-active {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-weight: 600;
}

.view-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.view-header h2 {
  margin: 0;
  font-size: 1.2rem;
  flex: 1;
}

.player-card,
.panel-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem;
  box-shadow: var(--shadow);
}

video,
audio {
  width: 100%;
  display: block;
  border-radius: 12px;
  background: #111;
}

audio {
  background: transparent;
}

.player-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.75rem;
}

#pdfFrame {
  width: 100%;
  min-height: 70vh;
  border: 0;
  border-radius: 12px;
  background: #fff;
}

.flat-item {
  display: block;
  width: 100%;
  text-align: left;
  border-radius: 12px;
  margin-bottom: 0.45rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem;
}

.stat-card strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.05rem;
}

.stat-row {
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}

.stat-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

.cue-raw {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85rem;
  max-height: 40vh;
  overflow: auto;
  margin: 0;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 5.2rem;
  transform: translateX(-50%);
  background: #1c1914;
  color: #fff;
  padding: 0.7rem 1rem;
  border-radius: 999px;
  max-width: min(92vw, 420px);
  text-align: center;
  z-index: 30;
  box-shadow: var(--shadow);
}

@media (min-width: 720px) {
  .episode {
    grid-template-columns: 1fr auto;
    align-items: center;
  }
}
