:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --bg-elev: #151923;
  --bg-elev-2: #1d2331;
  --fg: #eef1f6;
  --fg-muted: #9aa3b5;
  --line: #2a3243;
  --accent: #4f8cff;
  --accent-fg: #ffffff;
  --accent-2: #ff8a4c;
  --success: #3ccf7a;
  --danger: #ff5c6c;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --max: 620px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
img { display: block; max-width: 100%; }

.wrap { max-width: var(--max); margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0 18px;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
.topbar .brand { display: flex; align-items: center; gap: 10px; color: var(--fg); }
.topbar .brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, var(--accent), #8b5cf6); display: grid; place-items: center; font-size: 15px; }
.topbar nav { display: flex; gap: 8px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--bg-elev); color: var(--fg);
  border-radius: 12px; padding: 12px 16px; font-size: 16px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px;
  transition: transform 80ms ease, background 120ms ease, border-color 120ms ease;
}
.btn:hover { background: var(--bg-elev-2); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: #3b7af0; }
.btn-danger { color: var(--danger); border-color: rgba(255, 92, 108, 0.4); }
.btn-danger:hover { background: rgba(255, 92, 108, 0.12); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--fg-muted); }
.btn-sm { min-height: 38px; padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn-block { width: 100%; }

.card {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.muted { color: var(--fg-muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- Library ---------- */
.episode-list { display: grid; gap: 12px; }
.episode-card {
  display: grid; grid-template-columns: 84px 1fr; gap: 14px; align-items: center;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  color: var(--fg); min-height: 108px;
}
.episode-card:hover { text-decoration: none; background: var(--bg-elev-2); }
.artwork {
  width: 84px; height: 84px; border-radius: 12px; background: linear-gradient(135deg, #263248, #1a2030);
  display: grid; place-items: center; font-size: 30px; overflow: hidden; flex-shrink: 0;
}
.artwork img { width: 100%; height: 100%; object-fit: cover; }
.episode-card h3 { margin: 0 0 4px; font-size: 17px; line-height: 1.3; }
.episode-card p { margin: 0; }
.progress { height: 6px; background: var(--bg-elev-2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--bg-elev-2); color: var(--fg-muted); border: 1px solid var(--line); }
.badge.ok { color: var(--success); }
.badge.warn { color: var(--accent-2); }
.empty { text-align: center; padding: 48px 16px; color: var(--fg-muted); }
.empty .big { font-size: 42px; margin-bottom: 8px; }

/* ---------- Forms ---------- */
label.field { display: grid; gap: 6px; font-size: 14px; color: var(--fg-muted); font-weight: 600; }
input[type="text"], textarea, select, input[type="number"] {
  width: 100%; font: inherit; font-size: 16px; color: var(--fg); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { min-height: 88px; resize: vertical; }
input[type="file"] { color: var(--fg-muted); font-size: 14px; }
.drop {
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 14px; background: var(--bg); display: grid; gap: 6px;
}
.drop strong { color: var(--fg); font-size: 15px; }
.upload-progress { height: 8px; background: var(--bg-elev-2); border-radius: 999px; overflow: hidden; }
.upload-progress > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 150ms ease; }
.error { color: var(--danger); font-size: 14px; }
.notice { color: var(--success); font-size: 14px; }

/* ---------- Player ---------- */
.player { display: grid; gap: 18px; }
.player-hero { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; }
.player-hero .artwork { width: 96px; height: 96px; }
.player-hero h2 { margin: 0 0 4px; font-size: 20px; line-height: 1.25; }
.timeline { display: grid; gap: 6px; }
.timeline input[type="range"] { width: 100%; accent-color: var(--accent); height: 34px; margin: 0; }
.times { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; color: var(--fg-muted); font-size: 14px; }

.big-button {
  appearance: none; border: none; width: 100%; min-height: 150px; border-radius: 28px; cursor: pointer;
  font-size: 30px; font-weight: 800; letter-spacing: -0.01em; color: #fff;
  background: linear-gradient(160deg, var(--accent), #2f5fd6);
  box-shadow: 0 14px 40px rgba(79, 140, 255, 0.35);
  display: grid; place-items: center; gap: 4px; padding: 18px; transition: transform 80ms ease, box-shadow 120ms ease;
}
.big-button .sub { font-size: 15px; font-weight: 600; opacity: 0.85; }
.big-button:active { transform: scale(0.985); }
.big-button:disabled { opacity: 0.6; cursor: wait; }
.big-button.is-playing { background: linear-gradient(160deg, var(--accent-2), #d95f2a); box-shadow: 0 14px 40px rgba(255, 138, 76, 0.35); }
.big-button.is-voice { background: linear-gradient(160deg, #22c55e, #15803d); box-shadow: 0 14px 40px rgba(60, 207, 122, 0.3); }
.big-button.is-connecting { background: linear-gradient(160deg, #6b7280, #4b5563); box-shadow: none; }

.secondary-controls { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.secondary-controls .btn { min-height: 64px; font-size: 17px; flex-direction: column; gap: 2px; }
.secondary-controls .btn small { font-size: 12px; color: var(--fg-muted); font-weight: 500; }

.voice-panel { display: grid; gap: 12px; }
.voice-status { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); font-size: 17px; font-weight: 600; }
.voice-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--fg-muted); flex-shrink: 0; }
.voice-dot.listening { background: var(--success); animation: pulse 1.4s ease-in-out infinite; }
.voice-dot.thinking { background: var(--accent-2); animation: pulse 0.8s ease-in-out infinite; }
.voice-dot.speaking { background: var(--accent); animation: pulse 0.6s ease-in-out infinite; }
.voice-dot.error { background: var(--danger); }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.35); opacity: 0.6; } }
.voice-live { display: grid; gap: 8px; max-height: 32vh; overflow: auto; padding-right: 4px; }
.voice-live .bubble { font-size: 15px; }

.bubble { padding: 10px 14px; border-radius: 14px; max-width: 92%; word-wrap: break-word; white-space: pre-wrap; }
.bubble.user { background: var(--accent); color: #fff; justify-self: end; border-bottom-right-radius: 4px; }
.bubble.assistant { background: var(--bg-elev-2); border: 1px solid var(--line); justify-self: start; border-bottom-left-radius: 4px; }
.bubble.partial { opacity: 0.7; font-style: italic; }
.bubble .tag { display: block; font-size: 12px; opacity: 0.75; margin-bottom: 4px; font-weight: 600; }

/* ---------- History ---------- */
.thread { display: grid; gap: 10px; }
.thread .event { text-align: center; color: var(--fg-muted); font-size: 12px; padding: 4px 0; }
.thread details { justify-self: stretch; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 13px; color: var(--fg-muted); }
.thread details summary { cursor: pointer; font-weight: 600; }
.thread details pre { white-space: pre-wrap; word-break: break-word; margin: 8px 0 0; font-size: 12.5px; color: var(--fg); max-height: 320px; overflow: auto; }
.thread .meta { font-size: 11px; opacity: 0.7; margin-top: 4px; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 8px; position: sticky; bottom: 0; background: var(--bg); padding: 12px 0 calc(8px + env(safe-area-inset-bottom)); }
.composer textarea { min-height: 52px; max-height: 160px; }
pre.prompt { white-space: pre-wrap; word-break: break-word; font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; max-height: 60vh; overflow: auto; color: var(--fg); }
.typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--fg-muted); animation: pulse 1s ease-in-out infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; } .typing i:nth-child(3) { animation-delay: 0.3s; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--fg); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; z-index: 50; max-width: 90vw; }
.toast.error { border-color: var(--danger); }

@media (min-width: 700px) {
  .big-button { min-height: 170px; font-size: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  .voice-dot, .typing i { animation: none; }
}
