/* ==========================================================================
   Semaphore Trainer — App Stylesheet
   Nautical training interface
   ========================================================================== */

/* ---------- Design Tokens ---------- */
:root {
  /* Colors */
  --bg-primary: #0f2032;
  --bg-secondary: #172c42;
  --bg-card: #1d3550;
  --bg-card-hover: #274463;
  --bg-surface: rgba(255, 255, 255, 0.04);

  --text-primary: #f8f2e8;
  --text-secondary: #d4c4aa;
  --text-muted: #8da0b5;

  --accent-primary: #66734f;
  --accent-primary-dim: rgba(102, 115, 79, 0.16);
  --accent-secondary: #57a6b9;
  --accent-warm: #909b63;
  --accent-success: #82c7a5;
  --accent-danger: #f87171;      /* Red */

  --gradient-primary: linear-gradient(135deg, #66734f 0%, #4e5a3e 100%);
  --gradient-warm: linear-gradient(135deg, #66734f 0%, #909b63 100%);
  --gradient-cool: linear-gradient(135deg, #57a6b9 0%, #66734f 100%);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(102, 115, 79, 0.36);

  /* Glass effect */
  --glass-bg: rgba(12, 26, 42, 0.72);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-blur: 20px;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(129, 140, 248, 0.2);

  /* Typography */
  --font-sans: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --arm-left-color: #7c8b5b;
  --arm-right-color: #2b7c8f;
  --arm-left-rgb: 124, 139, 91;
  --arm-right-rgb: 43, 124, 143;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;

  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(102, 115, 79, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(87, 166, 185, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 60% 80%, rgba(196, 139, 53, 0.06) 0%, transparent 50%);
  background-attachment: fixed;
}

.app-page {
  position: relative;
}

.app-page::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.2), transparent 40%);
}

.welcome-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(247, 241, 230, 0.82);
  backdrop-filter: blur(8px);
}

.welcome-modal.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.welcome-modal__panel {
  width: min(720px, 100%);
  padding: 32px;
  border-radius: 28px;
  background: rgba(255, 253, 248, 0.96);
  border: 1px solid rgba(49, 81, 113, 0.12);
  box-shadow: 0 28px 60px rgba(16, 32, 51, 0.16);
}

.welcome-modal__title {
  color: #102033;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 0.95;
}

.welcome-modal__body,
.welcome-modal__note {
  color: #4f6479;
  font-size: 1.02rem;
  line-height: 1.6;
}

.welcome-modal__body {
  margin-top: 14px;
}

.welcome-modal__tips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 22px 0 18px;
}

.welcome-tip {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 16px;
  border-radius: 18px;
  background: rgba(247, 241, 230, 0.85);
  border: 1px solid rgba(49, 81, 113, 0.1);
}

.welcome-tip__icon {
  display: inline-flex;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(102, 115, 79, 0.14);
  color: #4e5a3e;
}

.welcome-tip__icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.welcome-tip p {
  color: #102033;
  font-size: 0.98rem;
  line-height: 1.45;
}

.welcome-modal__note {
  margin-bottom: 18px;
}

.welcome-modal__button {
  min-height: 52px;
  padding: 0 22px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #66734f, #4e5a3e);
  color: #fffaf2;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 14px 24px rgba(78, 90, 62, 0.24);
}

/* ---------- Loading Overlay ---------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  transition: opacity 0.5s ease;
}

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

.loading-content {
  text-align: center;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-lg);
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-title {
  font-size: 1.75rem;
  font-weight: 800;
  background: var(--gradient-cool);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-sm);
}

.loading-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.app-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-md);
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 0;
  margin-bottom: var(--space-md);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 1.4rem;
  font-weight: 800;
}

.logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background-color: var(--accent-primary);
  -webkit-mask: url('../assets/icons/flags-icon.svg') center / contain no-repeat;
  mask: url('../assets/icons/flags-icon.svg') center / contain no-repeat;
  filter: drop-shadow(0 0 8px rgba(102, 115, 79, 0.35));
}

.logo-text {
  background: var(--gradient-cool);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.12em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

/* Inline header control (icon + select) */
.header-control {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 5px 10px 5px 8px;
  transition: border-color 0.2s ease;
}

