:root {
  --bg: #0e0f13;
  --panel: #171920;
  --panel-2: #20232c;
  --line: #2a2e39;
  --text: #f1f2f5;
  --muted: #9097a6;
  --accent: #ff4d6d;
  --yes: #2bd47d;
  --no: #ff4d5e;
  --maybe: #ffc145;
  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: #8ab4ff; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--no); min-height: 1.2em; margin: 0; }

/* ---------- brand / buttons ---------- */
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -0.02em; font-size: 18px; }
.brand.big { font-size: 26px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: linear-gradient(135deg, #ff8a5b, var(--accent)); box-shadow: 0 0 14px #ff4d6d99; }

.btn { border: 1px solid var(--line); background: var(--panel-2); padding: 11px 16px; border-radius: 12px; font-weight: 600; }
.btn.primary { background: linear-gradient(135deg, #ff7a59, var(--accent)); border: 0; color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 16px; }
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* ---------- layout ---------- */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 10px) 16px calc(var(--safe-b) + 10px);
  gap: 10px;
}
.topbar { display: flex; align-items: center; justify-content: space-between; }

.tabs { display: flex; gap: 2px; background: var(--panel); border: 1px solid var(--line); padding: 4px; border-radius: 14px; flex-shrink: 0; }
.tab { flex: 1 1 auto; min-width: 0; border: 0; background: transparent; padding: 8px 2px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.tab b { font-weight: 700; font-size: 11px; background: var(--panel-2); color: var(--muted); padding: 1px 6px; border-radius: 99px; }
@media (max-width: 400px) {
  .tab { font-size: 12px; }
  .tab b { padding: 1px 5px; font-size: 10px; }
}
.tab.active { background: var(--panel-2); color: var(--text); }
.tab.active b { background: var(--accent); color: #fff; }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 5px 12px; font-size: 13px; color: var(--muted); }
.chip.active { color: var(--text); border-color: var(--accent); background: #ff4d6d22; }

/* ---------- deck ---------- */
.deck-view { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.deck { position: relative; flex: 1; min-height: 0; }
.card {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px #0009;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  will-change: transform;
  transition: transform .28s cubic-bezier(.2,.8,.2,1), opacity .28s;
}
.card.dragging { transition: none; }
.card.back { transform: scale(.94) translateY(14px); opacity: .55; pointer-events: none; }
.card video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; pointer-events: none; }
.card .shade { position: absolute; inset: auto 0 0 0; height: 45%; background: linear-gradient(transparent, #000d); pointer-events: none; }
.card .info { position: absolute; left: 16px; right: 16px; bottom: 14px; pointer-events: none; }
.card .streamer { display: inline-block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; background: #ffffff1f; backdrop-filter: blur(6px); padding: 3px 9px; border-radius: 99px; }
.card .title { font-size: 20px; font-weight: 800; margin: 6px 0 2px; word-break: break-word; text-shadow: 0 1px 8px #000; }
.card .meta { font-size: 13px; color: #d0d4dc; }
.card .badge-maybe { position: absolute; top: 14px; left: 14px; background: var(--maybe); color: #241a00; font-weight: 800; font-size: 12px; padding: 3px 9px; border-radius: 99px; }
.card .sound { position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: #0008; backdrop-filter: blur(6px); display: grid; place-items: center; pointer-events: auto; font-size: 18px; }
.card .progress { position: absolute; left: 0; right: 0; top: 0; height: 3px; background: #ffffff22; pointer-events: none; }
.card .progress i { display: block; height: 100%; width: 0; background: #fff; }
.card .play { position: absolute; inset: 0; display: grid; place-items: center; font-size: 64px; opacity: 0; transition: opacity .2s; pointer-events: none; text-shadow: 0 2px 20px #000; }
.card.paused .play { opacity: .85; }
.card .loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }

.stamp { position: absolute; top: 36px; padding: 6px 14px; border: 4px solid; border-radius: 12px; font-size: 30px; font-weight: 900; letter-spacing: .04em; opacity: 0; pointer-events: none; text-transform: uppercase; }
.stamp.yes { left: 22px; color: var(--yes); border-color: var(--yes); transform: rotate(-14deg); }
.stamp.no { right: 22px; color: var(--no); border-color: var(--no); transform: rotate(14deg); }
.stamp.maybe { left: 50%; top: auto; bottom: 34%; transform: translateX(-50%); color: var(--maybe); border-color: var(--maybe); font-size: 24px; }

.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 10px; padding: 24px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty .big { font-size: 46px; }
.empty strong { color: var(--text); font-size: 18px; }

.actions { display: flex; justify-content: center; align-items: center; gap: 16px; flex-shrink: 0; }
.round { border-radius: 50%; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); transition: transform .12s, background .2s; }
.round:active { transform: scale(.92); }
.round.no, .round.yes { width: 68px; height: 68px; }
.round.no { color: var(--no); }
.round.yes { color: var(--yes); }
.round.maybe { width: 50px; height: 50px; font-size: 22px; }
.round.full { width: 50px; height: 50px; font-size: 17px; line-height: 1; color: #8ab4ff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.round.full small { font-size: 8.5px; font-weight: 700; letter-spacing: .02em; color: var(--muted); }
.round:disabled { opacity: .35; }
.hint { text-align: center; font-size: 12px; color: var(--muted); margin: 0; }

/* ---------- lists ---------- */
.list-view { flex: 1; min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 10px; padding-bottom: 8px; }
.row { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; display: grid; gap: 6px; }
.row-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.row-title { font-weight: 700; word-break: break-word; }
.row-sub { font-size: 12px; color: var(--muted); }
.pill { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 99px; white-space: nowrap; text-transform: uppercase; letter-spacing: .04em; }
.pill.queued { background: #8ab4ff22; color: #8ab4ff; }
.pill.processing { background: #ffc14522; color: var(--maybe); }
.pill.done { background: #2bd47d22; color: var(--yes); }
.pill.error { background: #ff4d5e22; color: var(--no); }
.pill.trashed { background: #ff4d5e22; color: var(--no); }
.bar { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #ff7a59, var(--accent)); border-radius: 99px; transition: width .4s; }
.links { display: grid; gap: 4px; font-size: 13px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.err-text { color: var(--no); font-size: 13px; word-break: break-word; }
.list-empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- toast / status ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 108px); transform: translateX(-50%);
  background: #2a2e39f2; backdrop-filter: blur(10px); border: 1px solid #3a3f4d;
  padding: 8px 8px 8px 14px; border-radius: 14px; display: flex; gap: 10px; align-items: center; width: max-content;
  box-shadow: 0 10px 30px #0008; z-index: 10; max-width: calc(100% - 32px); font-size: 14px;
}
.status-line { font-size: 11px; color: var(--muted); text-align: center; min-height: 1em; flex-shrink: 0; }
.status-line.bad { color: var(--no); }

@media (hover: none) { .desktop-only { display: none; } }
@media (min-width: 760px) {
  .app { padding-top: 22px; }
  .deck { max-height: 760px; }
}
@media (prefers-reduced-motion: reduce) {
  .card { transition: opacity .2s; }
}

/* ---------- frame regions (webcam / stream picture) ---------- */
.regions { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 12px; background: #000c; overflow-y: auto; }
.regions-card { width: 100%; max-width: 720px; display: grid; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.regions-card h2 { margin: 0; font-size: 18px; }
.regions-card p { margin: 0; font-size: 13px; }
.regions-tools { display: flex; gap: 8px; }
.region-tool { flex: 1; border: 2px solid var(--line); background: var(--panel-2); border-radius: 12px; padding: 9px 12px; font-weight: 700; }
.region-tool.webcam { --c: #ffc145; }
.region-tool.stream { --c: #4dc3ff; }
.region-tool.active { border-color: var(--c); color: var(--c); }
.region-tool.done::after { content: " ✓"; }
/* the stage is exactly the frame: its aspect ratio is set from the video, so a fraction of the stage is a fraction of the frame */
.regions-stage { position: relative; justify-self: center; width: 100%; background: #000; }
.regions-stage video { display: block; width: 100%; height: 100%; }
.regions-layer { position: absolute; inset: 0; pointer-events: none; }
.regions-hit { position: absolute; inset: -14px; cursor: crosshair; touch-action: none; user-select: none; -webkit-user-select: none; }
.region-rect { position: absolute; border: 2px solid var(--c); background: color-mix(in srgb, var(--c) 22%, transparent); pointer-events: none; }
.region-rect.webcam { --c: #ffc145; }
.region-rect.stream { --c: #4dc3ff; }
.region-rect span { position: absolute; left: 0; top: 0; padding: 1px 6px; font-size: 11px; font-weight: 700; color: #000; background: var(--c); border-bottom-right-radius: 6px; }
.regions-seek { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.regions-seek input { flex: 1; accent-color: var(--accent); }
.regions-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.regions-actions #regions-cancel { margin-right: auto; }
