:root {
  --bg: #000;
  --fg: #fff;
  --muted: rgba(255,255,255,.55);
  --line: rgba(255,255,255,.22);
  --red: #ff3b30;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --label: 11px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; margin: 0; }
html, body {
  height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; }

/* editorial label treatment */
.label { text-transform: uppercase; letter-spacing: 1.5px; font-size: var(--label); font-weight: 600; }

/* ---------- Auth ---------- */
.screen {
  position: fixed; top: 0; left: 0; right: 0;
  height: 100vh; height: 100dvh; height: 100svh;
  display: grid; place-items: center; padding: 32px;
}
.auth-card { width: 100%; max-width: 330px; text-align: center; }
.logo { width: 84px; height: 84px; margin: 0 auto 22px; filter: drop-shadow(0 10px 36px rgba(48,209,88,.3)); }
.logo img { width: 100%; height: 100%; display: block; }
.auth-card h1 { font-size: 25px; margin: 0 0 8px; letter-spacing: -.3px; font-weight: 700; }
.auth-card h1 span { opacity: .5; }
.tagline { color: var(--muted); margin: 0 0 34px; font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; }
.auth-mode { display: flex; flex-direction: column; gap: 10px; }
.field {
  background: transparent; border: 1px solid var(--line); color: var(--fg);
  padding: 15px 16px; border-radius: 2px; font-size: 16px; outline: none; text-align: center;
}
.field:focus { border-color: var(--fg); }
.primary {
  background: var(--fg); color: #000; border: 0; border-radius: 2px;
  padding: 16px; font-size: 13px; font-weight: 700; cursor: pointer;
  text-transform: uppercase; letter-spacing: 1.5px;
}
.primary:active { opacity: .8; }
.link { background: none; border: 0; color: var(--muted); font-size: 13px; padding: 8px; cursor: pointer; text-transform: uppercase; letter-spacing: 1px; }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 16px; }

/* ---------- App shell: full-bleed stage, floating overlays ----------
   100svh is the "small" viewport height (toolbars shown) — it always fits with
   nothing hidden, on both iOS Safari and standalone PWA. The earlier 100vh and
   visualViewport approaches over-reported height, pushing controls off-screen. */
#app {
  position: fixed; top: 0; left: 0; right: 0;
  height: 100vh; height: 100dvh; height: 100svh;
  overflow: hidden; background: #000;
}
.view { position: absolute; inset: 0; }

