:root {
  /* Type scale */
  --fs-meta:    11px;   /* dates, timestamps, counts */
  --fs-small:   12px;   /* secondary text, source snippets */
  --fs-body:    13px;   /* episode titles, search results, controls */
  --fs-reading: 14px;   /* primary reading text (transcript, answers) */
  --fs-heading: 15px;   /* transcript header, section titles */
  --fs-brand:   16px;   /* app title */

  --lh-tight:  1.35;
  --lh-normal: 1.5;
  --lh-loose:  1.6;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, Menlo, Consolas, monospace;

  /* Palette */
  --color-bg:          #121212;
  --color-bg-elev-1:   #1a1a1a;
  --color-bg-elev-2:   #1e1e1e;
  --color-bg-elev-3:   #222;
  --color-surface:     #2a2a2a;
  --color-surface-hi:  #333;

  --color-border:      #333;
  --color-border-soft: #2a2a2a;
  --color-border-hi:   #444;

  --color-text:        #e0e0e0;
  --color-text-strong: #f0f0f0;
  --color-text-soft:   #bbb;
  --color-text-muted:  #888;
  --color-text-dim:    #777;

  --color-accent:         #ff4d4d;
  --color-accent-soft:    #ff8a8a;
  --color-accent-surface: #2d1f1f;

  --color-info: #8ac4ff;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
}

/* Keyboard-only focus ring. Uses :focus-visible so mouse clicks don't
   leave lingering outlines but Tab navigation gets a clear signal. */
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Hide the focus ring entirely for mouse users on elements that have their
   own hover/active styles (otherwise it flashes after click). */
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}

header {
  padding: 10px 20px;
  background: #1e1e1e;
  border-bottom: 1px solid #333;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
}

header h1 {
  font-size: var(--fs-brand);
  color: var(--color-accent);
  white-space: nowrap;
}

/* Hamburger button is desktop-hidden; revealed by the mobile breakpoint below. */
#menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-soft);
  font-size: 22px;
  line-height: 1;
  padding: 2px 10px;
  border-radius: 4px;
  cursor: pointer;
}

#menu-toggle:hover {
  color: var(--color-text-strong);
  border-color: var(--color-border-hi);
}

/* Overlay that appears behind the drawer-mode sidebar so tapping outside closes it. */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 15;
}

#sidebar-backdrop.open {
  display: block;
}

#search-form {
  flex: 1;
  display: flex;
  gap: 8px;
  max-width: 600px;
}

#search-input {
  flex: 1;
  padding: 6px 10px;
  background: #2a2a2a;
  border: 1px solid #444;
  color: #e0e0e0;
  border-radius: 4px;
  font-size: 14px;
  outline: none;
}

#search-input:focus {
  border-color: var(--color-accent);
}

button {
  padding: 6px 14px;
  background: #333;
  color: #e0e0e0;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

button:hover {
  background: #444;
}

main {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

#sidebar {
  width: 340px;
  background: #1a1a1a;
  border-right: 1px solid #333;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#sidebar-header {
  padding: 8px 14px;
  background: #222;
  border-bottom: 1px solid #333;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #999;
  flex-shrink: 0;
}

#episode-list {
  flex: 1;
  overflow-y: auto;
}

.ep, .search-result {
  padding: 10px 14px;
  border-bottom: 1px solid #2a2a2a;
  cursor: pointer;
}

.ep:hover, .search-result:hover {
  background: #252525;
}

.ep.active {
  background: #2d1f1f;
  border-left: 3px solid var(--color-accent);
  padding-left: 11px;
}

.ep-date, .search-result-title {
  color: #888;
  font-size: 11px;
  margin-bottom: 3px;
}

.ep-title {
  font-size: 13px;
  line-height: 1.35;
}

.search-result-text {
  font-size: 13px;
  line-height: 1.4;
  color: #ddd;
}

.search-result-time {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--color-accent);
  font-size: 11px;
  margin-right: 8px;
}

#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#player-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 55vh;
  background: #000;
  flex-shrink: 0;
}

#player, #player iframe {
  width: 100%;
  height: 100%;
}

#transcript-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

#transcript-header {
  padding: 10px 14px;
  background: #1e1e1e;
  border-bottom: 1px solid #333;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

#transcript-header-text {
  flex: 1;
  min-width: 0;
}

#transcript-header h2 {
  font-size: 15px;
  margin-bottom: 2px;
  color: #f0f0f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#copy-link.copied {
  background: #2d4a2d;
  border-color: #4a7a4a;
}

#current-date {
  color: #888;
  font-size: 12px;
}

#transcript {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.seg {
  display: flex;
  gap: 12px;
  padding: 4px 14px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.5;
}

.seg:hover {
  background: #1e1e1e;
}

.seg.active {
  background: #2d1f1f;
}

.seg-time {
  color: #888;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  min-width: 60px;
  padding-top: 2px;
  flex-shrink: 0;
}

.seg-text {
  flex: 1;
}

