/* ============================================================
   HERALD — style.css
   Neon-on-dark design system. Themes via [data-theme] CSS vars.
   Layers: #webcam (0) → #app (1) → #overlay (2, pointer-none)
           → #subtitle-bar/#toasts/modals (3)
   ============================================================ */

/* ---------- Themes ---------- */
:root {
  --bg: #0a0e14; --panel: #111823; --panel2: #0d1420;
  --text: #e8f6ff; --dim: #7d95ad;
  --primary: #00d4ff; --accent: #ff2d95; --good: #00e589;
  --warn: #ffdd00; --danger: #ff5566;
  --btn-bg: #0f2233; --btn-bg-hover: #15324a; --btn-border: #00d4ff;
  --btn-text: #e8f6ff;
  --btn-scale: 1; --font-scale: 1;
  --font-size-base: calc(20px * var(--font-scale));
}
[data-theme="contrast-yellow"] {
  --bg: #000; --panel: #0a0a0a; --panel2: #111;
  --text: #ffd400; --dim: #bfa100;
  --primary: #ffd400; --accent: #ffd400; --good: #aaff00;
  --warn: #fff; --danger: #ff5566;
  --btn-bg: #000; --btn-bg-hover: #221c00; --btn-border: #ffd400;
  --btn-text: #ffd400;
}
[data-theme="contrast-white"] {
  --bg: #000; --panel: #0a0a0a; --panel2: #111;
  --text: #fff; --dim: #bbb;
  --primary: #fff; --accent: #ffe066; --good: #aaff00;
  --warn: #ffe066; --danger: #ff5566;
  --btn-bg: #000; --btn-bg-hover: #1a1a1a; --btn-border: #fff;
  --btn-text: #fff;
}
[data-theme="contrast-blue"] {
  --bg: #0b1b3a; --panel: #10254d; --panel2: #0d1e3e;
  --text: #ffe066; --dim: #c7b355;
  --primary: #ffe066; --accent: #7fd4ff; --good: #aaff00;
  --warn: #fff; --danger: #ff5566;
  --btn-bg: #0e2145; --btn-bg-hover: #16305e; --btn-border: #ffe066;
  --btn-text: #ffe066;
}
[data-theme="soft-dark"] {
  --bg: #14161c; --panel: #1b1e26; --panel2: #171a21;
  --text: #d8dee9; --dim: #8a93a5;
  --primary: #89b8d6; --accent: #c792ea; --good: #9ece6a;
  --warn: #e0af68; --danger: #f7768e;
  --btn-bg: #20242e; --btn-bg-hover: #2a3040; --btn-border: #89b8d6;
  --btn-text: #d8dee9;
}

/* ---------- Reset & base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--font-size-base);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button { font-family: inherit; cursor: pointer; }
h1, h2, h3 { font-weight: 800; letter-spacing: 0.5px; }

/* ---------- Layer 0: webcam ---------- */
#webcam {
  position: fixed; inset: 0; width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: var(--webcam-opacity, 0.35);
  filter: saturate(0.55) brightness(0.7);
  pointer-events: none;
  z-index: 0;
}

/* ---------- Layer 1: app ---------- */
#app {
  position: fixed; inset: 0; z-index: 1;
  display: flex; flex-direction: column;
  min-width: 320px;
}

/* ---------- Top bar ---------- */
#top-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border-bottom: 3px solid var(--primary);
  box-shadow: 0 0 24px color-mix(in srgb, var(--primary) 25%, transparent);
  flex-wrap: wrap;
}
#logo { display: flex; align-items: center; gap: 8px; }
#logo-glyph { font-size: 30px; filter: drop-shadow(0 0 8px var(--primary)); }
#logo-text {
  font-size: 24px; font-weight: 900; letter-spacing: 3px;
  color: var(--primary);
  text-shadow: 0 0 12px var(--primary);
}
#mode-tabs { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; justify-content: center; }
.tab-btn {
  min-height: calc(62px * var(--btn-scale));
  padding: 8px 20px;
  font-size: calc(21px * var(--font-scale));
  font-weight: 800;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: 3px solid var(--btn-border);
  border-radius: 12px;
  transition: transform 0.08s, background 0.15s;
}
.tab-btn:hover { background: var(--btn-bg-hover); transform: translateY(-1px); }
.tab-btn.active {
  background: var(--primary); color: var(--bg);
  box-shadow: 0 0 18px var(--primary);
}