.header-control:hover {
  border-color: var(--border-accent);
}

.ctrl-label {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.ctrl-select {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  padding: 0;
  max-width: 130px;
}

.ctrl-select:focus { color: var(--text-primary); }
.ctrl-select option { background: var(--bg-secondary); color: var(--text-primary); }

/* Labeled header button (Reference Chart) */
.header-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.header-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-accent);
  box-shadow: var(--shadow-glow);
}

.header-btn.active {
  background: var(--accent-primary-dim);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* ---------- Settings Panel ---------- */
.settings-panel {
  max-height: 0;
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  transition: max-height 0.3s ease, padding 0.3s ease;
}

.settings-panel.visible {
  max-height: 200px;
  padding: var(--space-md);
}

.setting-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.setting-row label {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
}

.setting-row select {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
}

/* ---------- Mode Selector ---------- */
.mode-selector {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
}

.mode-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
  color: var(--text-primary);
}

.mode-btn.active {
  background: var(--accent-primary-dim);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  box-shadow: var(--shadow-glow);
}

.mode-icon {
  font-size: 1.1rem;
}

.mode-label {
  font-weight: 600;
}

/* ---------- Main Content ---------- */
.main-content {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

/* ---------- Video Section ---------- */
.video-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.video-container {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  aspect-ratio: 16 / 9;
}

.video-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Mirror for natural feel */
}

.video-container canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1); /* Mirror to match video */
  pointer-events: none;
}

.video-container .confetti-canvas {
  z-index: 20;
  transform: none; /* Confetti doesn't need to be mirrored */
}

/* ---------- Detection Overlay ---------- */
.detection-overlay {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  z-index: 10;
}

.detected-letter-container {
  text-align: center;
}

.detected-letter {
  font-family: var(--font-mono);
  font-size: 4rem;
  font-weight: 800;
  line-height: 1;
  padding: var(--space-md) var(--space-xl);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  transition: all 0.3s ease;
  min-width: 100px;
}

.detected-letter.empty {
  color: var(--text-muted);
  opacity: 0.5;
}

.detected-letter:not(.empty) {
  color: var(--accent-primary);
  text-shadow: 0 0 30px rgba(129, 140, 248, 0.4);
}

.detected-letter.stable {
  color: var(--accent-success);
  border-color: var(--accent-success);
  text-shadow: 0 0 30px rgba(52, 211, 153, 0.4);
  box-shadow: 0 0 24px rgba(52, 211, 153, 0.15);
}

.detected-letter.success-flash {
  animation: successPulse 0.6s ease;
}

@keyframes successPulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.15); box-shadow: 0 0 40px rgba(52, 211, 153, 0.4); }
  100% { transform: scale(1); }
}

/* ---------- Stability Bar ---------- */
.stability-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  margin-top: var(--space-sm);
  overflow: hidden;
}

.stability-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--gradient-cool);
  border-radius: var(--radius-full);
  transition: width 0.1s linear;
}

.stability-bar-fill.full {
  background: var(--accent-success);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}

/* ---------- Status Bar ---------- */
.status-bar {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  text-align: center;
}

.status-text {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
}

/* ---------- Info Panel ---------- */
.info-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  transition: border-color 0.3s ease;
}

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

.info-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

/* Collapsible Info Cards */
.collapsible-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.collapsible-header .info-title {
  margin-bottom: 0;
  color: var(--text-primary);
  transition: color 0.2s ease;
}

.collapsible-header:hover .info-title {
  color: var(--accent-primary);
}

.chevron-icon {
  color: var(--text-muted);
  transition: transform 0.3s ease, color 0.2s ease;
}

.collapsible-header:hover .chevron-icon {
  color: var(--accent-primary);
}

.collapsible-card.open .chevron-icon {
  transform: rotate(180deg);
}

.collapsible-content {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: all 0.3s ease;
}

.collapsible-card.open .collapsible-content {
  margin-top: var(--space-md);
  max-height: 250px;
  opacity: 1;
}

/* Slider Overrides within Info Cards */
.setting-slider-group {
  margin-bottom: var(--space-md);
}

