/* Promptmatics — dark-first broadcast teleprompter.
   Design tokens ported verbatim (oklch) from design-reference/lovable/styles.css. */

:root {
  --radius: 0.5rem;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);

  --background: oklch(0.155 0.008 265);
  --foreground: oklch(0.95 0.005 265);
  --panel: oklch(0.195 0.009 265);
  --card: oklch(0.205 0.009 265);
  --card-foreground: oklch(0.95 0.005 265);
  --popover: oklch(0.205 0.009 265);
  --popover-foreground: oklch(0.95 0.005 265);

  --primary: oklch(0.8 0.15 78);
  --primary-foreground: oklch(0.19 0.02 78);
  --secondary: oklch(0.26 0.01 265);
  --secondary-foreground: oklch(0.93 0.005 265);
  --muted: oklch(0.24 0.009 265);
  --muted-foreground: oklch(0.66 0.012 265);
  --accent: oklch(0.28 0.012 265);
  --accent-foreground: oklch(0.95 0.005 265);
  --destructive: oklch(0.62 0.2 25);
  --destructive-foreground: oklch(0.97 0.01 25);
  --border: oklch(0.3 0.01 265);
  --input: oklch(0.3 0.01 265);
  --ring: oklch(0.8 0.15 78);

  /* prompter stage */
  --stage: oklch(0.115 0.006 265);
  --ahead: oklch(0.97 0.003 265);
  --read: oklch(0.42 0.008 265);
  --current: oklch(0.86 0.14 78);
  --cue: oklch(0.62 0.06 200);
  --tally: oklch(0.63 0.22 25);
  --signal: oklch(0.79 0.13 178);
  --hold: oklch(0.74 0.14 300);

  --sidebar: oklch(0.185 0.009 265);
  --sidebar-foreground: oklch(0.93 0.005 265);
  --sidebar-primary: oklch(0.8 0.15 78);
  --sidebar-primary-foreground: oklch(0.19 0.02 78);
  --sidebar-accent: oklch(0.26 0.01 265);
  --sidebar-accent-foreground: oklch(0.95 0.005 265);
  --sidebar-border: oklch(0.3 0.01 265);
  --sidebar-ring: oklch(0.8 0.15 78);

  --shadow-panel: 0 24px 60px -24px oklch(0 0 0 / 0.8);
  --gradient-veil: linear-gradient(
    to bottom,
    var(--stage) 0%,
    color-mix(in oklab, var(--stage) 70%, transparent) 42%,
    transparent 100%
  );

  --font-sans: "Inter Tight", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  --font-serif: "Source Serif 4", Georgia, serif;
  --font-mono: "JetBrains Mono", Consolas, ui-monospace, monospace;

  /* prompter display settings (driven by JS) */
  --fs: 44px;
  --lh: 1.55;
  --margin: 10%;
  --script-font: var(--font-sans);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

::selection { background: color-mix(in oklab, var(--primary) 35%, transparent); }

button { font-family: inherit; }

* { scrollbar-width: thin; scrollbar-color: var(--secondary) transparent; }

/* The hidden attribute must always win, even over explicit display values */
[hidden] { display: none !important; }

.icon { width: 16px; height: 16px; flex-shrink: 0; }
.icon-sm { width: 14px; height: 14px; }
.icon-xs { width: 12px; height: 12px; }
.muted { color: var(--muted-foreground); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ── Top bar ── */

#topbar {
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  background: color-mix(in oklab, var(--panel) 80%, transparent);
  backdrop-filter: blur(8px);
  padding: 10px 16px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.logo {
  width: 28px; height: 28px;
  display: block;
  border-radius: var(--radius-md);
  object-fit: cover;
}

.brand-text { line-height: 1; }
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.brand-mode {
  margin-top: 3px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.doc-title {
  margin: 0 12px;
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  color: var(--muted-foreground);
}
@media (max-width: 640px) { .doc-title { display: none; } }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--foreground);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--accent); }
.icon-btn.active { background: color-mix(in oklab, var(--primary) 15%, transparent); color: var(--primary); }

