:root {
  color-scheme: light;
  --bg: #ffffff;
  --card: #ffffff;
  --muted: #666666;
  --text: #000000;
  --accent: #000000;
  --accent-blue: #0070f3;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --soft: #fafafa;
  --border: #cbd5e1;
  --border-hover: #94a3b8;
  --shadow: 0 0 0 1px #cbd5e1;
  --radius: 8px;
  --button-height: 38px;
  --topbar-bg: #ffffff;
  --vrm-bg: radial-gradient(circle at center, #f3f4f6 0%, #e5e7eb 100%);
}

body.dark-theme {
  color-scheme: dark;
  --bg: #000000;
  --card: #0a0a0a;
  --muted: #888888;
  --text: #ffffff;
  --accent: #ffffff;
  --accent-blue: #0070f3;
  --accent-green: #10b981;
  --accent-yellow: #f59e0b;
  --soft: #111111;
  --border: #333333;
  --border-hover: #444444;
  --shadow: 0 0 0 1px #333333;
  --topbar-bg: #000000;
  --vrm-bg: radial-gradient(circle at center, #1e293b 0%, #090d16 100%);
}

* {
  box-sizing: border-box;
}

/* ICON SYSTEM - consistent inline-SVG icons (Feather-style) replacing emoji */
.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
}

.header-with-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-sparkle {
  stroke: none;
  fill: currentColor;
}

/* Theme toggle: two icons in the DOM, CSS swaps which is visible */
.theme-toggle-btn {
  gap: 0;
}

.theme-toggle-btn .icon-moon {
  display: none;
}

body.dark-theme .theme-toggle-btn .icon-sun {
  display: none;
}

body.dark-theme .theme-toggle-btn .icon-moon {
  display: block;
}

body {
  margin: 0;
  font-family: "Geist Sans", "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* TOPBAR STYLE - Compact & Minimalist */
.topbar {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  max-height: 64px;
  display: flex;
  align-items: center;
  z-index: 100;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.topbar-container {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-eyebrow {
  display: inline-flex;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--soft);
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid var(--border);
}

.brand-block h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  margin: 1px 0 0 0;
  font-size: 11px;
  color: var(--muted);
}

/* Navigation Pills */
.app-nav {
  display: flex;
  gap: 4px;
  align-items: center;
}

.nav-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13px;
  transition: all 0.15s ease;
}

.nav-pill:hover {
  color: var(--text);
  background: var(--soft);
}

.nav-pill.active {
  background: var(--soft);
  border-color: var(--border);
  color: var(--text);
}

/* Theme Toggle Button & Settings Popover */
.theme-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s ease;
}

.theme-toggle-btn:hover {
  background: var(--soft);
  border-color: var(--border-hover);
}

.settings-trigger-box {
  position: relative;
}

.settings-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.settings-toggle-btn:hover,
.settings-toggle-btn.active {
  background: var(--soft);
  color: var(--text);
  border-color: var(--border-hover);
}

.settings-dropdown {
  position: absolute;
  right: 0;
  top: 40px;
  width: 320px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.15);
  padding: 16px;
  display: none;
  flex-direction: column;
  gap: 14px;
  z-index: 200;
}

body.dark-theme .settings-dropdown {
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
}

.settings-dropdown.active {
  display: flex;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Commit-confidence gate: checkbox + slider that decide whether a committed word
   is kept. Dimmed (not hidden) when the gate is off, so the value stays visible. */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
  font-size: 12px;
}

.toggle-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent, #3ac6a8);
  cursor: pointer;
}

.conf-gate-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.conf-gate-row.disabled {
  opacity: 0.45;
}

.conf-gate-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent, #3ac6a8);
  cursor: pointer;
}

.conf-gate-value {
  min-width: 84px;
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.setting-hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
}

.advanced-settings {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.advanced-settings summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  list-style: none;
  user-select: none;
}

.advanced-settings summary::-webkit-details-marker {
  display: none;
}

.advanced-settings summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 5px;
  transition: transform 0.15s ease;
}

.advanced-settings[open] summary::before {
  transform: rotate(90deg);
}