.setting-slider-group:last-child {
  margin-bottom: 0;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xs);
}

.slider-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.slider-val {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent-primary);
  font-weight: 600;
}

.styled-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  outline: none;
  transition: border-color 0.2s ease;
}

.styled-slider:focus {
  border-color: var(--accent-primary);
}

.styled-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.styled-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: var(--shadow-glow);
}

.styled-slider::-moz-range-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: var(--accent-primary);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.styled-slider::-moz-range-thumb:hover {
  transform: scale(1.15);
  box-shadow: var(--shadow-glow);
}

/* SVG Icon Toggle */
.setting-toggle-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

.icon-toggle {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: all 0.2s ease;
  color: var(--text-secondary);
}

.icon-toggle:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
  color: var(--text-primary);
  box-shadow: var(--shadow-glow);
}

.icon-toggle input {
  display: none;
}

.icon-toggle-switch {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.icon-eye-open, .icon-eye-closed {
  position: absolute;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* Base state (active/checked) */
.icon-toggle input:checked + .icon-toggle-switch .icon-eye-open {
  opacity: 1;
  transform: scale(1);
  color: var(--accent-primary);
}

.icon-toggle input:checked + .icon-toggle-switch .icon-eye-closed {
  opacity: 0;
  transform: scale(0.8);
}

/* Inactive/unchecked state */
.icon-toggle input:not(:checked) + .icon-toggle-switch .icon-eye-open {
  opacity: 0;
  transform: scale(0.8);
}

.icon-toggle input:not(:checked) + .icon-toggle-switch .icon-eye-closed {
  opacity: 1;
  transform: scale(1);
  color: var(--text-muted);
}

/* Arm display */
.arm-display {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.arm-item {
  flex: 1;
  text-align: center;
  padding: var(--space-md);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.arm-item-left {
  border-color: var(--arm-left-color);
  box-shadow: 0 0 8px rgba(var(--arm-left-rgb), 0.15);
}

.arm-item-right {
  border-color: var(--arm-right-color);
  box-shadow: 0 0 8px rgba(var(--arm-right-rgb), 0.15);
}

.arm-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.arm-item-left .arm-label { color: var(--arm-left-color); }
.arm-item-right .arm-label { color: var(--arm-right-color); }

.arm-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-secondary);
}

.arm-item-left .arm-value { color: var(--arm-left-color); }
.arm-item-right .arm-value { color: var(--arm-right-color); }

.confidence-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.confidence-value {
  font-family: var(--font-mono);
  color: var(--accent-primary);
  font-weight: 600;
}

/* ---------- Game Panels ---------- */
.game-panel {
  max-height: 0;
  overflow: hidden;
  padding: 0;
  border: none;
  opacity: 0;
  transition: all 0.35s ease;
}

.game-panel.visible {
  max-height: 500px;
  padding: var(--space-lg);
  border: 1px solid var(--border-subtle);
  opacity: 1;
}

/* Quiz mode */
.quiz-content {
  text-align: center;
}

.quiz-instruction {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: var(--space-md);
}

.quiz-target {
  font-family: var(--font-mono);
  font-size: 4rem;
  font-weight: 900;
  background: var(--gradient-warm);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
  margin-bottom: var(--space-md);
  transition: transform 0.3s ease;
}

.quiz-target.correct-flash {
  animation: correctFlash 0.8s ease;
}

@keyframes correctFlash {
  0% { transform: scale(1); filter: brightness(1); }
  30% { transform: scale(1.2); filter: brightness(1.5); }
  100% { transform: scale(1); filter: brightness(1); }
}

.quiz-stats {
  display: flex;
  justify-content: center;
  gap: var(--space-lg);
}

.quiz-score, .quiz-streak {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Spell mode */
.spell-content {
  text-align: center;
}

.spell-input-group {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.spell-input {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  transition: border-color 0.2s ease;
}

.spell-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-dim);
}

.spell-end-behavior-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.behavior-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.segmented-control {
  display: flex;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 3px;
  flex: 1;
  max-width: 100%;
  position: relative;
}

.segmented-control__indicator {
  position: absolute;
  top: 3px;
  left: 3px;
  height: calc(100% - 6px);
  background: #102033;
  border-radius: calc(var(--radius-sm) - 3px);
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 0;
  pointer-events: none;
}

.segmented-control input[type="radio"] {
  display: none;
}

.segmented-control label {
  flex: 1 1 auto;
  text-align: center;
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: calc(var(--radius-sm) - 3px);
  transition: all 0.2s ease;
  user-select: none;
  white-space: nowrap;
  position: relative;
  z-index: 1;
}

.segmented-control label:hover {
  color: var(--text-primary);
}

.segmented-control input[type="radio"]:checked + label {
  background: transparent !important;
  color: var(--bg-primary);
  font-weight: 600;
  transition: background 0s !important;
}

.spell-input::placeholder {
  color: var(--text-muted);
}

.spell-word-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-xs);
  margin-bottom: var(--space-md);
  min-height: 2.5rem;
  align-items: center;
}

