/* Суфлёр — стили. Внешний файл, без inline-стилей: под CSP style-src 'self'. */

:root {
  --bg: #0e0f12;
  --panel: #15171c;
  --panel-2: #1c1f26;
  --line: #2a2e37;
  --text: #e9eaee;
  --muted: #9aa0ab;
  --accent: #ffc83d;
  --accent-hover: #ffd567;
  --accent-ink: #1a1400;
  --danger: #ff7a7a;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}
body.prompting { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.btn svg, .hb svg {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #242832; border-color: #363b47; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: #1f232b; border-color: var(--line); }
.btn.danger { color: var(--danger); }
.btn.icon { width: 40px; padding: 0; }

/* ---------- редактор ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: rgba(14, 15, 18, .86);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.brand img { border-radius: 7px; }
.spacer { flex: 1; }

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start;
  max-width: 1440px; margin: 0 auto;
  padding: 20px max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.script-pane {
  display: flex; flex-direction: column; gap: 12px;
  position: sticky; top: 80px;
  height: calc(100vh - 104px); height: calc(100dvh - 104px);
  min-height: 420px;
}
.script-bar { display: flex; gap: 6px; align-items: center; }
.script-bar select {
  flex: 1 1 auto; min-width: 0; height: 40px;
  padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2);
}
.title-input {
  width: 100%; padding: 4px 2px 8px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent;
  font-size: 22px; font-weight: 650; letter-spacing: .1px;
}
.title-input:focus { outline: none; border-bottom-color: var(--accent); }
.title-input::placeholder, textarea::placeholder { color: #5f6571; }
#textInput {
  flex: 1; width: 100%; min-height: 240px; resize: none;
  padding: 18px 20px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--panel);
  font-size: 17px; line-height: 1.65;
}
#textInput:focus { outline: none; border-color: #4a4f5c; }
#textInput.drop { border-color: var(--accent); background: #1a1a14; }
.stats { color: var(--muted); font-size: 13.5px; min-height: 20px; font-variant-numeric: tabular-nums; }
.stats b { color: var(--text); font-weight: 600; }

/* ---------- панель настроек (живёт и в редакторе, и в выдвижной панели суфлёра) ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 4px 18px 10px; }
.group + .group { border-top: 1px solid var(--line); }
.group h3 { margin: 16px 0 4px; font-size: 12px; font-weight: 650; letter-spacing: .9px; text-transform: uppercase; color: var(--muted); }
.row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 12px; padding: 9px 0; }
.row > input[type=range], .row > .seg, .row > .fit, .row > .hint { grid-column: 1 / -1; }
.row output { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; font-size: 14px; }
.hint { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.45; }

input[type=range] { width: 100%; margin: 6px 0 0; accent-color: var(--accent); height: 22px; cursor: pointer; }

.fit { display: flex; gap: 8px; }
.fit input {
  width: 96px; flex: none; height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); font-variant-numeric: tabular-nums;
}
.fit input:focus { outline: none; border-color: var(--accent); }
.fit .btn { flex: 1; }

.seg { display: flex; gap: 3px; padding: 3px; border-radius: 11px; background: var(--panel-2); border: 1px solid var(--line); }
.seg button {
  flex: 1 1 0; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 4px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 13px; cursor: pointer; line-height: 1.2;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: #2d323d; color: var(--text); box-shadow: inset 0 0 0 1px #3a404c; }
.seg-themes { flex-wrap: wrap; }
.seg-themes button { flex-basis: calc(50% - 2px); }
.swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); }
.sw-dark { background: linear-gradient(135deg, #000 50%, #f5f5f0 50%); }
.sw-amber { background: linear-gradient(135deg, #000 50%, #ffd75e 50%); }
.sw-green { background: linear-gradient(135deg, #000 50%, #8dffa6 50%); }
.sw-light { background: linear-gradient(135deg, #fff 50%, #111 50%); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; cursor: pointer; }
.switch input {
  -webkit-appearance: none; appearance: none; flex: none; margin: 0;
  position: relative; width: 44px; height: 26px; border-radius: 13px;
  background: #343945; cursor: pointer; transition: background-color .15s;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.4); transition: transform .15s;
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding-top: 14px; }
  .script-pane { position: static; height: auto; min-height: 0; }
  #textInput { flex: none; height: 55vh; height: 55dvh; resize: vertical; }
}
@media (max-width: 520px) {
  .hide-sm { display: none; }
  .topbar { gap: 4px; }
  .brand { min-width: 0; overflow: hidden; white-space: nowrap; }
  .script-bar .btn, .topbar .btn:not(.primary) { width: 40px; padding: 0; flex: none; }
  .topbar .btn.primary { padding: 0 16px; flex: none; }
  #helpBtn { display: none; } /* горячие клавиши на телефоне ни к чему */
  .panel { padding: 2px 14px 8px; }
}

/* ---------- суфлёр ---------- */
#prompter {
  --p-bg: #000; --p-bg-rgb: 0 0 0; --p-fg: #f5f5f0; --p-cue: #ff9f5a; --p-mark: #ffc83d;
  position: fixed; inset: 0; z-index: 10;
  background: var(--p-bg); color: var(--p-fg); overflow: hidden;
}
#prompter[data-theme="amber"] { --p-fg: #ffd75e; --p-cue: #7fc8ff; }
#prompter[data-theme="green"] { --p-fg: #8dffa6; --p-cue: #ffb36b; }
#prompter[data-theme="light"] { --p-bg: #fff; --p-bg-rgb: 255 255 255; --p-fg: #121212; --p-cue: #c2410c; --p-mark: #e09400; }

#stage {
  position: absolute; inset: 0; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#scroller {
  position: absolute; top: 0; left: 0; right: 0; margin: 0 auto;
  width: var(--w, 88%);
  will-change: transform;
  font-size: var(--fs, 56px); line-height: var(--lh, 1.4);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-weight: 500; letter-spacing: .005em;
  overflow-wrap: break-word; hyphens: manual;
}
#prompter[data-font="serif"] #scroller { font-family: Georgia, "Times New Roman", "PT Serif", serif; font-weight: 400; }
#prompter[data-font="mono"] #scroller { font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; font-weight: 400; letter-spacing: 0; }
#prompter[data-bold="true"] #scroller { font-weight: 700; }
#prompter[data-align="center"] #scroller { text-align: center; }
#content p { margin: 0 0 .65em; }
#content .cue { color: var(--p-cue); font-style: italic; font-weight: 400; }
#prompter[data-cues="false"] #content .cue { color: inherit; font-style: inherit; font-weight: inherit; }
#content .end-mark { margin-top: 1.2em; text-align: center; color: var(--p-mark); opacity: .7; letter-spacing: .5em; font-size: .6em; }

