/* Bookmark TV — X-mobile-inspired dark UI */
:root {
  --bg: #000;
  --surface: #0a0a0a;
  --border: #2f3336;
  --text: #e7e9ea;
  --muted: #71767b;
  --blue: #1d9bf0;
  --blue-dim: rgba(29, 155, 240, .12);
  --like: #f91880;
  --danger: #f4212e;
  --radius: 16px;
  --topbar-h: 53px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- Top bar ---------- */
#topbar {
  height: calc(var(--topbar-h) + var(--sat));
  padding-top: var(--sat);
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding-left: 16px; padding-right: 8px;
  background: rgba(0,0,0,.72);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-name { font-size: 17px; font-weight: 800; letter-spacing: -.2px; white-space: nowrap; }
.count-pill {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: #16181c; border: 1px solid var(--border);
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.top-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text); transition: background .15s;
}
.icon-btn:active { background: rgba(231,233,234,.12); }
.icon-btn.primary-ring { color: var(--blue); }
.icon-btn.toggled { color: var(--blue); }

/* ---------- Feed ---------- */
#feed {
  flex: 1 1 auto; position: relative;
  overflow-y: auto; overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  background: var(--bg);
}
#feed::-webkit-scrollbar { display: none; }
.card {
  position: relative;
  height: 100%; min-height: 100%;
  scroll-snap-align: start; scroll-snap-stop: always;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); overflow: hidden;
}
.card video {
  width: 100%; height: 100%;
  object-fit: contain; background: var(--bg);
  display: block;
}
.tapzone { position: absolute; inset: 0; z-index: 3; }

/* shimmer while resolving */
.card.loading .shimmer {
  position: absolute; inset: 0; z-index: 2;
  background: linear-gradient(100deg, #0a0a0a 40%, #16181c 50%, #0a0a0a 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.card .spin {
  position: absolute; z-index: 2; width: 34px; height: 34px;
  border: 3px solid var(--border); border-top-color: var(--blue);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* error card */
.card.error { flex-direction: column; gap: 10px; padding: 32px; text-align: center; }
.card.error .err-icon {
  width: 56px; height: 56px; border-radius: 999px;
  background: #16181c; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 24px;
}
.card.error p { color: var(--muted); font-size: 14px; line-height: 1.45; max-width: 300px; }
.card.error .err-actions { display: flex; gap: 10px; margin-top: 6px; }

/* caption overlay */
.caption {
  position: absolute; z-index: 4;
  left: 12px; right: 76px; bottom: calc(14px + var(--sab));
  pointer-events: none; text-shadow: 0 1px 8px rgba(0,0,0,.8);
}
.caption .handle { font-weight: 800; font-size: 14px; margin-bottom: 4px; }
.caption .handle .badge {
  display: inline-block; width: 15px; height: 15px; border-radius: 999px;
  background: var(--blue); color: #fff; font-size: 10px; line-height: 15px;
  text-align: center; margin-left: 4px; vertical-align: 1px;
}
.caption .text {
  font-size: 13.5px; line-height: 1.4; color: #e7e9ea;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* right action rail */
.rail {
  position: absolute; z-index: 5;
  right: 6px; bottom: calc(70px + var(--sab));
  display: flex; flex-direction: column; gap: 14px; align-items: center;
}
.rail-btn {
  width: 44px; height: 44px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20,22,25,.55); color: #fff;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.08);
  transition: transform .12s;
}
.rail-btn:active { transform: scale(.88); }
.rail-btn.liked { color: var(--like); border-color: rgba(249,24,128,.35); }
.rail-btn.liked svg { fill: var(--like); }

/* progress */
.progress {
  position: absolute; z-index: 6; left: 0; right: 0;
  bottom: 0; height: calc(3px + var(--sab)); padding-bottom: var(--sab);
  background: rgba(255,255,255,.14);
}
.progress .fill { height: 3px; width: 0%; background: var(--blue); }

/* center flash on tap */
.flash {
  position: absolute; z-index: 7; left: 50%; top: 50%;
  transform: translate(-50%,-50%) scale(.6); opacity: 0;
  width: 84px; height: 84px; border-radius: 999px;
  background: rgba(0,0,0,.55); display: flex;
  align-items: center; justify-content: center; pointer-events: none;
}
.flash.show { animation: flash .45s ease-out; }
@keyframes flash {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.6); }
  25% { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(1.15); }
}

