:root {
  --bg: #f9f7f4;
  --surface: #ffffff;
  --text: #1a1310;
  --muted: #6b6056;
  --border: #e8e2da;
  --accent: #2E86AB;
  --radius: 8px;
  --max: 760px;
}

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

body {
  font-family: "TeX Gyre Heros", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 17px;
  /* .video-wrap below breaks out to 100vw to escape .wrap's 760px column;
     on non-overlay scrollbars (Windows/Linux) 100vw includes the scrollbar's
     own width, so that element overshoots the real viewport by a few px and
     shifts/overflows the whole page horizontally. Clip it here instead of
     chasing scrollbar width per-platform. */
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */
.wrap { max-width: var(--max); margin: 0 auto; padding: 0 20px; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}
header .inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
header .logo { font-weight: 700; font-size: 1.05rem; color: var(--text); }
header .logo span { color: var(--accent); }
header nav { margin-left: auto; font-size: 0.88rem; color: var(--muted); }
header nav a { color: var(--muted); margin-left: 16px; }

main { padding: 40px 0 80px; }

footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  font-size: 0.83rem;
  color: var(--muted);
  text-align: center;
}

/* ── Home ── */
.home-hero { padding: 48px 0 36px; }
.home-hero h1 { font-size: 2rem; font-weight: 700; line-height: 1.25; max-width: 540px; }
.home-hero p { margin-top: 12px; color: var(--muted); font-size: 1.05rem; max-width: 500px; }

.channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 32px;
}
.channel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  transition: box-shadow .15s;
}
.channel-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,.08); }
.channel-card .emoji { font-size: 1.5rem; }
.channel-card h2 { font-size: 1.05rem; margin-top: 8px; }
.channel-card p { font-size: 0.88rem; color: var(--muted); margin-top: 6px; line-height: 1.5; }
.channel-card .count { font-size: 0.8rem; color: var(--muted); margin-top: 10px; }

/* ── Channel page ── */
.channel-header { margin-bottom: 28px; }
.channel-header h1 { font-size: 1.65rem; }
.channel-header p { color: var(--muted); margin-top: 6px; }
.channel-header .tg-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 0.88rem;
  background: #229ED9;
  color: white;
  padding: 5px 12px;
  border-radius: 20px;
}
.channel-header .tg-link:hover { text-decoration: none; opacity: .9; }

.episode-list { list-style: none; }
.episode-list li {
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.episode-list li:last-child { border-bottom: none; }
.episode-list .ep-title { font-size: 0.97rem; }
.episode-list .ep-date { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

.pagination { margin-top: 28px; display: flex; gap: 8px; align-items: center; font-size: 0.88rem; }
.pagination a {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
}
.pagination .cur {
  padding: 5px 12px;
  background: var(--accent);
  color: white;
  border-radius: 4px;
}

/* ── Episode page ── */
.ep-meta { color: var(--muted); font-size: 0.88rem; margin: 8px 0 20px; }
.ep-meta a { color: var(--muted); }

.audio-player {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 20px 0;
}
.audio-player audio { width: 100%; margin-top: 8px; }
.audio-player .player-links { display: flex; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.audio-player .btn-tg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  background: #229ED9;
  color: white;
  padding: 5px 12px;
  border-radius: 20px;
}
.audio-player .btn-pdf {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  background: var(--accent);
  color: white;
  padding: 5px 12px;
  border-radius: 20px;
}
.audio-player .btn-tg:hover,
.audio-player .btn-pdf:hover { text-decoration: none; opacity: .9; }

.vocab-section { margin: 28px 0; }
.vocab-section h2 { font-size: 1.1rem; margin-bottom: 12px; }
.vocab-list { list-style: none; }
.vocab-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.93rem;
  display: flex;
  gap: 12px;
}
.vocab-list li:last-child { border-bottom: none; }
.vocab-list .term { font-weight: 600; min-width: 140px; color: var(--accent); }
.vocab-list .def { color: var(--text); }

.transcript-section { margin: 28px 0; }
.transcript-section h2 { font-size: 1.1rem; margin-bottom: 12px; display: flex; align-items: baseline; gap: 10px; }
.karaoke-hint { font-size: 0.75rem; font-weight: 400; color: var(--muted); }
.transcript-text {
  font-size: 0.93rem;
  line-height: 1.75;
  color: #2a221a;
  max-width: 68ch;
}
.transcript-text p { margin-bottom: 1em; }

/* Karaoke sync — CSS Custom Highlight API (no per-word spans).
   Only paintable text properties work inside ::highlight() (FF/Safari). */
.transcript-text p.para { cursor: pointer; }
::highlight(k-seg) {
  background-color: oklch(94% 0.05 75);
}
::highlight(k-word) {
  background-color: oklch(78% 0.15 65);
  color: oklch(20% 0.05 50);
}
/* Tier-2 fallback: real <mark> around the active sentence */
.transcript-text mark.k-mark {
  background: oklch(90% 0.09 75);
  color: inherit;
  border-radius: 3px;
  padding: 1px 0;
}
/* Fallback tier (no Highlight API): current paragraph gets a soft wash */
.transcript-text p.para-active {
  background: oklch(97% 0.02 70);
  border-radius: 4px;
}

.related-section { margin: 36px 0; }
.related-section h2 { font-size: 1.1rem; margin-bottom: 12px; }
.related-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.related-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.9rem;
}

