* { box-sizing: border-box; }

/* Make sure [hidden] always wins over explicit display:flex/grid declarations
   we use elsewhere — otherwise #video-wrap and similar stay visible. */
[hidden] { display: none !important; }

/* Hide native scrollbars on the main scroll containers — scrolling still
   works (wheel, trackpad, keys), the bar is just invisible. */
#sidebar,
#sidebar > #feeds,
#sidebar > #channels-section,
#transcript-pane,
.view-section,
.tile-expand-eps,
.accordion-body,
.modal-body {
  scrollbar-width: none;          /* Firefox */
  -ms-overflow-style: none;       /* old IE/Edge */
}
#sidebar::-webkit-scrollbar,
#sidebar > #feeds::-webkit-scrollbar,
#sidebar > #channels-section::-webkit-scrollbar,
#transcript-pane::-webkit-scrollbar,
.view-section::-webkit-scrollbar,
.tile-expand-eps::-webkit-scrollbar,
.accordion-body::-webkit-scrollbar,
.modal-body::-webkit-scrollbar { display: none; }   /* Chromium/Safari */

:root {
  /* ---- palette ---- */
  --bg: #1b1d22;
  --bg-2: #24272d;
  --bg-3: #2e3239;
  --fg: #e7e9ee;
  --fg-dim: #9ba0aa;
  --border: #353a42;

  --accent: #7aa2f7;
  --accent-dim: #3b4a6b;
  --warn: #e0af68;
  --error: #f7768e;
  --ok: #9ece6a;

  --active: #2a3754;
  --loop: #5f4b32;

  /* Foreground colors that pair with the saturated badge / button backgrounds.
     Tokyo-night-ish dark tints of each accent so text stays readable. */
  --on-accent: var(--on-accent);
  --on-ok:     var(--on-ok);
  --on-warn:   var(--on-warn);
  --on-error:  var(--on-error);

  /* CEFR level palette — green→red gradation, but desaturated to live
     comfortably inside the Tokyo-night-ish neutral UI. Used by both filter
     pills (.level-pill) and tile chips (.chip.level). Tune here only. */
  --lvl-a1: #8ec06a;   /* near --ok */
  --lvl-a2: #b3bd66;
  --lvl-b1: #d6ad62;   /* near --warn */
  --lvl-b2: #cf8e63;
  --lvl-c1: #cf7273;
  --lvl-c2: #c46974;   /* near --error, less hot */

  /* Note highlight — derived from --warn so palette tweaks ripple through. */
  --note-bg:       color-mix(in srgb, var(--warn) 13%, transparent);
  --note-bg-hover: color-mix(in srgb, var(--warn) 22%, transparent);
  --note-border:   color-mix(in srgb, var(--warn) 40%, transparent);

  /* ---- shadows / overlays ---- */
  --shadow-pop:   0 4px 12px rgba(0, 0, 0, 0.40);  /* tooltip popovers */
  --shadow-menu:  0 6px 16px rgba(0, 0, 0, 0.50);  /* selection / note menu */
  --shadow-float: 0 10px 28px rgba(0, 0, 0, 0.55); /* video / modal */
  --backdrop:     rgba(0, 0, 0, 0.55);

  /* ---- typography ---- */
  --font-sans:  -apple-system, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono:  ui-monospace, "SF Mono", Menlo, monospace;
  --font-serif: "New York", "Charter", "Iowan Old Style", "Source Serif Pro", Georgia, ui-serif, serif;

  font-family: var(--font-sans);
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.45;
}

body {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}
body.sidebar-collapsed {
  grid-template-columns: 1fr;
}
body.sidebar-collapsed #sidebar { display: none; }
body.sidebar-collapsed .rail-toggle { display: flex; }
.rail-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  width: 30px;
  height: 30px;
  font-size: 16px;
  align-items: center;
  justify-content: center;
}

button {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 10px;
  cursor: pointer;
  font: inherit;
}
/* Generic hover = neutral lift (--bg-3). Reserve --accent-dim strictly for
   "active/selected" states (episode.active, .icon-btn.active, .seg .text
   selection). Keeps the saturated blue meaningful instead of flickering on
   every casual hover. */
button:hover { background: var(--bg-3); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, select {
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 8px;
  font: inherit;
}
input[type="url"], input[type="text"] { width: 100%; }

/* Custom checkbox — system blue is too saturated against the dark UI. We draw
   a small flat box that matches the rest of the palette: bg-3 unchecked,
   accent-dim with --fg checkmark when on. */
input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-3);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  vertical-align: -2px;
  transition: background 0.12s ease, border-color 0.12s ease;
}
input[type="checkbox"]:hover { border-color: var(--fg-dim); }
input[type="checkbox"]:checked {
  background: var(--accent-dim);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3.5px;
  top: 0px;
  width: 3px;
  height: 7px;
  border: solid var(--fg);
  border-width: 0 1.6px 1.6px 0;
  transform: rotate(45deg);
}
input[type="checkbox"]:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

.muted { color: var(--fg-dim); }
.mono { font-family: var(--font-mono); font-size: 12px; }
.small { font-size: 12px; }

/* ----- icons (inline SVG via icons.js) ----- */
[data-icon] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
[data-icon] svg {
  width: 1em;
  height: 1em;
  flex: 0 0 auto;
  display: block;
}
.icon-btn [data-icon] svg              { width: 16px; height: 16px; }
.fv-close [data-icon] svg              { width: 14px; height: 14px; }
#feeds .feed-actions [data-icon] svg,
#feeds .ep-actions [data-icon] svg     { width: 12px; height: 12px; }
.badge [data-icon] svg                 { width: 9px;  height: 9px; }
.regen-btn [data-icon] svg,
#export-notes-new [data-icon] svg,
#export-notes-all [data-icon] svg,
#explain-regen [data-icon] svg         { width: 12px; height: 12px; margin-right: 2px; }
.rail-toggle [data-icon] svg           { width: 18px; height: 18px; }
#add-feed-btn [data-icon] svg          { width: 14px; height: 14px; }

@keyframes icon-spin { to { transform: rotate(360deg); } }
.spin svg,
.spin [data-icon] svg,
[data-icon].spin svg                   { animation: icon-spin 1.1s linear infinite; transform-origin: 50% 50%; }

/* ----- sidebar ----- */
#sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 10px;
}
#sidebar > #feeds,
#sidebar > #channels-section {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  /* header pinned above; channels list scrolls as one block. */
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sidebar-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.sidebar-actions .icon-btn {
  width: 22px;
  height: 22px;
  font-size: 13px;
}

/* ----- filters / sort ----- */
.filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.filters input[type="search"] {
  width: 100%;
  padding: 4px 8px;
  font-size: 12px;
}
.filter-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.filter-row select {
  flex: 1;
  font-size: 11px;
  padding: 3px 5px;
  min-width: 0;
}
.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: var(--fg-dim);
  cursor: pointer;
  user-select: none;
}
.filter-toggle input { margin: 0; }
.sidebar-head h1 {
  font-size: 14px;
  margin: 0;
  font-weight: 600;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
#add-feed-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}
#add-feed-form {
  margin: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#add-feed-form .row {
  display: flex;
  gap: 6px;
}

#feeds .feed {
  margin-bottom: 8px;
}
#feeds .feed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
  border-radius: 4px;
}
#feeds .feed-head:hover { background: var(--bg-3); }
#feeds .feed-title {
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
#feeds .feed-actions { display: flex; gap: 4px; opacity: 0.6; }
#feeds .feed-actions button { padding: 1px 6px; font-size: 11px; }
#feeds .feed-head:hover .feed-actions { opacity: 1; }