/* ---------- Camera / video (behind everything) ---------- */
.camera-wrap { position: absolute; inset: 0; background: #000; }
#preview, #ghost-canvas, #overlay-canvas, #pb-video, #pb-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
#ghost-canvas, #overlay-canvas, #pb-overlay { pointer-events: none; }
#ghost-canvas { opacity: 0; transition: opacity .15s; }
.mirror { transform: scaleX(-1); }
#capture-layer { position: absolute; inset: 0; z-index: 1; touch-action: none; }

/* ---------- Floating controls ---------- */
.ic { width: 24px; height: 24px; display: block; }
.ic.sm { width: 17px; height: 17px; }

.glass {
  -webkit-backdrop-filter: blur(18px) saturate(150%); backdrop-filter: blur(18px) saturate(150%);
  background: rgba(0,0,0,.32); border: .5px solid var(--line); color: #fff; cursor: pointer;
}
.top-controls {
  position: absolute; z-index: 6; top: calc(14px + var(--safe-top)); right: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.top-controls .glass { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; }
.top-controls .glass:active { transform: scale(.92); }
.top-controls .glass.active { background: var(--fg); color: #000; border-color: transparent; }

.reset {
  position: absolute; z-index: 6; left: 14px; top: calc(14px + var(--safe-top));
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
}

.hint {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 5;
  bottom: calc(86px + var(--safe-bottom)); white-space: nowrap;
  padding: 8px 15px; border-radius: 2px; color: #fff;
  text-transform: uppercase; letter-spacing: 1.2px; font-size: var(--label); font-weight: 600;
  background: rgba(0,0,0,.34); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  pointer-events: none; transition: opacity .25s;
}

/* zoom badge (shown while pinching) */
.zoom-badge {
  position: absolute; z-index: 6; top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; letter-spacing: .5px;
  background: rgba(0,0,0,.5); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: .5px solid var(--line); color: #fff;
}

/* new-version prompt */
.update-banner {
  position: absolute; z-index: 35; left: 14px; right: 14px; bottom: calc(74px + var(--safe-bottom));
  display: flex; align-items: center; gap: 12px;
  background: #fff; color: #000; border-radius: 4px; padding: 12px 14px;
  font-size: 13px; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.update-banner span { flex: 1; }
.update-banner .primary { padding: 9px 16px; background: #000; color: #fff; }

/* review actions */
.review-actions {
  position: absolute; z-index: 6; left: 0; right: 0; bottom: calc(84px + var(--safe-bottom));
  display: flex; gap: 10px; justify-content: center; padding: 0 24px;
}
.pill {
  border: 0; border-radius: 2px; padding: 14px 26px; font-size: var(--label); font-weight: 700; cursor: pointer;
  text-transform: uppercase; letter-spacing: 1.2px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 120px;
}
.pill:active { opacity: .8; }
.pill.accent { background: var(--fg); color: #000; }
.pill.ghost { background: rgba(0,0,0,.4); color: #fff; border: .5px solid var(--line); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.pb-status {
  position: absolute; z-index: 6; left: 0; right: 0; bottom: calc(150px + var(--safe-bottom));
  text-align: center; color: #fff; font-size: var(--label); text-transform: uppercase; letter-spacing: 1px;
}

/* coach overlay */
.coach { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; padding: 36px; background: rgba(0,0,0,.6); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.coach-card { text-align: center; max-width: 300px; }
.coach-card p { color: #fff; font-size: 15px; line-height: 1.55; margin: 22px 0 26px; }
.coach-ring { width: 72px; height: 72px; margin: 0 auto; border-radius: 50%; border: 2px solid #fff; animation: coachpulse 1.6s ease-in-out infinite; }
@keyframes coachpulse {
  0%,100% { transform: scale(.85); opacity: .5; box-shadow: 0 0 0 0 rgba(255,255,255,.4); }
  50% { transform: scale(1.05); opacity: 1; box-shadow: 0 0 0 14px rgba(255,255,255,0); }
}

/* ---------- Upload chips ---------- */
.uploads { position: absolute; top: calc(14px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 8; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.upload-chip {
  pointer-events: auto; display: inline-flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.55); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border: .5px solid var(--line); color: #fff; border-radius: 2px; padding: 8px 14px;
  font-size: var(--label); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; animation: slideup .2s ease;
}
.upload-chip .spin { width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .7s linear infinite; }
.upload-chip.fail { color: var(--red); }
.upload-chip.done .spin, .upload-chip.fail .spin { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buffer fill bar (very bottom edge) ---------- */
#buffer-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(255,255,255,.12); z-index: 7; }
#buffer-fill { height: 100%; width: 0%; background: #fff; transition: width .08s linear; }
.tick { position: absolute; top: -1px; width: 1px; height: 4px; background: rgba(255,255,255,.9); }

/* ---------- Feed ---------- */
.feed { position: absolute; inset: 0; overflow-y: scroll; scroll-snap-type: y mandatory; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.feed::-webkit-scrollbar { display: none; }
.slide {
  position: relative; height: 100%; scroll-snap-align: start; scroll-snap-stop: always;
  background: #000; display: flex; align-items: center; justify-content: center; touch-action: pan-y;
}
.slide video, .slide .slide-overlay { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.slide .slide-overlay { pointer-events: none; }
.slide::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 240px; background: linear-gradient(transparent, rgba(0,0,0,.6)); pointer-events: none; }
.slide .meta { position: absolute; left: 18px; bottom: calc(92px + var(--safe-bottom)); right: 80px; z-index: 2; pointer-events: none; }
.slide .meta .who { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; opacity: .85; }
.slide .meta .tags { font-size: 13px; margin-top: 4px; opacity: .9; }
.feed-filter {
  position: absolute; top: calc(8px + var(--safe-top)); left: 0; right: 0; z-index: 5;
  display: flex; gap: 8px; overflow-x: auto; padding: 6px 12px; scrollbar-width: none;
}
.feed-filter::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; background: rgba(0,0,0,.42); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: .5px solid var(--line); color: var(--muted); border-radius: 999px; padding: 6px 14px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; cursor: pointer;
}
.chip.active { background: #fff; color: #000; border-color: transparent; }
.chip-sep { flex: 0 0 auto; width: 1px; align-self: center; height: 18px; background: var(--line); margin: 0 2px; }
.new-clips {
  position: absolute; top: calc(54px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 6;
  background: #fff; color: #000; border: 0; border-radius: 999px; padding: 8px 16px; cursor: pointer;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; box-shadow: 0 6px 20px rgba(0,0,0,.5);
}

.slide .loop-count {
  position: absolute; top: calc(54px + var(--safe-top)); left: 16px; z-index: 2;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  text-shadow: 0 1px 5px rgba(0,0,0,.7); pointer-events: none;
}
.slide .muted-flag {
  position: absolute; top: calc(52px + var(--safe-top)); right: 16px; z-index: 2;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); background: rgba(0,0,0,.4);
  border: .5px solid var(--line); border-radius: 2px; padding: 6px 11px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px;
}
.feed-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); padding: 40px; text-align: center; font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; }

.slide-actions {
  position: absolute; right: 14px; bottom: calc(96px + var(--safe-bottom)); z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 22px;
}
.act-btn { background: none; border: 0; color: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.act-btn svg { width: 32px; height: 32px; display: block; filter: drop-shadow(0 1px 4px rgba(0,0,0,.6)); transition: transform .15s ease; }
.act-btn:active svg { transform: scale(.82); }
.act-label, .like-count { font-size: 12px; font-weight: 700; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.like-btn .heart { fill: none; stroke: #fff; stroke-width: 1.6; }
.like-btn.liked .heart { fill: #fff; stroke: #fff; }

.heart-burst { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 4; opacity: 0; }
.heart-burst::before { content: '♥'; font-size: 104px; color: #fff; filter: drop-shadow(0 4px 16px rgba(0,0,0,.55)); transform: scale(0); }
.heart-burst.show { animation: burstfade .8s ease; }
.heart-burst.show::before { animation: burstpop .8s ease; }
@keyframes burstfade { 0%,100% { opacity: 0; } 18% { opacity: 1; } }
@keyframes burstpop { 0% { transform: scale(0) rotate(-12deg); } 30% { transform: scale(1.12) rotate(6deg); } 50% { transform: scale(.95); } 100% { transform: scale(1.08); } }

/* ---------- Settings ---------- */
#settings-view { background: #000; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.settings { padding: calc(30px + var(--safe-top)) 22px calc(130px + var(--safe-bottom)); max-width: 460px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.settings-title { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: .5px solid var(--line); padding-bottom: 20px; }
.set-row.col { flex-direction: column; align-items: stretch; gap: 12px; }
.set-label { text-transform: uppercase; letter-spacing: 1.2px; font-size: 11px; color: var(--muted); font-weight: 600; }
.set-hint { font-size: 12px; color: var(--muted); margin-top: 4px; opacity: .8; }
.set-value { font-size: 15px; }
.set-actions { display: flex; align-items: center; gap: 14px; }
.set-actions .primary { padding: 12px 22px; }
.set-saved { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.toggle { flex: 0 0 auto; width: 50px; height: 30px; border-radius: 999px; border: .5px solid var(--line); background: rgba(255,255,255,.1); position: relative; cursor: pointer; transition: background .15s; }
.toggle[aria-checked="true"] { background: #fff; }
.toggle .knob { position: absolute; top: 3px; left: 3px; width: 23px; height: 23px; border-radius: 50%; background: #fff; transition: transform .18s ease, background .15s; }
.toggle[aria-checked="true"] .knob { transform: translateX(20px); background: #000; }
.settings .pill { align-self: flex-start; }

.set-link { background: none; border: 0; color: #fff; text-align: left; font-size: 15px; padding: 4px 0; cursor: pointer; border-bottom: .5px solid var(--line); padding-bottom: 18px; }

/* ---------- My Clips ---------- */
.overlay-view { position: fixed; top: 0; left: 0; right: 0; height: 100vh; height: 100dvh; height: 100svh; background: #000; z-index: 50; display: flex; flex-direction: column; }
.ov-header { display: flex; align-items: center; justify-content: space-between; padding: calc(12px + var(--safe-top)) 14px 12px; border-bottom: .5px solid var(--line); }
.ov-back { background: none; border: 0; color: #fff; font-size: 16px; cursor: pointer; flex: 1; text-align: left; }
.ov-title { font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; font-size: 13px; }
.ov-spacer { flex: 1; }
.ov-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; padding: 40px; text-align: center; }
.myclips-grid { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding-bottom: calc(20px + var(--safe-bottom)); align-content: start; }
.mc-cell { position: relative; aspect-ratio: 9 / 16; background: #111; overflow: hidden; cursor: pointer; }
.mc-cell img, .mc-cell video { width: 100%; height: 100%; object-fit: cover; }
.mc-cell.mc-noposter { display: grid; place-items: center; }
.mc-cell.mc-noposter::after { content: '▶'; color: rgba(255,255,255,.5); font-size: 22px; }
.mc-del { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; background: rgba(0,0,0,.55); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border: 0; color: #fff; font-size: 14px; display: grid; place-items: center; cursor: pointer; }
.mc-loops { position: absolute; bottom: 6px; left: 6px; font-size: 11px; font-weight: 700; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.clip-modal { position: fixed; inset: 0; z-index: 60; background: #000; display: grid; place-items: center; }
.clip-modal video { width: 100%; height: 100%; object-fit: contain; }

/* ---------- Notice ---------- */
.notice {
  position: absolute; left: 14px; right: 14px; top: calc(14px + var(--safe-top)); z-index: 8;
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); background: rgba(0,0,0,.6);
  border: .5px solid var(--line); border-radius: 2px; padding: 12px 14px; font-size: 12px;
  display: flex; align-items: center; gap: 10px;
}
.notice button { margin-left: auto; }
.notice .primary { padding: 8px 12px; }
.notice .link { color: var(--muted); padding: 4px 8px; }

/* ---------- Hovering tab switcher ---------- */
.tabs {
  position: absolute; bottom: calc(18px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); z-index: 20;
  display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px;
  background: rgba(0,0,0,.4); -webkit-backdrop-filter: blur(22px) saturate(150%); backdrop-filter: blur(22px) saturate(150%);
  border: .5px solid var(--line);
}
.tab {
  background: none; border: 0; color: var(--muted); padding: 9px 16px; border-radius: 999px; cursor: pointer;
  text-transform: uppercase; letter-spacing: 1.2px; font-size: var(--label); font-weight: 600; transition: color .15s, background .15s;
}
.tab.active { color: #000; background: #fff; }
.tab:active { transform: scale(.96); }

/* ---------- Motion ---------- */
.view.show { animation: fadein .22s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.review-actions:not(.hidden) { animation: slideup .22s ease; }
@keyframes slideup { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; } }
