/* Submate web player. Shares the design tokens of style.css but stays
   standalone so marketing-page styles never bleed into the player. */
:root {
  --bg:           #0a0a0a;
  --bg-elev:      #14141a;
  --bg-card:      rgba(31, 41, 55, 0.45);
  --border:       rgba(255, 255, 255, 0.08);
  --border-hi:    rgba(255, 255, 255, 0.16);
  --text:         #f5f5f7;
  --text-mute:    #a1a1aa;
  --text-dim:     #71717a;
  --accent:       #60a5fa;
  --accent-hi:    #2563eb;
  --accent-glow:  rgba(96, 165, 250, 0.35);
  --topbar-h:     52px;
}

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

/* The hidden attribute must always win, including over elements whose
   class sets display:flex (backdrops, urlbar, lang controls). */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display',
               'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

/* ---------------- top bar ---------------- */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--border);
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: 10;
}
.brand {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
}
.brand .dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  margin-right: 7px;
  vertical-align: middle;
}
.app-link {
  margin-left: auto;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

/* Language pair inside the urlbar. Compact screens: the select is an
   invisible full-size layer over a flag "face" — tapping opens the
   native dropdown, which lists the full language names. Desktop: the
   flag face hides and the select renders normally. */
.lang-controls {
  display: flex;
  align-items: stretch;
  gap: 4px;
  flex: 0 0 auto;
  position: relative;
}

/* One-time coach mark under the language pickers. */
.lang-tip {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  z-index: 60;
  max-width: 240px;
  padding: 10px 13px;
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.45;
  cursor: pointer;
  animation: langTipIn 0.35s ease;
}
.lang-tip::before {
  content: '';
  position: absolute;
  top: -6px;
  right: 26px;
  width: 10px;
  height: 10px;
  transform: rotate(45deg);
  background: var(--bg-elev);
  border-left: 1px solid var(--accent);
  border-top: 1px solid var(--accent);
}
@keyframes langTipIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.lang-tip.leaving {
  opacity: 0;
  transition: opacity 0.4s ease;
}
.flag-select {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}
.flag-face {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  padding: 0 4px;
  background: var(--bg-elev);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  font-size: 17px;
}
.flag-select .lang-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.lang-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  min-width: 0;
  text-overflow: ellipsis;
}
.lang-arrow {
  color: var(--text-dim);
  font-size: 13px;
  align-self: center;
  display: none;
}
@media (min-width: 640px) {
  .flag-face { display: none; }
  .flag-select .lang-select {
    position: static;
    opacity: 1;
    width: auto;
    height: auto;
    max-width: 220px;
  }
  .lang-arrow { display: inline; }
}