#feeds .episodes {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
}
#feeds .episode {
  padding: 5px 8px 5px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}
#feeds .episode.listened .ep-title { color: var(--fg-dim); }
#feeds .episode .ep-actions {
  position: absolute;
  right: 6px;
  top: 5px;
  display: flex;
  gap: 2px;
  opacity: 0;
}
#feeds .episode:hover .ep-actions { opacity: 1; }
#feeds .episode .ep-actions button {
  padding: 1px 5px;
  font-size: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
}
#feeds .episode .ep-actions button:hover { color: var(--fg); }
.empty-list-msg {
  padding: 12px 8px;
  font-size: 11px;
  color: var(--fg-dim);
  text-align: center;
}
#feeds .episode:hover { background: var(--bg-3); }
#feeds .episode.active { background: var(--accent-dim); }
#feeds .episode .ep-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#feeds .episode .ep-sub {
  font-size: 11px;
  color: var(--fg-dim);
  display: flex;
  gap: 6px;
}
#feeds .badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-3);
}
#feeds .badge.ok { background: var(--ok); color: var(--on-ok); }
#feeds .badge.warn { background: var(--warn); color: var(--on-warn); }
#feeds .feed-count {
  font-size: 11px;
  color: var(--fg-dim);
  margin-left: 6px;
  font-weight: 400;
}
#feeds .empty-feed {
  font-size: 12px;
  color: var(--warn);
  padding: 4px 10px 4px 14px;
}

/* ----- main ----- */
#main {
  display: flex;
  flex-direction: column;
  /* No overflow:hidden — would clip popovers (volume/speed) escaping the
     player-controls row. Containment of scrolling content is done by
     #transcript-pane / .modal-body etc. on their own. */
  min-height: 0;
}

#welcome {
  padding: 30px;
  max-width: 640px;
}
#welcome h2 { margin: 0 0 10px; }
.kbd-list {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 20px;
}
.kbd-list li { font-size: 13px; }
kbd {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 11px;
}

#player-pane {
  display: flex;
  flex-direction: column;
  /* See #main note — popovers must be allowed to escape this container. */
  min-height: 0;
  height: 100%;
}

/* Line 1: ⚙ + status + title + date + save (single row, title truncates) */
.player-head {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  min-width: 0;  /* allow children to shrink so title can ellipsis */
}
.player-head h2.ep-title-row {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
}
.ep-title-row .ep-title-text {
  display: inline-block;
  white-space: nowrap;
}
/* When the title overflows we add `.marquee` from JS — the inner span slowly
 * shifts left, pauses, returns. CSS variable --marquee-shift is set in JS
 * to (containerWidth - textWidth) so the title slides exactly enough to
 * reveal the end. Container has overflow:hidden so the off-screen part
 * is clipped on each side. */
.ep-title-row.marquee .ep-title-text {
  animation: ep-title-marquee 14s ease-in-out infinite alternate;
}
@keyframes ep-title-marquee {
  0%, 12%   { transform: translateX(0); }
  88%, 100% { transform: translateX(var(--marquee-shift, 0)); }
}
.status-slot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  max-width: 240px;
  overflow: hidden;
  white-space: nowrap;
}
#job-status {
  text-overflow: ellipsis;
  overflow: hidden;
  max-width: 220px;
}
.player-head #ep-meta {
  flex: 0 0 auto;
  white-space: nowrap;
}
.icon-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}
.icon-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.icon-btn:disabled { opacity: 0.3; }

.settings-pane {
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-3);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.tx-opt {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--fg-dim);
}
.settings-pane select,
.settings-pane input[type="text"] {
  padding: 2px 5px;
  font-size: 12px;
}
.settings-pane input[type="text"] { width: 50px; }
.regen-btn {
  margin-left: auto;        /* push to right of the row */
  font-size: 12px;
  padding: 3px 10px;
}
.regen-btn:disabled { cursor: not-allowed; }

/* Disabled player controls during preparation. */
.player-controls.locked button,
.player-controls.locked input,
.player-controls.locked select { opacity: 0.4; pointer-events: none; }

/* Line 3: compact controls — small icon buttons + flex seekbar */
.player-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  background: var(--bg-2);
}
.player-controls .icon-btn {
  width: 26px;
  height: 26px;
  font-size: 12px;
  line-height: 1;
  padding: 0;
}
.player-controls .speed-btn {
  width: auto;
  min-width: 38px;
  padding: 0 6px;
  font-size: 11px;
  font-family: var(--font-mono);
}
/* ----- seekbar (custom thin track, accent fill, thumb on hover) -----
   --seek-fill (set from app.js on each timeupdate) drives the gradient stop
   so the played portion is var(--accent) and the rest is var(--bg-3). */
#seekbar {
  flex: 1;
  min-width: 60px;
  margin: 0 6px;
  -webkit-appearance: none;
  appearance: none;
  height: 14px;             /* hit-area; visible track is the inner 4px */
  background: transparent;
  cursor: pointer;
  outline: none;
}
#seekbar::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--seek-fill, 0%),
    var(--bg-3) var(--seek-fill, 0%),
    var(--bg-3) 100%
  );
}
#seekbar::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -4px;          /* center 12px thumb against 4px track */
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-2);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: grab;
  opacity: 0;
  transition: opacity 0.16s ease, transform 0.12s ease;
}
#seekbar:hover::-webkit-slider-thumb,
#seekbar:focus::-webkit-slider-thumb,
#seekbar:active::-webkit-slider-thumb { opacity: 1; }
#seekbar:active::-webkit-slider-thumb { transform: scale(1.15); cursor: grabbing; }

#seekbar::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  border: none;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--seek-fill, 0%),
    var(--bg-3) var(--seek-fill, 0%),
    var(--bg-3) 100%
  );
}
#seekbar::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-2);
  background: var(--accent);
  cursor: grab;
  opacity: 0;
}
#seekbar:hover::-moz-range-thumb,
#seekbar:focus::-moz-range-thumb { opacity: 1; }

/* Vertical volume slider in the popover — same accent / bg-3 palette. */
#volume::-webkit-slider-runnable-track {
  background: var(--bg-3);
  border-radius: 2px;
}
#volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-2);
  cursor: pointer;
}
#time-display {
  flex: 0 0 auto;
  margin: 0 4px;
  color: var(--fg-dim);
}
#loop-btn.active { background: var(--loop); border-color: var(--warn); color: var(--warn); }
#recenter-btn { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
#loop-indicator { margin-left: 4px; }

/* Popovers (volume, speed). Open DOWN into the transcript area — there's
   plenty of room there. Going up was clipping at the viewport top because
   the player-controls row sits high in the layout. */
.popover-wrap { position: relative; }
.popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  box-shadow: var(--shadow-pop);
  z-index: 20;
}
/* Volume slider — horizontal, same look as the main seekbar (thin track,
   accent fill, thumb on hover). --vol-fill is set from app.js on input. */
