/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Color system */
  --bg:           #080a0d;
  --surface:      #0f1318;
  --surface2:     #161b22;
  --surface3:     #1c232d;
  --border:       #242c38;
  --border-soft:  #1a2030;
  --text:         #e2e8f0;
  --text-muted:   #64748b;
  --text-dim:     #94a3b8;
  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow:  rgba(59,130,246,0.25);
  --live:         #ef4444;
  --live-hover:   #dc2626;
  --live-glow:    rgba(239,68,68,0.3);
  --success:      #22c55e;
  --warning:      #f59e0b;
  --frame:        #a855f7;
  --frame-glow:   rgba(168,85,247,0.25);

  /* Spacing */
  --radius:    10px;
  --radius-sm: 7px;
  --radius-xs: 5px;

  /* Layout */
  --topbar-h:  52px;
  --controls-h: 152px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout shell ─────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 100;
  gap: 12px;
}

/* Video area: fills between topbar and controls */
.video-area {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  bottom: var(--controls-h);
  background: #000;
}

/*
 * Wrapper fills the entire video area. The <video> uses object-fit: contain
 * so the complete frame is always visible regardless of stream aspect ratio
 * (letterboxing/pillarboxing as needed). This is essential for review work:
 * judges must see every pixel, never a cropped or stretched image.
 */
.video-wrapper {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
}
.video-wrapper.zoomed { cursor: grab; }
.video-wrapper.panning { cursor: grabbing; }

video {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: contain;
  transform-origin: 0 0;
  transition: transform 0.08s linear;
  will-change: transform;
}
.video-wrapper.panning video { transition: none; }

.controls {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--controls-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 14px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Topbar ───────────────────────────────────────────────────── */
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.app-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  white-space: nowrap;
}

.source-selector select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.source-selector select:focus { border-color: var(--accent); }

.review-mode-switch {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.btn-mode {
  height: 28px;
  min-width: 74px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  background: transparent;
  border-color: transparent;
}

.btn-mode[aria-pressed="true"] {
  background: var(--surface3);
  color: #fff;
  border-color: transparent;
  box-shadow: none;
}

.btn-mode:hover:not(:disabled) {
  border-color: transparent;
  box-shadow: none;
}

#btnModeFast[aria-pressed="true"] {
  color: var(--warning);
  box-shadow: inset 0 0 0 1px rgba(245,158,11,0.18);
}

#btnModePrecise[aria-pressed="true"] {
  color: var(--frame);
  box-shadow: inset 0 0 0 1px rgba(168,85,247,0.24);
}

/* Status pill */
.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}

.status-dot.live    { background: var(--live);    box-shadow: 0 0 7px var(--live);    animation: pulse 1.8s ease-in-out infinite; }
.status-dot.ok      { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.warning { background: var(--warning); }
.status-dot.error   { background: var(--live); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

/* Icon button (fullscreen) */
.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--surface3); border-color: var(--border); color: var(--text); }
.btn-icon svg { width: 18px; height: 18px; fill: currentColor; }

/* ── Video overlay ────────────────────────────────────────────── */
.video-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: opacity 0.2s;
}

.video-overlay.hidden {
  display: none;
}

.overlay-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.overlay-content p {
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: 0.02em;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Review mode — video border ──────────────────────────────── */
.video-wrapper.is-review {
  box-shadow: inset 0 0 0 3px var(--warning);
}
.video-wrapper.is-clip {
  box-shadow: inset 0 0 0 3px var(--frame);
}

/* ── Review mode banner ───────────────────────────────────────── */
.review-banner {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 5px 0;
  background: rgba(8,10,13,0.72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  pointer-events: none;
}
.review-banner.hidden { display: none; }

.review-banner-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 6px var(--warning);
  flex-shrink: 0;
}
.is-clip .review-banner-dot {
  background: var(--frame);
  box-shadow: 0 0 6px var(--frame);
}

.review-banner-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--warning);
  text-transform: uppercase;
}
.is-clip .review-banner-label { color: var(--frame); }

.review-banner-meta {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.review-banner-meta.hidden { display: none; }

/* ── Offset badge ─────────────────────────────────────────────── */
.offset-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 20;
  background: var(--live);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 4px 10px;
  border-radius: 4px;
  pointer-events: none;
  min-width: 52px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}

.offset-badge.review {
  background: rgba(8,10,13,0.85);
  color: var(--text);
  border: 1px solid var(--border);
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
  min-width: 80px;
}

/* Frame counter badge — shown below the offset badge in clip mode */
.frame-badge {
  position: absolute;
  top: 44px;
  left: 14px;
  z-index: 20;
  background: rgba(8,10,13,0.85);
  color: var(--frame);
  border: 1px solid rgba(168,85,247,0.3);
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.frame-badge.hidden { display: none; }

/* ── Scrubber ─────────────────────────────────────────────────── */
.scrubber-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.time-label {
  font-size: 11px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Mono', monospace;
  color: var(--text-muted);
  min-width: 62px;
  text-align: center;
  flex-shrink: 0;
  letter-spacing: 0.04em;
}

.live-label {
  color: var(--live);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  font-family: inherit;
}

.scrubber-track {
  flex: 1;
  height: 6px;
  background: var(--surface3);
  border-radius: 3px;
  position: relative;
  cursor: pointer;
  border: 1px solid var(--border-soft);
  transition: height 0.15s, background 0.15s;
  /* Expand clickable area */
  margin: 10px 0;
}

.scrubber-track::before {
  content: '';
  position: absolute;
  inset: -10px 0;
}

.scrubber-track:hover {
  height: 9px;
  background: var(--surface2);
}

.scrubber-track.dragging {
  height: 7px;
  cursor: grabbing;
}

.scrubber-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  pointer-events: none;
  transition: width 0.4s linear;
}