#smartBadge.active .icon { animation: tally-breathe 1.6s ease-in-out infinite; }

.primary-btn {
  margin-left: 4px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.primary-btn:hover { opacity: 0.9; }
.primary-btn .icon-sm { stroke-width: 2.5; }

/* ── State pill ── */

.state-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  background: color-mix(in oklab, var(--panel) 70%, transparent);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.state-pill .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }

.state-pill.idle { color: var(--muted-foreground); }
.state-pill.live { color: var(--tally); }
.state-pill.live .dot { animation: tally-breathe 1.6s ease-in-out infinite; }
.state-pill.paused, .state-pill.hold { color: var(--primary); }
.state-pill.adlib { color: var(--hold); }
.state-pill.cued { color: var(--signal); }

@keyframes tally-breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ── Stage ── */

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  user-select: none;
  background:
    radial-gradient(
      120% 70% at 50% 0%,
      color-mix(in oklab, var(--panel) 45%, transparent) 0%,
      transparent 65%
    ),
    var(--stage);
}

#viewport { position: absolute; inset: 0; overflow: hidden; }

#stage.mirror-h #viewport { transform: scaleX(-1); }
#stage.mirror-v #viewport { transform: scaleY(-1); }
#stage.mirror-h.mirror-v #viewport { transform: scale(-1, -1); }

#scriptRoot {
  padding: 50vh var(--margin) 70vh;
  font-family: var(--script-font);
  font-size: var(--fs);
  line-height: var(--lh);
  font-weight: 500;
  letter-spacing: -0.01em;
  will-change: transform;
}

/* ── Eyeline marker ── */

#eyeline {
  position: absolute;
  left: 0; right: 0;
  top: 42%;
  z-index: 10;
  pointer-events: none;
  display: flex;
  align-items: center;
  transform: translateY(-50%);
  color: var(--muted-foreground);
}
#eyeline[data-tone="live"] { color: var(--tally); }
#eyeline[data-tone="adlib"] { color: var(--hold); }
#eyeline[data-tone="cued"] { color: var(--signal); }

.eye-arrow {
  width: 0; height: 0;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
  filter: drop-shadow(0 0 8px currentColor);
}
.eye-arrow-left { margin-left: 12px; border-left: 13px solid currentColor; }
.eye-arrow-right { margin-right: 12px; border-right: 13px solid currentColor; }

.eye-line { position: relative; flex: 1; margin: 0 12px; height: 2px; }
.eye-line-glow { position: absolute; inset: 0; background: currentColor; filter: blur(6px); opacity: 0.5; }
.eye-line-core { position: absolute; inset: 0; background: currentColor; opacity: 0.9; }

.eye-band {
  display: none;
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 2.6rem;
  background: color-mix(in oklab, var(--primary) 6%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--primary) 15%, transparent);
}

#eyeline[data-style="line"] { color: var(--primary); }
#eyeline[data-style="line"] .eye-arrow { display: none; }
#eyeline[data-style="line"] .eye-line { margin: 0; }
#eyeline[data-style="line"] .eye-line-glow { filter: blur(4px); opacity: 0.4; }
#eyeline[data-style="line"] .eye-line-core { opacity: 0.7; }

#eyeline[data-style="band"] .eye-arrow,
#eyeline[data-style="band"] .eye-line { display: none; }
#eyeline[data-style="band"] .eye-band { display: block; }

/* ── Script text ── */

