:root {
  --font-size: 40px;
  --band-lines: 3;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  color: #f5f5f7;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body { position: fixed; inset: 0; }

[hidden] { display: none !important; }

/* Live preview: fills the screen, mirrored like a mirror. CSS only. */
#preview,
.preview {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #000;
  z-index: 0;
}

/* Wake lock fallback video: present and playable, but invisible. */
.keep-awake {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 2px;
  height: 2px;
  opacity: 0.01;
  pointer-events: none;
  z-index: -1;
}

.tap-layer {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: none;
}
body.state-running .tap-layer,
body.state-paused .tap-layer { display: block; }

/* Script band: immediately below the camera cutout. */
.band {
  position: fixed;
  top: max(env(safe-area-inset-top, 0px), 12px);
  left: 0;
  right: 0;
  padding: 4px calc(16px + env(safe-area-inset-right, 0px)) 8px calc(16px + env(safe-area-inset-left, 0px));
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.78), rgba(0, 0, 0, 0.55));
  pointer-events: none;
  z-index: 3;
  visibility: hidden;
}
body.state-countdown .band,
body.state-running .band,
body.state-paused .band { visibility: visible; }

.band-viewport {
  position: relative;
  height: calc(var(--font-size) * 1.25 * var(--band-lines));
  max-height: 40vh;
  max-height: 40dvh;
  overflow: hidden;
}

.band-text {
  font-size: var(--font-size);
  line-height: 1.25;
  font-weight: 600;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  will-change: transform;
  transform: translate3d(0, 0, 0);
}

.countdown {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40vmin;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 6;
}

.notice {
  position: fixed;
  left: calc(16px + env(safe-area-inset-left, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  top: 42%;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(28, 28, 30, 0.94);
  color: #fff;
  font-size: 16px;
  line-height: 1.35;
  text-align: center;
  z-index: 8;
  pointer-events: none;
}

/* Editor sheet: lower part of the screen, above the home indicator, never over the band area. */
.sheet {
  position: fixed;
  left: env(safe-area-inset-left, 0px);
  right: env(safe-area-inset-right, 0px);
  bottom: 0;
  max-height: 64vh;
  max-height: min(64dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 96px));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  background: rgba(18, 18, 20, 0.9);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-radius: 18px 18px 0 0;
  z-index: 4;
}
body:not(.state-idle) .sheet { display: none; }

.title { margin: 0 0 8px; font-size: 20px; font-weight: 700; }

.field { display: block; margin: 10px 0; }
.field-label { display: flex; justify-content: space-between; font-size: 14px; color: #c7c7cc; margin-bottom: 6px; }
output { color: #fff; font-variant-numeric: tabular-nums; }

textarea {
  width: 100%;
  min-height: 110px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #3a3a3c;
  background: #000;
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  resize: vertical;
}

input[type="range"] { width: 100%; accent-color: #ffd60a; min-height: 32px; }

.actions { display: flex; gap: 10px; margin-top: 12px; }
.actions .btn { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 12px;
  background: #3a3a3c;
  color: #fff;
  font-family: inherit;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:disabled { opacity: 0.45; }
.btn-primary { background: #ffd60a; color: #000; }
.btn-stop { background: #e5383b; }
.btn-big { min-height: 56px; font-size: 19px; flex: 1; }
.btn-link { background: transparent; color: #c7c7cc; font-weight: 500; font-size: 15px; width: 100%; margin-top: 6px; }

.fineprint { margin: 6px 0 0; font-size: 12px; color: #8e8e93; text-align: center; }

.message {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(229, 56, 59, 0.18);
  border: 1px solid rgba(229, 56, 59, 0.6);
  font-size: 15px;
  line-height: 1.35;
}
.message p { margin: 0 0 8px; }
.message p:last-child { margin-bottom: 0; }

.frame-msg {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 30%;
  z-index: 9;
  background: #1c1c1e;
}

/* Run and done bars: lower safe area. */
.bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px calc(16px + env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
  z-index: 5;
}
.bar-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.bar-row:first-child { margin-top: 0; }
.mini-label { font-size: 13px; color: #e5e5ea; white-space: nowrap; min-width: 84px; }
.done-title { margin: 0 0 4px; font-weight: 600; text-align: center; }
#doneBar .btn:not(.btn-big) { width: 100%; margin-top: 8px; }
body.state-countdown #pause,
body.state-countdown #runSpeed,
body.state-countdown .mini-label { visibility: hidden; }

.rec {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font-weight: 700;
  font-size: 14px;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #ff3b30; animation: blink 1s steps(2, start) infinite; }
.rec.paused .rec-dot { animation: none; opacity: 0.5; }
@keyframes blink { to { visibility: hidden; } }

.tag, .run-note {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 13px;
}
.tag { background: rgba(255, 214, 10, 0.85); color: #000; font-weight: 700; }