/* ---------- Status pills ---------- */
#status-pills { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 15px; font-weight: 700;
  padding: 6px 12px; border-radius: 999px;
  background: var(--panel2);
  border: 2px solid var(--dim);
  color: var(--dim);
  white-space: nowrap;
}
.pill.ok   { border-color: var(--good); color: var(--good); box-shadow: 0 0 10px color-mix(in srgb, var(--good) 40%, transparent); }
.pill.bad  { border-color: var(--danger); color: var(--danger); }
.pill.warn { border-color: var(--warn); color: var(--warn); }
.pill-btn { cursor: pointer; }
.pill-btn:hover { background: var(--btn-bg-hover); }

/* ---------- Stage & panes ---------- */
#stage { flex: 1; overflow: hidden; position: relative; }
.mode-pane {
  position: absolute; inset: 0;
  padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto; overflow-x: hidden;
}
.mode-pane[hidden] { display: none; }

/* ============================================================
   Dwell buttons (universal selection surface)
   ============================================================ */
.dwell-btn {
  position: relative;
  border-radius: 12px;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
.dwell-btn:focus-visible { box-shadow: 0 0 0 4px var(--warn); }
.dwell-active::after {
  content: '';
  position: absolute;
  left: 0; right: auto; bottom: 0;
  height: 7px; width: var(--dwell-progress, 0%);
  background: linear-gradient(90deg, var(--good), var(--warn));
  box-shadow: 0 0 12px var(--good);
  border-radius: 0 0 9px 9px;
  transition: width 0.05s linear;
  pointer-events: none;
  z-index: 2;
}
/* mouth is open & live → everything glows a touch, signalling "confirm armed" */
.mouth-live .dwell-active { box-shadow: 0 0 0 2px color-mix(in srgb, var(--good) 55%, transparent); }
.selected-pop {
  animation: selPop 0.35s ease;
}
@keyframes selPop {
  0% { transform: scale(1); }
  40% { transform: scale(0.96); box-shadow: 0 0 30px var(--good) !important; }
  100% { transform: scale(1); }
}

/* ============================================================
   SPEAK pane
   ============================================================ */
#pane-speak { align-items: stretch; }
#spoken-banner {
  display: flex; align-items: center; gap: 16px;
  background: var(--panel);
  border: 3px solid var(--good);
  border-radius: 16px;
  padding: 14px 22px;
  min-height: 84px;
  box-shadow: 0 0 18px color-mix(in srgb, var(--good) 25%, transparent);
}
#spoken-emoji { font-size: 44px; }
#spoken-text {
  font-size: calc(28px * var(--font-scale));
  font-weight: 800;
  overflow: hidden; text-overflow: ellipsis;
}
#phrase-tabs { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.phrase-tab {
  min-height: calc(62px * var(--btn-scale));
  padding: 6px 22px;
  font-size: calc(22px * var(--font-scale));
  font-weight: 800;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: 3px solid var(--dim);
  border-radius: 12px;
}
.phrase-tab.active { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 14px color-mix(in srgb, var(--primary) 45%, transparent); }
.phrase-tab.edit-on { border-color: var(--warn); color: var(--warn); box-shadow: 0 0 12px var(--warn); }
#phrase-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 5), 1fr);
  gap: 16px;
  align-content: start;
  flex: 1;
}
.phrase-btn {
  min-height: calc(148px * var(--btn-scale));
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  padding: 14px 10px;
  font-size: calc(27px * var(--font-scale));
  font-weight: 800;
  text-align: center;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: 4px solid var(--btn-border);
  border-radius: 18px;
  text-transform: uppercase;
  transition: background 0.15s, transform 0.1s;
  overflow: hidden;
  position: relative;
}
.phrase-btn:hover { background: var(--btn-bg-hover); transform: translateY(-2px); }
.phrase-btn .p-emoji { font-size: calc(42px * var(--btn-scale)); line-height: 1; }
.phrase-btn .p-text { line-height: 1.15; padding: 0 4px; }
.p-count {
  position: absolute;
  top: 8px; right: 8px;
  min-width: 34px; height: 34px;
  padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  background: var(--warn);
  color: #000;
  font-size: 17px;
  font-weight: 900;
  box-shadow: 0 0 10px color-mix(in srgb, var(--warn) 60%, transparent);
}
.phrase-btn.editing { border-style: dashed; border-color: var(--warn); }
.phrase-btn.editing::before {
  content: '✏️';
  position: absolute; top: 6px; left: 8px;
  font-size: 20px;
}
.phrase-btn.add-btn { border-style: dashed; border-color: var(--dim); color: var(--dim); }
#speak-hint { text-align: center; color: var(--dim); font-size: 16px; padding: 4px; }