.h {
  margin: 40px 0 16px;
  font-size: max(14px, calc(var(--fs) * 0.42));
  font-weight: 600;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

#scriptRoot p { margin: 0 0 32px; }

.s {
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s;
}
.s:hover { background: color-mix(in oklab, var(--accent) 40%, transparent); }

.w {
  display: inline-block;
  margin-right: 0.28em;
  border-radius: var(--radius-sm);
  color: var(--ahead);
  transition: color 260ms ease;
}
.w.read { color: var(--read); transition: color 420ms ease, opacity 420ms ease; }
#stage.hl-word .w.now { color: var(--current); transition: color 120ms ease; }

/* Words changed by a smart rewrite — lasting subtle marker */
.w.rw {
  background-image: linear-gradient(
    to top,
    color-mix(in oklab, var(--hold) 45%, transparent) 0 2px,
    transparent 2px
  );
}

.cue {
  font-size: 0.62em;
  font-style: italic;
  color: var(--cue);
  margin-right: 0.3em;
  padding: 0 0.25em;
  border-radius: var(--radius-sm);
  vertical-align: middle;
}
#stage.hide-cues .cue { display: none; }

/* Line-by-line matching: the sentence being read carries a soft primary wash */
#stage.hl-line .s.active-line { background: color-mix(in oklab, var(--primary) 10%, transparent); }

.s.pulse { animation: pulse 1.1s ease-out; }
@keyframes pulse {
  0% { background: color-mix(in oklab, var(--signal) 30%, transparent); }
  100% { background: transparent; }
}

/* Smart mode: region below the horizon while a rewrite is in flight */
.rewriting {
  animation: rewrite-pulse 1.6s ease-in-out infinite;
  filter: saturate(0.55);
}
@keyframes rewrite-pulse {
  0%, 100% { opacity: 0.42; }
  50% { opacity: 0.78; }
}

/* Smart mode: freshly rewritten region settles in from a soft tint */
.fresh {
  border-radius: 10px;
  animation: fresh-in 2.4s ease-out;
}
@keyframes fresh-in {
  0% { background: color-mix(in oklab, var(--signal) 16%, transparent); }
  100% { background: transparent; }
}

/* ── Veils ── */

.veil-top {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 7rem;
  z-index: 15;
  pointer-events: none;
  background: var(--gradient-veil);
}
.veil-bottom {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 10rem;
  z-index: 15;
  pointer-events: none;
  background: var(--gradient-veil);
  transform: scaleY(-1);
}

/* ── HUD ── */

#hud {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  padding: 0 16px 16px;
  pointer-events: none;
}
.hud-bar {
  margin: 0 auto;
  max-width: 56rem;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  background: color-mix(in oklab, var(--panel) 80%, transparent);
  border-radius: var(--radius-xl);
  padding: 10px 16px;
  box-shadow: var(--shadow-panel);
  backdrop-filter: blur(12px);
}

.stat { display: flex; flex-direction: column; line-height: 1; }
.stat-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}
.stat-value {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--foreground);
}

.progress-wrap {
  margin-left: auto;
  flex: 1;
  min-width: 8rem;
  display: flex;
  align-items: center;
  gap: 12px;
}
.progress-track {
  height: 4px;
  flex: 1;
  border-radius: 999px;
  background: var(--secondary);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 200ms;
}
.progress-count {
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted-foreground);
}

/* ── Overlays ── */

#backBtn {
  position: absolute;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: color-mix(in oklab, var(--signal) 15%, transparent);
  color: var(--signal);
  border: 1px solid color-mix(in oklab, var(--signal) 30%, transparent);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

#countdown {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklab, var(--stage) 80%, transparent);
  backdrop-filter: blur(4px);
}
#countdownNum {
  font-family: var(--font-mono);
  font-size: 9rem;
  line-height: 1;
  font-weight: 600;
  color: var(--primary);
}
#countdownNum.pop { animation: count-pop 300ms cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes count-pop {
  from { opacity: 0; transform: scale(0.82); }
  to { opacity: 1; transform: scale(1); }
}

#toast {
  position: absolute;
  bottom: 84px;
  right: 20px;
  z-index: 25;
  background: color-mix(in oklab, var(--panel) 92%, transparent);
  color: var(--signal);
  border: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-panel);
  animation: toast-in 0.25s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; }
}

/* ── Sheets (settings / library) ── */

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgb(0 0 0 / 0.5);
}

