:root {
  --bg: #0b0b0f;
  --surface: #16161d;
  --surface2: #23232d;
  --line: #ffffff14;
  --text: #f3f3f6;
  --muted: #9a9aa8;
  --accent: #ffd23f;
  --danger: #ff4d4f;

  /* prompter (set from JS) */
  --fs: 34px;
  --lh: 1.32;
  --lines: 4;
  --w: 86%;
  --top: 8px;
  --eye: 0;
  --hl: #ffd23f;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", sans-serif;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; }

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

.bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}
.bar.bottom {
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
}
h1 { font-size: 24px; margin: 0; flex: 1; letter-spacing: .2px; }
h1 span { color: var(--accent); }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 22px 0 2px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }

.btn {
  border: 0; border-radius: 12px; padding: 11px 16px;
  font-weight: 650; font-size: 15px; line-height: 1;
  background: var(--surface2); color: var(--text);
}
.btn.primary { background: var(--accent); color: #111; }
.btn.big { padding: 15px 22px; font-size: 17px; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:active { transform: scale(.97); }

.icon-btn {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: var(--surface2); color: var(--text);
  display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; }
.muted { color: var(--muted); font-size: 14px; }

/* ---------- home ---------- */
#list { list-style: none; margin: 0; padding: 4px 16px; overflow: auto; flex: 1; }
#list li {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: 16px;
  padding: 14px 10px 14px 16px; margin-bottom: 10px;
}
#list li:active { background: var(--surface2); }
#list .meta { flex: 1; min-width: 0; }
#list strong { display: block; font-size: 17px; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#list .meta span { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#list .del { background: transparent; color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; text-align: center; padding: 8px 24px calc(env(safe-area-inset-bottom) + 16px); margin: 0; }

/* ---------- editor ---------- */
#title {
  flex: 1; min-width: 0; background: transparent; border: 0; outline: none;
  color: var(--text); font-size: 20px; font-weight: 700;
}
#body {
  flex: 1; margin: 0 16px; padding: 16px; border: 0; border-radius: 16px; outline: none; resize: none;
  background: var(--surface); color: var(--text); font-family: inherit; font-size: 18px; line-height: 1.55;
}
#stats { flex: 1; color: var(--muted); font-size: 14px; }

/* ---------- prompter ---------- */
#prompter {
  background: #000; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#cam {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover;
}
#cam.mirror { transform: scaleX(-1); } /* optional selfie-style preview */

#tools { display: flex; gap: 10px; }
.pill {
  border: 0; border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 650;
  background: rgba(255, 255, 255, .14); color: #fff;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.pill.on { background: var(--accent); color: #111; }
#filters {
  width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 10px;
  touch-action: pan-x;
}
#filterChips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
#filterChips::-webkit-scrollbar { display: none; }
#filterChips .pill { flex: none; }
#filters label { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #eee; text-shadow: 0 1px 4px #000; }
#filters input[type="range"] { flex: 1; accent-color: var(--accent); touch-action: pan-x; }
#box {
  position: absolute; z-index: 2;
  left: 50%; top: calc(env(safe-area-inset-top) + var(--top));
  transform: translateX(-50%);
  width: var(--w); max-width: 900px;
  padding: 10px 18px;
  border-radius: 20px;
  background: rgba(0, 0, 0, .62);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
#box[data-anchor="left"] {
  left: calc(env(safe-area-inset-left) + var(--top)); top: 50%;
  transform: translateY(-50%);
}
#box[data-anchor="right"] {
  left: auto; right: calc(env(safe-area-inset-right) + var(--top)); top: 50%;
  transform: translateY(-50%);
}
#viewport {
  position: relative; overflow: hidden;
  height: calc(var(--fs) * var(--lh) * var(--lines));
  -webkit-mask-image: linear-gradient(#000 0, #000 70%, transparent 100%);
          mask-image: linear-gradient(#000 0, #000 70%, transparent 100%);
}
#viewport.mirror { transform: scaleX(-1); }
#text {
  position: relative;
  font-size: var(--fs); line-height: var(--lh); font-weight: 650;
  transition: transform .32s cubic-bezier(.2, .7, .2, 1);
  will-change: transform;
}
#text p { margin: 0; }
#text p.gap { height: calc(var(--fs) * var(--lh) * .5); }
#text .w { color: #fff; transition: color .15s ease, opacity .15s ease; cursor: pointer; }
#text .w.done { color: var(--hl); opacity: .9; }
#text .w.now { color: #fff; box-shadow: inset 0 -.12em 0 var(--hl); border-radius: 2px; }
#text .cue { color: #8fd8ff; font-style: italic; font-weight: 500; font-size: .72em; }
#text .sym { color: #bbb; }
#eye {
  position: absolute; left: 3px;
  top: calc(10px + (var(--eye) + .5) * var(--fs) * var(--lh) - 7px);
  border: 7px solid transparent; border-left: 9px solid var(--hl);
  opacity: .9;
}
#box[data-anchor="right"] #eye { left: auto; right: 3px; border-left-color: transparent; border-right: 9px solid var(--hl); }

