:root {
  color-scheme: dark;
  --accent: #17736d;
  --accent-strong: #1e8f88;
  --danger: #e0574a;
  --ink: #f4f4f2;
  --muted: rgba(244, 244, 242, 0.62);
  --line: rgba(255, 255, 255, 0.16);
  --surface: rgba(18, 18, 18, 0.96);
  --surface-soft: rgba(255, 255, 255, 0.07);
  --radius: 10px;
  --bar-height: 138px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: #050505;
  color: var(--ink);
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* -------------------------------------------------------------- the stage */

.stage-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--prompt-bg, #050505);
  color: var(--prompt-text, #ffffff);
}

.top-bar {
  position: relative;
  z-index: 4;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top, 0px)) 12px 10px;
}

.stage-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.85;
}

.ghost-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: inherit;
  font-size: 0.82rem;
  font-weight: 800;
}

.ghost-button.accent {
  background: var(--accent);
  border-color: transparent;
  color: #ffffff;
}

.ghost-button.danger {
  color: var(--danger);
  border-color: rgba(224, 87, 74, 0.42);
}

.accent-button {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.glyph-stack {
  display: inline-grid;
  gap: 3px;
  width: 15px;
}

.glyph-stack i {
  display: block;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
}

.teleprompter-stage {
  position: relative;
  z-index: 3;
  flex: 1;
  overflow: auto;
  margin: 0 auto;
  scrollbar-width: none;
}

.teleprompter-stage::-webkit-scrollbar {
  display: none;
}

.teleprompter-stage article {
  margin: 0 auto;
  padding: 26vh 20px 46vh;
  white-space: pre-wrap;
  line-height: 1.7;
  font-weight: 800;
  font-size: clamp(24px, var(--prompt-font-size, 56px), 4000px);
}

.teleprompter-stage.mirrored article {
  transform: scaleX(-1);
}

.width-narrow { width: min(720px, 100%); }
.width-wide   { width: min(1080px, 100%); }
.width-max    { width: 100%; }
.height-high  { min-height: 0; }
.height-low   { max-height: 62vh; }

.family-system article { font-family: Inter, "Segoe UI", Arial, sans-serif; }
.family-display article { font-family: Impact, "Arial Black", sans-serif; font-weight: 900; }
.family-mono article { font-family: Consolas, "Courier New", monospace; }

.bionic-word { font-weight: 500; }
.bionic-word strong { font-weight: 950; }

/* Themes drive the stage and seed the colour pickers. */
.theme-black  { --prompt-bg: #050505; --prompt-text: #ffffff; }
.theme-white  { --prompt-bg: #f7f7f7; --prompt-text: #101010; }
.theme-yellow { --prompt-bg: #050505; --prompt-text: #f5df4d; }

/* ---------------------------------------------------------- control bar */

.control-bar {
  position: relative;
  z-index: 4;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "transport scrub"
    "tools     tools"
    "record    record";
  align-items: center;
  gap: 10px 14px;
  padding: 12px 14px calc(22px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.74) 38%);
}

.transport {
  grid-area: transport;
  display: flex;
  align-items: center;
  gap: 10px;
}

.play-button {
  width: 52px;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #e5352b;
  display: grid;
  place-items: center;
}

.play-glyph {
  width: 0;
  height: 0;
  margin-left: 4px;
  border-left: 16px solid #ffffff;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
}

/* Playing swaps the triangle for a pause bar pair. */
.play-button.playing .play-glyph {
  width: 16px;
  height: 18px;
  margin-left: 0;
  border: 0;
  background: #ffffff;
  clip-path: polygon(0 0, 38% 0, 38% 100%, 0 100%, 0 0, 62% 0, 100% 0, 100% 100%, 62% 100%, 62% 0);
}

.icon-button {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-soft);
  color: inherit;
  display: grid;
  place-items: center;
}

.restart-glyph {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  transform: rotate(-45deg);
}

.scrub-row {
  grid-area: scrub;
  display: flex;
  align-items: center;
}

.scrub {
  width: 100%;
  margin: 0;
}

.tool-row {
  grid-area: tools;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 28%;
  min-height: 38px;
  min-width: 74px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: inherit;
  font-size: 0.78rem;
  font-weight: 800;
}

.tool-button.active {
  background: var(--accent);
  border-color: transparent;
  color: #ffffff;
}

.record-row {
  grid-area: record;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-top: 4px;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e5352b;
  animation: rec-pulse 1.1s ease-in-out infinite;
}

.rec-dot[hidden] { display: none; }

@keyframes rec-pulse {
  50% { opacity: 0.2; }
}

.rec-timer {
  min-width: 52px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85);
}

.record-button {
  width: 60px;
  height: 60px;
  padding: 0;
  border: 4px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  display: grid;
  place-items: center;
}

.record-glyph {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e5352b;
  transition: width 150ms ease, height 150ms ease, border-radius 150ms ease;
}

.record-button.recording .record-glyph {
  width: 22px;
  height: 22px;
  border-radius: 5px;
}

.round-button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  color: #ffffff;
  font-size: 0.76rem;
  font-weight: 800;
}

