:root {
  --bg: #0d0c0b;
  --ink: #f4efe8;
  --muted: #a39b91;
  --line: rgba(244, 239, 232, 0.14);
  --glass: rgba(20, 18, 16, 0.55);
  --accent: #e8c9a0;
  --danger: #ff8a7a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --dock-h: calc(186px + var(--safe-bottom));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", -apple-system, system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-family: "Instrument Serif", serif; font-weight: 400; font-size: 44px; line-height: 0.98; margin: 0; letter-spacing: -0.01em; }
h1 em { color: var(--accent); }

/* Stage: the mirror */
.stage {
  position: fixed;
  inset: 0 0 var(--dock-h) 0;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 30%, #1d1a17 0%, var(--bg) 70%);
  border-radius: 0 0 28px 28px;
  touch-action: none;
}
.feed {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.35s ease;
}
.feed.on { opacity: 1; }
.feed.mirror { transform: scaleX(-1); }
#local.on.dim { filter: blur(14px) brightness(0.6); transform: scale(1.08); }
#local.on.dim.mirror { transform: scaleX(-1) scale(1.08); }

.empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; justify-content: flex-start;
  padding: calc(var(--safe-top) + min(22vh, 150px)) 28px 0;
  background:
    linear-gradient(to bottom, rgba(13, 12, 11, 0.25), rgba(13, 12, 11, 0.1) 40%, rgba(13, 12, 11, 0.55)),
    url("/assets/room.jpg") center top / max(100%, 140vh * 9 / 16) auto no-repeat var(--bg);
  animation: heroIn 1.2s ease both;
  transition: opacity 0.3s ease;
}
.empty p { color: var(--muted); font-size: 15px; line-height: 1.5; margin: 16px 0 0; }
.empty.gone { opacity: 0; pointer-events: none; }

.topbar {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  display: flex; align-items: center; gap: 8px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }
.top-actions form { margin: 0; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line);
}
.status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 500;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line);
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status.live::before { background: #ff5a4e; box-shadow: 0 0 0 4px rgba(255, 90, 78, 0.22); animation: pulse 1.6s infinite; }
.status.busy::before { background: var(--accent); animation: pulse 0.9s infinite; }
.timer {
  min-width: 52px;
  padding: 8px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line);
}
@keyframes pulse { 50% { opacity: 0.35; } }

.hint {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  font-size: 12px; color: var(--muted);
  padding: 6px 12px; border-radius: 999px; background: var(--glass);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  white-space: nowrap;
  animation: fadeOut 0.5s ease 4s forwards;
}
@keyframes fadeOut { to { opacity: 0; } }

/* Dock: the closet */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--dock-h);
  padding: 14px 0 calc(var(--safe-bottom) + 12px);
  display: flex; flex-direction: column; gap: 12px;
}
.rail {
  display: flex; gap: 10px;
  padding: 4px 16px;
  align-items: center;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}
.rail::-webkit-scrollbar { display: none; }
.add, .item {
  flex: 0 0 auto;
  width: 64px; height: 84px;
  border-radius: 16px;
  scroll-snap-align: start;
}
.add {
  display: grid; place-items: center;
  border: 1.5px dashed var(--line);
  color: var(--muted);
  cursor: pointer;
}
.add input { display: none; }
.item {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #1a1815;
  transition: transform 0.15s ease, border-color 0.2s ease;
  -webkit-touch-callout: none;
}
.item img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.item:active { transform: scale(0.94); }
.item.selected { border: 2px solid var(--accent); box-shadow: 0 0 0 3px rgba(232, 201, 160, 0.2); }
.item.uploading img { opacity: 0.4; }
.item.uploading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.item .tag {
  position: absolute; left: 4px; bottom: 4px;
  font-size: 9px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 2px 5px; border-radius: 6px;
  background: rgba(13, 12, 11, 0.7);
}
@keyframes spin { to { transform: rotate(360deg); } }