.popover #volume {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 14px;
  background: transparent;
  outline: none;
  cursor: pointer;
  margin: 0;
}
.popover #volume::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--vol-fill, 100%),
    var(--bg-3) var(--vol-fill, 100%),
    var(--bg-3) 100%
  );
}
.popover #volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-2);
  cursor: pointer;
}
.popover #volume::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--vol-fill, 100%),
    var(--bg-3) var(--vol-fill, 100%),
    var(--bg-3) 100%
  );
  border: none;
}
.popover #volume::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-2);
  background: var(--accent);
  cursor: pointer;
}
.popover-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  min-width: 70px;
}
.popover-list button {
  text-align: left;
  padding: 4px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  background: transparent;
  border: 1px solid transparent;
}
.popover-list button:hover { background: var(--bg-3); }
.popover-list button.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

/* Below controls: transcript fills full width — video lives in a separate
   floating window now (see #video-wrap below). */
#media-row {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  background: var(--bg-2);
}

/* ------- floating video window ------- */
#video-wrap {
  position: fixed;
  z-index: 80;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-float);
  overflow: hidden;
  user-select: none;
  display: flex;
  flex-direction: column;
}
#video-wrap.dragging,
#video-wrap.resizing { transition: none; }
#video-wrap video {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: block;
  background: #000;
  pointer-events: none;  /* drag clicks shouldn't be eaten by the <video> */
}
.fv-handle {
  flex: 0 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 0 8px;
  background: var(--bg-3);
  cursor: move;
  font-size: 11px;
  color: var(--fg-dim);
  border-bottom: 1px solid var(--border);
}
.fv-title { user-select: none; pointer-events: none; }
.fv-close {
  width: 18px;
  height: 18px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-dim);
  border-radius: 3px;
}
.fv-close:hover { background: var(--bg-2); color: var(--error); border-color: var(--error); }
.fv-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 50%, var(--fg-dim) 50%, var(--fg-dim) 60%, transparent 60%, transparent 70%, var(--fg-dim) 70%, var(--fg-dim) 80%, transparent 80%);
  opacity: 0.6;
}
.fv-resize:hover { opacity: 1; }

#transcript-pane {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  position: relative;
  background: var(--bg-2);  /* same as player so the boundary disappears */
  /* Soft fade at top + bottom so text dissolves into the background instead
     of being clipped by a hard edge. Mask is in pane coords (not scrolled),
     so it always covers the visible window. */
  mask-image: linear-gradient(
    to bottom,
    transparent 0,
    black 32px,
    black calc(100% - 64px),
    transparent 100%
  );
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0,
    black 32px,
    black calc(100% - 64px),
    transparent 100%
  );
}
.empty {
  padding: 30px;
  text-align: center;
}
#segments {
  list-style: none;
  margin: 0;
  padding: 12px 16px 50vh 12px;  /* 12px gap between video and the row's hover/active highlight */
}
.seg {
  padding: 3px 12px 3px 0;  /* no inner left pad — loop button sits at row edge */
  border-radius: 6px;
  margin-bottom: 1px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.08s ease;
}
.seg .text { flex: 1 1 auto; min-width: 0; }
.seg .seg-actions { flex: 0 0 auto; }

/* Left-side controls column (loop + optional mic). Compact horizontal flex
   group. Loop button is always rendered to reserve layout space (visibility
   not display) so text doesn't shift when it appears on hover. */
.seg .seg-controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
}
.seg .seg-loop,
.seg .seg-mic {
  flex: 0 0 22px;
  width: 22px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
  padding: 0;
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid transparent;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.seg .seg-loop                           { visibility: hidden; }
.seg:hover .seg-loop,
.seg.loop  .seg-loop                     { visibility: visible; }
.seg:hover .seg-loop,
.seg.active .seg-loop                    { opacity: 1; }
.seg .seg-loop:hover,
.seg .seg-mic:hover {
  background: var(--bg-3);
  border-color: var(--border);
  color: var(--fg);
}
.seg.loop .seg-loop {
  background: var(--loop);
  border-color: var(--warn);
  color: var(--warn);
}
/* Mic stays visible whenever pronunciationEnabled (rendered conditionally
   in JS), so the user can spot it without hovering. Slightly dimmed until
   hover; gets accent emphasis when its panel is open. */
.seg .seg-mic                            { visibility: visible; opacity: 0.55; }
.seg:hover  .seg-mic,
.seg.active .seg-mic,
.seg.practicing .seg-mic                 { opacity: 1; }
.seg.practicing .seg-mic {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* Per user request: hide the merge/split actions (`.seg-actions` block).
   Kept in DOM (and the `mkBtn` calls remain) so hotkeys keep working —
   only the visual cluster is removed. Flip back via `display: flex` to
   restore. */
.seg .seg-actions { display: none; }
.seg:hover { background: var(--bg-3); }  /* slightly raised against pane bg */
/* timestamp inline element is removed from segments — kept in the row tooltip
   for debug. The .ts class is unused now but the rule stays harmlessly empty. */
/* All text at the same 1.5× size. Active is bright (--fg), inactive is dim
   gray (--fg-dim) — no row geometry changes, just color. */
.seg .text {
  /* Serif stack — slightly nicer for long-form reading than the default sans
     used for UI chrome. New York is bundled with macOS; Charter/Iowan also
     lovely. Falls back to system serif then generic. */
  font-family: var(--font-serif);
  font-size: 21px;
  line-height: 1.2;
  color: var(--fg-dim);
  outline: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  transition: color 0.12s ease, font-size 0.12s ease;
}
/* Active block bumps up by 5% so the eye locks onto it without the whole row
   needing colour fireworks. Active text stays dim — only .played words bump
   to --fg below, which combined with the size bump is "this is now". */
.seg.active .text {
  font-size: 22.05px;
  color: var(--fg-dim);
}
.seg .text { user-select: text; }
.seg .text::selection { background: var(--accent-dim); color: var(--fg); }

/* Each word is wrapped in <span class="w"> so we can colour them word-by-word
   for progressive reveal on the active segment. */
.seg .text .w { color: inherit; }
/* No color transition — instant flip avoids the perceived lag. */
.seg.active .text .w.played { color: var(--fg); }

/* Notes overlay: word(s) covered by a saved note get .noted. */
.seg .text .w.noted {
  background: var(--note-bg);
  border-bottom: 1px solid var(--note-border);
  border-radius: 2px;
  padding: 0 1px;
  cursor: help;
}
.seg .text .w.noted:hover {
  background: var(--note-bg-hover);
}

/* ---- selection menu (floating toolbar above text selection) ---- */
.selection-menu {
  position: fixed;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  display: flex;
  gap: 2px;
  box-shadow: var(--shadow-menu);
  z-index: 60;
}
.selection-menu button {
  font-size: 12px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid transparent;
}
.selection-menu button:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

/* Note popover (clicking a noted word) */
.note-menu {
  flex-direction: column;
  align-items: stretch;
  max-width: 360px;
  padding: 6px;
}
.note-menu-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 4px;
}
.note-menu-item + .note-menu-item {
  border-top: 1px solid var(--border);
  margin-top: 2px;
  padding-top: 8px;
}
.note-menu-text {
  font-size: 12px;
  color: var(--fg);
  word-break: break-word;
}
.note-menu-explain {
  font-size: 11px;
  color: var(--fg-dim);
  line-height: 1.3;
  max-height: 4em;
  overflow: hidden;
}
.note-menu-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}
.note-menu-actions button {
  font-size: 11px;
  padding: 2px 8px;
}
.note-menu-actions .danger {
  color: var(--error);
  border-color: var(--error);
}
.note-menu-actions .danger:hover {
  background: var(--error);
  color: var(--on-error);
}