.spell-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2.5rem;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  transition: all 0.3s ease;
}

.spell-letter.current {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-primary-dim);
  box-shadow: var(--shadow-glow);
  transform: scale(1.1);
}

.spell-letter.completed {
  border-color: var(--accent-success);
  color: var(--accent-success);
  background: rgba(52, 211, 153, 0.1);
}

.spell-placeholder {
  color: #102033; /* High contrast dark navy */
  font-size: 1.25rem;
  font-weight: 600;
  opacity: 1;
  text-align: center;
  padding: 20px;
  margin-top: 24px;
}

.spell-progress {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------- Reference Chart ---------- */
.reference-chart {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  transition: all 0.4s ease;
}

.reference-chart.visible {
  max-height: 800px;
  opacity: 1;
  padding: var(--space-xl);
  overflow-y: auto;
}

.ref-header {
  text-align: center;
  margin-bottom: var(--space-lg);
}

.ref-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.ref-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.semaphore-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: var(--space-sm);
}

.ref-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end; /* Canvas goes to bottom */
  padding: var(--space-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  min-height: 110px;
}

.ref-cell:hover {
  border-color: var(--accent-primary);
  background: var(--accent-primary-dim);
  transform: translateY(-2px);
}

.ref-letter {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-primary);
  margin-bottom: var(--space-xs);
  text-align: center;
  word-break: break-word;
  line-height: 1.1;
  flex-grow: 1; /* Allow it to grow and push canvas down */
  display: flex;
  align-items: center;
  justify-content: center;
}

.ref-canvas {
  display: block;
}

/* ---------- Responsive Design ---------- */
@media (max-width: 768px) {
  .app-container {
    padding: var(--space-sm);
  }

  .main-content {
    grid-template-columns: 1fr;
  }

  .mode-selector {
    flex-direction: column;
  }

  .mode-btn {
    padding: var(--space-sm) var(--space-md);
  }

  .video-container {
    aspect-ratio: 4 / 3;
  }

  .detected-letter {
    font-size: 2.5rem;
    padding: var(--space-sm) var(--space-md);
  }

  .info-panel {
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  .info-card {
    flex: 1;
    min-width: 140px;
    padding: var(--space-md);
  }

  .semaphore-grid {
    grid-template-columns: repeat(auto-fill, minmax(75px, 1fr));
  }

  .quiz-target {
    font-size: 3rem;
  }
}

@media (max-width: 480px) {
  .logo-text {
    font-size: 1rem;
  }

  .detected-letter {
    font-size: 2rem;
  }

  .arm-display {
    flex-direction: column;
    gap: var(--space-sm);
  }

  .quiz-target {
    font-size: 2.5rem;
  }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Mini Semaphore Display */
.mini-semaphore-display {
  position: absolute;
  bottom: 24px;
  left: 24px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  z-index: 15;
  width: 160px;       /* Fixed width to contain text */
  min-height: 200px;  /* Ensure room for canvas + text */
}

.mini-semaphore-display.visible {
  opacity: 1;
  transform: translateY(0);
}

.mini-semaphore-persp {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: var(--space-xs);
  line-height: 1.2;
}

#mini-semaphore-canvas {
  width: 120px;
  height: 120px;
  display: block;
  position: relative !important;
  transform: none !important; /* Cancel mirroring if inherited */
}

#mini-semaphore-label {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 1.5rem; /* Larger font to match larger card */
  color: var(--text-primary);
  margin-top: 8px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  text-align: center;
  word-break: break-word;
  line-height: 1.2;
}

