:root {
  --bg: #0f1115;
  --card: #1a1d24;
  --card2: #232733;
  --ink: #f4f5f7;
  --muted: #9aa1ad;
  --line: #2c3140;
  --brand: #6366f1;
  --brand2: #4f46e5;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --green: #22c55e;
  --pink: #ec4899;
  --radius: 18px;
  --tap: 56px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior-y: contain;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* When the PIN gate is up, freeze the whole page — no scroll, no rubber-band. */
body.locked { position: fixed; inset: 0; width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; touch-action: none; }

/* ---------- PIN GATE ---------- */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; overflow: hidden; touch-action: none; overscroll-behavior: none; }
.gate-inner { width: 100%; max-width: 360px; text-align: center; }
.logo { font-size: 56px; }
.gate h1 { margin: 6px 0 2px; font-size: 28px; letter-spacing: .5px; }
.gate-sub { color: var(--muted); margin: 0 0 18px; }
.pin-dots { height: 22px; display: flex; gap: 14px; justify-content: center; margin-bottom: 8px; }
.pin-dots .dot { width: 16px; height: 16px; border-radius: 50%; background: var(--card2); border: 2px solid var(--line); }
.pin-dots .dot.on { background: var(--brand); border-color: var(--brand); }
.pin-error { color: var(--pink); height: 20px; font-weight: 600; margin-bottom: 8px; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.key {
  height: 74px; font-size: 28px; font-weight: 600;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius);
  touch-action: manipulation;            /* kills Safari double-tap zoom */
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.key:active { background: var(--card2); transform: scale(.97); }
.key-muted { color: var(--muted); background: transparent; }
.key-go { background: var(--brand2); border-color: var(--brand2); color: #fff; }

/* ---------- TOP BAR / TABS ---------- */
.app { min-height: 100dvh; padding-bottom: 96px; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: rgba(15,17,21,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 20px; font-weight: 800; }
.link-btn { background: none; border: none; color: var(--muted); font-size: 15px; padding: 8px; }

.pay-banner {
  margin: 12px 16px 0; padding: 14px 16px; border-radius: 14px;
  background: linear-gradient(135deg, #db2777, #ec4899); color: #fff; font-weight: 700;
  display: flex; align-items: center; gap: 10px;
}

.tabs { display: flex; gap: 8px; padding: 14px 16px 4px; position: sticky; top: 57px; background: var(--bg); z-index: 4; }
.tab {
  flex: 1; height: 44px; border-radius: 12px; font-size: 14px; font-weight: 700;
  background: var(--card); color: var(--muted); border: 1px solid var(--line);
}
.tab.active { color: #fff; }
.tab[data-status="needs_edit"].active { background: var(--amber); border-color: var(--amber); color: #201500; }
.tab[data-status="in_progress"].active { background: var(--blue); border-color: var(--blue); }
.tab[data-status="edited"].active { background: var(--green); border-color: var(--green); color: #06210f; }

/* ---------- LIST / CARDS ---------- */
.list { padding: 12px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 46px; margin-bottom: 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card-main { padding: 16px; display: flex; gap: 14px; align-items: center; }
.thumb {
  width: 52px; height: 52px; border-radius: 14px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 26px; background: var(--card2);
}
.card-info { flex: 1; min-width: 0; }
.card-title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip { font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .3px; }
.chip.set { background: #312e81; color: #c7d2fe; }
.chip.edited { background: #14532d; color: #bbf7d0; }
.chip.due { background: #831843; color: #fbcfe8; }
.chip.posted { background: #1e293b; color: #cbd5e1; }
.chev { color: var(--muted); font-size: 22px; }

/* ---------- SHEETS ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.sheet {
  position: relative; width: 100%; max-height: 92dvh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 18px 28px;
  border-top: 1px solid var(--line); animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.grabber { width: 44px; height: 5px; background: var(--line); border-radius: 3px; margin: 8px auto 14px; }
.sheet h2 { margin: 4px 0 4px; font-size: 20px; }
.sheet h3 { margin: 22px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

.clip-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.clip-row .role-tag { font-size: 11px; font-weight: 800; color: var(--brand); background: #1e1b4b; padding: 3px 8px; border-radius: 8px; }
.clip-name { flex: 1; min-width: 0; }
.clip-name input {
  width: 100%; background: var(--card2); border: 1px solid var(--line); color: var(--ink);
  border-radius: 10px; padding: 12px; font-size: 15px;
}

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: var(--tap); border-radius: 14px; font-size: 16px; font-weight: 700;
  border: 1px solid var(--line); background: var(--card2); color: var(--ink); padding: 0 16px; margin-top: 10px;
}
.btn:active { transform: scale(.99); }
.btn.primary { background: var(--brand2); border-color: var(--brand2); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: #fca5a5; border-color: #7f1d1d; background: transparent; }
.btn.small { min-height: 44px; font-size: 14px; margin-top: 0; width: auto; padding: 0 14px; }

.seg { display: flex; gap: 8px; margin-top: 6px; }
.seg button {
  flex: 1; min-height: 50px; border-radius: 12px; font-weight: 800; font-size: 14px;
  background: var(--card2); color: var(--muted); border: 1px solid var(--line);
}
.seg button.on[data-v="needs_edit"] { background: var(--amber); color: #201500; border-color: var(--amber); }
.seg button.on[data-v="in_progress"] { background: var(--blue); color: #fff; border-color: var(--blue); }
.seg button.on[data-v="edited"] { background: var(--green); color: #06210f; border-color: var(--green); }

/* edited version block */
.edited-block { background: var(--card2); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-top: 12px; }
.edited-head { display: flex; align-items: center; gap: 10px; }
.edited-head .en { flex: 1; font-weight: 700; }
.play-btn { width: 46px; height: 46px; border-radius: 50%; background: var(--brand2); border: none; color: #fff; font-size: 18px; }
.pay-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 12px; border-radius: 12px; background: #1f2937; }
.pay-row.due { background: #500724; }
.pay-row .pay-txt { flex: 1; font-weight: 700; }
.platforms { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.plat {
  display: flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 12px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--muted); font-weight: 700;
}
.plat.on { background: #052e16; border-color: var(--green); color: #bbf7d0; }
.plat .box { width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--line); display: grid; place-items: center; font-size: 14px; }
.plat.on .box { background: var(--green); border-color: var(--green); color: #06210f; }

/* upload */
.mode-toggle { display: flex; gap: 8px; margin: 4px 0 16px; }
.mode-toggle button { flex: 1; min-height: 52px; border-radius: 14px; font-weight: 800; background: var(--card2); color: var(--muted); border: 1px solid var(--line); }
.mode-toggle button.on { background: var(--brand2); color: #fff; border-color: var(--brand2); }
.filecard { border: 1px dashed var(--line); border-radius: 14px; padding: 16px; margin-top: 12px; background: var(--card2); }
.filecard label.pick { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-weight: 700; }
.filecard .fname { color: var(--muted); font-size: 13px; margin-top: 8px; word-break: break-all; }
.filecard input[type=file] { display: none; }
.filecard .role-select { display: flex; gap: 8px; margin-top: 10px; }
.filecard .role-select button { flex: 1; min-height: 44px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-weight: 700; }
.filecard .role-select button.on { background: #1e1b4b; color: #c7d2fe; border-color: var(--brand); }
.namefield { width: 100%; margin-top: 10px; background: var(--card); border: 1px solid var(--line); color: var(--ink); border-radius: 10px; padding: 12px; font-size: 15px; }

.progress { height: 10px; background: var(--card); border-radius: 6px; overflow: hidden; margin-top: 14px; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; width: 0; background: var(--brand); transition: width .15s; }
.progress-label { text-align: center; color: var(--muted); font-size: 13px; margin-top: 8px; }

/* FAB */
.fab {
  position: fixed; right: 20px; bottom: calc(24px + env(safe-area-inset-bottom));
  width: 64px; height: 64px; border-radius: 50%; font-size: 34px; font-weight: 300; line-height: 1;
  background: var(--brand2); color: #fff; border: none; box-shadow: 0 8px 24px rgba(79,70,229,.5); z-index: 10;
}
.fab:active { transform: scale(.95); }

/* player */
.player-wrap { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; }
.player-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.9); }
.player-box { position: relative; width: 100%; max-width: 720px; padding: 12px; }
.player-box video { width: 100%; border-radius: 14px; background: #000; max-height: 80dvh; }
.player-close { position: absolute; top: -6px; right: 14px; z-index: 2; width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; border: none; font-size: 18px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 12px; border: 1px solid var(--line);
  z-index: 60; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: 90vw; text-align: center;
}