.round-button[hidden] { display: none; }

.round-button.active {
  background: rgba(255, 255, 255, 0.92);
  border-color: transparent;
  color: #101010;
}

@media (prefers-reduced-motion: reduce) {
  .rec-dot { animation: none; }
  .record-glyph { transition: none; }
}

/* -------------------------------------------------------------- popovers */

.popover {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(var(--bar-height) + env(safe-area-inset-bottom, 0px));
  z-index: 6;
  max-height: 46vh;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.popover[hidden] { display: none; }

.popover-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  align-items: start;
}

.popover-grid > * { min-width: 0; }

.wide-row { grid-column: 1 / -1; }

fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.range-row > span {
  width: 100%;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chip {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: rgba(255, 255, 255, 0.86);
  font-size: 0.78rem;
  font-weight: 800;
}

.chip[hidden] { display: none; }

.chip.active {
  background: #ffffff;
  border-color: transparent;
  color: #101010;
}

.range-row {
  display: grid;
  gap: 6px;
}

.number-slider {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  gap: 8px;
  align-items: center;
}

.number-slider input[type="number"] {
  min-height: 34px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-weight: 900;
  text-align: center;
}

input[type="range"] {
  width: 100%;
  padding: 0;
  accent-color: var(--accent-strong);
}

input[type="color"] {
  width: 100%;
  min-height: 36px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.range-row output {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.5;
}

.theme-dot {
  width: 34px;
  height: 34px;
  border: 2px solid transparent;
  border-radius: 50%;
}

.theme-dot.active {
  border-color: var(--accent-strong);
  outline: 2px solid rgba(255, 255, 255, 0.5);
}

.theme-black-dot { background: #050505; }
.theme-white-dot { background: #ffffff; }
.theme-yellow-dot { background: #f5df4d; }

/* ---------------------------------------------------------- camera layer */

.camera-only { display: none; }
body.has-native-camera .camera-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
body.has-native-camera fieldset.camera-only { display: flex; }
body.has-native-camera .record-row.camera-only { display: flex; }
body.has-native-camera .record-row.camera-only[hidden] { display: none; }

/* With the camera live the WebView itself is transparent, so no layer above
   the preview may paint an opaque background. */
html.camera-live,
body.camera-live,
body.camera-live .stage-shell {
  background: transparent;
}

body.camera-live .teleprompter-stage article {
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.9), 0 0 3px rgba(0, 0, 0, 0.95);
}

body.camera-live .top-bar {
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0));
}

.stage-shell.hide-script .teleprompter-stage { visibility: hidden; }

.stage-shell.clean-view .top-bar,
.stage-shell.clean-view .tool-row,
.stage-shell.clean-view .scrub-row,
.stage-shell.clean-view .transport {
  display: none;
}

.stage-shell.clean-view .control-bar { background: none; }

.show-chrome-button {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 0px));
  right: 12px;
  z-index: 5;
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #ffffff;
  font-size: 0.76rem;
  font-weight: 800;
}

.show-chrome-button[hidden] { display: none; }

/* ----------------------------------------------------------- frame guide */

.frame-guide {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.frame-guide[hidden] { display: none; }

.frame-guide-box {
  position: relative;
  height: 100%;
  max-width: 100%;
  aspect-ratio: var(--guide-ratio, 9 / 16);
  border: 2px dashed rgba(255, 255, 255, 0.72);
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.34);
}