.app-shell {
  padding-bottom: var(--space-2xl);
}

.wordmark-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.back-link,
.eyebrow,
.section-kicker {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.74rem;
  font-weight: 700;
}

.back-link {
  display: inline-flex;
  align-items: center;
  color: var(--text-secondary);
  border-bottom: 1px solid transparent;
}

.back-link:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

.eyebrow,
.section-kicker {
  color: var(--accent-secondary);
}

.logo {
  font-family: var(--font-display);
  letter-spacing: 0;
  font-size: 2rem;
}

.logo-text {
  background: linear-gradient(135deg, #f8f2e8 20%, #d4c4aa 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-icon {
  filter: drop-shadow(0 0 10px rgba(102, 115, 79, 0.35));
}

.stage-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
  padding: var(--space-lg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 248, 236, 0.06), rgba(23, 44, 66, 0.32));
}

.stage-title {
  margin-top: 6px;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 0.95;
}

.stage-copy {
  max-width: 28rem;
  color: var(--text-secondary);
  font-size: 1rem;
}

.info-card-quiet {
  background: linear-gradient(180deg, rgba(255, 248, 236, 0.05), rgba(29, 53, 80, 0.84));
}

@media (max-width: 820px) {
  .stage-heading {
    flex-direction: column;
    align-items: flex-start;
  }
}

body {
  color: #102033;
  background:
    radial-gradient(circle at top left, rgba(102, 115, 79, 0.08), transparent 30%),
    radial-gradient(circle at 88% 16%, rgba(43, 124, 143, 0.08), transparent 26%),
    linear-gradient(180deg, #f7f1e6 0%, #f2eadb 100%);
}

.app-page::before {
  background:
    linear-gradient(rgba(16, 32, 51, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16, 32, 51, 0.03) 1px, transparent 1px);
}

.loading-overlay {
  background: rgba(247, 241, 230, 0.96);
}

.loading-text {
  color: #4f6479;
}

.app-header {
  max-width: 1440px;
  margin: 0 auto var(--space-md);
  padding: 18px 16px 0;
  align-items: end;
}

.header-left,
.header-right {
  align-items: center;
}

.back-link {
  color: #4f6479;
}

.wordmark-block .eyebrow {
  color: #2b7c8f;
}

.header-control {
  background: rgba(255, 253, 248, 0.86);
  border-color: rgba(49, 81, 113, 0.14);
  box-shadow: 0 10px 18px rgba(16, 32, 51, 0.06);
}

.ctrl-label {
  color: #4f6479;
}

.ctrl-select {
  color: #102033;
}

.ctrl-select option {
  background: #fffaf2;
  color: #102033;
}

.app-container {
  padding-top: 0;
}

.app-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.mode-selector {
  margin-bottom: 0;
  padding: 8px;
  border-radius: 20px;
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid rgba(49, 81, 113, 0.12);
  box-shadow: 0 12px 22px rgba(16, 32, 51, 0.08);
}

.mode-btn {
  min-height: 54px;
  background: transparent;
  border: none;
  color: #4f6479;
}

.mode-btn:hover {
  background: rgba(16, 32, 51, 0.05);
  border-color: transparent;
  color: #102033;
  box-shadow: none;
}

.mode-btn.active {
  background: linear-gradient(135deg, rgba(102, 115, 79, 0.15), rgba(43, 124, 143, 0.1));
  color: #102033;
  border: 1px solid rgba(102, 115, 79, 0.22);
  box-shadow: none;
}

.mode-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: rgba(16, 32, 51, 0.06);
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 18px;
  border: 1px solid rgba(49, 81, 113, 0.12);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.9);
  color: #102033;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 22px rgba(16, 32, 51, 0.08);
}

.toolbar-btn-help {
  min-width: 110px;
}

.toolbar-btn.active {
  border-color: rgba(102, 115, 79, 0.26);
  background: rgba(102, 115, 79, 0.1);
}