/* position pill */
.pos-pill {
  position: absolute; z-index: 6; top: 10px; left: 50%; transform: translateX(-50%);
  font-size: 11px; font-weight: 700; color: rgba(255,255,255,.75);
  background: rgba(0,0,0,.5); padding: 4px 10px; border-radius: 999px;
  pointer-events: none; letter-spacing: .4px;
}

/* ---------- Empty state ---------- */
.empty {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 32px; text-align: center; background: var(--bg);
}
.empty h1 { font-size: 24px; font-weight: 800; letter-spacing: -.3px; }
.empty p { color: var(--muted); font-size: 14.5px; line-height: 1.5; max-width: 300px; }
.empty .btn-primary { margin-top: 10px; min-width: 220px; }

/* ---------- Buttons ---------- */
.btn-primary {
  background: var(--blue); color: #fff; font-weight: 700; font-size: 15px;
  padding: 12px 28px; border-radius: 999px; transition: opacity .15s;
}
.btn-primary:active { opacity: .85; }
.btn-primary:disabled { opacity: .5; }
.btn-block { width: 100%; }
.btn-ghost {
  color: var(--text); font-weight: 600; font-size: 14px;
  padding: 10px 18px; border-radius: 999px; border: 1px solid var(--border);
}
.btn-ghost:active { background: rgba(231,233,234,.08); }
.btn-ghost.danger { color: var(--danger); }

/* ---------- Import sheet ---------- */
.scrim {
  position: absolute; inset: 0; z-index: 40; background: rgba(0,0,0,.6);
}
.sheet {
  position: absolute; z-index: 41; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(20px + var(--sab));
  display: flex; flex-direction: column; gap: 12px;
  animation: sheetUp .25s ease-out; max-height: 88%;
  overflow-y: auto;
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: .5; } }
.grabber { width: 40px; height: 4px; border-radius: 999px; background: var(--border); margin: 4px auto 2px; }
.sheet h2 { font-size: 20px; font-weight: 800; }
.sheet-sub { color: var(--muted); font-size: 13.5px; line-height: 1.45; }
.sheet textarea {
  background: #000; border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); font: 13px/1.5 monospace; padding: 12px;
  resize: vertical; min-height: 120px; -webkit-user-select: text; user-select: text;
}
.sheet textarea:focus { outline: none; border-color: var(--blue); }
.sheet-row { display: flex; gap: 10px; }
.sheet-row .btn-ghost { flex: 1; }
.import-status { font-size: 13px; color: var(--muted); }
.import-status b { color: var(--text); }

/* ---------- Start overlay ---------- */
.start-overlay {
  position: absolute; inset: 0; z-index: 50;
  background: rgba(0,0,0,.82);
  display: flex; flex-direction: column; gap: 16px;
  align-items: center; justify-content: center;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.start-btn {
  width: 96px; height: 96px; border-radius: 999px; background: var(--blue);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 32px rgba(29,155,240,.45);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 8px 32px rgba(29,155,240,.45); }
  50% { box-shadow: 0 8px 48px rgba(29,155,240,.7); }
}
.start-overlay p { font-weight: 700; font-size: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: absolute; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(28px + var(--sab)); max-width: 86%;
  background: #1d1f23; border: 1px solid var(--border); color: var(--text);
  font-size: 13.5px; padding: 11px 16px; border-radius: 12px;
  text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  animation: toastIn .2s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } }

[hidden] { display: none !important; }
