:root {
  --bg: #0b0b0c;
  --panel: #151517;
  --line: #2a2a2e;
  --fg: #f4f4f2;
  --muted: #8b8b90;
  --accent: #ffd23f;
  --live: #3ddc84;
  --danger: #ff5c5c;
  --said: rgba(244, 244, 242, 0.28);
  --ahead: rgba(244, 244, 242, 0.62);
  --size: 56px;
  --width: 80vw;
  --rl: 30; /* reading line, % of screen height */
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }

/* ---------- Editor ---------- */
.editor {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 16px 32px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.editor-head h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
.editor-head .sub { margin: 6px 0 0; color: var(--muted); }

textarea {
  flex: 1;
  min-height: 42vh;
  width: 100%;
  resize: vertical;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  font: 18px/1.6 inherit;
  font-family: inherit;
  outline: none;
}
textarea:focus { border-color: var(--accent); }

.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px 20px;
}
.settings label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.settings label output { color: var(--fg); margin-left: 4px; }
.settings label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--fg); font-size: 14px; }
select, input[type=range] { width: 100%; accent-color: var(--accent); }
select {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  font-size: 14px;
}

.display { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.display label {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.display label:has(input:checked) { border-color: var(--accent); }
.display input { accent-color: var(--accent); margin-top: 3px; }
.display b { display: block; font-size: 15px; }
.display small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

.float-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  font-size: 14px;
}

.actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.support { color: var(--muted); font-size: 13px; }
.support.bad { color: var(--danger); }
.primary {
  background: var(--accent);
  color: #111;
  border: 0;
  border-radius: 999px;
  padding: 14px 28px;
  font-weight: 650;
  font-size: 16px;
}
.primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Prompter ---------- */
.prompter { position: fixed; inset: 0; overflow: hidden; background: var(--bg); touch-action: manipulation; overscroll-behavior: none; }
.stage { position: absolute; inset: 0; overflow: hidden; }
.stage.mirror { transform: scaleX(-1); }
.text {
  width: min(var(--width), 100% - 32px);
  margin: 0 auto;
  padding-top: calc(var(--rl) * 1vh);
  padding-bottom: 100vh;
  font-size: var(--size);
  line-height: 1.32;
  font-weight: 600;
  letter-spacing: -0.01em;
  will-change: transform;
  color: var(--ahead);
}
.text p { margin: 0 0 0.6em; }
.w { cursor: pointer; transition: color 0.25s ease; border-radius: 0.12em; }
.w.cur { color: var(--fg); }
.w.said { color: var(--said); }
.w.next { box-shadow: inset 0 -0.08em 0 var(--accent); }

.marker {
  position: absolute;
  left: 0;
  top: calc(var(--rl) * 1% + var(--size) * 0.66 - 9px);
  width: 0;
  height: 0;
  border-left: 14px solid var(--accent);
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  opacity: 0.8;
  pointer-events: none;
}

.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(var(--bg), transparent);
  font-size: 13px;
  color: var(--muted);
  opacity: 0.35;
  transition: opacity 0.2s;
}
.hud:hover, .prompter.paused .hud { opacity: 1; }
.keys { flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mic, .ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 0 var(--live); animation: pulse 1.6s infinite; }
.prompter.paused .dot { background: var(--muted); animation: none; }
.prompter.failed .dot { background: var(--danger); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6); }
  70% { box-shadow: 0 0 0 8px rgba(61, 220, 132, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); }
}

.heard {
  position: absolute;
  left: 16px; right: 16px;
  bottom: max(14px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 15px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl; /* keep the newest words visible */
  pointer-events: none;
}
.error {
  position: absolute;
  left: 50%; bottom: 60px;
  transform: translateX(-50%);
  max-width: min(560px, 100% - 32px);
  background: #2a1414;
  border: 1px solid var(--danger);
  color: #ffd6d6;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
}

/* small floating window: keep chrome out of the way of the text */
.prompter.floating .hud { opacity: 0; padding-top: 6px; }
.prompter.floating .hud:hover, .prompter.floating.paused .hud { opacity: 1; }
.prompter.floating .heard { font-size: 12px; left: 0; right: 0; bottom: 0; padding: 14px 12px 5px; background: linear-gradient(transparent, var(--bg) 55%); }
.prompter.floating .marker { border-left-width: 8px; border-top-width: 6px; border-bottom-width: 6px; margin-top: 3px; }
.prompter.floating .error { bottom: 26px; font-size: 13px; padding: 8px 12px; }

/* ---------- Phone camera: script on top, selfie preview below ---------- */
.cam, .rec, .timer { display: none; }
.prompter.camera .stage { top: env(safe-area-inset-top, 0px); bottom: 50%; }
.prompter.camera .cam {
  display: block;
  position: absolute;
  left: 0; top: 50%;
  width: 100%; height: 50%;
  object-fit: contain; /* show the whole frame that gets recorded */
  transform: scaleX(-1); /* selfie preview is mirrored, the recording is not */
  background: #000;
}
.prompter.camera .hud {
  top: auto; bottom: 0;
  opacity: 1;
  justify-content: space-between;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
}
.prompter.camera .keys { display: none; }
.prompter.camera .rec {
  display: block;
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: 72px; height: 72px;
  padding: 0;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
}
.rec span {
  display: block;
  margin: auto;
  width: 54px; height: 54px;
  border-radius: 50%;
  background: #ff3b30;
  transition: all 0.2s ease;
}
.prompter.recording .rec span { width: 28px; height: 28px; border-radius: 6px; }
.prompter.counting .rec span { opacity: 0.5; }
.prompter.camera.recording .timer {
  display: block;
  position: absolute;
  left: 50%;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 84px);
  transform: translateX(-50%);
  background: #ff3b30;
  color: #fff;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 3px 10px;
  border-radius: 6px;
}
.prompter.recording #exit { visibility: hidden; }
.cam-info { display: none; }
.prompter.camera .cam-info:not(:empty) {
  display: block;
  position: absolute;
  top: calc(50% + 10px);
  left: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.5);
  color: rgba(255, 255, 255, 0.85);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.countdown {
  position: absolute;
  left: 0; right: 0; top: 50%; bottom: 0;
  display: grid;
  place-items: center;
  font-size: 120px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
.prompter.camera .heard { font-size: 12px; left: 0; right: 0; bottom: 50%; padding: 14px 12px 5px; background: linear-gradient(transparent, var(--bg) 55%); }
.prompter.camera .error { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 100px); font-size: 13px; }

.review {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
  z-index: 5;
}
.review video { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.review-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
}
.review-actions button { flex: 1; padding: 14px; font-size: 16px; justify-content: center; }

@media (max-width: 640px) {
  .keys { display: none; }
  .prompter:not(.floating):not(.camera) .hud { justify-content: space-between; opacity: 0.7; }
}