/* ---- explain modal ---- */
.modal {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: min(560px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
}
.modal-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.explain-source {
  background: var(--bg-3);
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 12px;
  font-style: italic;
  color: var(--fg-dim);
  font-size: 13px;
}
.explain-content {
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.explain-content.loading { color: var(--fg-dim); font-style: italic; }
.explain-content.error { color: var(--error); }

/* AI-generated disclosure — required by EU AI Act for generative-AI output.
 * Renders as a muted info strip below the explanation. Same pattern used on
 * every other AI-rendered text surface (notes that came from explain). */
.ai-disclosure {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 10px;
  border: 1px solid color-mix(in srgb, var(--fg-dim) 25%, var(--border));
  border-radius: 6px;
  background: color-mix(in srgb, var(--bg-3) 40%, transparent);
  color: var(--fg-dim);
  font-size: 11.5px;
  line-height: 1.3;
}
.ai-disclosure-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0.7;
}
.ai-disclosure-icon svg { width: 13px; height: 13px; }
/* Hide when explain-content is empty/loading — no synthetic output yet. */
.explain-content.loading + .ai-disclosure,
.explain-content:empty + .ai-disclosure { display: none; }

.explain-question {
  margin-top: 12px;
  width: 100%;
  resize: vertical;
  min-height: 44px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.explain-question:focus { outline: 1px solid var(--accent); }
/* Note: the old `.seg .seg-actions { display: flex; opacity: 0 }` rule and
   its hover/active toggles were removed when seg-actions was hidden by
   default (see `display: none` above near .seg-controls). The mkBtn calls in
   app.js are kept because hotkeys (S / M / Shift+M) still rely on the
   underlying functions. To restore the visual cluster, swap `display: none`
   for `display: flex; opacity: 0` and re-add the `:hover/.active`
   opacity-1 rules. */

/* ═══════════════════════════════════════════════════════════════════════
   Pronunciation trainer — inline practice panel hosted under a segment.
   Phoneme-level scoring via wav2vec2 + Piper TTS for the reference voice.
   ═══════════════════════════════════════════════════════════════════════ */
.pron {
  margin: 6px 0 12px 0;
  padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--fg);
}
.pron-head {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pron-rec.recording {
  background: var(--error);
  border-color: var(--error);
  color: var(--on-error);
  animation: pron-pulse 1.1s ease-in-out infinite;
}
@keyframes pron-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--error) 35%, transparent); }
  50%      { box-shadow: 0 0 0 6px color-mix(in srgb, var(--error)  5%, transparent); }
}
.pron-status { margin-left: 4px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pron-status[data-mode="error"] { color: var(--error); }
.pron-status[data-mode="ok"]    { color: var(--ok); }
.pron-status[data-mode="rec"]   { color: var(--error); }
.pron-timer { color: var(--fg-dim); }
.pron-style {
  font-size: 11px;
  padding: 2px 4px;
  background: var(--bg-2);
  color: var(--fg-dim);
  border: 1px solid var(--border);
  border-radius: 3px;
}
.pron-style:hover { color: var(--fg); }

/* Debug toggle button + baseline panel */
.pron-dbg {
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 0 6px;
  width: auto;
  color: var(--fg-dim);
  background: transparent;
  border: 1px solid var(--border);
}
.pron-dbg.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.pron-baseline {
  margin-top: 8px;
  padding: 6px 8px;
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  border: 1px dashed var(--border);
  border-radius: 5px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
}
.pron-baseline-head { display: flex; align-items: baseline; gap: 6px; }
.pron-baseline-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--fg-dim);
  text-transform: uppercase;
}
.pron-baseline-label[data-error] { color: var(--error); text-transform: none; }
.pron-baseline-words { display: flex; flex-wrap: wrap; gap: 4px; }
.pron-baseline-word {
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--bg-2);
  border-left: 3px solid var(--border);
  font-family: var(--font-serif);
  color: var(--fg);
}
.pron-baseline-word.ok  { border-left-color: var(--ok); }
.pron-baseline-word.meh { border-left-color: var(--warn); }
.pron-baseline-word.bad { border-left-color: var(--error); }
.pron-close { margin-left: auto; }

.pron-result { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.pron-overall {
  font-size: 13px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.pron-pct { font-weight: 700; font-size: 18px; font-family: var(--font-mono); }

.pron-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pron-word {
  padding: 5px 8px 6px;
  border-radius: 5px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left-width: 3px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.pron-word-head { display: flex; align-items: center; gap: 4px; }
.pron-word-text { font-family: var(--font-serif); font-size: 14px; color: var(--fg); flex: 1; min-width: 0; }
.pron-speak-word, .pron-tts {
  width: 18px;
  height: 18px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  flex: 0 0 auto;
}
.pron-speak-word [data-icon] svg,
.pron-tts        [data-icon] svg { width: 12px; height: 12px; }

/* Two semantic flavours of TTS button: expected (what should sound — accent
   blue) vs got (what model decoded — warn yellow). Colors mirror the
   per-word card border-left so visual association is consistent. */
.pron-speak-exp, .pron-tts-exp        { color: var(--accent); }
.pron-speak-exp:hover, .pron-tts-exp:hover { background: color-mix(in srgb, var(--accent) 15%, transparent); border-color: var(--accent); }
.pron-phonemes { display: flex; gap: 4px; flex-wrap: wrap; font-family: var(--font-mono); font-size: 11px; }
.pron-ph {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  padding: 1px 4px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  border: 1px solid transparent;
}
.pron-ph-exp { color: var(--fg); }
.pron-ph-usr { color: var(--fg-dim); font-size: 9px; }
.pron-ph-usr::before { content: "→"; padding-right: 2px; opacity: 0.7; }

/* Score-driven coloring (3 buckets) */
.pron-word.ok,  .pron-pct.ok  { border-left-color: var(--ok);    color: var(--ok); }
.pron-word.meh, .pron-pct.meh { border-left-color: var(--warn);  color: var(--warn); }
.pron-word.bad, .pron-pct.bad { border-left-color: var(--error); color: var(--error); }
.pron-ph.ok    { background: color-mix(in srgb, var(--ok)    18%, transparent); }
.pron-ph.meh   { background: color-mix(in srgb, var(--warn)  18%, transparent); }
.pron-ph.bad   { background: color-mix(in srgb, var(--error) 18%, transparent); }
.pron-word.ok  .pron-word-text,
.pron-word.meh .pron-word-text,
.pron-word.bad .pron-word-text { color: var(--fg); }
/* ═══════ end pronunciation styles ═══════════════════════════════════ */


/* ═══════ Step 3: onboarding + subscription modals ════════════════════
   Single modal-backdrop class used by both. Card centered, fade-in.   */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-float);
  padding: 24px 28px;
  max-width: 480px;
  width: 100%;
  color: var(--fg);
}
.modal-card h2 { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.modal-card p.muted { color: var(--fg-dim); font-size: 13px; margin: 0 0 18px; }
.modal-card .row { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.modal-card .row > span { width: 80px; font-size: 13px; color: var(--fg-dim); }
.modal-card select {
  flex: 1;
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}
.modal-card button.primary {
  background: var(--accent-dim);
  color: var(--fg);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
}
.modal-card button.primary:hover { background: color-mix(in srgb, var(--accent) 30%, var(--accent-dim)); }
.modal-card button.danger {
  background: color-mix(in srgb, var(--error) 25%, var(--bg-3));
  color: var(--fg);
  border: 1px solid var(--error);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
}
.modal-card button.danger:hover { background: color-mix(in srgb, var(--error) 45%, var(--bg-3)); }
/* Generic input inside our uiPrompt modal. */
.modal-card .ui-modal-input {
  width: 100%;
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font: inherit;
  margin-top: 8px;
}
.modal-card .ui-modal-input:focus { outline: 1px solid var(--accent); }
.modal-card .modal-warning {
  font-size: 12px;
  line-height: 1.5;
  color: var(--fg-dim);
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, var(--border));
  border-radius: 6px;
  padding: 10px 12px;
  margin: 4px 0 8px;
}
.modal-card .modal-warning strong { color: var(--warn); }
.modal-card input[type="text"],
.modal-card input[type="url"],
.modal-card textarea {
  flex: 1;
  background: var(--bg-3);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
}
.modal-card textarea { resize: vertical; min-height: 40px; }
.modal-card input[type="checkbox"] { transform: scale(1.1); }

/* Tile edit/delete row (admin only) */
.tile-admin-actions {
  display: flex;
  gap: 4px;
  position: absolute;
  top: 8px;
  right: 8px;
}
.tile-admin-actions button {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  color: var(--fg);
  width: 24px; height: 24px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tile-admin-actions button:hover { background: var(--bg-3); border-color: var(--accent); }
.tile { position: relative; }

/* Subscription plans table */
.sub-plans { display: grid; gap: 12px; margin-top: 8px; }
.sub-plan {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--bg-3);
}
.sub-plan.current { border-color: var(--accent); }
.sub-plan h3 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.sub-plan .price { color: var(--fg-dim); font-size: 12px; margin-bottom: 6px; }
.sub-plan ul { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.sub-plan li { padding: 2px 0; }
.sub-plan li.feature::before { content: "✓ "; color: var(--ok); }
.sub-plan li.limitation::before { content: "✗ "; color: var(--fg-dim); }

/* Tier pill in sidebar header — small badge showing free/pro at a glance */
.sub-tier-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-3);
  color: var(--fg-dim);
  border: 1px solid var(--border);
}
.sub-tier-pill[data-tier="pro"] {
  background: var(--accent-dim);
  color: var(--fg);
  border-color: var(--accent);
}

/* When a feature is disabled by tier, fade the button + change cursor.
   We rely on a class because `disabled` would block pointer events and
   the click handler needs to fire to show the upgrade modal. */
.feature-locked {
  opacity: 0.4;
  cursor: not-allowed;
}


/* ═══════ View tabs (Player / Dashboard / Notes / Practice) ════════════ */

.view-tabs {
  display: flex;
  gap: 4px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.view-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-dim);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.view-tab:hover { background: var(--bg-3); color: var(--fg); }
.view-tab.active {
  background: var(--accent-dim);
  color: var(--fg);
  border-color: var(--accent);
}

.view-section {
  padding: 16px 24px;
  overflow-y: auto;
  max-height: calc(100vh - 50px);   /* leave room for tabs row */
}
.view-section .view-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.view-section .view-head h2 { font-size: 18px; font-weight: 600; margin: 0; }
.view-section .view-head h3 { font-size: 14px; font-weight: 500; margin: 0; color: var(--fg-dim); }


/* ═══════ Dashboard ═══════════════════════════════════════════════════ */

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
  margin-bottom: 6px;
}
.stat-value { font-size: 22px; font-weight: 600; color: var(--fg); }