.toolbar-btn__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(102, 115, 79, 0.12);
  color: #4e5a3e;
}

.main-content {
  align-items: start;
}

.video-container {
  border-radius: 26px;
  background: #183149;
  border: 1px solid rgba(49, 81, 113, 0.18);
  box-shadow: 0 24px 42px rgba(16, 32, 51, 0.18);
}

.status-bar,
.info-card,
.reference-chart {
  background: rgba(255, 253, 248, 0.92);
  border-color: rgba(49, 81, 113, 0.12);
  box-shadow: 0 12px 24px rgba(16, 32, 51, 0.08);
}

.status-text,
.info-title,
.quiz-instruction,
.confidence-row,
.slider-label,
.behavior-label,
.ref-subtitle {
  color: #4f6479;
}

.ref-header h2,
.arm-value,
.quiz-score,
.quiz-streak,
.spell-progress,
#mini-semaphore-label,
.collapsible-header .info-title {
  color: #102033;
}

.arm-item,
.spell-end-behavior-group,
.spell-input,
.ref-cell,
.icon-toggle,
.styled-slider {
  background: rgba(247, 241, 230, 0.9);
  border-color: rgba(49, 81, 113, 0.12);
}

.spell-input {
  color: #102033;
}

.spell-input::placeholder,
.spell-placeholder {
  color: #102033;
}

.segmented-control {
  background: rgba(16, 32, 51, 0.06);
}

.segmented-control label {
  color: #4f6479;
}

.segmented-control input[type="radio"]:checked + label {
  background: transparent !important;
  color: #fffaf2;
  transition: background 0s !important;
}

.reference-chart.visible {
  background: rgba(255, 253, 248, 0.96);
}

.ref-cell:hover {
  background: rgba(102, 115, 79, 0.08);
}

.mini-semaphore-display {
  background: rgba(255, 253, 248, 0.95);
  border-color: rgba(49, 81, 113, 0.12);
}

.mini-semaphore-persp {
  color: #4f6479;
}

@media (max-width: 900px) {
  .app-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-btn {
    justify-content: center;
  }
}

/* ---------- Trainer Redesign Overrides ---------- */
.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding-top: 22px;
}

.header-left {
  min-width: 0;
  gap: 18px;
}

.back-link {
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.88);
  border: 1px solid rgba(49, 81, 113, 0.12);
  box-shadow: 0 10px 18px rgba(16, 32, 51, 0.06);
  color: #35506c;
  text-decoration: none;
  letter-spacing: 0.08em;
}

.back-link svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.back-link:hover {
  color: #102033;
  border-color: rgba(102, 115, 79, 0.22);
  background: #fffdf8;
}

.wordmark-block {
  flex: 1 1 auto;
  min-width: 0;
  gap: 0;
}

.logo {
  gap: 10px;
  max-width: 760px;
  font-size: clamp(1.8rem, 2.45vw, 2.55rem);
  line-height: 0.94;
  white-space: nowrap;
}

.logo-text {
  background: none;
  -webkit-text-fill-color: #102033;
  color: #102033;
}

.logo-icon {
  width: 34px;
  height: 34px;
  filter: none;
}

.header-right {
  flex: 0 0 auto;
  gap: 10px;
  justify-content: flex-end;
}

.header-control {
  min-height: 48px;
  padding: 0 12px 0 10px;
  border-radius: 16px;
}

.ctrl-select {
  font-size: 0.92rem;
  font-weight: 600;
  max-width: 168px;
}

.app-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  align-items: center;
  gap: 20px;
  margin-bottom: var(--space-lg);
}