#heard {
  position: absolute; z-index: 2; left: 16px; right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 205px);
  text-align: center; color: rgba(255, 255, 255, .8); font-size: 14px;
  text-shadow: 0 1px 6px #000; pointer-events: none; min-height: 1em;
}

#hud {
  position: absolute; z-index: 3; left: 0; right: 0; bottom: 0;
  padding: 28px 16px calc(env(safe-area-inset-bottom) + 18px);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .6));
  transition: opacity .5s;
}
#hud.idle { opacity: .15; }
#hud .row { display: flex; align-items: center; gap: 16px; }
#hud .icon-btn { background: rgba(255, 255, 255, .14); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.round {
  width: 66px; height: 66px; border-radius: 50%; border: 0;
  background: #fff; color: #111; display: grid; place-items: center; position: relative;
}
.round svg { width: 28px; height: 28px; }
.round.rec { background: transparent; border: 4px solid #fff; }
.round.rec::after {
  content: ""; width: 46px; height: 46px; border-radius: 50%;
  background: var(--danger); transition: all .2s ease;
}
.round.rec.on::after { width: 24px; height: 24px; border-radius: 6px; }
.round:active { transform: scale(.94); }

#status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #e6e6ea; text-shadow: 0 1px 4px #000; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #666; transition: box-shadow .15s; }
.dot.live { background: #3ddc84; }
.dot.hit { box-shadow: 0 0 0 6px rgba(61, 220, 132, .35); }
#recTime {
  background: var(--danger); color: #fff; padding: 6px 12px; border-radius: 999px;
  font: 700 13px/1 ui-monospace, Menlo, Consolas, monospace;
}
#countdown {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center;
  font-size: 140px; font-weight: 800; color: #fff;
  text-shadow: 0 4px 40px rgba(0, 0, 0, .7); pointer-events: none;
}

/* ---------- sheets ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .35);
}
.panel {
  width: 100%; max-width: 560px; max-height: 70vh; overflow: auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(env(safe-area-inset-bottom) + 18px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .5);
}
#result .panel { max-height: 92vh; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; position: sticky; top: -18px; background: var(--surface); padding: 6px 0; z-index: 1; }
.field { display: flex; flex-direction: column; gap: 10px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.field.switch { flex-direction: row; align-items: center; justify-content: space-between; }
.lbl { font-size: 15px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.lbl output { color: var(--accent); font-variant-numeric: tabular-nums; }
.help { color: var(--muted); font-size: 13px; }
.field input[type="range"] { width: 100%; accent-color: var(--accent); }
.field input[list], .field input[type="text"], .field select {
  background: var(--surface2); border: 0; border-radius: 10px; padding: 12px; color: var(--text); font-size: 16px; outline: none;
}
.field input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 50px; height: 30px; border-radius: 30px; background: var(--surface2); position: relative; transition: background .2s;
}
.field input[type="checkbox"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s;
}
.field input[type="checkbox"]:checked { background: var(--accent); }
.field input[type="checkbox"]:checked::after { transform: translateX(20px); }
.seg { display: flex; background: var(--surface2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  padding: 10px 6px; border-radius: 9px; font-size: 14px; font-weight: 600;
}
.seg button.on { background: var(--bg); color: var(--text); }
.swatches { display: flex; gap: 12px; flex-wrap: wrap; }
.swatches button { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; background: var(--c); }
.swatches button.on { border-color: #fff; }
#resetSettings { margin-top: 14px; width: 100%; }

#resultVideo { width: 100%; max-height: 62vh; background: #000; border-radius: 14px; margin: 8px 0 14px; }
.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; padding: 14px 10px; }

#toast {
  position: fixed; z-index: 20; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 240px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); width: max-content;
  background: rgba(30, 30, 38, .95); color: #fff; padding: 12px 16px; border-radius: 14px;
  font-size: 14px; line-height: 1.35; text-align: center;
  transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
