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

:root {
  --bg: #0d0d0d;
  --card: #111;
  --border: #2a2a2a;
  --accent: #6366f1;
  --good: #22c55e;
  --bad: #ef4444;
  --trim: #f59e0b;
  --text: #fff;
  --sub: #888;
  --radius: 14px;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; -webkit-tap-highlight-color: transparent; }

/* ── Login ─────────────────────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; overflow: auto; }
.login-wrap { width: 100%; max-width: 340px; padding: 32px 24px; }
.login-logo { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 40px; }
.login-logo h1 { font-size: 22px; font-weight: 700; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.field input { width: 100%; padding: 13px 16px; background: #1a1a1a; border: 1.5px solid var(--border); border-radius: 11px; color: var(--text); font-size: 16px; outline: none; transition: border-color 0.2s; }
.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--sub); }
.btn-primary { padding: 13px; background: var(--accent); color: #fff; border: none; border-radius: 11px; font-size: 15px; font-weight: 600; cursor: pointer; transition: opacity 0.2s, transform 0.1s; }
.btn-primary:hover { opacity: 0.88; }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.login-error { color: var(--bad); font-size: 13px; text-align: center; min-height: 18px; }

/* ── App shell ─────────────────────────────────────────────────────── */
.viewer-body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.app { display: flex; flex-direction: column; height: 100%; width: 100%; max-width: 540px; margin: 0 auto; }

/* ── Top bar ───────────────────────────────────────────────────────── */
.top-bar { flex-shrink: 0; padding: 10px 16px 6px; }
.progress-track { height: 3px; background: var(--border); border-radius: 99px; overflow: hidden; margin-bottom: 7px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; width: 0%; }
.top-row { display: flex; align-items: center; justify-content: space-between; }
.stat-text { font-size: 12px; color: var(--sub); }
.top-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn { background: none; border: none; color: var(--sub); cursor: pointer; padding: 4px 6px; display: flex; align-items: center; gap: 5px; border-radius: 8px; transition: color 0.2s; }
.icon-btn:hover { color: var(--text); }
.icon-btn:disabled { opacity: 0.28; cursor: not-allowed; pointer-events: none; }
.undo-btn { font-size: 12px; }
.undo-label { font-size: 12px; font-weight: 500; }

/* ── Stage ─────────────────────────────────────────────────────────── */
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px 12px; }

/* ── Card ──────────────────────────────────────────────────────────── */
.card {
  position: relative; background: #000;
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 6px 32px rgba(0,0,0,0.7);
  user-select: none; touch-action: none; will-change: transform;
  width: 100%; height: 100%;
  cursor: grab;
  display: flex; align-items: center; justify-content: center;
}
.card:active { cursor: grabbing; }

.card video {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  background: #000;
}

/* ── Info bar (top of card) ────────────────────────────────────────── */
.info-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 12;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px;
  padding: 10px 12px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.72) 0%, transparent 100%);
  pointer-events: none;
}
.cat-badge {
  background: rgba(99,102,241,0.85); color: #fff;
  padding: 4px 11px; border-radius: 99px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase;
}
.meta-chips { display: flex; align-items: center; gap: 6px; }
.chip {
  background: rgba(0,0,0,0.55); backdrop-filter: blur(4px);
  color: rgba(255,255,255,0.8); padding: 3px 9px; border-radius: 99px;
  font-size: 11px; font-weight: 500; letter-spacing: 0.3px;
  border: 1px solid rgba(255,255,255,0.1);
}
.chip:empty { display: none; }