mark {
  background: var(--color-accent);
  color: #fff;
  padding: 0 2px;
  border-radius: 2px;
}

.empty-state {
  padding: 30px 20px;
  text-align: center;
  color: #777;
  font-size: 14px;
}

/* ── Welcome panel (shown when no episode is loaded) ───────────────────── */
body.no-episode #player-wrap,
body.no-episode #transcript-header {
  display: none;
}

.welcome {
  max-width: 600px;
  margin: 40px auto 0;
  padding: 20px 24px 40px;
}

.welcome-eyebrow {
  font-size: var(--fs-meta);
  color: var(--color-text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
  text-align: center;
}

.welcome-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--color-text-strong);
  margin-bottom: 4px;
  text-align: center;
}

.welcome-sub {
  font-size: var(--fs-body);
  color: var(--color-text-muted);
  text-align: center;
  margin-bottom: 32px;
}

.welcome-section-label {
  font-size: var(--fs-meta);
  color: var(--color-text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--color-border);
}

.welcome-tips {
  list-style: none;
  padding: 0;
  margin: 0;
}

.welcome-tips li {
  display: flex;
  gap: 14px;
  padding: 12px 0;
  font-size: var(--fs-reading);
  line-height: 1.5;
  color: var(--color-text-soft);
  border-bottom: 1px solid var(--color-border-soft);
}

.welcome-tips li:last-child {
  border-bottom: none;
}

.welcome-tip-icon {
  flex-shrink: 0;
  font-size: 22px;
  line-height: 1.3;
  width: 28px;
  text-align: center;
}

.welcome-tips strong {
  color: var(--color-text-strong);
  font-weight: 600;
}

/* Inline "working" text with animated dots, reusable across panels. */
.loading-inline {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  color: #888;
}

.loading-inline::after {
  content: '';
  display: inline-block;
  width: 1em;
  overflow: hidden;
  vertical-align: bottom;
  animation: ellipsis 1.4s steps(4, end) infinite;
}

@keyframes ellipsis {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%, 100% { content: '...'; }
}

/* Shimmer skeleton block for lists while loading. */
.skeleton {
  background: linear-gradient(
    90deg,
    #1a1a1a 25%,
    #242424 50%,
    #1a1a1a 75%
  );
  background-size: 200% 100%;
  border-radius: 3px;
  animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.skeleton-row {
  padding: 12px 14px;
  border-bottom: 1px solid #202020;
}

.skeleton-row .skeleton {
  height: 10px;
  margin-bottom: 6px;
}

.skeleton-row .skeleton:last-child {
  width: 70%;
  margin-bottom: 0;
}

/* Ask-AI side panel */
#ask-btn {
  background: linear-gradient(180deg, #3a2525, #2a1a1a);
  border-color: #663333;
  color: #ff8a8a;
  font-weight: 500;
}

#ask-btn:hover {
  background: linear-gradient(180deg, #4a2f2f, #3a2525);
}

#ask-btn.busy {
  opacity: 0.5;
  cursor: wait;
}

#ask-panel {
  width: 420px;
  background: #161616;
  border-left: 1px solid #333;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  animation: ask-slide-in 0.18s ease-out;
}

#ask-panel[hidden] {
  display: none;
}

@keyframes ask-slide-in {
  from {
    transform: translateX(24px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

#ask-panel-header {
  padding: 10px 14px;
  background: #1e1e1e;
  border-bottom: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#ask-panel-title {
  font-size: 14px;
  font-weight: 500;
  color: #f0f0f0;
}

#ask-panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

#ask-clear {
  padding: 3px 9px;
  font-size: 11px;
  background: transparent;
  color: #888;
  border: 1px solid #333;
  border-radius: 3px;
}

#ask-clear:hover {
  color: #ccc;
  border-color: #555;
  background: #222;
}

#ask-close {
  background: transparent;
  border: none;
  color: #888;
  font-size: 22px;
  line-height: 1;
  padding: 0 6px;
  cursor: pointer;
}

#ask-close:hover {
  color: #fff;
}

#ask-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.ask-empty {
  padding: 30px 10px;
  text-align: center;
  color: #777;
  font-size: 13px;
  line-height: 1.5;
}