/* ============================================================
   ASK pane
   ============================================================ */
#ask-layout { display: flex; gap: 16px; flex: 1; min-height: 0; }
#ask-main { flex: 1.6; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
#ask-side {
  flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0;
  overflow: hidden;              /* followups + say-backs NEVER scroll away;
                                    only the (lower) quick list scrolls */
}
#ask-side h3 { color: var(--primary); font-size: 20px; margin-top: 6px; }
#ask-quick {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 28vh; overflow-y: auto; /* the long list may scroll — the AI rows above don't */
  min-height: 0;
}
#ask-followups, #ask-say { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.ask-quick-btn, .followup-btn {
  min-height: calc(54px * var(--btn-scale));
  padding: 8px 14px;
  font-size: calc(19px * var(--font-scale));
  font-weight: 700;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: 3px solid var(--btn-border);
  border-radius: 12px;
  text-align: left;
}
.followup-btn { border-color: var(--accent); }
.followup-btn:hover, .ask-quick-btn:hover { background: var(--btn-bg-hover); }
/* "You could say" — the user's own voice, one tap */
.ask-say-row { display: flex; flex-direction: column; gap: 8px; }
.say-btn {
  min-height: calc(62px * var(--btn-scale));
  padding: 8px 16px;
  font-size: calc(22px * var(--font-scale));
  font-weight: 800;
  color: var(--bg);
  background: var(--good);
  border: 3px solid #fff;
  border-radius: 14px;
  text-align: left;
  box-shadow: 0 0 12px color-mix(in srgb, var(--good) 35%, transparent);
}
.say-btn:hover { filter: brightness(1.1); }
.big-btn {
  min-height: calc(64px * var(--btn-scale));
  padding: 10px 22px;
  font-size: calc(22px * var(--font-scale));
  font-weight: 800;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: 4px solid var(--btn-border);
  border-radius: 14px;
}
.big-btn:hover { background: var(--btn-bg-hover); }
.big-accent { border-color: var(--good); color: var(--good); }
.big-send { border-color: var(--accent); color: var(--accent); }

/* ============================================================
   WRITE pane
   ============================================================ */
#pane-write { gap: 12px; }
#write-head h2 { color: var(--accent); font-size: 28px; }
#write-step-label {
  font-size: calc(26px * var(--font-scale));
  font-weight: 800;
  padding: 10px 16px;
  background: var(--panel); border-left: 8px solid var(--accent);
  border-radius: 10px;
}
#write-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(calc(220px * var(--btn-scale)), 1fr));
  gap: 12px;
}
.write-opt {
  min-height: calc(92px * var(--btn-scale));
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: calc(23px * var(--font-scale));
  font-weight: 800;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: 4px solid var(--btn-border);
  border-radius: 14px;
  text-transform: uppercase;
}
.write-opt .wo-emoji { font-size: 34px; }
#write-draft-wrap { flex: 1; min-height: 120px; }
#write-draft {
  height: 100%;
  overflow-y: auto;
  background: var(--panel); border: 3px solid var(--good);
  border-radius: 14px; padding: 16px 20px;
  font-size: calc(24px * var(--font-scale));
  line-height: 1.45;
  white-space: pre-wrap;
}
#write-controls { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ============================================================
   PAINT pane
   ============================================================ */
#pane-paint { padding: 12px; gap: 10px; }
#paint-canvas-wrap { flex: 1; position: relative; min-height: 0; border-radius: 16px; overflow: hidden; border: 3px solid var(--dim); }
#paint-canvas-wrap canvas { position: absolute; inset: 0; }
#paint-tools { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.tool-btn {
  min-height: 60px; min-width: 64px;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 6px 12px;
  font-size: 17px; font-weight: 700;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: 3px solid var(--dim);
  border-radius: 12px;
}
.tool-btn.sel { border-color: var(--primary); box-shadow: 0 0 12px color-mix(in srgb, var(--primary) 50%, transparent); }
.tool-btn .t-icon { font-size: 26px; }