.advanced-settings summary:hover {
  color: var(--text);
}

.advanced-settings .setting-item {
  margin-top: 10px;
}

.ws-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ws-config {
  display: flex;
  gap: 8px;
}

.ws-url-input {
  flex: 1;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  width: 100%;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.ws-url-input:focus {
  border-color: var(--accent);
}

/* APP MAIN CONTENT - Layout Lock */
.app {
  flex: 1;
  padding: 20px 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 20px;
  height: 100%;
  min-height: 0;
}

.col-left,
.col-right {
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100%;
  min-height: 0;
}

/* SHARP VERCEL CARDS */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: none;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.card:hover {
  border-color: var(--border-hover);
}

.card-header {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  letter-spacing: -0.01em;
}

.card-header-compact {
  font-weight: 600;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* VIDEO CAMERA SECTION */
.video-card {
  flex: 0 0 auto;
}

.video-wrapper {
  position: relative;
  background: #000000;
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  width: 100%;
  max-height: 340px;
  border: 1px solid var(--border);
}

.video-card video,
#canvas {
  transform: scaleX(-1);
}

/* The wrapper's max-height can squash it wider than 16:9; the video then
   letterboxes (object-fit: contain) but a plain 100%x100% canvas would keep
   stretching over the black bars, skewing the landmark overlay off the hand.
   Letterbox the canvas bitmap exactly like the video so they always align. */
#canvas {
  object-fit: contain;
}

/* Dwell-commit progress ring: fills clockwise while the signer holds the ending
   pose (dwell_progress 0..1 from the server); full ring = word committed. */