.sheet {
  position: fixed;
  top: 0; bottom: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  box-shadow: var(--shadow-panel);
}
.sheet-right {
  right: 0;
  width: min(28rem, 100%);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  animation: sheet-in-right 0.25s ease-out;
}
.sheet-left {
  left: 0;
  width: min(48rem, 100%);
  border-right: 1px solid var(--border);
  animation: sheet-in-left 0.25s ease-out;
}
@keyframes sheet-in-right { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sheet-in-left { from { transform: translateX(-24px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  flex-shrink: 0;
}
.sheet-header.bordered { border-bottom: 1px solid color-mix(in oklab, var(--border) 60%, transparent); }
.sheet-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-right: auto;
}
.sheet-close { margin-left: 4px; color: var(--muted-foreground); }
.sheet-close:hover { color: var(--foreground); }

.sheet-body { padding: 0 20px 40px; }

.group { border-bottom: 1px solid color-mix(in oklab, var(--border) 60%, transparent); padding: 20px 0; }
.group:first-child { padding-top: 0; }
.group:last-child { border-bottom: 0; }
.group-title {
  margin-bottom: 16px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}
.group-body { display: flex; flex-direction: column; gap: 16px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.row-text { min-width: 0; }
.row-label { font-size: 14px; font-weight: 500; }
.row-hint { margin-top: 2px; font-size: 12px; color: var(--muted-foreground); }

.slider-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.slider-value {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted-foreground);
}

input[type="range"] {
  width: 100%;
  height: 16px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: var(--secondary);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin-top: -5px;
  border-radius: 999px;
  border: 0;
  background: var(--primary);
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: var(--secondary);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 999px;
  border: 0;
  background: var(--primary);
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--secondary) 50%, transparent);
  padding: 2px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.segmented button:hover { color: var(--foreground); }
.segmented button.active { background: var(--primary); color: var(--primary-foreground); }

.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--input);
  transition: background-color 0.15s;
  pointer-events: none;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 999px;
  background: var(--background);
  transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:disabled + .track { opacity: 0.4; }
.switch input:disabled { cursor: not-allowed; }

.select {
  appearance: none;
  background: color-mix(in oklab, var(--secondary) 50%, transparent);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  color: var(--foreground);
  font-family: inherit;
  font-size: 13px;
  padding: 6px 10px;
  cursor: pointer;
}
.sel-mic { width: 208px; }
.sel-matching { width: 160px; }
.sel-model { width: 176px; }
.select option { background: var(--popover); color: var(--popover-foreground); }

.matching-wrap { display: flex; align-items: center; gap: 8px; }

.preset-row { display: flex; gap: 8px; }

.btn-secondary, .btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, opacity 0.15s;
}
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.btn-secondary:hover { background: color-mix(in oklab, var(--secondary) 80%, var(--foreground) 6%); }
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover { background: var(--accent); }
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-toggle.active { background: var(--primary); color: var(--primary-foreground); }

.smart-hint {
  border: 1px solid color-mix(in oklab, var(--primary) 25%, transparent);
  background: color-mix(in oklab, var(--primary) 10%, transparent);
  color: var(--primary);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 12px;
}

/* ── API key cards ── */

.key-card {
  border: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  background: color-mix(in oklab, var(--secondary) 30%, transparent);
  border-radius: var(--radius-lg);
  padding: 12px;
}
.key-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.key-label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }

.key-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.key-chip .chip-icon { width: 12px; height: 12px; }
.key-chip.present { background: color-mix(in oklab, var(--signal) 15%, transparent); color: var(--signal); }
.key-chip.missing { background: var(--muted); color: var(--muted-foreground); }

.key-inputs { display: flex; gap: 8px; }
.key-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--foreground);
  background: transparent;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  padding: 6px 10px;
}
.key-input:focus { outline: 2px solid color-mix(in oklab, var(--ring) 50%, transparent); outline-offset: 1px; }
.key-note { margin-top: 8px; font-size: 11px; color: var(--muted-foreground); }
.key-note a {
  color: var(--signal);
  text-decoration: none;
  white-space: nowrap;
}
.key-note a:hover { text-decoration: underline; }
/* The free-credit line is the reason someone completes the setup — let it
   carry a little weight in an otherwise muted paragraph. */
.key-note-offer { color: var(--signal); font-weight: 600; }