/* ============================================================
   MESSAGES pane
   ============================================================ */
#wa-setup {
  margin: auto; max-width: 640px;
  background: var(--panel); border: 4px solid var(--accent);
  border-radius: 20px; padding: 30px;
  display: flex; flex-direction: column; gap: 16px;
  text-align: center;
}
#wa-setup h2 { font-size: 30px; color: var(--accent); }
#wa-setup p { color: var(--dim); font-size: 19px; line-height: 1.5; }
#wa-setup ol { text-align: left; color: var(--text); padding-left: 24px; line-height: 1.7; font-size: 18px; }
.cta-btn {
  min-height: 72px;
  font-size: 24px; font-weight: 900;
  color: var(--bg);
  background: var(--accent);
  border: 4px solid var(--accent);
  border-radius: 16px;
  box-shadow: 0 0 24px color-mix(in srgb, var(--accent) 55%, transparent);
}
.cta-btn:hover { filter: brightness(1.15); }
#wa-layout { display: flex; gap: 14px; flex: 1; min-height: 0; }
#wa-conversations {
  width: 320px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
}
.wa-conv {
  padding: 12px 14px;
  background: var(--btn-bg); border: 3px solid var(--dim);
  border-radius: 12px;
  text-align: left;
  color: var(--btn-text);
}
.wa-conv.active { border-color: var(--accent); box-shadow: 0 0 14px color-mix(in srgb, var(--accent) 40%, transparent); }
.wa-conv .wc-name { font-weight: 800; font-size: 20px; }
.wa-conv .wc-preview { color: var(--dim); font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#wa-main { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
#wa-thread-head { font-size: 22px; font-weight: 800; color: var(--accent); }
#wa-thread {
  flex: 1; overflow-y: auto;
  background: var(--panel); border: 3px solid var(--dim);
  border-radius: 14px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.wa-msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; font-size: 19px; line-height: 1.35; }
.wa-msg.in { align-self: flex-start; background: var(--panel2); border: 2px solid var(--dim); }
.wa-msg.out { align-self: flex-end; background: color-mix(in srgb, var(--good) 18%, var(--panel2)); border: 2px solid var(--good); }
.wa-msg .wm-meta { display: block; font-size: 13px; color: var(--dim); margin-top: 4px; }
#wa-thread-actions { display: flex; gap: 10px; flex-wrap: wrap; }
#wa-reply-options { display: flex; gap: 10px; flex-wrap: wrap; }
.wa-reply-btn {
  padding: 12px 18px; font-size: 20px; font-weight: 700;
  color: var(--btn-text);
  background: var(--btn-bg); border: 3px solid var(--good);
  border-radius: 12px; text-align: left;
}

/* ============================================================
   SETTINGS pane
   ============================================================ */