.rt-dwell-ring {
  --p: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  margin-left: 8px;
  flex: 0 0 auto;
  background:
    conic-gradient(var(--accent, #3ac6a8) calc(var(--p) * 360deg), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent 55%, #000 58%);
  mask: radial-gradient(farthest-side, transparent 55%, #000 58%);
  opacity: 0;
  transition: opacity 0.15s ease;
}
.rt-dwell-ring.active { opacity: 1; }
.rt-dwell-ring.committed {
  background: conic-gradient(var(--accent, #3ac6a8) 360deg, transparent 0);
  opacity: 1;
}

/* Accumulated-word chips: click to open the commit's top-5 and correct a word
   before sending. A pinned chip (user-chosen) is sent as a single-candidate
   slot so sentence rescoring cannot override the human choice. */
.sign-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-200);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  position: relative;
}
.sign-chip:hover { border-color: var(--border); }
.sign-chip.pinned { border-color: var(--accent, #3ac6a8); }
.sign-chip .chip-caret { font-size: 0.7em; opacity: 0.55; }
/* Per-word delete. Faint until the chip is hovered so a row of words stays
   readable, but always focusable/tappable (touch has no hover). */
.sign-chip .chip-del {
  border: 0;
  background: none;
  padding: 0 1px;
  margin-left: 1px;
  font: inherit;
  font-size: 1.05em;
  line-height: 1;
  color: var(--muted, #888);   /* --text-muted is not defined anywhere; --muted is */
  opacity: 0.4;
  cursor: pointer;
  transition: opacity 0.12s ease, color 0.12s ease;
}
.sign-chip:hover .chip-del,
.sign-chip .chip-del:focus-visible { opacity: 1; }
.sign-chip .chip-del:hover { color: #e05252; opacity: 1; }
@media (hover: none) {
  .sign-chip .chip-del { opacity: 0.75; }
}
.chip-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 50;
  min-width: 150px;
  background: var(--bg-100, #fff);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  padding: 4px;
  display: flex;
  flex-direction: column;
}
.chip-menu button {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 8px;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  border-radius: 4px;
  cursor: pointer;
  color: inherit;
}
.chip-menu button:hover,
.chip-menu button:focus-visible { background: var(--bg-200); }
.chip-menu button.current { font-weight: 700; }
.chip-menu .chip-conf {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85em;
}

.video-card video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.9);
  color: #ffffff;
  text-align: center;
  transition: all 0.3s;
}

.overlay-icon {
  color: var(--muted);
}

.overlay-icon svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.overlay-text {
  font-weight: 600;
  font-size: 14px;
}

.overlay-sub {
  font-size: 12px;
  color: var(--muted);
  max-width: 240px;
}

.overlay-btn {
  height: 36px;
  border: 1px solid transparent;
  padding: 0 16px;
  border-radius: 6px;
  background: #ffffff;
  color: #000000;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
  border: 1px solid #ffffff;
}

.overlay-btn:hover {
  background: #eaeaea;
}

/* Realtime inference read-out overlay (top-left of the live camera).
   Deliberately self-contained dark/translucent styling so it stays legible
   over any video frame regardless of the page theme. Not mirrored (only the
   <video>/#canvas get scaleX(-1)). */
.rt-panel {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 6;
  display: none;                 /* shown by JS while the camera runs */
  min-width: 188px;
  max-width: 62%;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(8, 12, 24, 0.62);
  border: 1px solid rgba(120, 220, 255, 0.22);
  color: #e8f6ff;
  font-size: 12px;
  line-height: 1.45;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  pointer-events: none;          /* never steal clicks from the video card */
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.rt-panel.visible { display: block; }

.rt-row { display: flex; align-items: baseline; gap: 6px; }
.rt-key { color: #8fd0ff; font-weight: 600; }
.rt-word {
  font-weight: 700;
  font-size: 15px;
  color: #41f0e6;               /* cyan — matches the python overlay's word */
}
.rt-word.rt-low { color: #ffd27a; }   /* low-confidence guess */

.rt-meta {
  margin-top: 3px;
  color: #9fb6c8;
  font-size: 11px;
  flex-wrap: wrap;
}
.rt-meta .rt-sep { opacity: 0.5; }
.rt-meta #rtStatus.rt-hands { color: #6ee7a8; }

.rt-rank {
  margin-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 5px;
}
.rt-rank-title {
  color: #9fb6c8;
  font-size: 10px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: 3px;
}
.rt-rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.rt-rank-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-variant-numeric: tabular-nums;
}
.rt-rank-list li.rt-top .rt-rank-label,
.rt-rank-list li.rt-top .rt-rank-conf { color: #6effa0; font-weight: 700; }
.rt-rank-list li.rt-empty { justify-content: center; opacity: 0.55; }
.rt-rank-conf { color: #cfe6f5; }

.compact-stop {
  height: 26px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  background: transparent;
  color: #ff453a;
  border-radius: 6px;
  border: 1px solid rgba(255, 69, 58, 0.4);
}

.compact-stop:hover {
  background: rgba(255, 69, 58, 0.1);
  border-color: #ff453a;
}

.compact-stop:disabled {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
  cursor: not-allowed;
}

/* STATUS & ACCUMULATED SECTION */
.status-card {
  flex: 1;
  min-height: 0;
  justify-content: flex-start;
}

.accumulated-box {
  background: var(--soft);
  border-radius: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.accumulated-words {
  min-height: 46px;
  max-height: 60px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.accumulated-words span.word-tag {
  background: var(--card);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 12px;
  border: 1px solid var(--border);
}

.empty-text {
  color: var(--muted);
  font-size: 12px;
}

.accumulated-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.input-row.compact {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 2px;
}

.input-display {
  flex: 1;
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--soft);
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.translation-result {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}

/* HIGH-CONTRAST VERCEL BUTTONS */
.pill-btn {
  height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.highlight-btn {
  background: var(--text);
  color: var(--bg);
  border: 1px solid var(--text);
}

.highlight-btn:hover {
  background: var(--soft);
  color: var(--text);
  border-color: var(--border-hover);
}

body.dark-theme .highlight-btn:hover {
  background: #eaeaea;
  color: #000000;
}

.play-audio-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.play-audio-btn:hover {
  background: var(--soft);
  border-color: var(--border-hover);
}

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ghost-btn:hover {
  background: var(--soft);
  color: var(--text);
  border-color: var(--border-hover);
}

.ghost-btn.small {
  height: 30px;
  padding: 0 10px;
  font-size: 11px;
}

/* AVATAR VRM CARD */
.avatar-card {
  flex: 0 0 auto;
}

.avatar-wrapper {
  position: relative;
  background: var(--vrm-bg);
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  width: 100%;
  max-height: 340px;
  border: 1px solid var(--border);
  transition: background 0.15s ease;
}

/* VRM AVATAR LOADING SPINNER (avatar-wrapper on the live-demo page, vrm-card on chat) */
.avatar-loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--vrm-bg);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.avatar-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--text);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.vrm-frame {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: none;
}

.motion-status-overlay {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: var(--card);
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  max-width: calc(100% - 16px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.motion-status-overlay.ok { color: var(--accent-green); }
.motion-status-overlay.warn { color: var(--accent-yellow); }
.motion-status-overlay.error { color: #ff453a; }

.manual-controls {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}

.manual-controls input {
  flex: 1;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

.manual-controls input:focus {
  border-color: var(--accent);
}

.manual-btns {
  display: flex;
  gap: 6px;
}

.manual-btns button {
  height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.motion-btn {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text) !important;
}

.motion-btn:hover {
  opacity: 0.9;
}

.mic-btn {
  background: transparent;
  color: var(--text);
}

.mic-btn:hover {
  background: var(--soft);
}

/* CONFIDENCE BADGE & STATUS LIGHTS */
/* `display: inline-flex` below beats the `hidden` attribute's UA `display: none`,
   so hiding the badge (confidence gate off) needs this explicit rule. */
.confidence-badge[hidden] {
  display: none;
}

.confidence-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--soft);
  color: var(--muted);
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.confidence-badge .icon {
  width: 12px;
  height: 12px;
}

.conf-ring {
  --pct: 0;
  --ring-color: var(--muted);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  background: conic-gradient(var(--ring-color) calc(var(--pct) * 1%), var(--border) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
  transition: background 0.2s ease;
}

.confidence-card.confident .conf-ring {
  --ring-color: #10b981;
}

.confidence-card.confident {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.3);
}

/* VERCEL FLUSH TABS PANEL */
.system-tabs-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
}

.tabs-header {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  margin-bottom: 10px;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--text);
}

.tab-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.tab-panel {
  display: none;
  height: 100%;
  overflow-y: auto;
}

.tab-panel.active {
  display: block;
}

/* INSTRUCTIONS LIST */
.steps {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 12.5px;
}

.steps li {
  margin-bottom: 6px;
}

/* HISTORIES PANEL */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

.history-empty {
  text-align: center;
  color: var(--muted);
  padding: 20px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  font-size: 12px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--soft);
  transition: border-color 0.15s ease;
}

.history-item:hover {
  border-color: var(--border-hover);
}

.history-title {
  font-weight: 600;
  font-size: 13px;
}

.history-meta {
  color: var(--muted);
  font-size: 10px;
  margin-top: 1px;
}

.history-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 11px;
}

.history-badge.good { background: rgba(16, 185, 129, 0.1); color: #10b981; }
.history-badge.mid { background: rgba(245, 158, 11, 0.1); color: #f59e0b; }
.history-badge.low { background: rgba(239, 68, 68, 0.1); color: #ff453a; }

/* VERCEL CODE-STYLE LOG PANEL */
.log-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: 6px;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
}

.log-hint {
  color: var(--muted);
}

.log-list {
  flex: 1;
  font-family: Menlo, Monaco, Lucida Console, Consolas, monospace;
  font-size: 11px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.log-item {
  padding: 6px 10px;
  border-radius: 4px;
  background: var(--soft);
  border: 1px solid var(--border);
  word-break: break-all;
}

.log-item.info { border-left: 2px solid var(--muted); }
.log-item.warn { border-left: 2px solid var(--accent-yellow); }
.log-item.error { border-left: 2px solid #ff453a; }

.log-empty {
  color: var(--muted);
  padding: 10px;
}

.error {
  margin-top: 6px;
  color: #ff453a;
  font-size: 12px;
  font-weight: 500;
}

/* TOAST NOTIFICATIONS */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: auto;
}

body.dark-theme .toast {
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast .icon {
  width: 16px;
  height: 16px;
}

.toast-ok { border-color: rgba(16, 185, 129, 0.35); }
.toast-ok .icon { color: #10b981; }
.toast-error { border-color: rgba(255, 69, 58, 0.35); }
.toast-error .icon { color: #ff453a; }
.toast-warn { border-color: rgba(245, 158, 11, 0.35); }
.toast-warn .icon { color: #f59e0b; }
.toast-info .icon { color: var(--muted); }

.toast-text {
  flex: 1;
}

.toast-action {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.toast-action:hover {
  background: var(--soft);
  border-color: var(--border-hover);
}

@media (max-width: 1024px) {
  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .toast {
    max-width: none;
  }
}

/* RESPONSIVE DESIGN */
@media (max-width: 1024px) {
  body {
    overflow-y: auto;
    height: auto;
  }
  
  .topbar {
    height: auto;
    max-height: none;
    padding: 14px 16px;
  }
  
  .topbar-container {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  
  .settings-trigger-box {
    width: 100%;
  }
  
  .settings-toggle-btn {
    width: 100%;
  }
  
  .settings-dropdown {
    width: 100%;
    position: static;
    box-shadow: none;
    border-radius: 6px;
    margin-top: 8px;
  }

  .app {
    overflow: visible;
    height: auto;
    padding: 12px;
  }
  
  .dashboard-grid {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }
  
  .col-left,
  .col-right {
    height: auto;
    overflow: visible;
  }
}

/* SMALL-PHONE REFINEMENTS (stack controls, bigger touch targets) */
@media (max-width: 640px) {
  .video-wrapper,
  .avatar-wrapper {
    max-height: none;
  }

  .input-row.compact {
    flex-direction: column;
    align-items: stretch;
  }

  .accumulated-actions {
    flex-wrap: wrap;
  }

  .manual-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .manual-btns {
    justify-content: stretch;
  }

  .manual-btns button {
    flex: 1;
  }

  .tabs-header {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
  }

  .tab-btn {
    white-space: nowrap;
  }

  /* Comfortable ~40-44px touch targets on small screens without bloating desktop density */
  .pill-btn,
  .ghost-btn,
  .tab-btn,
  .nav-pill,
  .theme-toggle-btn,
  .settings-toggle-btn,
  .manual-btns button,
  .overlay-btn {
    min-height: 40px;
  }

  .compact-stop {
    min-height: 32px;
  }
}

/* ── Few-shot enrollment (โหมดลงทะเบียนท่า) ─────────────────────────────── */
.header-btns {
  display: flex;
  gap: 8px;
  align-items: center;
}
.enroll-panel {
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px dashed rgba(127, 127, 127, 0.35);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.enroll-words {
  width: 100%;
  resize: vertical;
  min-height: 44px;
  font-family: inherit;
}
.enroll-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.enroll-takes-label {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.enroll-takes {
  width: auto;
  padding: 4px 8px;
}
.enroll-status {
  font-size: 0.85em;
  color: var(--text);
  opacity: 0.75;
}
.overlay-btn.small {
  padding: 8px 14px;
  font-size: 0.9em;
}
.enroll-overlay {
  position: absolute;
  inset: 0;
  z-index: 20; /* above the start overlay + rt panel */
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  color: #fff;
  padding: 16px;
}
.enroll-overlay[hidden] {
  display: none;
}
.enroll-word {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.2;
}
.enroll-sub {
  font-size: 0.95rem;
  opacity: 0.85;
}
.enroll-hint {
  font-size: 1.05rem;
}
.enroll-cancel {
  margin-top: 6px;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.5);
}

/* Vocabulary category switchboard (video-card header) */
.vocab-cat {
  max-width: 190px;
  padding: 5px 8px;
  font-size: 12px;
}

/* Word audition (ทดสอบความแม่น) results */
.audition-results {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(127, 127, 127, 0.3);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 260px;
  overflow-y: auto;
  font-size: 0.9em;
}
.audition-head {
  font-weight: 600;
  margin-bottom: 4px;
}
.audition-row.pass { color: #1d9d5f; }
.audition-row.fail { color: #d4544f; }
