:root {
  --bg: #0c0e13;
  --panel: #171a22;
  --panel-2: #1f2330;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #3b82f6;
  --danger: #ef4444;
  --ok: #22c55e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100%;
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-size: 20px; font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--danger); }

.view { padding: 18px; max-width: 1100px; margin: 0 auto; }
.hidden { display: none !important; }
.center { text-align: center; }

.card {
  background: var(--panel);
  border-radius: 14px;
  padding: 28px;
  max-width: 460px;
  margin: 8vh auto 0;
}
.card h2 { margin-top: 0; }
.card p { color: var(--muted); }

input[type="text"], input[type="search"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #2a2f3c;
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  margin: 8px 0;
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid #2a2f3c;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 15px;
  cursor: pointer;
}
.btn:hover { background: #262b3a; }
.btn.primary { background: var(--accent); border-color: var(--accent); width: 100%; }
.btn.danger { color: var(--danger); border-color: #4a2630; }
.btn.play { min-width: 52px; font-size: 18px; }

.searchbar { display: flex; gap: 8px; }
.searchbar input { margin: 0; }

.section-title { margin: 24px 0 10px; color: var(--muted); font-weight: 600; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.tile {
  background: var(--panel);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  border: 1px solid transparent;
}
.tile:hover { border-color: #2a2f3c; }
.tile .t-title { font-weight: 600; line-height: 1.3; }
.tile .t-meta { color: var(--muted); font-size: 13px; margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); }
.badge.ready { color: var(--ok); }
.badge.processing, .badge.queued { color: #eab308; }
.badge.error { color: var(--danger); }
.tile .row-actions { margin-top: 10px; display: flex; gap: 8px; }

.library-actions { display: flex; gap: 8px; margin-top: 18px; }

/* Player */
#view-player { max-width: 1280px; }
.stage {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin: 12px 0;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
}
#canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.player-msg {
  position: absolute;
  color: var(--muted);
  font-size: 16px;
  text-align: center;
  padding: 20px;
}
.controls { display: flex; align-items: center; gap: 12px; }
#seek { flex: 1; accent-color: var(--accent); height: 26px; }
.time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 96px; text-align: right; }
.player-title { color: var(--muted); margin-top: 10px; }
.qr-box { margin-top: 14px; background: var(--panel); border-radius: 12px; padding: 16px; max-width: 260px; }
.qr-box svg { width: 100%; height: auto; }

/* Tap gestures: no text-select / double-tap-zoom getting in the way */
.stage { cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation; }

/* Skip controls + CC button */
.btn.ctrl { min-width: 48px; font-variant-numeric: tabular-nums; }
.btn.cc { font-weight: 700; letter-spacing: 0.5px; }
.btn.cc:disabled { opacity: 0.4; cursor: default; }
.btn.cc.active { background: var(--text); color: #0c0e13; border-color: var(--text); }
.hint-text { color: var(--muted); font-size: 12px; margin: 8px 0 0; text-align: center; }

/* Subtitles (CC) overlay — sits over the canvas, never intercepts taps */
.subtitle {
  position: absolute;
  bottom: 6%;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: clamp(15px, 2.6vw, 26px);
  line-height: 1.3;
  text-align: center;
  white-space: pre-wrap;
  pointer-events: none;
}

/* Double-tap skip flash (YouTube-style) */
.skip-hint {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  padding: 14px 18px;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.skip-hint.left { left: 8%; }
.skip-hint.right { right: 8%; }
.skip-hint.show { opacity: 1; }

/* Full-screen mode — fills the viewport with just the video + controls.
   Uses a CSS class (works on every browser, incl. iOS Safari which doesn't
   support the Fullscreen API on non-video elements). */
body.fs { overflow: hidden; }
body.fs #topbar,
body.fs #back,
body.fs #player-title,
body.fs .hint-text,
body.fs #qr-box { display: none; }
body.fs #view-player {
  position: fixed;
  inset: 0;
  max-width: none;
  margin: 0;
  padding: 0;
  background: #000;
  z-index: 9999;
  display: flex;
  flex-direction: column;
}
body.fs .stage {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  border-radius: 0;
  aspect-ratio: auto;
}
body.fs .controls {
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.55);
}
.btn.ctrl#fs { font-size: 18px; line-height: 1; }
