:root {
  --bg: #0b0d10;
  --panel: #161a20;
  --line: #2a303a;
  --text: #eef1f5;
  --muted: #8d97a5;
  --accent: #4f8cff;
  --danger: #ff4d4f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

.view { position: fixed; inset: 0; display: none; }
.view.active { display: flex; }

/* ---------- editor ---------- */
#editor { flex-direction: column; gap: 12px; padding: calc(12px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); }
.bar { display: flex; align-items: center; justify-content: space-between; }
.bar h1 { margin: 0; font-size: 20px; }
.row { display: flex; gap: 8px; align-items: center; }
select, input[type=text], textarea {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font: inherit; min-width: 0; }
select { flex: 1; }
textarea { flex: 1; resize: none; line-height: 1.5; font-size: 17px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; white-space: nowrap; }
.chip.danger { color: var(--danger); }
.primary { background: var(--accent); color: #fff; border-radius: 12px; padding: 12px 18px; font-weight: 600; }
.primary.big { padding: 16px; font-size: 17px; }
.meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }

/* ---------- camera ---------- */
#camera { background: #000; overflow: hidden; }
#preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
#preview.mirror { transform: scaleX(-1); }
#noCam { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 12px;
  align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--muted); }

#prompter { position: absolute; left: 0; right: 0; top: var(--safe-top); height: 38%;
  overflow: hidden; background: rgba(0,0,0,.5); }
#prompterInner { position: absolute; left: 0; right: 0; top: 0; will-change: transform; padding: 0 20px; }
#prompterText { white-space: pre-wrap; word-wrap: break-word; font-weight: 600; line-height: 1.35;
  font-size: 32px; text-align: center; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
#prompter.flip #prompterInner { transform-origin: center; }
#readLine { position: absolute; left: 0; right: 0; height: 2px; background: rgba(255,210,60,.55); pointer-events: none; }
#progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255,255,255,.15); }
#progress i { display: block; height: 100%; width: 0; background: var(--accent); }

#topbar { position: absolute; left: 0; right: 0; bottom: calc(110px + var(--safe-bottom)); display: flex;
  justify-content: space-between; align-items: center; padding: 0 16px; pointer-events: none; }
#topbar > * { pointer-events: auto; }
#timer { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.55); padding: 6px 12px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.round { width: 48px; height: 48px; border-radius: 50%; background: rgba(0,0,0,.55); font-size: 20px;
  display: grid; place-items: center; }

#controls { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  align-items: center; padding: 14px 12px calc(14px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.65)); }
#recBtn { width: 72px; height: 72px; border-radius: 50%; background: transparent; border: 4px solid #fff;
  display: grid; place-items: center; padding: 0; }
#recBtn span { width: 52px; height: 52px; border-radius: 50%; background: var(--danger); transition: all .15s; }
#recBtn.recording span { width: 28px; height: 28px; border-radius: 6px; }

#countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 140px; font-weight: 700;
  background: rgba(0,0,0,.4); text-shadow: 0 2px 12px rgba(0,0,0,.7); pointer-events: none; }

#settings { position: absolute; left: 0; right: 0; bottom: calc(100px + var(--safe-bottom)); margin: 0 12px;
  background: rgba(22,26,32,.95); border: 1px solid var(--line); border-radius: 16px; padding: 12px 16px;
  display: grid; gap: 10px; max-height: 55%; overflow: auto; }
#settings label { display: grid; gap: 4px; font-size: 14px; }
#settings output { float: right; color: var(--muted); }
#settings input[type=range] { width: 100%; accent-color: var(--accent); }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tog { display: flex !important; align-items: center; gap: 8px; }

/* ---------- result ---------- */
#result { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; padding: 16px; z-index: 10; }
.sheet { width: 100%; max-width: 480px; background: var(--panel); border-radius: 16px; padding: 14px; display: grid; gap: 10px; }
#resultVideo { width: 100%; max-height: 60vh; border-radius: 10px; background: #000; }
#resultInfo { margin: 0; color: var(--muted); font-size: 13px; }
.sheet .row .primary { flex: 1; }

@media (orientation: landscape) {
  #prompter { height: 45%; }
}