/* ---------------- stage ---------------- */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------------- intro / landing ---------------- */
.stage { overflow-y: auto; }
.intro {
  margin: 0 auto;
  width: 100%;
  max-width: 720px;
  padding: max(4vh, 20px) 24px 48px;
  text-align: center;
}
.intro-title {
  font-size: clamp(28px, 6vw, 40px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.grad {
  background: linear-gradient(90deg, #60a5fa, #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.intro-lede {
  margin-top: 14px;
  color: var(--text-mute);
  font-size: 15px;
  line-height: 1.6;
}
.url-form {
  margin-top: 26px;
  display: flex;
  gap: 8px;
}
.url-input {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg-elev);
  border: 2px solid var(--accent);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 14px;
  outline: none;
}
.url-input::placeholder { color: var(--text-dim); font-weight: 500; }
.url-submit {
  flex: 0 0 auto;
  background: var(--accent-hi);
  border: 1px solid var(--accent);
  border-radius: 10px;
  color: #eff6ff;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  padding: 12px 22px;
  cursor: pointer;
}
.url-submit:active { transform: translateY(1px); }
.intro-trust {
  margin: 10px 0 0; color: var(--text-dim); font-size: 11px;
}
.player-proof {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-top: 18px;
}
.player-proof span { min-width: 92px; text-align: center; }
.player-proof b,
.player-proof small { display: block; }
.player-proof b { color: #dbeafe; font-size: 17px; }
.player-proof small {
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 10px;
}
@media (max-width: 520px) {
  .url-form { flex-direction: column; }
  .url-submit { width: 100%; }
  .player-proof { gap: 10px; }
  .player-proof span { min-width: 0; flex: 1; }
}
.url-error {
  margin-top: 10px;
  color: #f87171;
  font-size: 13px;
  font-weight: 600;
}
/* The prefix trick, advertised properly */
.prefix-callout {
  margin-top: 26px;
  padding: 16px 18px;
  text-align: left;
  background:
    linear-gradient(135deg, rgba(96, 165, 250, 0.10),
                            rgba(167, 139, 250, 0.07)),
    var(--bg-elev);
  border: 1px solid rgba(96, 165, 250, 0.35);
  border-radius: 12px;
}
.prefix-callout-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}
.prefix-callout-text {
  margin-top: 6px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
}
.prefix-callout-text strong { color: var(--accent); }
.prefix-example {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  overflow-x: auto;
  white-space: nowrap;
}
.prefix-hi {
  color: var(--accent);
  font-weight: 700;
}
.prefix-rest { color: var(--text-mute); }
.prefix-note {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}
.prefix-note code {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 11px;
  color: var(--text-mute);
}

/* Cached-videos list on the landing screen */
.video-list {
  margin-top: 36px;
  text-align: left;
}
.video-list-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.video-card {
  display: block;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  color: var(--text);
}
.video-card:hover {
  border-color: var(--border-hi);
  color: var(--text);
}
.video-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #000;
}
.video-card-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  padding: 8px 10px 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.video-card-langs {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 2px 10px 10px;
}

/* ---------------- watch layout ---------------- */
.watch {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column; /* portrait: video on top, subs below */
}
.video-pane {
  flex: 0 0 auto;
  background: #000;
}
.video-box {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}
.video-box iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.subs-pane {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 16px calc(10px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

/* Draggable divider between the panes. Runs along the cross axis of
   the .watch flex container in both orientations; the ::before layer
   widens the touch/click target beyond the visible bar. */
.divider {
  position: relative;
  flex: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  cursor: row-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 5;
}
.divider::before {
  content: '';
  position: absolute;
  inset: -8px;
}
.divider::after {
  content: '';
  width: 44px;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.28);
  transition: background 0.15s ease;
}
.divider.dragging::after,
.divider:hover::after { background: rgba(255, 255, 255, 0.55); }

/* User-driven split: --video-split (a %) becomes the video pane's
   flex-basis along the current main axis. The video box drops its
   16:9 lock and letterboxes inside whatever space it gets. */
.watch.resized .video-pane { flex: 0 0 var(--video-split); }
.watch.resized .video-box {
  aspect-ratio: auto;
  height: 100%;
}
.watch.resized .subs-pane {
  min-width: 0;
  max-width: none;
}
.watch.dragging iframe { pointer-events: none; }
/* Persistent URL bar under the topbar (watch mode only). Hidden in
   short phone-landscape where vertical space belongs to the video. */
.urlbar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.urlbar-input {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 10px;
  outline: none;
}
.urlbar-input:focus { border-color: var(--accent); }
.urlbar-go {
  flex: 0 0 auto;
  background: var(--accent-hi);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #eff6ff;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  padding: 8px 14px;
  cursor: pointer;
}
@media (orientation: landscape) and (max-height: 500px) {
  .urlbar { display: none; }
}
/* 16px stops iOS from auto-zooming the page when the input focuses. */
@media (max-width: 639px) {
  .urlbar-input { font-size: 16px; font-weight: 500; }
}

/* Wide / landscape: video left, subtitle rail right — mirrors the
   app's landscape stage. */
@media (orientation: landscape) and (min-width: 640px) {
  .watch { flex-direction: row; }
  .video-pane {
    flex: 2 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
  }
  .video-box {
    aspect-ratio: auto;
    height: 100%;
  }
  .subs-pane {
    flex: 1 1 0;
    min-width: 280px;
    max-width: 480px;
    border-left: 1px solid var(--border);
  }
  .divider { cursor: col-resize; }
  .divider::after {
    width: 5px;
    height: 64px;
  }
}

/* ---------------- status / progress ---------------- */
.status {
  margin: auto 0;
  padding: 18px 4px;
  text-align: center;
}
.spinner {
  width: 26px; height: 26px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 3px solid var(--border-hi);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.status-msg {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.5;
}
.status-hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}
.progress-track {
  margin: 14px auto 0;
  max-width: 320px;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  transition: width 0.4s ease;
}
.status-error .status-msg { color: #fca5a5; }
.error-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.retry-btn {
  background: var(--bg-elev);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 18px;
  cursor: pointer;
}
.error-app-cta {
  font-size: 13px;
  font-weight: 700;
}

/* ---------------- cues ---------------- */
.cues {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.cue-src {
  font-size: clamp(19px, 2.6vh + 8px, 26px);
  font-weight: 700;
  line-height: 1.45;
  color: var(--text);
}
.cue-tgt {
  margin-top: 6px;
  font-size: clamp(19px, 2.6vh + 8px, 26px);
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-mute);
}
/* v2: translation still streaming in for the current cue */
.cue-tgt.translating {
  color: var(--text-dim);
  font-style: italic;
  animation: transPulse 1.4s ease-in-out infinite;
}
@keyframes transPulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.9; }
}

.cue-next { opacity: 0.32; }
.cue-next .cue-src { font-size: clamp(15px, 2vh + 6px, 20px); }
.cue-next .cue-tgt { font-size: clamp(12px, 1.5vh + 5px, 15px); }
.cue:empty { display: none; }

/* Source-language words: individually tappable for dictionary lookup.
   .spoken marks the word currently being said — deliberately very
   faint so it guides the eye without shouting. */
.w {
  cursor: pointer;
  border-radius: 4px;
  /* No horizontal padding: for unspaced scripts (Thai etc.) the spans
     must render exactly like the original run of text, with zero
     visual gap between segments. */
  padding: 0;
  transition: background-color 0.12s ease;
}
.w:hover { background: rgba(255, 255, 255, 0.08); }
.w.spoken { background: rgba(96, 165, 250, 0.30); }

/* ---------------- word-highlight toggle ---------------- */
.wh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mute);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.wh-toggle input {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  margin: 0;
  cursor: pointer;
}
/* Subtitles without per-word timings can't highlight the spoken word:
   the whole control greys out and stops reacting. */