.mode-selector {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  width: 100%;
  gap: 6px;
  padding: 6px;
  border-radius: 20px;
  background: rgba(16, 32, 51, 0.04);
  border: 1px solid rgba(49, 81, 113, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.mode-indicator {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 0;
  height: 0;
  background: #fffdf8;
  border-radius: 14px;
  box-shadow: 0 4px 12px rgba(16, 32, 51, 0.12);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 0;
  pointer-events: none;
}

.mode-btn {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1 1 0;
  min-height: 54px;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 14px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  background: transparent;
  color: #4f6479;
  border: none !important;
  box-shadow: none !important;
}

.mode-btn:not(.active):hover {
  background: rgba(16, 32, 51, 0.05);
}

.mode-btn.active {
  background: transparent !important;
  color: #102033 !important;
  box-shadow: none !important;
  border: none !important;
  font-weight: 600;
  transition: background 0s, border 0s, box-shadow 0s !important;
}

.mode-label {
  font-size: 1.15rem;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
}

.toolbar-btn {
  min-height: 54px;
  padding: 0 20px;
}

.toolbar-btn__icon {
  font-size: 1rem;
}

.toolbar-btn__icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.main-content {
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
}

.video-container {
  isolation: isolate;
}

.video-tools {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 18;
  width: min(314px, calc(100% - 120px));
  padding: 12px 14px;
  border-radius: 20px;
  background: rgba(255, 253, 248, 0.82);
  border: 1px solid rgba(49, 81, 113, 0.14);
  box-shadow: 0 16px 26px rgba(16, 32, 51, 0.13);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.video-tools__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 8px;
  transition: margin-bottom 0.3s ease;
}

.video-tools__title-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.video-tools__title {
  display: inline-block;
  color: #102033;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.video-tools__title-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: rgba(16, 32, 51, 0.08);
  color: #4f6479;
  flex: 0 0 auto;
}

.video-tools__title-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.video-tools__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: none;
  border-radius: 12px;
  background: rgba(16, 32, 51, 0.08);
  color: #35506c;
  cursor: pointer;
}

.video-tools__toggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.2s ease;
}

.video-tools__body {
  display: grid;
  gap: 10px;
  max-height: 600px;
  opacity: 1;
  transition: max-height 0.35s ease, opacity 0.25s ease;
}

.video-tools.collapsed {
  width: 200px;
}

.video-tools.collapsed .video-tools__header {
  margin-bottom: 0;
}

.video-tools.collapsed .video-tools__body {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.video-tools.collapsed .video-tools__toggle svg {
  transform: rotate(-90deg);
}

.video-tools__group + .video-tools__group {
  margin-top: 10px;
}

.video-tools__group--tight .video-tools__row + .video-tools__row {
  margin-top: 8px;
}

.video-tools__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.video-tools__row + .video-tools__row {
  margin-top: 10px;
}

.video-tools__label {
  color: #35506c;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.2;
}

.video-tools__select-wrap {
  position: relative;
  margin-top: 6px;
}

.video-tools__select-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 15px;
  height: 15px;
  transform: translateY(-50%);
  fill: none;
  stroke: #4f6479;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.video-tools__select {
  width: 100%;
  min-height: 42px;
  padding: 0 36px 0 34px;
  border: 1px solid rgba(49, 81, 113, 0.12);
  border-radius: 14px;
  background: rgba(247, 241, 230, 0.95);
  color: #102033;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  outline: none;
}

.video-tools__select option {
  color: #102033;
  background: #fffaf2;
}

.camera-fab {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 19;
  width: 60px;
  height: 60px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 250, 242, 0.32);
  border-radius: 20px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 16px 28px rgba(16, 32, 51, 0.2);
  color: #102033;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.camera-fab:hover {
  transform: translateY(-1px);
}

.camera-fab:focus-visible {
  outline: 2px solid rgba(33, 96, 253, 0.5);
  outline-offset: 3px;
}

.camera-fab[data-state="off"] {
  background: var(--accent-primary);
  border-color: rgba(255, 250, 242, 0.36);
  color: #fffaf2;
}

.camera-fab__icon {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.camera-fab__icon svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.camera-fab[data-state="on"] .camera-fab__icon--on,
.camera-fab[data-state="off"] .camera-fab__icon--off {
  opacity: 1;
  transform: scale(1);
}

.overlay-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.overlay-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.overlay-switch__track {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: rgba(16, 32, 51, 0.12);
  transition: background 0.2s ease;
}

.overlay-switch__track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fffdf8;
  box-shadow: 0 3px 8px rgba(16, 32, 51, 0.22);
  transition: transform 0.2s ease;
}