.key-head-right { display: flex; align-items: center; gap: 8px; }
.key-edit { font-size: 12px; padding: 3px 10px; }
.key-card.collapsed .key-inputs,
.key-card.collapsed .key-note { display: none; }
.key-card.collapsed .key-head { margin-bottom: 0; }

/* ── Script library ── */

.lib-grid {
  display: grid;
  grid-template-columns: 15rem 1fr;
  flex: 1;
  min-height: 0;
}
@media (max-width: 640px) { .lib-grid { grid-template-columns: 1fr; } }

.lib-side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  border-right: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  padding: 12px;
}
.lib-actions { display: flex; gap: 8px; margin-bottom: 8px; }
.lib-new { flex: 1; justify-content: center; }

.lib-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: var(--radius-md);
  padding: 8px 10px;
  text-align: left;
  font-size: 14px;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.lib-item:hover { background: var(--accent); color: var(--foreground); }
.lib-item.active { background: color-mix(in oklab, var(--primary) 15%, transparent); color: var(--primary); }
.lib-item .lib-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lib-del {
  display: grid;
  place-items: center;
  opacity: 0;
  color: inherit;
  transition: opacity 0.15s;
}
.lib-item:hover .lib-del { opacity: 0.6; }
.lib-item .lib-del:hover { opacity: 1; }

.lib-main { display: flex; flex-direction: column; padding: 16px; min-height: 0; }

#scriptTitle {
  border: 0;
  background: transparent;
  color: var(--foreground);
  font-family: inherit;
  font-size: 18px;
  font-weight: 600;
  padding: 0;
  margin-bottom: 12px;
  outline: none;
}
#scriptTitle::placeholder { color: var(--muted-foreground); }

#scriptBody {
  flex: 1;
  min-height: 0;
  resize: none;
  background: color-mix(in oklab, var(--stage) 60%, transparent);
  border: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  border-radius: var(--radius-md);
  color: var(--foreground);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 12px;
  outline: none;
}
#scriptBody:focus { border-color: color-mix(in oklab, var(--ring) 50%, transparent); }
#scriptBody::placeholder { color: var(--muted-foreground); }

.lib-foot {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--muted-foreground);
}
.lib-note { margin-left: auto; }
.lib-note code { color: color-mix(in oklab, var(--foreground) 70%, transparent); font-family: var(--font-mono); }

/* ── Hover tooltips ──
   Styled replacement for the native title attribute on icon buttons; the
   accessible name lives on aria-label so nothing is lost to screen readers. */

[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 80;
  transform: translateX(-50%) translateY(-2px);
  border: 1px solid color-mix(in oklab, var(--border) 80%, transparent);
  border-radius: var(--radius-md);
  background: var(--popover);
  color: var(--popover-foreground);
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: var(--shadow-panel);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
}
[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  transition-delay: 250ms;
}

/* Right-cluster controls: anchor to the button's right edge so the bubble
   never runs off the viewport (body clips overflow). */
.topbar-actions [data-tip]::after,
[data-tip].sheet-close::after { left: auto; right: 0; transform: translateX(0) translateY(-2px); }
.topbar-actions [data-tip]:hover::after,
.topbar-actions [data-tip]:focus-visible::after,
[data-tip].sheet-close:hover::after,
[data-tip].sheet-close:focus-visible::after { transform: translateX(0) translateY(0); }

/* ── Onboarding: header key nudge ── */