.heatmap-wrap {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  /* Don't span full width — the grid is naturally narrow (~14 columns
   * for 90 days). A centered inline-block reads better than a row-wide
   * card with a tiny grid in the corner. */
  display: inline-block;
  max-width: 100%;
}
.heatmap-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 10px;
}
.heatmap {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 11px);
  gap: 2px;
  overflow-x: auto;
  padding-bottom: 2px;
  /* Fit the natural grid width — no full-row stretch. */
  width: fit-content;
  max-width: 100%;
}
.heatmap-cell {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: var(--bg-3);
  display: inline-block;
}
.heatmap-cell[data-level="1"] { background: color-mix(in srgb, var(--accent) 25%, var(--bg-3)); }
.heatmap-cell[data-level="2"] { background: color-mix(in srgb, var(--accent) 50%, var(--bg-3)); }
.heatmap-cell[data-level="3"] { background: color-mix(in srgb, var(--accent) 75%, var(--bg-3)); }
.heatmap-cell[data-level="4"] { background: var(--accent); }
.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  justify-content: flex-end;
}

/* Plan & limits card on the dashboard. */
.plan-limits-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  margin-bottom: 24px;
}
.plan-limits-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.plan-limits-head h3 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
}
.plan-limits-head .link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.plan-limits-head .link-btn:hover { text-decoration: underline; }
.plan-limits-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 720px) {
  .plan-limits-list { grid-template-columns: repeat(3, 1fr); }
}
.plan-limit-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  margin-bottom: 4px;
}
.plan-limit-label { font-weight: 600; }
.plan-limit-bar {
  height: 6px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
}
.plan-limit-fill {
  height: 100%;
  transition: width 0.3s ease;
  background: var(--accent);
}
.plan-limit-fill.ok    { background: var(--ok); }
.plan-limit-fill.warn  { background: var(--warn); }
.plan-limit-fill.danger { background: var(--error); }
.plan-limit-foot { margin-top: 4px; }

/* Login screen — full-viewport takeover shown when /api/auth/me 401s
 * (multi-user mode + no session). Sits above sidebar+main via z-index. */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-brand {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  text-align: center;
}
.login-tagline {
  color: var(--fg-dim);
  font-size: 14px;
  margin: 0 0 8px;
  text-align: center;
}
.login-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  text-decoration: none;
}
.login-btn:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}
.login-btn-google {
  background: #fff;
  color: #1d1d1f;
  border-color: rgba(0, 0, 0, 0.08);
}
.login-btn-google:hover {
  background: #f5f5f7;
  border-color: rgba(0, 0, 0, 0.16);
}
.login-btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}
.login-btn-primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
}
.login-btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--fg-dim);
  font-size: 12px;
  margin: 4px 0;
}
.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
}
.login-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}
.login-input:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}
.login-status {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--fg-dim);
  text-align: center;
  line-height: 1.4;
}
.login-status.is-ok {
  color: color-mix(in srgb, var(--ok) 75%, var(--fg));
}
.login-status.is-error {
  color: var(--error);
}
.login-footer {
  margin-top: 12px;
  display: flex;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fg-dim);
}
.login-footer a {
  color: var(--fg-dim);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.login-footer a:hover {
  color: var(--fg);
  border-bottom-color: var(--fg-dim);
}

/* Signup-accept block on the onboarding modal. Two required-checkbox
 * rows: Terms+Privacy + age confirmation. Submit-disabled-until-checked
 * is enforced in JS. Hidden in single-user mode. */
.signup-accept {
  margin: 16px 0 4px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--bg-3) 60%, transparent);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.signup-checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12.5px;
  line-height: 1.4;
  cursor: pointer;
}
.signup-checkbox-row input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 2px;
}
.signup-checkbox-row a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.signup-checkbox-row a:hover { border-bottom-color: var(--accent); }

/* Legal pages (Privacy / Terms / Contact). Server returns markdown via
 * /api/legal/<slug>; client renders with the small md→DOM converter in
 * app.js. Type set on the serif stack for a calm, document-y feel. */