.overlay-switch input:checked + .overlay-switch__track {
  background: linear-gradient(135deg, #66734f, #7b8c5d);
}

.overlay-switch input:checked + .overlay-switch__track::after {
  transform: translateX(18px);
}

.segmented-control--compact {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  padding: 4px;
  border-radius: 14px;
  background: rgba(16, 32, 51, 0.08);
}

.segmented-control--compact label {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 800;
}

.detection-overlay {
  top: 18px;
  right: 18px;
}

.detected-letter {
  min-width: 118px;
  padding: 16px 28px;
  border-radius: 22px;
  background: rgba(16, 32, 51, 0.84);
  border-color: rgba(126, 211, 173, 0.46);
}

.detected-letter:not(.empty) {
  color: #9fe0bf;
  text-shadow: none;
}

.stability-bar {
  margin-top: 10px;
  height: 5px;
}

.mini-semaphore-display {
  bottom: 18px;
  left: 18px;
  width: auto;
  min-width: 180px;
  min-height: 0;
  padding: 14px 14px 16px;
  border-radius: 22px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 18px 30px rgba(16, 32, 51, 0.14);
}

.mini-semaphore-display.size-sm {
  min-width: 154px;
}

.mini-semaphore-display.size-md {
  min-width: 182px;
}

.mini-semaphore-display.size-lg {
  min-width: 214px;
}

.mini-semaphore-persp {
  margin-bottom: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.15;
}

#mini-semaphore-canvas {
  display: block;
  margin: 0 auto;
}

.mini-semaphore-display.size-sm #mini-semaphore-canvas {
  width: 96px;
  height: 96px;
}

.mini-semaphore-display.size-md #mini-semaphore-canvas {
  width: 132px;
  height: 132px;
}

.mini-semaphore-display.size-lg #mini-semaphore-canvas {
  width: 164px;
  height: 164px;
}

#mini-semaphore-label {
  margin-top: 6px;
  font-size: 2rem;
  font-weight: 800;
  color: #102033;
  text-shadow: none;
}

.status-bar {
  min-height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
}

.status-text {
  font-size: 1.1rem;
  font-weight: 600;
}

.info-panel {
  gap: 16px;
}

.info-card {
  border-radius: 22px;
  padding: 20px;
}

.info-title {
  margin-bottom: 14px;
  font-size: 0.82rem;
  letter-spacing: 0.14em;
}

.arm-display {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.arm-item {
  min-height: 108px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 18px 14px;
  background: rgba(247, 241, 230, 0.95);
}

.arm-label {
  display: block;
  margin-bottom: 8px;
}

.arm-value {
  font-size: 1.72rem;
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.confidence-row {
  margin-top: 14px;
  font-size: 0.98rem;
  font-weight: 700;
}

#quiz-panel,
#spell-panel {
  display: none;
}

#quiz-panel.visible,
#spell-panel.visible {
  display: block;
}

@media (max-width: 1100px) {
  .main-content {
    grid-template-columns: 1fr;
  }

  .info-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

@media (max-width: 900px) {
  .app-header {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .header-left,
  .header-right {
    width: 100%;
  }

  .header-left {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .header-right {
    justify-content: flex-start;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .toolbar-actions .toolbar-btn {
    flex: 1 1 0;
    justify-content: center;
  }

  .video-tools {
    width: min(314px, calc(100% - 36px));
  }
}

@media (max-width: 720px) {
  .logo {
    font-size: 1.72rem;
  }

  .mode-selector {
    display: grid;
    grid-template-columns: 1fr;
  }

  .video-tools {
    position: static;
    width: 100%;
    margin: 14px;
  }

  .detection-overlay {
    top: auto;
    right: 14px;
    bottom: 14px;
  }

  .mini-semaphore-display {
    left: auto;
    right: 14px;
    bottom: 106px;
  }
}

/* ---------- Developer Footer ---------- */
.site-footer {
  padding: 16px 16px 32px;
  text-align: center;
  color: var(--text-secondary);
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.footer-content p {
  margin: 0;
}

.developer-credit {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-card);
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
}

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

.social-links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: color 0.2s ease, transform 0.2s ease;
}

.social-links a:hover {
  color: var(--signal-primary);
  transform: translateY(-2px);
}

.social-links svg {
  width: 20px;
  height: 20px;
}