.key-nudge {
  display: inline-flex;
  align-items: center;
  border: 1px solid color-mix(in oklab, var(--signal) 30%, transparent);
  background: color-mix(in oklab, var(--signal) 10%, transparent);
  border-radius: 999px;
  color: var(--signal);
  overflow: hidden;
}
.key-nudge-main,
.key-nudge-x {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
}
.key-nudge-main {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 5px 5px 12px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.key-nudge-x { display: grid; place-items: center; padding: 6px 9px 6px 4px; opacity: 0.65; }
.key-nudge-main:hover,
.key-nudge-x:hover { background: color-mix(in oklab, var(--signal) 20%, transparent); }
.key-nudge-x:hover { opacity: 1; }

/* The slot's other sibling: once a key is stored the nudge becomes a request
   for an opinion. Muted/secondary on purpose — it must never compete with the
   signal-coloured key nudge it replaces, or with Start. */
.fb-nudge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  background: color-mix(in oklab, var(--secondary) 40%, transparent);
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.fb-nudge:hover { background: var(--secondary); color: var(--foreground); }

/* Narrow windows: the header has no room for either chip (id beats the class). */
@media (max-width: 900px) {
  #keyChip,
  #feedbackChip { display: none; }
}

/* ── Onboarding: modal shells (welcome card + no-key dialog) ── */

.modal-scrim {
  position: fixed;
  inset: 0;
  background: color-mix(in oklab, var(--background) 80%, transparent);
  backdrop-filter: blur(4px);
}
#welcomeOverlay { z-index: 58; }
#welcomeCard { z-index: 59; }
#needKeyOverlay { z-index: 64; }
#needKeyDialog { z-index: 65; }

.modal-card,
.welcome-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow-panel);
  animation: modal-in 0.2s ease-out;
}
.modal-card {
  width: min(34rem, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
}
.welcome-card { width: min(44rem, calc(100vw - 32px)); }
.modal-card:focus-visible,
.welcome-card:focus-visible,
.tour-card:focus-visible { outline: none; }

@keyframes modal-in {
  from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

.modal-x {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.modal-x:hover { background: var(--secondary); color: var(--foreground); }
/* Disabled mid-send (the feedback modal locks it): it has to read as dead, the
   way the disabled Cancel beside it does — full colour plus a hover background
   would say "live" while the click does nothing. */
.modal-x:disabled { opacity: 0.5; cursor: not-allowed; }
.modal-x:disabled:hover { background: transparent; color: var(--muted-foreground); }

.modal-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}
.modal-eyebrow .icon-sm { color: var(--signal); }

.modal-title { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.modal-text { font-size: 16px; line-height: 1.6; color: var(--muted-foreground); }

.modal-link,
.tour-link,
.welcome-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
  font-size: 14px;
  color: var(--primary);
  text-decoration: none;
}
.modal-link:hover,
.tour-link:hover,
.welcome-link:hover { text-decoration: underline; }

/* Prose, not a readout — so it takes the 15px readability pass like every other
   instructional line. Shared atom: the welcome card, the no-key dialog and the
   tour cards all grow together, which is the point. */
.trust-line {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--muted-foreground);
}
.trust-line .icon-sm { margin-top: 2px; color: var(--signal); }

.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
/* Onboarding buttons carry instructional weight — one step up from the
   chrome-sized .btn-* default used across the settings sheet. */
.modal-actions .btn-primary,
.modal-actions .btn-secondary { height: 36px; padding: 0 14px; font-size: 14px; }

/* ── Onboarding: welcome card ── */

.welcome-body { padding: 28px 28px 24px; }
.welcome-title { margin-top: 10px; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }

.welcome-grid { margin-top: 22px; display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .welcome-grid { grid-template-columns: 1fr; } }

.welcome-tile {
  border: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  background: color-mix(in oklab, var(--secondary) 30%, transparent);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.welcome-tile.accent {
  border-color: color-mix(in oklab, var(--signal) 40%, transparent);
  background: color-mix(in oklab, var(--signal) 10%, transparent);
}
.welcome-tile-head { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 500; }
.welcome-tile .icon-sm { color: var(--primary); }
.welcome-tile.accent .icon-sm { color: var(--signal); }
.welcome-tile p { margin-top: 8px; font-size: 15px; line-height: 1.6; color: var(--muted-foreground); }
.welcome-body .trust-line { margin-top: 22px; }

.welcome-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  border-top: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  background: color-mix(in oklab, var(--secondary) 20%, transparent);
  padding: 16px 28px;
}
.welcome-foot .btn-primary,
.welcome-foot .btn-secondary,
.welcome-foot .btn-ghost { height: 36px; padding: 0 14px; font-size: 14px; }
.welcome-link { margin-left: auto; }

/* ── Onboarding: guided tour ── */

#tourRoot { position: fixed; inset: 0; z-index: 70; pointer-events: none; }

/* No spotlight target (centered step): a real scrim, dismissible by click. */
.tour-dim {
  position: absolute;
  inset: 0;
  background: color-mix(in oklab, var(--background) 80%, transparent);
  backdrop-filter: blur(4px);
  pointer-events: auto;
}

/* The spotlight IS the scrim: an inverted 9999px shadow punches the hole.
   Pass-through by design, so the highlighted control can still be used. */
.tour-spot {
  position: fixed;
  border-radius: var(--radius-lg);
  outline: 2px solid color-mix(in oklab, var(--primary) 70%, transparent);
  box-shadow: 0 0 0 9999px oklch(0 0 0 / 0.72), 0 0 26px 2px var(--primary);
  pointer-events: none;
  transition: all 300ms ease-out;
}

/* A column so a step that is genuinely taller than the window scrolls inside
   .tour-body while the footer (dots + Next) stays put. The card itself must
   never clip — the arrow hangs 7px outside it. onboarding.js sets the width
   and the viewport height budget, then measures what it actually got. */
.tour-card {
  position: fixed;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow-panel);
  animation: tour-in 0.18s ease-out;
}
@keyframes tour-in { from { opacity: 0; } to { opacity: 1; } }