.dim { position: absolute; left: 0; right: 0; pointer-events: none; }
.dim-top {
  top: 0; height: calc(var(--gy) - var(--lhpx) * .5);
  background: linear-gradient(to bottom,
    rgb(var(--p-bg-rgb) / .9) 0%,
    rgb(var(--p-bg-rgb) / .6) calc(100% - var(--lhpx) * .7),
    rgb(var(--p-bg-rgb) / 0) 100%);
}
.dim-bottom {
  top: calc(var(--gy) + var(--lhpx) * .5); bottom: 0;
  background: linear-gradient(to bottom,
    rgb(var(--p-bg-rgb) / 0) 0%,
    rgb(var(--p-bg-rgb) / .35) calc(var(--lhpx) * .7),
    rgb(var(--p-bg-rgb) / .7) 100%);
}
#prompter[data-dim="false"] .dim { display: none; }

.marks { position: absolute; left: 0; right: 0; top: var(--gy); height: 0; pointer-events: none; }
.mark {
  position: absolute; top: calc(var(--mk) * -.5); width: calc(var(--mk) * .8); height: var(--mk);
  background: var(--p-mark);
}
.mark-l { left: max(6px, calc((100% - var(--w)) / 2 - var(--mk) * .8 - 14px)); clip-path: polygon(0 0, 100% 50%, 0 100%); }
.mark-r { right: max(6px, calc((100% - var(--w)) / 2 - var(--mk) * .8 - 14px)); clip-path: polygon(100% 0, 0 50%, 100% 100%); }
#prompter[data-marks="false"] .marks { display: none; }