.wh-toggle.wh-disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}
.wh-toggle.wh-disabled input { cursor: default; }

/* ---------------- dictionary sheet ---------------- */
.define-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.define-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg-elev);
  border: 1px solid var(--border-hi);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 18px 20px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
}
@media (min-width: 640px) {
  .define-backdrop { align-items: center; }
  .define-sheet {
    border-radius: 14px;
    border-bottom: 1px solid var(--border-hi);
    padding-bottom: 16px;
  }
}
.define-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.define-word {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
}
.define-reading {
  font-size: 14px;
  color: var(--text-mute);
}
.define-pos {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}
.define-body {
  margin-top: 10px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  min-height: 24px;
}
.define-body.loading { color: var(--text-dim); }
.define-example {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.define-example-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.define-example-src {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
}
.define-example-tgt {
  margin-top: 3px;
  font-size: 13px;
  color: var(--text-mute);
  line-height: 1.5;
}
.define-save {
  margin-top: 14px;
  width: 100%;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.5);
  border-radius: 9px;
  color: #fbbf24;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 11px;
  cursor: pointer;
}
.define-close {
  margin-top: 8px;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-hi);
  border-radius: 9px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px;
  cursor: pointer;
}

/* ---------------- pane footer ---------------- */
.pane-footer {
  flex: 0 0 auto;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.footer-cta { font-size: 12px; font-weight: 600; }

/* ---------------- not-logged-in gate ---------------- */
.gate-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}
.gate-body {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-mute);
}
.gate-primary {
  display: block;
  width: 100%;
  margin-top: 16px;
  text-align: center;
  background: var(--accent-hi);
  border: 1px solid var(--accent);
  border-radius: 9px;
  color: #eff6ff;
  font-size: 14px;
  font-weight: 800;
  padding: 11px;
  cursor: pointer;
}
.gate-secondary {
  margin-top: 8px;
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-hi);
  border-radius: 9px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px;
  cursor: pointer;
}
.gate-app-link { display: block; text-align: center; text-decoration: none; }
.gate-login-btn {
  display: block;
  width: 100%;
  text-align: center;
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
}

/* Save-as-flashcard star: floats at the bottom-right of the subtitle
   pane so the cue text keeps its full width. Subtle circular backdrop
   keeps it legible if long text runs underneath. */
.subs-pane { position: relative; }
.cue-star {
  position: absolute;
  right: 12px;
  bottom: calc(54px + env(safe-area-inset-bottom));
  width: 44px;
  height: 44px;
  background: rgba(20, 20, 26, 0.85);
  border: 1px solid var(--border-hi);
  border-radius: 50%;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  color: rgba(251, 191, 36, 0.85);
  padding: 0;
  z-index: 5;
}
.cue-star:hover,
.cue-star:active { color: #fbbf24; border-color: rgba(251, 191, 36, 0.5); }