.tour-arrow {
  position: absolute;
  width: 14px;
  height: 14px;
  transform: rotate(45deg);
  background: var(--panel);
  border: 1px solid var(--border);
}
.tour-arrow.up { top: -7px; border-right: 0; border-bottom: 0; }
.tour-arrow.down { bottom: -7px; border-top: 0; border-left: 0; }

.tour-x {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.tour-x:hover { background: var(--secondary); color: var(--foreground); }

.tour-body { padding: 18px 18px 14px; min-height: 0; overflow-y: auto; }
.tour-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}
.tour-eyebrow kbd {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--secondary);
  color: var(--foreground);
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: normal;
  text-transform: none;
}
.tour-title { margin-top: 8px; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.tour-text { margin-top: 8px; font-size: 15px; line-height: 1.6; color: var(--muted-foreground); }
.tour-text strong { color: var(--foreground); font-weight: 600; }
.tour-p { display: block; margin-top: 10px; }
.tour-text .tour-link,
.tour-text .trust-line { margin-top: 10px; }

.tour-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  background: color-mix(in oklab, var(--secondary) 20%, transparent);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  padding: 12px 18px;
  flex-shrink: 0;
}
.tour-dots { display: flex; align-items: center; gap: 5px; }
.tour-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--border); transition: background-color 0.15s; }
.tour-dot.on { background: var(--primary); }
.tour-skip {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--muted-foreground);
  font-size: 14px;
  padding: 6px 4px;
  cursor: pointer;
  transition: color 0.15s;
}
.tour-skip:hover { color: var(--foreground); }
.tour-foot .btn-primary,
.tour-foot .btn-secondary { height: 34px; padding: 0 14px; font-size: 14px; }

/* ── Feedback modal ──────────────────────────────────────────────────────
   Reuses the onboarding modal shell (.modal-scrim / .modal-card / .modal-x /
   .modal-eyebrow / .modal-title / .modal-text) and the shared .btn-* atoms;
   only the form itself is new. Instructional copy sits at 15px throughout,
   matching the onboarding readability pass. The numeric counter and the
   shortcut hint are readouts, not prose, and stay a step down. */

#fbOverlay { z-index: 66; }
#fbModal { z-index: 67; }

.fb-modal { width: min(36rem, calc(100vw - 32px)); }
.fb-form { display: flex; flex-direction: column; gap: 14px; }

/* A real <fieldset>: one `disabled` locks every control at once while a send
   is in flight, exactly as the design's disabled fieldset does. */
.fb-fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
  transition: opacity 0.15s;
}
.fb-fields:disabled { opacity: 0.7; }

