/* =========================================================================
       CORE RESET & STRICT ANTI-OVERFLOW (320px–460px MOBILE-FIRST)
       ========================================================================= */
    *, *::before, *::after {
      box-sizing: border-box;
      -webkit-tap-highlight-color: transparent;
    }

    html, body {
      margin: 0;
      padding: 0;
      width: 100%;
      background-color: #032a31;
      color: #f1faf4;
      font-family: 'Inter', system-ui, -apple-system, sans-serif;
      overflow-x: hidden;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }

    /* Subtle cinema column framing on tablets & desktops */
    @media (min-width: 480px) {
      body {
        background-color: #060607;
      }
      #app-shell {
        border-left: 1px solid rgba(255, 245, 235, 0.08);
        border-right: 1px solid rgba(255, 245, 235, 0.08);
        box-shadow: 0 0 90px rgba(0, 0, 0, 0.8);
      }
    }

    /* Hairline warm border utility */
    .hairline {
      border-color: rgba(255, 245, 235, 0.08);
    }

    /* Cleanly hide horizontal scrollbars on filter rows */
    .no-scrollbar::-webkit-scrollbar {
      display: none;
    }
    .no-scrollbar {
      -ms-overflow-style: none;
      scrollbar-width: none;
    }

    /* Monospace tabular alignment for zero timestamp jitter */
    .tabular-nums {
      font-variant-numeric: tabular-nums;
    }

    /* =========================================================================
       16:9 VIDEO / CINEMA STAGE
       ========================================================================= */
    .stage-16x9 {
      position: relative;
      width: 100%;
      aspect-ratio: 16 / 9;
      background-color: #111010;
      overflow: hidden;
    }

    @supports not (aspect-ratio: 16 / 9) {
      .stage-16x9 {
        height: 0;
        padding-bottom: 56.25%;
      }
    }

    .stage-16x9 iframe,
    .stage-16x9 #yt-player-slot {
      position: absolute;
      inset: 0;
      width: 100%;
      height: 100%;
    }

    /* =========================================================================
       NATIVE EDITORIAL SCRUBBER BAR
       ========================================================================= */
    input[type="range"].cinema-scrubber {
      -webkit-appearance: none;
      appearance: none;
      width: 100%;
      height: 22px;
      background: transparent;
      cursor: pointer;
      margin: 0;
    }

    input[type="range"].cinema-scrubber:focus {
      outline: none;
    }

    input[type="range"].cinema-scrubber::-webkit-slider-runnable-track {
      height: 3.5px;
      border-radius: 9999px;
      background: linear-gradient(
        to right,
        #9be9d4 0%,
        #9be9d4 var(--pct, 0%),
        rgba(255, 245, 235, 0.14) var(--pct, 0%),
        rgba(255, 245, 235, 0.14) 100%
      );
      transition: height 0.15s ease;
    }

    input[type="range"].cinema-scrubber:active::-webkit-slider-runnable-track {
      height: 5px;
    }

    input[type="range"].cinema-scrubber::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      width: 12px;
      height: 12px;
      margin-top: -4.25px;
      border-radius: 50%;
      background-color: #f1faf4;
      box-shadow: 0 1px 5px rgba(0, 0, 0, 0.7);
      transition: transform 0.15s ease;
    }

    input[type="range"].cinema-scrubber:active::-webkit-slider-thumb {
      transform: scale(1.22);
    }

    input[type="range"].cinema-scrubber::-moz-range-track {
      height: 3.5px;
      border-radius: 9999px;
      background: rgba(255, 245, 235, 0.14);
    }

    input[type="range"].cinema-scrubber::-moz-range-progress {
      height: 3.5px;
      border-radius: 9999px;
      background: #9be9d4;
    }

    input[type="range"].cinema-scrubber::-moz-range-thumb {
      width: 12px;
      height: 12px;
      border: none;
      border-radius: 50%;
      background-color: #f1faf4;
      box-shadow: 0 1px 5px rgba(0, 0, 0, 0.7);
    }

    /* =========================================================================
       SPOTIFY-LYRICS DIALOGUE LINES & INLINE SLANG TOKENS
       ========================================================================= */
    .dialogue-row {
      position: relative;
      transition: background-color 0.2s ease;
    }

    .dialogue-row::before {
      content: '';
      position: absolute;
      left: 0;
      top: 14px;
      bottom: 14px;
      width: 2.5px;
      border-radius: 9999px;
      background-color: transparent;
      transform: scaleY(0.35);
      transition: background-color 0.22s ease, transform 0.22s ease;
    }

    .dialogue-row.is-active {
      background-color: rgba(255, 245, 235, 0.03);
    }

    .dialogue-row.is-active::before {
      background-color: #9be9d4;
      transform: scaleY(1);
    }

    /* Clickable colloquial expression highlight */
    .slang-mark {
      display: inline;
      padding: 1px 5px 2px;
      margin: 0 1px;
      border-radius: 6px;
      background-color: rgba(145, 231, 207, 0.15);
      border-bottom: 1.5px solid #9be9d4;
      color: #f1faf4;
      font-weight: 600;
      cursor: pointer;
      transition: background-color 0.18s ease;
      -webkit-box-decoration-break: clone;
      box-decoration-break: clone;
    }

    .slang-mark:hover,
    .slang-mark:active,
    .slang-mark.is-selected {
      background-color: rgba(145, 231, 207, 0.30);
    }

    /* Russian translation blur + tap-to-peek */
    .ru-line {
      transition: filter 0.25s ease, opacity 0.25s ease;
    }

    .ru-line.is-blurred {
      filter: blur(5.5px);
      opacity: 0.5;
      user-select: none;
      cursor: pointer;
    }

    .ru-line.is-blurred.is-peeked {
      filter: blur(0px);
      opacity: 0.95;
    }

    /* Minimal TTS speaking bars */
    @keyframes speakPulse {
      0%, 100% { transform: scaleY(0.3); opacity: 0.5; }
      50% { transform: scaleY(1); opacity: 1; }
    }

    .tts-bar {
      width: 2.5px;
      border-radius: 9999px;
      background-color: #9be9d4;
      transform-origin: bottom;
      transform: scaleY(0.35);
      opacity: 0.45;
    }

    .tts-speaking .tts-bar {
      animation: speakPulse 0.8s ease-in-out infinite;
    }

    .tts-bar:nth-child(1) { height: 10px; animation-delay: 0s; }
    .tts-bar:nth-child(2) { height: 15px; animation-delay: 0.2s; }
    .tts-bar:nth-child(3) { height: 8px; animation-delay: 0.38s; }

    /* =========================================================================
       NATIVE iOS-STYLE BOTTOM SHEETS
       ========================================================================= */
    .sheet-overlay {
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.24s ease;
    }

    .sheet-overlay.is-open {
      opacity: 1;
      pointer-events: auto;
    }

    .sheet-card {
      transform: translateY(100%);
      transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
      padding-bottom: max(22px, env(safe-area-inset-bottom));
    }

    .sheet-overlay.is-open .sheet-card {
      transform: translateY(0);
    }

    /* Tablet/desktop: keep the mobile-first player, but use wider catalog space. */
    @media (min-width: 768px) {
      #app-shell { max-width: 1024px; }
      #clips-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
      #view-player > main, #view-dictionary > main { max-width: 720px; width: 100%; margin-left: auto; margin-right: auto; }
    }
    @media (prefers-reduced-motion: reduce) {
      .view-enter, .tts-bar { animation: none !important; }
      *, *::before, *::after { scroll-behavior: auto !important; }
    }
    button:focus-visible, a:focus-visible, input:focus-visible, [tabindex="0"]:focus-visible {
      outline: 2px solid #9be9d4;
      outline-offset: 3px;
    }

    /* Custom player controls are below the YouTube iframe. YouTube's own
       pause icon and branding are controlled by YouTube, not by CSS. */
    #stage-yt iframe, #yt-player-slot { pointer-events: none !important; }
    #stage-tts { cursor: default !important; }

    /* Keep the video in view while playback is running, but never scroll the page
       to chase a highlighted line. When stopped, the rest of the lesson is normal. */
    .player-sticky-panel {
      background: #032a31;
      isolation: isolate;
    }
    .player-sticky-panel.is-playing {
      position: sticky;
      top: 56px;
      z-index: 25;
      border-bottom: 1px solid rgba(255,245,235,.08);
      box-shadow: 0 10px 20px rgba(0,0,0,.45);
    }

    /* Imported, authorized time-coded subtitle file. */
    .caption-import-box {
      border: 1px solid rgba(255,245,235,.12);
      background: #073039;
      padding: 12px;
      border-radius: 16px;
      margin-top: 10px;
    }
    .caption-import-box summary { cursor: pointer; font-size: 12px; font-weight: 700; color: #f1faf4; }
    .caption-import-box input[type=file] { max-width: 100%; font-size: 12px; color: #b4d0ca; }
    .caption-import-box input[type=file]::file-selector-button {
      background: #9be9d4; color: #032a31; border: 0;
      border-radius: 9px; font-weight: 700; padding: 9px 12px; margin-right: 9px;
    }
    #imported-captions {
      border: 1px solid rgba(145,231,207,.35);
      border-radius: 18px;
      background: #0e3d44;
      padding: 14px 17px 16px;
      margin-bottom: 12px;
      min-height: 80px;
    }
    #imported-caption-text {
      font-size: clamp(17px,4.4vw,22px);
      line-height: 1.5;
      font-weight: 650;
      text-align: center;
      overflow-wrap: anywhere;
      color: #f1faf4;
      white-space: pre-line;
      margin: 8px 0 0;
    }
    #imported-caption-text[data-empty=true] { color: #b4d0ca; font-weight: 500; font-size: 13px; }
    #caption-cue-progress { height: 2px; width: 100%; background: rgba(255,245,235,.08); border-radius: 8px; overflow: hidden; margin-top: 12px; }
    #caption-cue-progress-fill { height: 100%; width: 0; background: #9be9d4; border-radius: inherit; transition: width .12s linear; }
    #imported-captions .live-word {
      display: inline; padding: 1px 3px; border-radius: 5px;
      color: #d9ebe2;
      transition: background-color .16s ease, color .16s ease, box-shadow .16s ease;
      -webkit-box-decoration-break: clone; box-decoration-break: clone;
    }
    #imported-captions .live-word.is-speaking {
      background: #9be9d4; color: #101010;
      box-shadow: 0 1px 12px rgba(145,231,207,.28);
    }
    @media (prefers-reduced-motion: reduce) {
      #imported-captions .live-word { transition: none; }
    }

    /* Source selection: no partial dialogue presented as a complete transcript. */
    #youtube-caption-source .subtitle-tool { min-height: 35px; padding: 7px 12px; }
    #youtube-caption-source .subtitle-tool[aria-pressed="true"] {
      border-color: rgba(145,231,207,.85);
      background: rgba(145,231,207,.16);
      color: #f1faf4;
      font-weight: 700;
    }
    /* Handwritten excerpts never masquerade as complete synchronized subtitles. */
    #youtube-caption-source, #word-ticker { display: none !important; }
    #study-details > summary { list-style-position: inside; cursor: pointer; }
    #study-details > summary::-webkit-details-marker { color: #9be9d4; }
    /* Readable live captions: every word is fully visible; no ticker, clip or gradient. */
    #word-ticker {
      background: linear-gradient(165deg, #211e1b, #151414 85%);
      border: 1px solid rgba(145,231,207,.25);
      box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
      border-radius: 19px;
      padding: 15px 16px 16px;
      margin-bottom: 12px;
    }
    #word-ticker .sub-kicker {
      color: #9be9d4;
      font-size: 10px;
      font-weight: 800;
      letter-spacing: .14em;
      text-transform: uppercase;
    }
    .ticker-viewport {
      width: 100%;
      min-height: 76px;
      height: auto;
      overflow: visible;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      padding: 10px 0 12px;
      border-bottom: 1px solid rgba(255,245,235,.1);
    }
    .ticker-track {
      position: static;
      transform: none !important;
      display: block;
      width: 100%;
      white-space: normal;
      height: auto;
      color: #f1faf4;
      will-change: auto;
    }
    .ticker-line {
      width: 100%;
      font-size: clamp(17px, 4.3vw, 21px);
      font-weight: 650;
      letter-spacing: -.012em;
      line-height: 1.53;
      overflow-wrap: anywhere;
    }
    .ticker-line[hidden] { display: none !important; }
    .ticker-word {
      display: inline;
      color: #f1faf4;
      padding: 2px 0;
      border-radius: 4px;
      transition: color .12s ease, background-color .12s ease;
    }
    .ticker-word.is-line { color: #f1faf4; }
    /* Stable transcript mode: no guessed karaoke timing. */
    #word-ticker.mode-lines .ticker-line { border-left: 3px solid #9be9d4; padding-left: 10px; }
    .subtitle-tool {
      border: 1px solid rgba(255,245,235,.13); border-radius: 999px;
      padding: 5px 9px; font-size: 11px; color: #AFA7A0;
      background: rgba(255,255,255,.025); cursor: pointer;
    }
    .subtitle-tool[aria-pressed="true"] { border-color: #9be9d4; color: #acefdf; }
    #caption-settings { margin-top: 12px; border-top: 1px solid rgba(255,245,235,.08); padding-top: 10px; }
    #caption-settings summary { color: #b4d0ca; font-size: 11px; cursor:pointer; list-style-position: inside; }
    .sync-btn { border: 1px solid rgba(255,245,235,.14); border-radius: 9px; padding: 6px 10px; font-size: 12px; color: #f1faf4; }
    #caption-offset { font-variant-numeric: tabular-nums; font-family: 'JetBrains Mono',monospace; color: #acefdf; font-size: 12px; }

    #cue-editor { margin-top: 14px; padding: 12px; border: 1px solid rgba(145,231,207,.24);
      border-radius: 13px; background: rgba(0,0,0,.2); }
    #cue-editor button { min-height: 36px; }
    #cue-en { font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
    .cue-mono { font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
    @media (max-width: 350px) { #cue-editor .sync-btn { font-size: 11px; padding: 6px 7px; } }

    .ticker-word.is-current {
      color: #17120d;
      background: #acefdf;
      box-shadow: 3px 0 0 #acefdf, -3px 0 0 #acefdf;
      -webkit-box-decoration-break: clone;
      box-decoration-break: clone;
      transition: background-color .10s ease, color .10s ease;
    }
    #ticker-translation {
      color: #BDB2A9;
      font-size: 13px;
      line-height: 1.55;
      white-space: normal;
      overflow-wrap: anywhere;
      overflow: visible;
      text-overflow: unset;
    }
    #ticker-speaker {
      color: #acefdf;
      font-size: 11px;
      letter-spacing: .09em;
    }
    @media (max-width: 350px) {
      #word-ticker { padding: 12px 13px; }
      .ticker-line { font-size: 17px; }
    }
    @media (prefers-reduced-motion: reduce) { .ticker-word { transition: none; } }

    /* Gentle fade-in for view switching */
    @keyframes viewIn {
      from { opacity: 0; transform: translateY(4px); }
      to { opacity: 1; transform: translateY(0); }
    }
    .view-enter {
      animation: viewIn 0.2s ease-out forwards;
    }


    /* v25 · scene-based vocabulary learning after first video viewing */
    .lesson-start { margin: 12px 0 24px; padding: 17px; border-radius: 20px;
      border: 1px solid rgba(216,158,99,.29); background: linear-gradient(130deg,#26201B,#191715); }
    .lesson-start-head { display:flex; justify-content:space-between; align-items:center; gap:12px; }
    .lesson-start-step { font-size:10px; color:#acefdf; font-weight:800; letter-spacing:.14em; }
    .lesson-start h2 { margin:5px 0 7px; font-size:19px; font-weight:800; color:#f1faf4; }
    .lesson-start p { font-size:12px; line-height:1.55; color:#a9c5c1; }
    .lesson-primary { border:0; min-height:52px; border-radius:14px; background:#9be9d4; color:#082f35;
      font-weight:800; font-size:14px; cursor:pointer; padding:0 20px; transition:transform .16s,background .16s; }
    .lesson-primary:hover { background:#c4fae6; }
    .lesson-primary:active { transform:scale(.987); }
    .lesson-secondary { min-height:44px; border-radius:13px; background:#104147; color:#e4f5ef;
      font-size:13px; font-weight:700; padding:0 15px; cursor:pointer; border:1px solid rgba(255,255,255,.12); }
    .lesson-secondary:disabled,.lesson-primary:disabled { opacity:.4; cursor:not-allowed; }
    .lesson-v25-view { min-height:100dvh; background:#032a31; }
    .lesson-v25-head { display:flex; justify-content:space-between; align-items:center; gap:12px;
      min-height:60px; padding:0 18px; border-bottom:1px solid rgba(255,255,255,.09); }
    .lesson-v25-layout { width:min(100%,720px); margin-inline:auto; padding:28px 18px 50px; }
    .lesson-progress-rail { height:5px; background:#285052; border-radius:40px; overflow:hidden; margin-top:14px; }
    #lesson-progress-fill { height:100%; width:0; border-radius:40px; background:#9be9d4; transition:width .22s; }
    .lesson-stage { color:#a0e9d9; font-size:11px; font-weight:800; letter-spacing:.14em; text-transform:uppercase; }
    .lesson-title { font-size:clamp(23px,5vw,34px); letter-spacing:-.035em; font-weight:800; line-height:1.16; margin:11px 0 12px; }
    .lesson-card { border:1px solid rgba(255,255,255,.12); background:linear-gradient(145deg,#0d4046,#073039);
      border-radius:25px; padding:clamp(22px,5.2vw,32px); margin:24px 0 18px; box-shadow:0 12px 33px rgba(0,0,0,.18); }
    .lesson-en { font-size:clamp(27px,7vw,42px); font-weight:850; line-height:1.22; letter-spacing:-.04em; color:#f1faf4; overflow-wrap:anywhere; }
    .lesson-ru { color:#acefdf; font-size:clamp(18px,4vw,24px); line-height:1.4; font-weight:700; margin-top:16px; }
    .lesson-help { margin-top:12px; color:#b9ceca; line-height:1.6; font-size:13px; }
    .lesson-context { border-left:2px solid #9be9d4; padding:5px 0 5px 14px; margin-top:17px;
      font-size:13px; line-height:1.6; color:#bed3cc; overflow-wrap:anywhere; }
    .lesson-choice { display:block; width:100%; min-height:55px; text-align:left; border-radius:14px;
      background:#134047; border:1px solid rgba(255,255,255,.1); color:#ebf7f1;
      padding:13px 15px; font-size:14px; font-weight:650; line-height:1.4; cursor:pointer; }
    .lesson-choice + .lesson-choice { margin-top:9px; }
    .lesson-choice:focus-visible,.lesson-secondary:focus-visible,.lesson-primary:focus-visible { outline:3px solid #9be9d4; outline-offset:3px; }
    .lesson-choice.correct { border-color:#74B98A; background:#1B3226; color:#D6F1DC; }
    .lesson-choice.incorrect { border-color:#C97670; background:#352220; color:#F6CECB; }
    .lesson-choice:disabled { cursor:default; }
    .lesson-recall-input { width:100%; min-height:56px; border-radius:14px; border:1px solid rgba(255,255,255,.23);
      background:#082c32; color:#f1faf4; font-size:17px; font-weight:650; padding:14px; outline:0; }
    .lesson-recall-input:focus { border-color:#9be9d4; box-shadow:0 0 0 2px rgba(145,231,207,.16); }
    .lesson-feedback { border-radius:13px; padding:14px 15px; background:rgba(145,231,207,.09); border:1px solid rgba(145,231,207,.28);
      font-size:13px; line-height:1.65; color:#daf1e7; }
    .lesson-caption { color:#aac5c5; font-size:12px; line-height:1.55; }
    .lesson-view-actions { display:flex; flex-wrap:wrap; align-items:center; gap:10px; margin-top:18px; }
    .lesson-view-actions button { flex:1 0 160px; }
    .lesson-learning-badge { display:inline-block; margin-top:10px; background:rgba(145,231,207,.13);
      border:1px solid rgba(145,231,207,.22); color:#acefdf; font-size:11px; font-weight:700;
      padding:5px 9px; border-radius:999px; }
    
    @media (min-width:768px) { #view-learning > main { max-width:720px; } }
    @media (prefers-reduced-motion:reduce) { #lesson-progress-fill,.lesson-primary { transition:none; } }