/* ── Swipe overlays ────────────────────────────────────────────────── */
.swipe-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; z-index: 20; transition: opacity 0.08s;
}
.swipe-overlay span {
  font-size: 38px; font-weight: 900; letter-spacing: 3px;
  border: 4px solid; padding: 8px 18px; border-radius: 10px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.overlay-keep { background: rgba(34,197,94,0.15); }
.overlay-keep span { color: var(--good); border-color: var(--good); }
.overlay-skip { background: rgba(239,68,68,0.15); }
.overlay-skip span { color: var(--bad); border-color: var(--bad); }

/* ── Player controls (bottom of card) ─────────────────────────────── */
.player-ctrl {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 15;
  padding: 36px 12px 12px;
  background: linear-gradient(to top, rgba(0,0,0,0.88) 0%, transparent 100%);
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s;
}
.player-ctrl.visible { opacity: 1; pointer-events: all; }

.seek-row { margin-bottom: 9px; }
.seek-bar {
  position: relative; height: 4px; background: rgba(255,255,255,0.25);
  border-radius: 99px; cursor: pointer;
  transition: height 0.15s;
}
.seek-bar:hover, .seek-bar.dragging { height: 6px; }
.seek-fill { position: absolute; left: 0; top: 0; bottom: 0; background: #fff; border-radius: 99px; pointer-events: none; }
.seek-thumb {
  position: absolute; top: 50%; width: 14px; height: 14px;
  background: #fff; border-radius: 50%; transform: translate(-50%, -50%);
  opacity: 0; transition: opacity 0.15s; pointer-events: none;
}
.seek-bar:hover .seek-thumb, .seek-bar.dragging .seek-thumb { opacity: 1; }

.ctrl-row { display: flex; align-items: center; gap: 10px; }
.ctrl-btn {
  background: none; border: none; color: rgba(255,255,255,0.9); cursor: pointer;
  padding: 4px; border-radius: 6px; display: flex; align-items: center;
  transition: color 0.15s, transform 0.1s; flex-shrink: 0;
}
.ctrl-btn:hover { color: #fff; }
.ctrl-btn:active { transform: scale(0.88); }
.ctrl-time { font-size: 12px; color: rgba(255,255,255,0.75); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ctrl-spacer { flex: 1; }

/* ── Empty state ───────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 40px 24px; }
.empty-state h2 { font-size: 26px; font-weight: 700; margin: 18px 0 10px; }
.empty-state p { color: var(--sub); font-size: 14px; line-height: 1.7; white-space: pre-line; }

/* ── Trim panel ────────────────────────────────────────────────────── */
.trim-panel {
  flex-shrink: 0; background: #161616; border-top: 1px solid var(--border);
  max-height: 0; overflow: hidden; opacity: 0;
  transition: max-height 0.32s ease, opacity 0.22s ease;
}
.trim-panel.open { max-height: 340px; opacity: 1; padding: 12px 14px 14px; }

.trim-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.trim-label { font-size: 11px; font-weight: 700; color: var(--sub); letter-spacing: 0.8px; }
.trim-times { display: flex; align-items: center; gap: 7px; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--sub); }
.trim-dur { color: var(--trim); font-weight: 600; }

.trim-track-wrap { padding: 4px 0 12px; }
.trim-track { height: 34px; background: rgba(255,255,255,0.07); border-radius: 8px; position: relative; }
.trim-excluded { position: absolute; top: 0; bottom: 0; background: rgba(0,0,0,0.5); pointer-events: none; }
.trim-excluded-left { left: 0; border-radius: 8px 0 0 8px; }
.trim-excluded-right { right: 0; border-radius: 0 8px 8px 0; }
.trim-playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,0.45); border-radius: 1px; pointer-events: none; transform: translateX(-50%); }
.trim-handle { position: absolute; top: 0; bottom: 0; width: 22px; display: flex; align-items: center; justify-content: center; cursor: ew-resize; z-index: 10; transform: translateX(-50%); }
.trim-handle .handle-bar { width: 4px; height: 24px; border-radius: 2px; }
.handle-start .handle-bar { background: var(--good); }
.handle-end .handle-bar { background: var(--bad); }

.seg-add-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 6px; }
.seg-add-btn {
  background: rgba(99,102,241,0.18); color: var(--accent); border: 1px solid rgba(99,102,241,0.35);
  border-radius: 8px; padding: 6px 13px; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background 0.18s; white-space: nowrap;
}
.seg-add-btn:hover { background: rgba(99,102,241,0.28); }
.seg-hint { font-size: 11px; color: var(--sub); }

.seg-list { display: flex; flex-direction: column; gap: 5px; max-height: 100px; overflow-y: auto; margin-bottom: 8px; }
.seg-item {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.05); border-radius: 8px; padding: 6px 10px;
  font-size: 12px;
}
.seg-num { font-weight: 700; color: var(--accent); min-width: 20px; }
.seg-range { color: var(--text); font-variant-numeric: tabular-nums; flex: 1; }
.seg-dur { color: var(--sub); font-size: 11px; }
.seg-del {
  background: none; border: none; color: var(--sub); cursor: pointer;
  padding: 2px 4px; border-radius: 4px; font-size: 14px; line-height: 1;
  transition: color 0.15s;
}
.seg-del:hover { color: var(--bad); }

.trim-actions { display: flex; gap: 9px; }
.trim-btn { flex: 1; padding: 9px; border: none; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity 0.2s, transform 0.1s; }
.trim-btn:active { transform: scale(0.97); }
.trim-reset { background: var(--border); color: var(--sub); }
.trim-reset:hover { color: var(--text); }
.trim-apply { background: var(--trim); color: #000; }
.trim-apply:hover { opacity: 0.88; }
.trim-apply:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Bottom action bar ─────────────────────────────────────────────── */
.actions-bar {
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  gap: 18px; padding: 10px 24px 18px;
}
.action-btn {
  width: 58px; height: 58px; border-radius: 50%; border: 2px solid;
  background: transparent; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform 0.13s, background 0.18s; flex-shrink: 0;
}
.action-btn:active { transform: scale(0.88); }
.action-skip { border-color: var(--bad); color: var(--bad); }
.action-skip:hover { background: rgba(239,68,68,0.1); }
.action-trim { border-color: var(--trim); color: var(--trim); width: 48px; height: 48px; }
.action-trim:hover { background: rgba(245,158,11,0.1); }
.action-trim.active { background: rgba(245,158,11,0.18); }
.action-keep { border-color: var(--good); color: var(--good); }
.action-keep:hover { background: rgba(34,197,94,0.1); }

/* ── Toast ─────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%) translateY(16px);
  background: #2a2a2a; color: var(--text); padding: 9px 18px; border-radius: 99px;
  font-size: 13px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity 0.22s, transform 0.22s; z-index: 100; white-space: nowrap;
  max-width: 90vw; text-overflow: ellipsis; overflow: hidden;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); }
.toast.success { background: var(--good); color: #000; }

/* ── Fullscreen tweaks ─────────────────────────────────────────────── */
:fullscreen .app, :-webkit-full-screen .app { max-width: 100%; }
:fullscreen .card, :-webkit-full-screen .card { border-radius: 0; }

/* ── Desktop ───────────────────────────────────────────────────────── */
@media (min-width: 600px) {
  .action-btn { width: 64px; height: 64px; }
  .action-trim { width: 52px; height: 52px; }
  .seek-bar { height: 5px; }
}