.frame-guide-label {
  position: absolute;
  bottom: calc(var(--guide-safe, 20%) + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
}

.frame-guide-safe {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: var(--guide-safe, 20%);
  border-top: 1px dashed rgba(255, 122, 122, 0.9);
  border-radius: 0 0 8px 8px;
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 80, 80, 0.13) 0 8px,
    rgba(255, 80, 80, 0.03) 8px 16px
  );
}

/* --------------------------------------------------- overlays and drawer */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 18;
  background: rgba(0, 0, 0, 0.55);
}

.scrim[hidden] { display: none; }

.editor-overlay,
.library-drawer {
  position: fixed;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #0d0d0d;
  color: var(--ink);
}

.editor-overlay[hidden],
.library-drawer[hidden] { display: none; }

.editor-overlay {
  inset: 0;
  padding: max(12px, env(safe-area-inset-top, 0px)) 14px calc(14px + env(safe-area-inset-bottom, 0px));
}

.library-drawer {
  top: 0;
  bottom: 0;
  left: 0;
  width: min(420px, 88vw);
  padding: max(12px, env(safe-area-inset-top, 0px)) 14px calc(14px + env(safe-area-inset-bottom, 0px));
  border-right: 1px solid var(--line);
  overflow: auto;
}

.overlay-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.title-input {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 900;
  outline: none;
}

.script-editor {
  flex: 1;
  min-height: 180px;
  width: 100%;
  resize: none;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  line-height: 1.75;
  font-size: 1rem;
  outline: none;
}

.editor-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.editor-meta label,
.search-box {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.76rem;
}

.editor-meta select,
.editor-meta input,
.search-box input {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  outline: none;
}

.editor-meta select:focus,
.editor-meta input:focus,
.search-box input:focus,
.script-editor:focus {
  border-color: var(--accent-strong);
}

.insight-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.insight-bar div,
.stats-grid div {
  flex: 1 1 92px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
}

.insight-bar strong,
.stats-grid strong {
  display: block;
  font-size: 1.05rem;
}

.insight-bar span,
.stats-grid span {
  color: var(--muted);
  font-size: 0.74rem;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.filter-row .chip {
  padding: 0 8px;
  justify-content: center;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.script-list {
  display: grid;
  gap: 8px;
  align-content: start;
}

.script-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  text-align: left;
}

.script-card.active { border-color: var(--accent-strong); }

.script-card h3 { margin: 0 0 6px; font-size: 0.95rem; }

.script-card p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 800;
}

.empty-state {
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty-state h2 { margin: 0 0 6px; color: var(--ink); font-size: 1rem; }
.empty-state p { margin: 0; font-size: 0.84rem; }

.utility-links {
  display: flex;
  gap: 12px;
  font-size: 0.78rem;
}

.utility-links a {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

/* -------------------------------------------------- share sheet and toast */

.share-sheet {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 40;
  display: grid;
  gap: 12px;
  width: min(520px, calc(100% - 24px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(14, 14, 14, 0.97);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

.share-sheet[hidden] { display: none; }

.share-head { display: grid; gap: 4px; }
.share-head strong { font-size: 1rem; }
.share-head span { color: var(--muted); font-size: 0.78rem; }

.share-targets { display: flex; flex-wrap: wrap; gap: 8px; }
.share-targets[hidden] { display: none; }

.share-target {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
}

.share-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.share-actions button { flex: 1 1 96px; justify-content: center; }

.app-toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 44;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(520px, calc(100% - 28px));
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(14, 14, 14, 0.96);
  color: #ffffff;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.45;
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.5);
}

.app-toast[hidden] { display: none; }

.toast-action {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 900;
}

.toast-action[hidden] { display: none; }

/* ----------------------------------------------------------- wide screens */

@media (min-width: 820px) {
  :root { --bar-height: 118px; }

  .control-bar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "transport scrub tools"
      "record    record record";
  }

  .tool-row { flex-wrap: nowrap; }
  .tool-button { flex: 0 0 auto; }

  .popover {
    left: auto;
    right: 14px;
    width: min(560px, calc(100% - 28px));
  }
}