#pane-settings { align-items: stretch; }
#settings-body { display: flex; flex-direction: column; gap: 16px; max-width: 900px; width: 100%; margin: 0 auto; }
.set-section {
  background: var(--panel);
  border: 3px solid var(--dim);
  border-radius: 16px;
  overflow: hidden;
}
.set-section > h3 {
  padding: 14px 18px;
  font-size: 22px;
  color: var(--primary);
  background: var(--panel2);
  border-bottom: 2px solid var(--dim);
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
}
.set-section > h3::after { content: '▾'; font-size: 18px; color: var(--dim); }
.set-section.collapsed > h3::after { content: '▸'; }
.set-section .set-body { padding: 14px 18px; display: flex; flex-direction: column; gap: 14px; }
.set-section.collapsed .set-body { display: none; }
.set-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.set-row label { flex: 1; min-width: 200px; font-size: 19px; font-weight: 700; }
.set-row .set-val { min-width: 64px; text-align: right; color: var(--primary); font-weight: 800; font-variant-numeric: tabular-nums; }
input[type="range"] {
  flex: 2; min-width: 180px; height: 40px; accent-color: var(--primary);
  cursor: pointer;
}
select, input[type="text"], input[type="url"] {
  font-size: 18px; padding: 8px 12px;
  background: var(--btn-bg); color: var(--text);
  border: 3px solid var(--dim); border-radius: 10px;
  min-width: 160px;
}
.toggle-btn {
  min-width: 110px; min-height: 52px;
  font-size: 19px; font-weight: 800;
  border-radius: 10px;
  border: 3px solid var(--danger); color: var(--danger);
  background: transparent;
}
.toggle-btn.on { border-color: var(--good); color: var(--good); box-shadow: 0 0 12px color-mix(in srgb, var(--good) 40%, transparent); }
.set-help { color: var(--dim); font-size: 15px; line-height: 1.45; }
.mouth-meter {
  height: 34px; flex: 2; min-width: 180px;
  background: var(--panel2); border: 2px solid var(--dim); border-radius: 8px;
  overflow: hidden; position: relative;
}
.mouth-meter-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--warn), var(--good));
  transition: width 0.08s linear;
}
.mouth-meter-mark {
  position: absolute; top: -4px; bottom: -4px; width: 4px;
  background: #fff; box-shadow: 0 0 8px #fff;
}
.theme-chip {
  padding: 10px 14px; min-height: 54px;
  font-size: 16px; font-weight: 700;
  border-radius: 10px; border: 3px solid var(--dim);
  color: var(--text); background: var(--btn-bg);
  display: inline-flex; align-items: center; gap: 8px;
}
.theme-chip.sel { border-color: var(--primary); box-shadow: 0 0 12px var(--primary); }
.theme-dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff; }
.cta-card {
  background: var(--panel);
  border: 4px solid var(--accent);
  border-radius: 20px;
  padding: 22px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 0 26px color-mix(in srgb, var(--accent) 30%, transparent);
}
.cta-card h3 { font-size: 24px; color: var(--accent); }
.cta-card p { color: var(--dim); font-size: 17px; line-height: 1.5; }
.cta-card .cta-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.wa-status-inline { font-weight: 800; font-size: 18px; }

/* ============================================================
   Layer 2: overlay canvas
   ============================================================ */
#overlay {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 2;
}

/* ============================================================
   Subtitle bar
   ============================================================ */
#subtitle-bar {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: 26px;
  max-width: min(92vw, 1100px);
  z-index: 40;
  display: flex; align-items: center; gap: 14px;
  background: rgba(4, 8, 14, 0.93);
  border: 4px solid var(--warn);
  border-radius: 18px;
  padding: 16px 20px;
  box-shadow: 0 0 34px color-mix(in srgb, var(--warn) 45%, transparent);
}
#subtitle-text {
  font-size: var(--subtitle-size, 32px);
  font-weight: 800;
  color: #fff;
  line-height: 1.3;
  text-align: center;
  max-height: 3.9em;
  overflow: hidden;
}
#subtitle-stop {
  flex-shrink: 0;
  min-width: 96px; height: 60px;
  font-size: 20px; font-weight: 900; letter-spacing: 1px;
  border-radius: 12px;
  background: var(--danger); color: #fff;
  border: 3px solid #fff;
}

/* ============================================================
   Captions bar (lasting subtitles of everything heard)
   ============================================================ */
#captions-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 35;
  display: flex; flex-direction: column; gap: 6px;
  background: rgba(4, 8, 14, 0.92);
  border-top: 3px solid var(--primary);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  max-height: 34vh;
}
#captions-bar.collapsed #cap-lines { display: none; }
#heard-replies {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  min-height: 8px;
}
#heard-replies[data-state="loading"] { opacity: 0.6; }
.heard-label { color: var(--good); font-weight: 800; font-size: 20px; }
.heard-btn {
  min-height: calc(58px * var(--btn-scale));
  padding: 8px 18px;
  font-size: calc(21px * var(--font-scale));
  font-weight: 800;
  color: var(--bg);
  background: var(--good);
  border: 3px solid #fff;
  border-radius: 14px;
  box-shadow: 0 0 16px color-mix(in srgb, var(--good) 50%, transparent);
}
.heard-btn.heard-say {
  background: var(--primary);
  box-shadow: 0 0 22px color-mix(in srgb, var(--primary) 65%, transparent);
  font-size: calc(24px * var(--font-scale));
}
#cap-converse.on {
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 12px color-mix(in srgb, var(--primary) 55%, transparent);
}
#cap-lines {
  display: flex; flex-direction: column; gap: 3px;
  overflow-y: auto;
  max-height: 20vh;
  font-size: var(--captions-size, 22px);
}
.cap-line { display: flex; gap: 12px; align-items: baseline; line-height: 1.35; }
.cap-time { color: var(--dim); font-size: 15px; font-weight: 700; flex-shrink: 0; min-width: 52px; }
.cap-text { color: var(--text); font-weight: 600; }
.cap-live { color: var(--dim); font-style: italic; }
.cap-hist-line {
  display: flex; gap: 12px; align-items: baseline;
  text-align: left; font-size: 19px;
  background: var(--panel2); border: 2px solid var(--dim); border-radius: 10px;
  padding: 10px 14px; color: var(--text);
}
#cap-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ============================================================
   Phone layout (data-device="phone") — bottom tab bar, thumb reach
   ============================================================ */