.legal-view { padding: 32px 16px; }
.legal-content {
  max-width: 760px;
  margin: 0 auto;
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.6;
  color: var(--fg);
}
.legal-content h1 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 24px;
  letter-spacing: -0.01em;
}
.legal-content h2 {
  font-size: 19px;
  font-weight: 600;
  margin: 30px 0 12px;
  color: color-mix(in srgb, var(--accent) 30%, var(--fg));
}
.legal-content h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 22px 0 10px;
  color: var(--fg);
}
.legal-content p { margin: 0 0 12px; }
.legal-content ul, .legal-content ol { margin: 0 0 12px; padding-left: 22px; }
.legal-content li { margin-bottom: 4px; }
.legal-content strong { color: var(--fg); font-weight: 600; }
.legal-content em { color: var(--fg-dim); }
.legal-content a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.legal-content a:hover { border-bottom-color: var(--accent); }
.legal-content hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}
.legal-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 20px;
  font-size: 14px;
  font-family: var(--font-sans);
}
.legal-content table th,
.legal-content table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.legal-content table th {
  font-weight: 600;
  color: var(--fg-dim);
}
.legal-content code {
  font-family: var(--font-mono);
  font-size: 13.5px;
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Footer pinned to the bottom of the main pane. Quiet, low-contrast. */
.app-footer {
  margin-top: 32px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 12px;
  color: var(--fg-dim);
}
.app-footer a {
  color: var(--fg-dim);
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 4px;
}
.app-footer a:hover { color: var(--fg); background: var(--bg-3); }
.app-footer .footer-sep { opacity: 0.6; }
.app-footer .footer-brand {
  color: var(--fg);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Account / GDPR controls on Dashboard. Export is always visible; delete
 * is hidden for the SINGLE_USER_MODE default user (would brick dev box). */
.account-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  margin-top: 24px;
}
.account-card-head h3 {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
}
.account-card-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.account-action {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.account-action-title { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.account-action-sub {
  font-size: 12.5px;
  color: var(--fg-dim);
  line-height: 1.4;
  max-width: 520px;
}
.account-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 6px 14px;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  transition: all 0.12s;
}
.account-btn:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.account-btn.danger {
  color: color-mix(in srgb, var(--error) 75%, var(--fg));
  border-color: color-mix(in srgb, var(--error) 35%, var(--border));
}
.account-btn.danger:hover {
  color: var(--bg);
  background: var(--error);
  border-color: var(--error);
}
.account-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg-dim);
  user-select: none;
  white-space: nowrap;
}
.account-toggle:hover { color: var(--fg); }
.account-toggle input[type="checkbox"] {
  transform: scale(1.1);
  cursor: pointer;
}

/* Pricing view. */
.pricing-content { max-width: 880px; margin: 0 auto; padding: 8px 4px 24px; }
.pricing-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  margin-bottom: 28px;
}
.pricing-head h2 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.pricing-head .pricing-sub {
  margin: 0;
  color: var(--fg-dim);
  font-size: 14px;
  max-width: 540px;
  line-height: 1.5;
}
.pricing-head .pricing-trial {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 28%, var(--border));
  color: color-mix(in srgb, var(--warn) 80%, var(--fg-dim));
  font-size: 12px;
  font-weight: 500;
}
.pricing-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: stretch;
}
@media (min-width: 680px) {
  .pricing-grid { grid-template-columns: repeat(2, 1fr); }
}
.pricing-card {
  position: relative;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 24px 24px;
  display: flex;
  flex-direction: column;
  transition: border-color 0.12s, transform 0.12s;
}
/* The featured tier (Pro) gets a soft accent glow + tinted bg so the page
 * has a clear primary CTA instead of two symmetric cards. */
.pricing-card.is-featured {
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--accent) 6%, var(--bg-2)) 0%,
      var(--bg-2) 60%);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}
.pricing-card.current {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent);
}
.pricing-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  gap: 8px;
}
.pricing-card-head h3 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--fg-dim);
}
.pricing-card.is-featured .pricing-card-head h3 {
  color: color-mix(in srgb, var(--accent) 75%, var(--fg));
}
.pricing-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: color-mix(in srgb, var(--accent) 85%, var(--fg));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
}
.pricing-badge.current-badge {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.pricing-price {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 12px 0 2px;
  line-height: 1.1;
}
.pricing-price .pricing-price-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-dim);
  margin-left: 4px;
}
.pricing-price-alt {
  color: var(--fg-dim);
  font-size: 12.5px;
  margin: 0 0 12px;
}
.pricing-tagline {
  color: var(--fg-dim);
  font-size: 13px;
  margin: 0 0 16px;
  line-height: 1.45;
}
.pricing-features {
  list-style: none;
  padding: 0;
  margin: 8px 0 20px;
  font-size: 13px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pricing-features li {
  padding: 0;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.pricing-features li.feature::before {
  content: '';
  display: inline-block;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ok) 18%, transparent);
  /* SVG checkmark (currentColor) */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10' fill='none' stroke='%239ece6a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><polyline points='1.5,5 4,7.5 8.5,2.5'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
}
.pricing-features li.limitation::before {
  content: '';
  display: inline-block;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--fg-dim) 10%, transparent);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10' fill='none' stroke='%239ba0aa' stroke-width='1.8' stroke-linecap='round'><line x1='2.5' y1='5' x2='7.5' y2='5'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
}
.pricing-features li.limitation { color: var(--fg-dim); }
.pricing-cta {
  margin-top: auto;
  background: var(--accent);
  color: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 11px 16px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.12s, transform 0.06s;
}
.pricing-cta:hover { filter: brightness(1.08); }
.pricing-cta:active { transform: translateY(1px); }
.pricing-cta.secondary {
  background: transparent;
  color: var(--fg-dim);
  border-color: var(--border);
}
.pricing-cta.secondary:hover {
  color: var(--fg);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}


/* ═══════ Aggregate lists (Notes + Practice) ══════════════════════════ */

.agg-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.agg-item {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
}
.agg-item:hover { border-color: var(--accent); }
.agg-item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.agg-item-title { font-weight: 600; color: var(--fg); }
.agg-item-meta { color: var(--fg-dim); font-size: 12px; }
.agg-item-context {
  color: var(--fg-dim);
  font-size: 13px;
  border-left: 2px solid var(--border);
  padding-left: 10px;
  margin-top: 6px;
  font-style: italic;
}
.agg-item-explanation {
  font-size: 13px;
  color: var(--fg);
  margin-top: 8px;
  line-height: 1.4;
}
.agg-score-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.agg-score-pill[data-tier="ok"]  { background: color-mix(in srgb, var(--ok) 20%, transparent);  color: var(--ok); }
.agg-score-pill[data-tier="meh"] { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.agg-score-pill[data-tier="bad"] { background: color-mix(in srgb, var(--error) 20%, transparent); color: var(--error); }

#notes-search {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 6px;
  padding: 4px 10px;
  font: inherit;
  width: 240px;
}

/* Practice-history card: three playback buttons (Original / Yours /
   Expected) mirroring the inline pronunciation panel in the player. */