#countdown {
  position: absolute; left: 0; right: 0; top: var(--gy); transform: translateY(-50%);
  text-align: center; pointer-events: none;
  font: 800 min(38vw, 38vh)/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--p-mark); font-variant-numeric: tabular-nums;
  text-shadow: 0 0 40px rgb(var(--p-bg-rgb) / .9);
}
#countdown.pop { animation: pop .9s ease-out both; }
@keyframes pop { from { opacity: 0; scale: 1.25; } 25% { opacity: 1; scale: 1; } to { opacity: .85; scale: .96; } }

#progress { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: rgb(128 128 128 / .2); pointer-events: none; }
#progressFill { height: 100%; background: var(--p-mark); transform-origin: 0 50%; transform: scaleX(0); }

#hud {
  position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 6px;
  width: max-content; max-width: calc(100vw - 20px); padding: 6px;
  border-radius: 16px; color: #eceef2;
  background: rgba(18, 20, 25, .88);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,.08); box-shadow: 0 10px 40px rgba(0,0,0,.45);
  transition: opacity .3s, transform .3s; z-index: 2;
}
.hud-group { display: flex; align-items: center; gap: 2px; }
.hud-group + .hud-group { padding-left: 6px; border-left: 1px solid rgba(255,255,255,.1); }
.hb {
  height: 42px; min-width: 42px; padding: 0 8px; border: 0; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: inherit; cursor: pointer; font-size: 17px; font-weight: 650;
}
.hb:hover { background: rgba(255,255,255,.09); }
.hb:active { background: rgba(255,255,255,.14); }
.hb.play { min-width: 54px; background: var(--accent); color: var(--accent-ink); }
.hb.play:hover { background: var(--accent-hover); }
.hb[aria-pressed="true"] { color: var(--accent); background: rgba(255, 200, 61, .12); }
.hb sup { font-size: .62em; margin-left: 1px; }
.hud-val { min-width: 72px; text-align: center; font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.05; }
.hud-val small { display: block; font-size: 10.5px; font-weight: 500; color: #9aa0ab; }
.hud-val.narrow { min-width: 44px; }
.hud-time { padding: 0 10px; font-size: 13px; color: #aab0bb; font-variant-numeric: tabular-nums; white-space: nowrap; }

@media (max-width: 520px) {
  #hud { gap: 4px 8px; padding: 5px; }
  .hud-group + .hud-group { border-left: 0; padding-left: 0; }
  .hb { min-width: 38px; height: 40px; padding: 0 6px; }
  .hb.play { min-width: 50px; }
  .hud-val { min-width: 56px; }
  .hud-val.narrow { min-width: 32px; }
  .hud-time { padding: 0 4px; }
  #hud [data-act="help"] { display: none; }
}
#prompter.idle #hud { opacity: 0; transform: translate(-50%, 14px); pointer-events: none; }
#prompter.idle { cursor: none; }

#endCard {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3;
  padding: 22px 24px; border-radius: 18px; text-align: center; color: var(--text);
  background: rgba(18, 20, 25, .94); border: 1px solid rgba(255,255,255,.1); box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
#endCard p { margin: 0 0 16px; font-size: 20px; font-weight: 650; }
.end-actions { display: flex; gap: 10px; justify-content: center; }

#drawer {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 4;
  width: min(400px, 100vw); overflow-y: auto; overscroll-behavior: contain;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) 14px;
  background: var(--bg); color: var(--text); border-left: 1px solid var(--line);
  transform: translateX(105%); transition: transform .25s ease; visibility: hidden;
}
#prompter.drawer-open #drawer { transform: none; visibility: visible; }
/* Панель управления остаётся в видимой части экрана, слева от настроек. */
#prompter.drawer-open #hud { left: calc((100% - min(400px, 100vw)) / 2); max-width: calc(100% - min(400px, 100vw) - 20px); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px 4px; font-size: 17px; }

