:root {
  --bg: #0b0b0f;
  --panel: #15151c;
  --panel2: #1d1d27;
  --line: #2a2a36;
  --text: #ececf1;
  --muted: #9a9aab;
  --accent: #ff3b5c;
  --accent2: #ff6b81;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { overflow: hidden; overscroll-behavior: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* ---------- Editor ---------- */
#editor { display: flex; flex-direction: column; height: 100dvh; height: 100vh; height: 100dvh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; letter-spacing: .3px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.topbar select { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; max-width: 220px; }

.btn { border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 9px 14px; font-weight: 600; }
.btn:hover { border-color: #444457; }
.btn.ghost { background: transparent; }
.btn.danger { color: #ff8a9b; }
.btn.small { padding: 7px 12px; font-size: 13px; margin-top: 14px; width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.big { padding: 14px 28px; font-size: 18px; border-radius: 14px; }

.layout { flex: 1; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.15fr) 320px; min-height: 0; }

/* ---------- Preview ---------- */
.preview-pane { display: flex; flex-direction: column; align-items: center; padding: 16px; gap: 12px; min-height: 0; border-left: 1px solid var(--line); background: #08080b; }
.pv-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%; }
.pv-title { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--accent2); font-weight: 700; margin-right: auto; }
.pv-head select { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 13px; }
.btn.small-inline { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.pv-frame { position: relative; overflow: hidden; border-radius: 10px; border: 2px solid #2f2f3c; box-shadow: 0 10px 40px rgba(0,0,0,.5); flex: none;
  touch-action: none; cursor: ns-resize; user-select: none; -webkit-user-select: none; }
.pv-root { position: absolute; left: 0; top: 0; transform-origin: 0 0; overflow: hidden; background: #000; }
.pv-stage { position: absolute; inset: 0; overflow: hidden; outline: 2px dashed rgba(127,127,140,.45); outline-offset: -2px; }
.pv-scroller { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
.pv-content { white-space: pre-wrap; overflow-wrap: break-word; }
.pv-guide { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid rgba(255, 59, 92, .55); pointer-events: none; }
.pv-guide .arrow { position: absolute; top: -0.75em; color: var(--accent); font-size: 22px; line-height: 1.5em; }
.pv-guide .arrow.l { left: 6px; } .pv-guide .arrow.r { right: 6px; }

.text-area { display: flex; flex-direction: column; padding: 16px; gap: 10px; min-height: 0; }
.title-input { background: transparent; border: none; border-bottom: 1px solid var(--line); padding: 8px 2px; font-size: 20px; font-weight: 700; outline: none; }
.title-input:focus { border-color: var(--accent); }
#scriptText { flex: 1; resize: none; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; font-size: 17px; line-height: 1.6; outline: none; min-height: 200px; }
#scriptText:focus { border-color: #444457; }
.stats { color: var(--muted); font-size: 13px; }

.settings { border-left: 1px solid var(--line); background: var(--panel); padding: 8px 18px 24px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.settings h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--accent2); margin: 20px 0 8px; }
.row { display: block; font-size: 14px; color: var(--text); margin: 10px 0; }
.row output { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.row select { width: 100%; margin-top: 6px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.row.inline { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--accent); height: 28px; }
input[type=color] { width: 48px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: none; padding: 2px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: none; padding: 7px 10px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--accent); color: #fff; }

.switch { position: relative; width: 46px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; background: #3a3a48; border-radius: 26px; transition: .2s; }
.switch i::after { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); }

.presets { display: flex; gap: 8px; margin: 8px 0 4px; }
.presets button { width: 44px; height: 36px; border-radius: 8px; border: 1px solid var(--line); font-weight: 800; }

.bottombar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.preview-hint { color: var(--muted); font-size: 14px; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0,1fr) 320px; grid-template-rows: minmax(0,1fr) minmax(0,1fr); }
  .text-area { grid-column: 1; grid-row: 1; }
  .preview-pane { grid-column: 1; grid-row: 2; border-left: none; border-top: 1px solid var(--line); }
  .settings { grid-column: 2; grid-row: 1 / 3; }
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto; overflow-y: auto; display: flex; flex-direction: column; }
  .text-area { min-height: 260px; }
  .preview-pane { position: sticky; top: 0; z-index: 3; height: 42vh; flex: none; border-bottom: 1px solid var(--line); }
  .settings { border-left: none; border-top: 1px solid var(--line); overflow: visible; }
  #editor { height: 100dvh; }
  .bottombar .btn.big { flex: 1; }
}

/* ---------- Prompter ---------- */
#prompter { position: fixed; inset: 0; background: #000; overflow: hidden; outline: none; touch-action: none; user-select: none; -webkit-user-select: none; }
#stage { position: absolute; inset: 0; overflow: hidden; }
#scroller { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
#content { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word; }
#content p, .pv-content p { margin: 0; }
#content .cue, .pv-content .cue { opacity: .55; font-style: italic; font-size: .6em; color: var(--cue, #7fd4ff); }
#content strong, .pv-content strong { color: var(--hl, #ffd54a); }
#content hr, .pv-content hr { border: none; border-top: 2px dashed currentColor; opacity: .3; margin: .6em 10%; }
#content .end, .pv-content .end { text-align: center; opacity: .4; font-size: .5em; padding-top: 1em; }

#guide { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid rgba(255, 59, 92, .55); pointer-events: none; z-index: 2; }
#guide .arrow { position: absolute; top: -0.75em; color: var(--accent); font-size: 22px; line-height: 1.5em; }
#guide .arrow.l { left: 6px; } #guide .arrow.r { right: 6px; }

#countdownEl { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 30vmin; font-weight: 900;
  color: #fff; background: rgba(0,0,0,.6); z-index: 5; pointer-events: none; opacity: 0; transition: opacity .2s; }
#countdownEl.on { opacity: 1; }

#progress { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255,255,255,.08); z-index: 3; }
#progressBar { height: 100%; width: 0; background: var(--accent); }

#hud { position: absolute; inset: 0; z-index: 4; pointer-events: none; transition: opacity .3s; }
#hud.idle { opacity: 0; }
#hud.idle * { pointer-events: none !important; }
.hud-top, .hud-bottom { pointer-events: auto; position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 12px;
  background: linear-gradient(rgba(0,0,0,.85), rgba(0,0,0,0)); color: #fff; }
.hud-top { top: 0; justify-content: space-between; padding-top: max(12px, env(safe-area-inset-top)); }
.hud-bottom { bottom: 0; justify-content: center; flex-wrap: wrap; background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.9));
  padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.hud-right { display: flex; gap: 8px; }
.hud-time { font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 600; opacity: .9; }
.hud-group { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.08); border-radius: 14px; padding: 4px; }
.hud-val { min-width: 74px; text-align: center; line-height: 1.1; }
.hud-val small { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; opacity: .6; }
.hud-val b { font-size: 18px; font-variant-numeric: tabular-nums; }
.hbtn { min-width: 52px; height: 52px; padding: 0 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,.18); background: rgba(30,30,40,.85);
  font-size: 20px; font-weight: 700; color: #fff; }
.hbtn.on { background: var(--accent); border-color: var(--accent); }
.hbtn:active { transform: scale(.95); }
.hbtn.play { width: 76px; height: 76px; border-radius: 50%; font-size: 30px; background: var(--accent); border-color: var(--accent); }

#toast { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0,0,0,.8); color: #fff; padding: 12px 22px;
  border-radius: 12px; font-size: 22px; font-weight: 700; z-index: 6; opacity: 0; transition: opacity .25s; pointer-events: none; }
#toast.on { opacity: 1; }

@media (max-width: 600px) {
  .hbtn { min-width: 44px; height: 44px; padding: 0 10px; font-size: 17px; }
  .hbtn.play { width: 60px; height: 60px; }
  .hud-val { min-width: 56px; }
}
