:root {
  --bg: #000;
  --fg: #fff;
  --muted: #a1a1aa;
  --panel: rgba(24, 24, 27, 0.92);
  --line: rgba(255, 255, 255, 0.14);
  --accent: #ff3b30;
  --primary: #0a84ff;
  --font-size: 32px;
  --band: 45%;
  --band-bg: 0.55;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

#app {
  position: fixed;
  inset: 0;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Камера ---------- */
#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
#preview.mirrored { transform: scaleX(-1); }
#preview.fit { object-fit: contain; }

/* ---------- Суфлёр ---------- */
#prompter {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--band) + var(--safe-t));
  padding: var(--safe-t) calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l));
  background: rgba(0, 0, 0, var(--band-bg));
  overflow: hidden;
  touch-action: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 calc(var(--safe-t) + 12px), #000 85%, transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 calc(var(--safe-t) + 12px), #000 85%, transparent 100%);
}

#prompterText {
  font-size: var(--font-size);
  line-height: 1.35;
  font-weight: 600;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  will-change: transform;
  max-width: 40em;
  margin: 0 auto;
}
#prompterText p { margin: 0 0 0.6em; }

/* линия чтения: чуть ниже верхнего края блока, т.е. близко к камере */
#readingLine {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--safe-t) + var(--reading-offset, 40px));
  height: 0;
  border-top: 2px solid rgba(255, 59, 48, 0.55);
  pointer-events: none;
}
#readingLine::before {
  content: "";
  position: absolute;
  left: 4px;
  top: -8px;
  border: 7px solid transparent;
  border-left: 10px solid rgba(255, 59, 48, 0.8);
}

#prompterPaused {
  position: absolute;
  right: calc(12px + var(--safe-r));
  bottom: 10px;
  font-size: 14px;
  opacity: 0.6;
  pointer-events: none;
}
#app.playing #prompterPaused { display: none; }

/* ---------- Индикаторы ---------- */
#recBadge {
  position: absolute;
  top: calc(var(--band) + var(--safe-t) + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
#recBadge .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 160px;
  font-weight: 700;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(190px + var(--safe-b));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--panel);
  text-align: center;
  z-index: 50;
}

/* ---------- Панель управления ---------- */
#controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px calc(16px + var(--safe-r)) calc(14px + var(--safe-b)) calc(16px + var(--safe-l));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#controls .row { display: flex; align-items: center; justify-content: center; }
#controls .speed { gap: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
#controls .main { justify-content: space-between; max-width: 420px; width: 100%; margin: 0 auto; }

.pill {
  width: 44px; height: 36px;
  border: 0; border-radius: 18px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 22px; line-height: 1;
}
.round {
  width: 48px; height: 48px;
  border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex; align-items: center; justify-content: center;
}
.round svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
#btnPlay svg { fill: #fff; }
#btnPlay .i-pause { display: none; }
#app.playing #btnPlay .i-play { display: none; }
#app.playing #btnPlay .i-pause { display: block; }

#btnRecord {
  width: 76px; height: 76px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: transparent;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
}
#btnRecord span {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--accent);
  transition: all 0.2s ease;
}
#app.recording #btnRecord span { width: 30px; height: 30px; border-radius: 6px; }
#app.recording #btnEdit,
#app.recording #btnFlip { visibility: hidden; }
#app.counting #btnRecord span { opacity: 0.5; }

/* ---------- Экраны ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: #000;
  display: flex;
  flex-direction: column;
  padding: calc(20px + var(--safe-t)) calc(16px + var(--safe-r)) calc(20px + var(--safe-b)) calc(16px + var(--safe-l));
}

#start { align-items: center; justify-content: center; text-align: center; gap: 14px; }
#start h1 { margin: 0; font-size: 34px; }
#start p { margin: 0 0 12px; color: var(--muted); }

.primary, .secondary, .danger {
  min-height: 50px;
  padding: 0 24px;
  border: 0;
  border-radius: 14px;
  font-weight: 600;
  width: 100%;
  max-width: 360px;
}
.primary { background: var(--primary); }
.secondary { background: rgba(255, 255, 255, 0.14); }
.danger { background: transparent; color: var(--accent); }
.primary.small { min-height: 36px; width: auto; padding: 0 16px; border-radius: 10px; }

.error { color: #ff6961 !important; max-width: 360px; }
.info { color: var(--muted); font-size: 13px; text-align: center; margin: 8px 0; }

/* ---------- Редактор ---------- */
.sheet { background: #111; padding-left: 0; padding-right: 0; padding-bottom: 0; }
.sheet header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 calc(16px + var(--safe-r)) 12px calc(16px + var(--safe-l));
  border-bottom: 1px solid var(--line);
}
.sheet h2 { margin: 0; font-size: 18px; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
  display: flex; flex-direction: column; gap: 16px;
  -webkit-user-select: text; user-select: text;
}
#scriptInput {
  width: 100%;
  min-height: 40vh;
  resize: vertical;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #000;
  font-size: 16px; /* >=16px, иначе iOS зумит при фокусе */
  line-height: 1.45;
}
.file {
  align-self: flex-start;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 14px;
}
.file input { display: none; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { display: flex; justify-content: space-between; }
.field output { color: var(--muted); font-variant-numeric: tabular-nums; }
.field input[type=range] { width: 100%; accent-color: var(--primary); }
.field select {
  min-height: 40px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--line); background: #000; font-size: 16px;
}
.check { display: flex; gap: 10px; align-items: center; }
.check input { width: 22px; height: 22px; accent-color: var(--primary); }

/* ---------- Просмотр ---------- */
#review { gap: 12px; align-items: center; }
#reviewVideo { flex: 1; min-height: 0; width: 100%; background: #000; border-radius: 12px; }
.review-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; align-items: center; }