.fb-sentiment { display: flex; align-items: center; gap: 8px; }
.fb-sent {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  border-radius: 999px;
  background: color-mix(in oklab, var(--secondary) 30%, transparent);
  color: var(--muted-foreground);
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.fb-sent:hover { color: var(--foreground); }
.fb-sent.up.on {
  border-color: color-mix(in oklab, var(--signal) 50%, transparent);
  background: color-mix(in oklab, var(--signal) 15%, transparent);
  color: var(--signal);
}
.fb-sent.down.on {
  border-color: color-mix(in oklab, var(--tally) 50%, transparent);
  background: color-mix(in oklab, var(--tally) 15%, transparent);
  color: var(--tally);
}
.fb-fields:disabled .fb-sent { cursor: default; }

.fb-field { display: flex; flex-direction: column; gap: 6px; }
.fb-label { font-size: 15px; font-weight: 500; }

.fb-textarea {
  width: 100%;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background: color-mix(in oklab, var(--secondary) 30%, transparent);
  color: var(--foreground);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.55;
  padding: 10px 12px;
  resize: none;
}
.fb-textarea::placeholder { color: var(--muted-foreground); }
.fb-textarea:focus {
  outline: 2px solid color-mix(in oklab, var(--ring) 50%, transparent);
  outline-offset: 1px;
  border-color: color-mix(in oklab, var(--ring) 50%, transparent);
}

.fb-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 15px;
  line-height: 1.4;
  color: var(--muted-foreground);
}
.fb-meta .mono { font-size: 14px; flex-shrink: 0; }

.fb-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  border-radius: var(--radius-lg);
  background: color-mix(in oklab, var(--secondary) 20%, transparent);
  padding: 12px;
  cursor: pointer;
}
.fb-check input {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: var(--primary);
  cursor: pointer;
}
.fb-check-title { display: block; font-size: 15px; font-weight: 500; }
.fb-check-note {
  display: block;
  margin-top: 3px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--muted-foreground);
}
.fb-fields:disabled .fb-check,
.fb-fields:disabled .fb-check input { cursor: default; }

/* Bot trap: out of the layout, out of the tab order, out of the a11y tree.
   Clipped rather than offset off-canvas so it can never widen the card. */
.fb-trap {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.fb-error {
  border: 1px solid color-mix(in oklab, var(--tally) 40%, transparent);
  border-radius: var(--radius-lg);
  background: color-mix(in oklab, var(--tally) 10%, transparent);
  padding: 12px;
}
.fb-error-head { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 500; }
.fb-error-head .icon-sm { color: var(--tally); }
.fb-error-text {
  margin-top: 4px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--muted-foreground);
}
.fb-error .modal-link { margin-top: 8px; }

.fb-actions { align-items: center; }
.fb-actions .btn-primary,
.fb-actions .btn-ghost { height: 36px; padding: 0 14px; font-size: 14px; }
.fb-actions .btn-primary:disabled,
.fb-actions .btn-ghost:disabled { opacity: 0.5; cursor: not-allowed; }
.fb-shortcut { margin-left: auto; font-size: 13px; color: var(--muted-foreground); }
/* Below sm the row needs its width for the two buttons (as in the design). */
@media (max-width: 640px) { .fb-shortcut { display: none; } }

.fb-spin { animation: fb-spin 0.9s linear infinite; }
@keyframes fb-spin { to { transform: rotate(360deg); } }

.fb-success { padding: 8px 0; text-align: center; }
.fb-heart {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0 auto;
  border-radius: 999px;
  background: color-mix(in oklab, var(--signal) 15%, transparent);
  color: var(--signal);
}
.fb-heart .icon-sm { width: 20px; height: 20px; }
.fb-success .modal-title { margin-top: 16px; }
.fb-success .modal-text { margin: 8px auto 0; max-width: 26rem; }
.fb-success-actions { margin-top: 20px; display: flex; justify-content: center; gap: 8px; }
.fb-success-actions .btn-primary,
.fb-success-actions .btn-ghost { height: 36px; padding: 0 14px; font-size: 14px; }