/* ── Episode page: Audio/Video tabs ── */
.mode-tabs { display: flex; gap: 8px; margin: 16px 0 4px; }
.mode-tabs button {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.mode-tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Break out of .wrap's 760px reading column -- the grid needs real room.
   .video-wrap spans the full viewport width (regardless of the parent's
   max-width), then .video-grid re-centers the actual content inside it. */
.video-wrap {
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-top: 20px;
  padding: 0 20px;
}
/* Named areas (not just column count) so the pairing -- text sits above
   its controls/transcript, image sits above its vocab bin -- survives the
   mobile reflow instead of the 4 quadrants just stacking in DOM order. */
.video-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "text image" "controls vocab";
  gap: 14px;
  max-width: 1200px;
  margin: 0 auto;
}
#vtop-text-wrap { grid-area: text; }
#vtop-image-wrap { grid-area: image; }
#vbottom-left { grid-area: controls; }
#vbottom-right { grid-area: vocab; }

.video-quad {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* Top two quadrants mimic the rendered video's own palette/typography.
   Sizes use clamp() to scale smoothly with viewport width instead of
   jumping at fixed breakpoints -- same layout code from a small phone up
   to a wide desktop, just proportioned differently. */
.video-top {
  background: #f7f5f1;
  min-height: clamp(180px, 34vw, 380px);
  display: flex;
  align-items: center;
  padding: clamp(16px, 3vw, 32px) clamp(18px, 4vw, 40px);
}
#vtop-text {
  font-family: "TeX Gyre Heros", "Helvetica Neue", Arial, sans-serif;
  font-weight: 700;
  font-size: clamp(1.15rem, 3.6vw, 2.1rem);
  line-height: 1.45;
  color: #16233f;
}
#vtop-text .w { cursor: pointer; }
#vtop-text .w.active { text-decoration: underline; text-decoration-thickness: 4px; text-underline-offset: 6px; }
.video-top.video-image { padding: clamp(10px, 2vw, 20px); justify-content: center; }
.video-top.video-image img {
  max-width: 100%;
  max-height: clamp(180px, 34vw, 380px);
  border-radius: 14px;
  object-fit: cover;
}
.video-image-placeholder { color: #a89f8e; font-size: 0.85rem; text-align: center; }

/* Bottom-left: controls + full transcript with RU lines */
.video-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.video-controls button {
  font-size: 1rem;
  width: 36px; height: 36px; /* comfortable tap target on touch screens */
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}
.video-controls input[type="range"] { flex: 1; min-width: 0; }
.video-controls .time { font-size: 0.76rem; color: var(--muted); white-space: nowrap; }

.video-transcript {
  background: var(--surface);
  max-height: clamp(280px, 46vw, 460px);
  overflow-y: auto;
  padding: 14px 16px;
}
.video-transcript .vsent { margin-bottom: 14px; font-size: 0.9rem; line-height: 1.6; }
.video-transcript .vsent .en .w { cursor: pointer; border-radius: 3px; padding: 0 1px; }
.video-transcript .vsent .en .w:hover { background: oklch(94% 0.05 75); }
.video-transcript .vsent.active .en { background: oklch(97% 0.02 70); border-radius: 4px; }
.video-transcript .vsent .ru { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }

/* Bottom-right: per-episode vocabulary bin, click-to-add */
.video-vocab {
  background: var(--surface);
  max-height: clamp(220px, 46vw, 460px);
  overflow-y: auto;
  padding: 14px 16px;
}
.video-vocab h3 { font-size: 0.95rem; margin-bottom: 10px; }
.video-vocab .vocab-hint { font-size: 0.82rem; color: var(--muted); }
.video-vocab ul { list-style: none; }
.video-vocab li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.87rem;
  position: relative;
}
.video-vocab li:last-child { border-bottom: none; }
.video-vocab .vw-term { font-weight: 700; color: var(--accent); }
.video-vocab .vw-tr { color: var(--text); }
.video-vocab .vw-def { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.video-vocab .vw-remove {
  position: absolute; top: 8px; right: 0;
  border: none; background: none; color: var(--muted); cursor: pointer; font-size: 0.9rem;
  padding: 6px; /* tap target, not just the glyph */
}
.video-vocab .vw-loading { color: var(--muted); font-style: italic; }

/* Below ~640px, text next to a shrunk image gets cramped and starts
   wrapping hard (bad for reading full sentences) -- stack text above
   image, full width, instead of forcing them side by side. Controls and
   vocab already read fine full-width at any size, so they don't need a
   breakpoint of their own beyond the area reflow below. */
@media (max-width: 640px) {
  .video-grid { grid-template-columns: 1fr; grid-template-areas: "text" "image" "controls" "vocab"; }
  .video-top { min-height: clamp(160px, 42vw, 260px); }
  #vtop-text { font-size: clamp(1.2rem, 5.5vw, 1.6rem); }
  .video-top.video-image img { max-height: clamp(160px, 42vw, 260px); }
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .home-hero h1 { font-size: 1.5rem; }
  .episode-list li { flex-direction: column; gap: 4px; }
  .episode-list .ep-date { align-self: flex-start; }
}
