:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --line: #2a2f3a;
  --text: #eef0f4;
  --muted: #98a0b0;
  --accent: #5eead4;
  --accent-ink: #062a25;
  --danger: #fca5a5;
  --fs: 44px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

button {
  font: inherit; color: inherit; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 12px; min-height: 44px; padding: 0 16px;
}
button:hover { border-color: #3a4152; }
button:focus-visible, textarea:focus-visible, #prompt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; width: 100%; min-height: 52px; font-size: 1.05rem; }
button.ghost { background: transparent; }
button.icon { min-width: 44px; padding: 0 12px; font-size: 1.05rem; }
button.accent[data-on="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

/* ---------- Editor ---------- */
#editor {
  max-width: 720px; margin: 0 auto; min-height: 100%;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}
.top h1 { margin: 8px 0 4px; font-size: 1.6rem; letter-spacing: -.01em; }
.lead { margin: 0; color: var(--muted); }
#script {
  flex: 1; min-height: 40vh; width: 100%; resize: vertical;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
  font: inherit; font-size: 1.05rem; line-height: 1.6;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#count { margin-left: auto; font-variant-numeric: tabular-nums; }

/* ---------- Lector ---------- */
#reader { height: 100dvh; display: flex; flex-direction: column; background: #000; }
.bar {
  display: flex; gap: 8px; align-items: center; flex: none;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.spacer { flex: 1; }
.status {
  display: flex; gap: 12px; align-items: center; flex: none;
  padding: 6px 14px; background: var(--bg); color: var(--muted); font-size: .9rem;
}
.status.error { color: var(--danger); }
.meter { width: 64px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; flex: none; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 80ms linear; }
progress { flex: 1; min-width: 60px; height: 8px; accent-color: var(--accent); }

#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.guide {
  position: absolute; left: 0; right: 0; top: 35%; height: 0; pointer-events: none; z-index: 1;
  border-top: 1px dashed rgba(94, 234, 212, .35);
}
#prompt {
  position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 35vh 6vw 55vh; font-size: var(--fs); line-height: 1.45; font-weight: 600;
  white-space: pre-wrap; overflow-wrap: anywhere; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  transition: transform .2s;
}
#prompt::-webkit-scrollbar { display: none; }
#prompt.mirror { transform: scaleX(-1); }
.w { opacity: 1; transition: opacity .25s, color .25s; border-radius: 6px; cursor: pointer; }
.w.read { opacity: .32; }
.w.cur { background: rgba(94, 234, 212, .22); color: #fff; box-shadow: 0 0 0 4px rgba(94, 234, 212, .22); }
.end-mark { display: block; margin-top: 1.2em; color: var(--accent); font-weight: 700; opacity: 0; transition: opacity .3s; }
.end-mark.show { opacity: 1; }

.caption {
  flex: none; min-height: 2.6em; padding: 6px 14px max(8px, env(safe-area-inset-bottom));
  background: var(--bg); color: var(--muted); font-size: .9rem; border-top: 1px solid var(--line);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

@media (prefers-reduced-motion: reduce) {
  .w, #prompt, .meter i { transition: none; }
}