.go {
  margin: 0 16px;
  height: 52px; border-radius: 16px;
  background: var(--ink); color: var(--bg);
  font-weight: 600; font-size: 16px;
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.go:active { transform: scale(0.98); }
.go.stop { background: rgba(244, 239, 232, 0.1); color: var(--ink); border: 1px solid var(--line); }
.go:disabled { opacity: 0.45; }

/* Edit sheet */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: flex-end;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: 100%;
  background: #1a1815;
  border-radius: 24px 24px 0 0;
  padding: 20px 16px calc(var(--safe-bottom) + 16px);
  animation: up 0.25s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet img { width: 72px; height: 96px; object-fit: cover; border-radius: 12px; display: block; }
.sheet-label { color: var(--muted); font-size: 13px; margin: 16px 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  padding: 10px 14px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 14px;
}
.chips button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.danger { margin-top: 20px; width: 100%; height: 48px; border-radius: 14px; color: var(--danger); background: rgba(255, 138, 122, 0.08); }

.toast {
  position: fixed; left: 16px; right: 16px; z-index: 20;
  top: calc(var(--safe-top) + 64px);
  padding: 12px 14px; border-radius: 14px;
  background: #2a2522; border: 1px solid var(--line);
  font-size: 14px; text-align: center;
}

/* Login */
body.login {
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  min-height: 100%;
  padding: 24px 24px calc(var(--safe-bottom) + 28px);
}
.hero {
  position: fixed; inset: 0;
  background: url("/assets/hero.jpg") center 30% / cover no-repeat;
  animation: heroIn 1.2s ease both;
}
/* Fade the photo into the page so the card sits on solid ground */
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(13, 12, 11, 0.35) 0%, rgba(13, 12, 11, 0) 22%, rgba(13, 12, 11, 0) 42%, var(--bg) 78%);
}
@keyframes heroIn { from { opacity: 0; transform: scale(1.04); } }
.login-card { position: relative; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; animation: up 0.6s ease 0.3s both; }
.login-card h1 { margin-bottom: 6px; }
.login-card input {
  height: 52px; border-radius: 16px; padding: 0 16px;
  font: inherit; font-size: 16px; color: var(--ink);
  background: rgba(244, 239, 232, 0.06); border: 1px solid var(--line);
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card .go { margin: 0; }
.error { color: var(--danger); font-size: 14px; margin: 0; }
.login-card[hidden] { display: none; }
.login-note { color: var(--muted); font-size: 16px; line-height: 1.5; margin: -8px 0 10px; }
.login-note strong { color: var(--ink); font-weight: 500; word-break: break-all; }
.go.google { display: flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none; }

/* Combine mode */
button.add { background: none; font: inherit; }
.combine.on { border-style: solid; border-color: var(--accent); color: var(--accent); background: rgba(232, 201, 160, 0.08); }
.item.picked { border: 2px solid var(--accent); }
.item.picked img { opacity: 0.75; }
.item .pick {
  position: absolute; top: 5px; right: 5px;
  width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
  background: var(--accent); color: var(--bg);
}

/* Record button + full-screen recording mode */
.rec-btn .rec-dot { width: 16px; height: 16px; border-radius: 50%; background: #ff5a4e; box-shadow: 0 0 0 3px rgba(255, 90, 78, 0.22); }
body.recording .rec-btn, body.recording #flip ~ form { display: none; }
body.recording .stage { inset: 0; border-radius: 0; }
body.recording .hint { display: none; }
body.recording .dock {
  z-index: 5;
  background: linear-gradient(to bottom, rgba(13, 12, 11, 0), rgba(13, 12, 11, 0.55) 40%, rgba(13, 12, 11, 0.8));
}
body.recording .add { display: none; }
body.recording .go.stop { background: #ff5a4e; color: #fff; border-color: #ff5a4e; }

/* Recorded clip preview */
.clip-sheet { display: flex; flex-direction: column; gap: 12px; }
.clip-sheet video {
  width: 100%; max-height: 58vh;
  object-fit: contain;
  border-radius: 16px;
  background: #000;
}
.clip-sheet .go, .clip-sheet .danger { margin: 0; }

#flip svg { width: 23px; height: 23px; stroke-width: 1.6; }
#flip.spin svg { animation: flipSpin 0.45s ease; }
@keyframes flipSpin { from { transform: rotate(-180deg); } }
body.recording #closeCam { display: none; }

.timer.low { color: #ff8a7a; border-color: rgba(255, 138, 122, 0.4); }

/* Front-page guide */
.guide {
  position: fixed; inset: 0; z-index: 2;
  pointer-events: none;
  transition: opacity 0.3s ease;
  animation: up 0.8s ease 0.5s both;
}
.guide.gone { opacity: 0; }
.guide-arrows { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.guide-arrows path { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.guide-arrows .dots { stroke-dasharray: 0.1 7; animation: march 1.6s linear infinite; }
@keyframes march { to { stroke-dashoffset: -7.1; } }
.guide-note {
  position: absolute; left: 24px; margin: 0;
  bottom: calc(var(--dock-h) + 118px);
  font-size: 15px; font-weight: 500; line-height: 1.4; color: var(--ink);
  text-shadow: 0 1px 2px rgba(13, 12, 11, 0.9), 0 0 16px rgba(13, 12, 11, 0.9);
}
.guide-note.right { left: auto; right: 22px; bottom: calc(var(--dock-h) + 30px); text-align: right; }
.combine.idle { opacity: 0.55; }

/* Share */
.share-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 14px 0 11px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line);
}
.share-btn svg { width: 19px; height: 19px; color: var(--accent); }