[data-device="phone"] #top-bar {
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  align-items: stretch;
}
[data-device="phone"] #logo-text { font-size: 20px; }
[data-device="phone"] #logo { justify-content: center; }
[data-device="phone"] #status-pills { justify-content: center; font-size: 13px; }
[data-device="phone"] .pill { padding: 5px 10px; font-size: 14px; }
[data-device="phone"] #mode-tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  background: var(--panel);
  border-top: 3px solid var(--primary);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  gap: 4px;
}
[data-device="phone"] .tab-btn {
  flex: 1;
  min-height: 64px;
  min-width: 0;
  padding: 6px 2px;
  font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border-radius: 10px;
}
[data-device="phone"] .tb-emoji { font-size: 26px; }
[data-device="phone"] .tb-label { font-size: 12px; }
[data-device="phone"] .mode-pane { padding: 10px; padding-bottom: 120px; }
[data-device="phone"] #phrase-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px; }
[data-device="phone"] .phrase-btn { min-height: 118px; }
[data-device="phone"] #subtitle-bar { bottom: 108px; }
[data-device="phone"] #captions-bar { bottom: 92px; max-height: 26vh; padding-bottom: 8px; }
[data-device="phone"] #ask-layout, [data-device="phone"] #wa-layout { flex-direction: column; }
[data-device="phone"] #wa-conversations { width: auto; max-height: 170px; }
[data-device="phone"] #write-options { grid-template-columns: repeat(2, 1fr); }
[data-device="phone"] #paint-tools { gap: 6px; }
[data-device="phone"] .tool-btn { min-width: 52px; min-height: 54px; font-size: 14px; }
[data-device="phone"] #settings-body { max-width: none; }
[data-device="phone"] .set-row { flex-wrap: wrap; }
[data-device="phone"] .set-row label { flex-basis: 100%; }
[data-device="phone"] #paint-canvas-wrap { min-height: 46vh; }

/* ============================================================
   Tablet layout (data-device="tablet") — iPad / touch, generous targets
   ============================================================ */
[data-device="tablet"] { --btn-scale: 1.25; }
[data-device="tablet"] #phrase-grid { grid-template-columns: repeat(5, 1fr) !important; }
[data-device="tablet"] .phrase-btn { min-height: 168px; }
[data-device="tablet"] .mode-pane { padding: 22px; }
[data-device="tablet"] .tab-btn { flex: 1; }
[data-device="tablet"] #top-bar { flex-wrap: nowrap; }
[data-device="tablet"] #status-pills { flex-wrap: wrap; }

/* touch baseline: kill double-tap zoom delay + iOS callouts on buttons */
[data-device="phone"] button, [data-device="tablet"] button {
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}
/* touch-first feel: obvious pressed feedback */
[data-device="phone"] .dwell-btn:active, [data-device="tablet"] .dwell-btn:active {
  transform: scale(0.96);
  filter: brightness(1.3);
}
/* dwell disabled (pure tap mode) — no progress bars, no fill visuals */
.no-dwell .dwell-active::after { display: none; }

/* app feel on touch: no rubber-band refresh fighting the UI */
[data-device="phone"] body, [data-device="tablet"] body { overscroll-behavior: none; }