.ask-msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ask-msg-role {
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ask-msg-user .ask-msg-text {
  color: #e0e0e0;
  font-size: 14px;
  line-height: 1.45;
  background: #222;
  border-left: 3px solid var(--color-accent);
  padding: 8px 12px;
  border-radius: 3px;
  white-space: pre-wrap;
}

.ask-msg-assistant .ask-msg-text {
  font-size: 14px;
  line-height: 1.55;
  color: #eaeaea;
}

/* Markdown content inside the answer */
.ask-msg-assistant .ask-msg-text p { margin: 0 0 10px 0; }
.ask-msg-assistant .ask-msg-text p:last-child { margin-bottom: 0; }
.ask-msg-assistant .ask-msg-text ul,
.ask-msg-assistant .ask-msg-text ol {
  margin: 4px 0 10px 20px;
  padding: 0;
}
.ask-msg-assistant .ask-msg-text li { margin: 2px 0; }
.ask-msg-assistant .ask-msg-text strong { color: #fff; font-weight: 600; }
.ask-msg-assistant .ask-msg-text em { color: #ddd; }
.ask-msg-assistant .ask-msg-text code {
  background: #2a2a2a;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
}
.ask-msg-assistant .ask-msg-text pre {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 8px 10px;
  overflow-x: auto;
  margin: 6px 0 10px 0;
}
.ask-msg-assistant .ask-msg-text pre code {
  background: transparent;
  padding: 0;
}
.ask-msg-assistant .ask-msg-text blockquote {
  border-left: 3px solid #444;
  margin: 6px 0;
  padding: 2px 10px;
  color: #bbb;
}
.ask-msg-assistant .ask-msg-text a {
  color: #8ac4ff;
  text-decoration: underline;
}

/* Thinking animation */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #aaa;
}

.thinking-dots {
  display: inline-flex;
  gap: 4px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: thinking-bounce 1.2s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinking-bounce {
  0%, 70%, 100% { transform: translateY(0); opacity: 0.35; }
  35%           { transform: translateY(-4px); opacity: 1; }
}

.ask-msg-assistant.error .ask-msg-text {
  color: var(--color-accent-soft);
}

.retry-btn {
  align-self: flex-start;
  margin-top: 8px;
  padding: 4px 10px;
  font-size: var(--fs-small);
  background: var(--color-accent-surface);
  color: var(--color-accent-soft);
  border: 1px solid var(--color-border-hi);
  border-radius: 3px;
  cursor: pointer;
}

.retry-btn:hover {
  background: #3a2525;
  border-color: var(--color-accent);
}

.cite {
  display: inline-block;
  background: #2a2a2a;
  color: #ff8a8a;
  border: 1px solid #444;
  border-radius: 3px;
  padding: 0 5px;
  margin: 0 1px;
  font-size: 11px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  cursor: pointer;
  vertical-align: baseline;
  text-decoration: none;
}

.cite:hover {
  background: #3a2525;
  border-color: var(--color-accent);
}

.ask-sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #2a2a2a;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ask-sources-label {
  font-size: 11px;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.ask-source {
  padding: 6px 8px;
  background: #1a1a1a;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
}

.ask-source:hover {
  background: #242424;
}

.ask-source-head {
  color: #aaa;
  margin-bottom: 2px;
}

.ask-source-n {
  color: #ff8a8a;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  margin-right: 5px;
}

.ask-source-text {
  color: #888;
}

#ask-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 14px 14px;
  border-top: 1px solid #333;
  background: #1a1a1a;
  flex-shrink: 0;
}

#ask-input {
  width: 100%;
  padding: 8px 10px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 4px;
  color: #e0e0e0;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
}

#ask-input:focus {
  border-color: var(--color-accent);
}

#ask-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#ask-web-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #aaa;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

#ask-web-label input[type="checkbox"] {
  accent-color: var(--color-accent);
  cursor: pointer;
}

.web-badge {
  display: inline-block;
  font-size: 10px;
  color: var(--color-info);
  background: #1e2a38;
  border: 1px solid #3a5a7a;
  border-radius: 3px;
  padding: 1px 5px;
  margin-left: 6px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  vertical-align: middle;
}

/* ── Mobile (<= 768px) ──────────────────────────────────────────────────────
   - Sidebar becomes a slide-in drawer over the content.
   - Ask panel takes the full screen when open.
   - Hamburger button in the header toggles the drawer.
   - Stacked content (player + transcript) already works in flex-column. */
@media (max-width: 768px) {
  header {
    padding: 8px 12px;
    gap: 10px;
    flex-wrap: wrap;
  }

  header h1 {
    font-size: var(--fs-body);
  }

  #menu-toggle {
    display: inline-block;
  }

  /* Let the search form take the full row on very narrow screens */
  #search-form {
    flex-basis: 100%;
    order: 3;
  }

  #ask-btn {
    order: 2;
  }

  /* Drawer-mode sidebar */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: min(86vw, 340px);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 18px rgba(0, 0, 0, 0.4);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  /* Content becomes full-width; player auto-sizes, transcript scrolls below. */
  #content {
    width: 100%;
  }

  #player-wrap {
    max-height: 40vh;
  }

  /* Ask panel: full-screen overlay instead of side column */
  #ask-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    z-index: 25;
    border-left: none;
  }

  /* Bigger tap targets where we can */
  .ep, .search-result {
    padding: 12px 14px;
  }

  .seg {
    padding: 8px 14px;
  }

  .seg-time {
    min-width: 54px;
  }
}

/* Very narrow phones — tighten further */
@media (max-width: 400px) {
  header h1 {
    display: none;   /* hamburger + search + Ask is enough ID */
  }

  #sidebar {
    width: 92vw;
  }
}