/* ---------- плавающее окно и низкие экраны ---------- */
.floating [data-act="fs"], .floating [data-act="help"] { display: none; }
@media (max-height: 480px) {
  #hud { gap: 2px 4px; padding: 4px; border-radius: 12px; bottom: max(8px, env(safe-area-inset-bottom)); }
  .hb { height: 34px; min-width: 34px; padding: 0 6px; font-size: 15px; }
  .hb.play { min-width: 44px; }
  .btn svg, .hb svg { width: 18px; height: 18px; }
  .hud-group + .hud-group { padding-left: 4px; }
  .hud-val { min-width: 56px; font-size: 14px; }
  .hud-val.narrow { min-width: 36px; }
  .hud-time { display: none; }
  #endCard { padding: 14px 16px; }
  #endCard p { margin-bottom: 10px; font-size: 17px; }
}
@media (max-height: 480px) and (max-width: 640px) {
  .hud-group:has([data-act="smaller"]) { display: none; }
}

/* ---------- панель видео-окошка (телефоны, Safari) ---------- */
#pipBar {
  position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 30;
  display: flex; align-items: center; gap: 10px; padding: 8px;
  width: max-content; max-width: calc(100vw - 16px);
  border-radius: 16px; color: #eceef2;
  background: #121419; border: 1px solid #2a2e37; box-shadow: 0 12px 40px rgba(0,0,0,.6);
  transform: translate(-50%, calc(100% + 40px)); transition: transform .25s ease;
}
body.pip-on #pipBar { transform: translate(-50%, 0); }
body.pip-on .layout { padding-bottom: 150px; }
.pip-preview { position: relative; flex: none; width: 112px; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: #000; }
.pip-preview canvas, .pip-preview video { position: absolute; inset: 0; width: 100%; height: 100%; }
/* Сверху canvas: в режиме PiP браузер рисует в самом <video> заглушку. */
.pip-preview canvas { z-index: 1; }
.pip-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.pip-group { display: flex; align-items: center; gap: 2px; }
@media (max-width: 520px) {
  #pipBar { gap: 6px; padding: 6px; }
  .pip-preview { width: 84px; }
  #pipBar .hb { min-width: 36px; height: 38px; padding: 0 5px; }
  #pipBar .hb.play { min-width: 46px; }
  #pipBar .hud-val { min-width: 50px; }
}

/* ---------- общие оверлеи ---------- */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); overflow: auto;
  padding: 18px 22px 20px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
dialog::backdrop { background: rgba(0,0,0,.55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 19px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 9px 16px; margin: 14px 0; align-items: baseline; }
.keys dt { color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.keys dd { margin: 0; }
kbd {
  display: inline-block; min-width: 22px; padding: 1px 6px; border-radius: 6px; text-align: center;
  font: 600 12.5px/1.5 ui-monospace, "SF Mono", Menlo, monospace; color: var(--text);
  background: #262a33; border: 1px solid #3a3f4a; border-bottom-width: 2px;
}
@media (max-width: 520px) { .keys { grid-template-columns: 1fr; gap: 2px; } .keys dd { margin-bottom: 8px; } }

#toast {
  position: fixed; left: 50%; top: max(16px, env(safe-area-inset-top)); z-index: 50;
  transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  padding: 9px 16px; border-radius: 12px; font-weight: 600; font-size: 14.5px;
  background: rgba(28, 31, 38, .95); color: #fff; border: 1px solid rgba(255,255,255,.1);
  box-shadow: 0 10px 30px rgba(0,0,0,.4); transition: opacity .2s, transform .2s;
  font-variant-numeric: tabular-nums; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#updateBar {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 14px; padding: 8px 8px 8px 18px; border-radius: 14px;
  background: var(--panel-2); border: 1px solid var(--line); box-shadow: 0 12px 40px rgba(0,0,0,.5); white-space: nowrap;
}
body.prompting #updateBar { display: none; }

@media (prefers-reduced-motion: reduce) {
  #countdown.pop { animation: none; }
  #hud, #drawer, #toast { transition: none; }
}