.scrubber-track.dragging .scrubber-fill,
.scrubber-track.dragging .scrubber-thumb,
.scrubber-track.seeking .scrubber-fill,
.scrubber-track.seeking .scrubber-thumb {
  transition: none;
}

.scrubber-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  transform: translate(-50%, -50%);
  width: 13px;
  height: 13px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2.5px var(--accent), 0 2px 8px rgba(0,0,0,0.6);
  pointer-events: none;
  transition: left 0.4s linear, transform 0.15s, width 0.15s, height 0.15s;
  opacity: 0;
}

.scrubber-track:hover .scrubber-thumb,
.scrubber-track.dragging .scrubber-thumb {
  opacity: 1;
}

/* Scrubber time tooltip */
.scrubber-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 11px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  z-index: 10;
}

.scrubber-track:hover .scrubber-tooltip,
.scrubber-track.dragging .scrubber-tooltip {
  opacity: 1;
}

/* ── Buttons row ──────────────────────────────────────────────── */
.buttons-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: nowrap;
}

.button-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* Base button */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s, border-color 0.12s, transform 0.08s, box-shadow 0.12s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding: 0 14px;
  height: 40px;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--surface3);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow) inset;
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

/* Speed buttons */
.btn-speed {
  height: 34px;
  min-width: 40px;
  font-size: 12px;
  padding: 0 8px;
  border-radius: var(--radius-xs);
}

.btn-speed[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 12px var(--accent-glow);
}

.btn-speed[aria-pressed="true"]:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* Seek buttons */
.btn-seek {
  height: 40px;
  min-width: 60px;
  font-size: 12px;
  flex-direction: column;
  gap: 1px;
  padding: 4px 10px;
}

.btn-seek svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

.btn-seek span {
  font-size: 10px;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 0.04em;
  line-height: 1;
}

/* Frame nav buttons */
.btn-frame {
  min-width: 50px;
  border-color: rgba(168,85,247,0.3);
}

.btn-frame:hover:not(:disabled) {
  border-color: var(--frame);
  box-shadow: 0 0 0 1px var(--frame-glow) inset;
}

.btn-frame svg {
  fill: var(--frame);
}

.btn-frame:hover:not(:disabled) svg {
  fill: #c084fc;
}

/* Play/Pause — primary CTA */
.btn-playpause {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--accent);
  flex-shrink: 0;
  padding: 0;
  box-shadow: 0 0 20px var(--accent-glow);
  transition: background 0.12s, box-shadow 0.12s, transform 0.08s;
}

.btn-playpause:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 0 28px var(--accent-glow);
}

.btn-playpause:active:not(:disabled) {
  transform: scale(0.94);
}

.btn-playpause svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}

/* Live button */
.btn-live {
  min-width: 70px;
  height: 40px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.1em;
  border-color: rgba(239,68,68,0.4);
  color: var(--live);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-live svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex-shrink: 0;
}

.btn-live:hover:not(:disabled) {
  background: var(--live);
  color: #fff;
  border-color: var(--live);
  box-shadow: 0 0 16px var(--live-glow);
}

.btn-live.is-live {
  background: var(--live);
  border-color: var(--live);
  color: #fff;
  box-shadow: 0 0 14px var(--live-glow);
}

/* ── Zoom HUD ─────────────────────────────────────────────────── */
.zoom-hud {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(8,10,13,0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 4px 6px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.video-wrapper:hover .zoom-hud,
.video-wrapper.zoomed .zoom-hud { opacity: 1; pointer-events: auto; }

.zoom-hud button {
  width: 26px; height: 26px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 3px;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.zoom-hud button:hover { background: var(--surface3); }
.zoom-hud button svg { width: 14px; height: 14px; fill: currentColor; }
.zoom-level {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  color: var(--text-dim);
  min-width: 38px;
  text-align: center;
  letter-spacing: 0.04em;
}

/* ── Stream info chip ─────────────────────────────────────────── */
.stream-info {
  position: absolute;
  bottom: 14px;
  left: 14px;
  z-index: 20;
  background: rgba(8,10,13,0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 4px 9px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  pointer-events: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.2s;
}
.video-wrapper:hover .stream-info { opacity: 1; }
.stream-info strong { color: var(--text); font-weight: 600; }

/* ── Fullscreen mode ──────────────────────────────────────────── */
:fullscreen .topbar,
:fullscreen .controls,
:-webkit-full-screen .topbar,
:-webkit-full-screen .controls {
  display: none;
}

:fullscreen .video-area,
:-webkit-full-screen .video-area {
  top: 0;
  bottom: 0;
}

/* ── Responsive: tablets ──────────────────────────────────────── */
@media (max-width: 720px) {
  :root { --controls-h: 156px; }
  .controls { padding: 12px 14px 16px; gap: 10px; }
  .review-mode-switch { gap: 2px; }
  .btn-mode { min-width: 64px; padding: 0 8px; }
  .btn-seek { min-width: 50px; padding: 4px 8px; }
  .btn-live { min-width: 60px; }
  .buttons-row { gap: 7px; }
  .button-group { gap: 5px; }
  .btn-speed { min-width: 36px; }
}

@media (max-width: 520px) {
  :root { --topbar-h: 46px; --controls-h: 148px; }
  .app-name { display: none; }
  .review-mode-switch { padding: 2px; }
  .btn-mode { min-width: 54px; font-size: 10px; letter-spacing: 0.08em; }
  .btn-seek span { display: none; }
  .btn-seek { min-width: 42px; }
  .btn-speed { min-width: 34px; padding: 0 6px; font-size: 11px; }
  .btn-frame { min-width: 38px; }
  .btn-live span { display: none; }
}