.practice-controls {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.practice-play {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
.practice-play:hover { border-color: var(--accent); background: var(--bg-2); }
.practice-play span[data-icon] { width: 14px; height: 14px; display: inline-flex; }
.practice-play span[data-icon] svg { width: 14px; height: 14px; }

/* Pin button on a practice-history attempt. Visually quieter than the
 * playback buttons (it's a state toggle, not a primary action), with a
 * warn-tinted "pinned" state so the retention-exempt items stand out. */
.practice-pin-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s;
}
.practice-pin-btn:hover {
  color: var(--fg);
  border-color: color-mix(in srgb, var(--warn) 40%, var(--border));
}
.practice-pin-btn.is-pinned {
  color: color-mix(in srgb, var(--warn) 80%, var(--fg));
  border-color: color-mix(in srgb, var(--warn) 45%, var(--border));
  background: color-mix(in srgb, var(--warn) 8%, transparent);
}
.practice-pin-btn span[data-icon] { width: 12px; height: 12px; display: inline-flex; }
.practice-pin-btn span[data-icon] svg { width: 12px; height: 12px; }


/* ═══════ Step 5: Catalog / Library tiles + Playlists sidebar ═══════════ */

.view-head-actions { display: flex; gap: 8px; align-items: center; }
.view-head .primary {
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--fg);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.view-head .primary:hover { background: color-mix(in srgb, var(--accent) 30%, var(--accent-dim)); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}


#catalog-search, #library-search {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 6px;
  padding: 4px 10px;
  font: inherit;
  width: 240px;
}

/* ---- Catalog sections + tiles ---- */

/* Unified catalog toolbar: search · level filter · ESL · reset · admin */
.catalog-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.catalog-toolbar input[type="search"] {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  min-width: 220px;
  flex: 0 1 280px;
}
.catalog-toolbar-spacer { flex: 1 1 auto; }
.filter-reset {
  width: 22px; height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--fg-dim);
}
.filter-reset:hover { color: var(--error); border-color: var(--error); }
.filter-reset svg { width: 11px; height: 11px; }

/* Generic filter pill (used by both level pills and ESL pill). Native
 * checkbox hidden; the span renders as a colored pill toggling on check. */
.filter-pills { display: inline-flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.filter-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.filter-pill input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 1;
}
.filter-pill span {
  display: inline-block;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg-2);
  color: var(--fg-dim);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  transition: all 0.1s;
}
.filter-pill:hover span { color: var(--fg); }

/* CEFR colour gradation. --lvl-color drives outline + checked fill. Same
 * tokens feed .chip.level so palette tweaks ripple. Unchecked state stays
 * blended with --fg-dim so six pills don't shout from across the page. */
.level-pill[data-level="A1"] { --lvl-color: var(--lvl-a1); }
.level-pill[data-level="A2"] { --lvl-color: var(--lvl-a2); }
.level-pill[data-level="B1"] { --lvl-color: var(--lvl-b1); }
.level-pill[data-level="B2"] { --lvl-color: var(--lvl-b2); }
.level-pill[data-level="C1"] { --lvl-color: var(--lvl-c1); }
.level-pill[data-level="C2"] { --lvl-color: var(--lvl-c2); }
.level-pill span {
  color: color-mix(in srgb, var(--lvl-color) 65%, var(--fg-dim));
  border-color: color-mix(in srgb, var(--lvl-color) 32%, var(--border));
}
.level-pill:hover span {
  color: color-mix(in srgb, var(--lvl-color) 85%, var(--fg));
  border-color: color-mix(in srgb, var(--lvl-color) 55%, var(--border));
}
.level-pill input:checked ~ span {
  background: color-mix(in srgb, var(--lvl-color) 80%, var(--bg-2));
  border-color: color-mix(in srgb, var(--lvl-color) 60%, var(--border));
  color: var(--bg);
}

/* ESL pill — distinct warn-tinted styling, sits to the right of levels */
.esl-pill { margin-left: 2px; }
.esl-pill span {
  color: color-mix(in srgb, var(--warn) 65%, var(--fg-dim));
  border-color: color-mix(in srgb, var(--warn) 32%, var(--border));
}
.esl-pill:hover span {
  color: color-mix(in srgb, var(--warn) 85%, var(--fg));
  border-color: color-mix(in srgb, var(--warn) 55%, var(--border));
}
.esl-pill input:checked ~ span {
  background: color-mix(in srgb, var(--warn) 80%, var(--bg-2));
  border-color: color-mix(in srgb, var(--warn) 60%, var(--border));
  color: var(--bg);
}

/* Channel detail page */
.channel-head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
/* Channel back button — just an arrow icon, no label. Sits left of title. */
.channel-back-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--fg-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.1s;
}
.channel-back-btn:hover {
  color: var(--fg);
  border-color: var(--accent);
  background: var(--bg-3);
}
.channel-back-btn svg { width: 16px; height: 16px; }
.channel-head-meta { flex: 1; min-width: 0; }
.channel-head-meta h2 { font-size: 22px; margin: 0 0 6px; }
.channel-head-meta p { margin: 0 0 8px; font-size: 13px; line-height: 1.4; }

.channel-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.channel-toolbar input[type="search"],
.channel-toolbar select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
}
.channel-toolbar input[type="search"] { flex: 1; min-width: 160px; }

/* Channel episode list — reuses .channel-eps but in main pane, larger rows. */
#channel-episodes.channel-eps {
  max-height: none;
}
#channel-episodes .channel-ep {
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}
#channel-episodes .channel-ep .ep-meta {
  color: var(--fg-dim);
  font-size: 11px;
  flex-shrink: 0;
}
#channel-episodes .channel-ep.is-current-preview {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
/* Channel-page episode rows are info-only on the catalog detail page. */
#channel-episodes .channel-ep.channel-ep-static {
  cursor: default;
}
#channel-episodes .channel-ep.channel-ep-static:hover {
  background: transparent;
  color: var(--fg-dim);
}

.catalog-sections { display: flex; flex-direction: column; gap: 28px; }
.catalog-section h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
  margin: 0 0 12px;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.tile {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.12s, background 0.12s, transform 0.12s;
}
.tile:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--bg-3) 35%, var(--bg-2));
}
.tile.expanded { grid-column: 1 / -1; border-color: var(--accent); }
/* Subtle accent rail for recommended cards — purely opt-in via JS. */
.tile.is-recommended {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--accent) 60%, transparent);
}
.tile-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.tile-image {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-3);
  /* Inner hairline tames bright cover art so it doesn't fight the chips. */
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bg) 25%, transparent);
}
.tile-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tile-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--fg);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tile-desc {
  font-size: 12.5px;
  color: var(--fg-dim);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  font-size: 10.5px;
  margin-top: 2px;
}
.chip {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.4;
}
/* CEFR-graded level chips. JS adds .chip.level + .chip.level-X. Same
 * palette as the filter pills above so the catalog reads consistently. */
/* Level chip text blends toward the neutral fg so the colour reads as a
 * "hint" rather than glowing on the dim card bg. Border and bg stay tinted
 * so the level is still scannable. */
.chip.level {
  color: color-mix(in srgb, var(--lvl-color, var(--accent)) 70%, var(--fg-dim));
  border-color: color-mix(in srgb, var(--lvl-color, var(--accent)) 28%, var(--border));
  background: color-mix(in srgb, var(--lvl-color, var(--accent)) 8%, transparent);
  font-weight: 600;
}
.chip.level-A1 { --lvl-color: var(--lvl-a1); }
.chip.level-A2 { --lvl-color: var(--lvl-a2); }
.chip.level-B1 { --lvl-color: var(--lvl-b1); }
.chip.level-B2 { --lvl-color: var(--lvl-b2); }
.chip.level-C1 { --lvl-color: var(--lvl-c1); }
.chip.level-C2 { --lvl-color: var(--lvl-c2); }
.chip.tag {}
.chip.has-transcript {
  color: color-mix(in srgb, var(--ok) 70%, var(--fg-dim));
  border-color: color-mix(in srgb, var(--ok) 25%, var(--border));
}
.chip.learner-voice {
  color: color-mix(in srgb, var(--warn) 75%, var(--fg-dim));
  border-color: color-mix(in srgb, var(--warn) 28%, var(--border));
  background: color-mix(in srgb, var(--warn) 7%, transparent);
  font-weight: 600;
}