/* phone: phrase tiles = the main surface — make them hero-sized */
[data-device="phone"] .phrase-btn { min-height: 21vh; font-size: 24px; }
[data-device="phone"] .phrase-btn .p-emoji { font-size: 38px; }
[data-device="phone"] .phrase-tab { min-height: 54px; font-size: 19px; padding: 4px 14px; }
[data-device="phone"] .phrase-grid { gap: 10px; }
/* phone: on-screen keyboard — keep keys thumb-sized but fit the screen */
[data-device="phone"] #kb-backdrop .kb-panel { max-height: 92vh; overflow-y: auto; max-width: 96vw; }
[data-device="phone"] #kb-backdrop .kb-key { min-height: 52px; font-size: 19px; padding: 4px 6px; }
[data-device="phone"] #kb-backdrop .kb-preview { font-size: 20px; }
/* phone: paint tools scroll sideways instead of wrapping tall */
[data-device="phone"] #paint-tools { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; padding-bottom: 6px; }
/* phone: settings rows stack cleanly */
[data-device="phone"] .set-row input[type="range"] { flex-basis: 100%; }
/* tablet: hero tiles too */
[data-device="tablet"] .phrase-btn { min-height: 20vh; }
[data-device="tablet"] .phrase-btn .p-emoji { font-size: 48px; }

/* ============================================================
   Toasts
   ============================================================ */
#toasts {
  position: fixed; top: 86px; right: 18px;
  z-index: 60;
  display: flex; flex-direction: column; gap: 10px;
  max-width: 380px;
}
.toast {
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 18px; font-weight: 700;
  background: var(--panel);
  border: 3px solid var(--primary);
  color: var(--text);
  box-shadow: 0 4px 24px rgba(0,0,0,0.6);
  animation: toastIn 0.25s ease;
}
.toast.good { border-color: var(--good); }
.toast.warn { border-color: var(--warn); }
@keyframes toastIn { from { transform: translateX(40px); opacity: 0; } }

/* ============================================================
   Context menu (right-click)
   ============================================================ */
#ctx-menu {
  position: fixed; z-index: 70;
  min-width: 220px;
  background: var(--panel);
  border: 3px solid var(--primary);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
}
.ctx-item {
  display: flex; width: 100%;
  align-items: center; gap: 10px;
  padding: 12px 14px;
  font-size: 19px; font-weight: 700;
  color: var(--text);
  background: transparent;
  border: none; border-radius: 8px;
  text-align: left;
}
.ctx-item:hover { background: var(--btn-bg-hover); }
.ctx-item.danger { color: var(--danger); }

/* ============================================================
   Modal root (keyboard.js etc.)
   ============================================================ */
#modal-root { position: fixed; inset: 0; z-index: 80; pointer-events: none; }
#modal-root > * { pointer-events: auto; }

/* ============================================================
   Start gate
   ============================================================ */
#start-gate {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(ellipse at center, rgba(10,14,20,0.94) 0%, rgba(4,6,10,0.99) 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
#start-gate[hidden] { display: none; }
#start-card {
  max-width: 620px; width: 100%;
  background: var(--panel);
  border: 4px solid var(--primary);
  border-radius: 24px;
  padding: 36px 40px;
  text-align: center;
  box-shadow: 0 0 60px color-mix(in srgb, var(--primary) 35%, transparent);
  display: flex; flex-direction: column; gap: 18px;
}
#start-logo { font-size: 72px; filter: drop-shadow(0 0 20px var(--primary)); }
#start-card h1 {
  font-size: 52px; letter-spacing: 10px;
  color: var(--primary);
  text-shadow: 0 0 24px var(--primary);
}
#start-card .tagline { font-size: 24px; color: var(--accent); font-weight: 700; }
#start-card ul { list-style: none; display: flex; flex-direction: column; gap: 10px; text-align: left; font-size: 20px; line-height: 1.4; }
.start-btn {
  min-height: 84px;
  font-size: 30px; font-weight: 900; letter-spacing: 3px;
  color: var(--bg);
  background: var(--primary);
  border: 4px solid var(--primary);
  border-radius: 18px;
  box-shadow: 0 0 34px color-mix(in srgb, var(--primary) 60%, transparent);
}
.start-btn:hover { filter: brightness(1.15); transform: translateY(-2px); }
.start-skip {
  background: none; border: none;
  color: var(--dim); font-size: 17px; text-decoration: underline;
}
#start-note { color: var(--dim); font-size: 14px; }

/* ---------- misc ---------- */
[hidden] { display: none !important; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-thumb { background: var(--btn-bg-hover); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: var(--panel2); }

@media (max-width: 900px) {
  #ask-layout, #wa-layout { flex-direction: column; }
  #wa-conversations { width: auto; max-height: 200px; }
  #mode-tabs { order: 3; width: 100%; }
}
@media (max-width: 600px) {
  :root { --font-size-base: calc(17px * var(--font-scale)); }
  #phrase-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