.tile-actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}
.tile-actions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
}
.tile-actions button:hover {
  color: var(--fg);
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}
.tile-actions button.primary {
  color: color-mix(in srgb, var(--accent) 80%, var(--fg));
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.tile-actions button.primary:hover {
  color: var(--bg);
  background: color-mix(in srgb, var(--accent) 80%, var(--bg-2));
  border-color: var(--accent);
}
.tile-actions button:disabled,
.tile-actions button[disabled] {
  opacity: 0.7;
  cursor: default;
}
.tile-actions button:disabled:hover,
.tile-actions button[disabled]:hover {
  background: transparent;
  color: var(--fg-dim);
  border-color: var(--border);
}

.tile-expand {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 4px;
}
.tile-expand-eps {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 320px;
  overflow-y: auto;
}
.tile-ep {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
}
.tile-ep:hover { background: var(--bg-3); }
.tile-ep-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-ep.listened .tile-ep-title,
.tile-ep.pending  .tile-ep-title { color: var(--fg-dim); }
.tile-ep-date { color: var(--fg-dim); font-size: 11px; }

/* ─── Unified episode-status badge (library tiles + sidebar accordion) ─── */
/* Five visual variants, all 14px square so layout doesn't shift between states:
 *   is-listened  — filled green dot with ✓
 *   is-ready     — filled accent dot
 *   is-pending   — hollow dim circle (no transcript yet)
 *   is-processing — SVG ring with progress arc + stage letter (D/T/A)
 *                   queued sub-state pulses without a letter.
 */
.ep-status {
  flex-shrink: 0;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  box-sizing: border-box;
  font-size: 9px;
  line-height: 1;
  font-weight: 700;
}
.ep-status.is-ready,
.ep-status.is-listened,
.ep-status.is-pending {
  border-radius: 50%;
}
.ep-status.is-ready    { background: var(--accent); }
.ep-status.is-listened { background: var(--ok); color: var(--bg); }
.ep-status.is-pending  { background: transparent; border: 1.5px solid var(--fg-dim); }

/* ── Processing ring ── */
.ep-status.is-processing { color: var(--accent); }
.ep-status.is-processing.stage-d { color: var(--accent); }
.ep-status.is-processing.stage-t { color: var(--warn); }
.ep-status.is-processing.stage-a { color: var(--ok); }
.ep-status .ep-ring {
  width: 14px;
  height: 14px;
  display: block;
  transform: rotate(-90deg);   /* arc starts at 12 o'clock */
}
.ep-status .ep-ring-track {
  fill: none;
  stroke: var(--bg-3);
  stroke-width: 2;
}
.ep-status .ep-ring-fill {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 100 100;
  transition: stroke-dashoffset 0.4s ease;
}
.ep-status .ep-stage-letter {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 7px;
  font-weight: 700;
  color: currentColor;
  letter-spacing: 0;
}
.ep-status.stage-q {
  color: var(--fg-dim);
  animation: ep-pulse 1.4s ease-in-out infinite;
}
.ep-status.stage-q .ep-ring-fill {
  stroke-dasharray: 3 4;
  stroke-dashoffset: 0;
}
@keyframes ep-pulse {
  0%, 100% { opacity: 0.6; }
  50%      { opacity: 1; }
}

/* Toolbar inside expanded tile — search/sort/filter for episodes. */
.tile-expand-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.tile-expand-toolbar input[type="search"],
.tile-expand-toolbar select {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
}
.tile-expand-toolbar input[type="search"] { flex: 1; min-width: 120px; }
.tile-expand-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--fg-dim);
  cursor: pointer;
}

/* Episode-status text dim in sidebar accordion items (badge added in JS). */
.accordion-item.listened .accordion-item-title,
.accordion-item.pending  .accordion-item-title { color: var(--fg-dim); }
.tile-ep-actions { display: flex; gap: 4px; }
.tile-ep-action {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}
.tile-ep-action:hover { border-color: var(--accent); }

/* ---- Sidebar: channel accordion ---- */

.channel-body {
  padding: 6px 8px 8px;
}
/* Tighten toolbar for narrow sidebar context. */
.channel-body .tile-expand-toolbar {
  gap: 4px;
  margin-bottom: 6px;
}
.channel-body .tile-expand-toolbar input[type="search"],
.channel-body .tile-expand-toolbar select {
  font-size: 11px;
  padding: 2px 6px;
}
.channel-body .tile-expand-toolbar input[type="search"] { min-width: 80px; }
.channel-body .tile-expand-toolbar label { font-size: 11px; }
.channel-eps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  /* No inner scroll — the sidebar (#channels-section) scrolls as one block. */
}
.channel-eps .accordion-item {
  padding: 4px 8px;
}
/* Channel icon next to title in the accordion head. */
.channel-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 3px;
  object-fit: cover;
  background: var(--bg-3);
}
/* Small dot next to title on collapsed channel that is the playing context */
.channel-playing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  display: inline-block;
  margin-right: -2px;
}
.channel-accordion.is-playing-channel .accordion-title { color: var(--fg); }

/* Sidebar empty-state hint when there are no channels. */
.sidebar-empty { padding: 10px 14px; line-height: 1.4; }
.sidebar-empty .link-btn {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

/* Catalog preview rows are info-only — no hover/cursor affordance. */
.tile-ep.tile-ep-static { cursor: default; }
.tile-ep.tile-ep-static:hover { background: transparent; }

/* ---- Sidebar: legacy playlists accordion shell (reused for channels) ---- */

.sidebar-accordion {
  border-bottom: 1px solid var(--border);
}
.sidebar-accordion-list { padding-bottom: 8px; }

.accordion-head {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: none;
  color: var(--fg);
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.accordion-head:hover { background: var(--bg-3); }
.accordion-head.open .accordion-chev { transform: rotate(90deg); }
.accordion-chev { transition: transform 0.15s; flex-shrink: 0; width: 14px; height: 14px; display: inline-flex; }
.accordion-chev svg { width: 14px; height: 14px; }
.accordion-title { flex: 1; font-weight: 500; font-size: 13px; }
.accordion-label { font-size: 11px; }

.accordion-body {
  list-style: none;
  padding: 0 0 8px;
  margin: 0;
  max-height: 280px;
  overflow-y: auto;
}
.accordion-body[hidden] { display: none; }
.accordion-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--fg-dim);
  cursor: pointer;
}
.accordion-item:hover { background: var(--bg-3); color: var(--fg); }
.accordion-item.active {
  color: var(--fg);
  background: var(--bg-3);
  box-shadow: inset 2px 0 0 var(--accent);
}
.accordion-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Playlist-row "play" icon — appears on hover */
.accordion-row-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.1s;
}
.accordion-head:hover .accordion-row-actions,
.accordion-head.open .accordion-row-actions { opacity: 1; }
.accordion-row-actions button {
  background: transparent;
  border: none;
  color: var(--fg-dim);
  cursor: pointer;
  padding: 2px;
  display: inline-flex;
}
.accordion-row-actions button:hover { color: var(--accent); }
.accordion-row-actions svg { width: 12px; height: 12px; }

