/* ============================================================
   สีหลอกสมอง — Modern Tactile Portrait Mobile Game UI
   - 100% Portrait-First Mobile Shell (Desktop Framed + Fullscreen Phone)
   - Self-Hosted Modern Thai Geometric Font: Prompt (500 / 700 / 900)
   - Zero External Requests | Tactile 3D Keycap Stroop Board (3x4)
   ============================================================ */

@font-face {
  font-family: 'Prompt';
  src: url('./fonts/Prompt-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Prompt';
  src: url('./fonts/Prompt-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Prompt';
  src: url('./fonts/Prompt-Black.ttf') format('truetype');
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --surface-outer: #d7e0ef;
  --surface-app: #f3f6fc;
  --surface-card: #ffffff;
  --surface-subtle: #e9eef8;
  --tray-bg: #171c2b;
  --tray-border: #2a334c;
  --border-soft: #d7dfef;
  --border-depth: #bfcbe2;

  --ink-primary: #121826;
  --ink-secondary: #4e5a74;
  --ink-muted: #76829d;

  --brand-indigo: #4f46e5;
  --brand-indigo-dark: #3730a3;
  --rule-text: #2563eb;
  --rule-bg: #db2777;
  --rule-mixed: #ea580c;
  --state-safe: #059669;
  --state-danger: #e11d48;

  --font-main: 'Prompt', -apple-system, BlinkMacSystemFont, 'Noto Sans Thai', 'Segoe UI', sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-main);
  color: var(--ink-primary);
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* Desktop Studio Backdrop — centers the strict mobile portrait frame */
body {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 18% 15%, rgba(79, 70, 229, 0.14), transparent 42%),
    radial-gradient(circle at 84% 85%, rgba(219, 39, 119, 0.12), transparent 44%),
    linear-gradient(155deg, #e2e8f5 0%, #cdd7ea 100%);
}

.hidden {
  display: none !important;
}

/* ---------- Strict Portrait Mobile Game Frame ---------- */
.app-shell {
  position: relative;
  width: 100%;
  max-width: 416px;
  height: 100dvh;
  background: var(--surface-app);
  background-image: radial-gradient(rgba(18, 24, 38, 0.055) 1px, transparent 1px);
  background-size: 16px 16px;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

/* Elevated Portrait Phone Frame on Desktop / Tablet Screens */
@media (min-width: 500px) {
  body {
    padding: 16px;
  }

  .app-shell {
    width: min(412px, 100vw - 32px);
    height: min(812px, calc(100dvh - 32px));
    border-radius: 30px;
    border: 5px solid #ffffff;
    box-shadow:
      0 26px 65px rgba(18, 24, 38, 0.22),
      0 6px 18px rgba(18, 24, 38, 0.1),
      inset 0 0 0 1px rgba(18, 24, 38, 0.08);
    padding: 13px 13px 12px;
  }
}

.vfx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 40;
}

/* ---------- Top Header ---------- */
.studio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: var(--tray-bg);
  padding: 5px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  flex-shrink: 0;
  box-shadow: 0 3px 0 #0b0e18;
}

.bm-tile {
  border-radius: 3px;
}
.bm-tile.t1 { background: #ef233c; }
.bm-tile.t2 { background: #ffd60a; }
.bm-tile.t3 { background: #22c55e; }
.bm-tile.t4 { background: #38bdf8; }

.brand-title {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.1;
  color: var(--ink-primary);
  white-space: nowrap;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mic-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  border: 1.5px solid transparent;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.mic-pill .mic-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mic-pill.mic-off {
  color: #065f46;
  background: #d1fae5;
  border-color: #a7f3d0;
}
.mic-pill.mic-off .mic-dot {
  background: #10b981;
}

.mic-pill.mic-on {
  color: #ffffff;
  background: #e11d48;
  border-color: #be123c;
  box-shadow: 0 3px 10px rgba(225, 29, 72, 0.32);
}
.mic-pill.mic-on .mic-dot {
  background: #ffffff;
  animation: pulseDot 0.9s infinite;
}

.mic-pill.mic-tap {
  color: #1d4ed8;
  background: #dbeafe;
  border-color: #bfdbfe;
}
.mic-pill.mic-tap .mic-dot {
  background: #2563eb;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.55; }
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  border: 1.5px solid var(--border-soft);
  border-bottom: 3px solid var(--border-depth);
  background: var(--surface-card);
  color: var(--ink-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, border-bottom-width 0.1s ease, background 0.15s ease;
}

.icon-btn:hover {
  background: #f8faff;
}
.icon-btn:active {
  transform: translateY(2px);
  border-bottom-width: 1.5px;
}

/* ---------- Unified Mission, Score & Stopwatch Deck ---------- */
.mission-deck {
  background: var(--surface-card);
  border: 1.5px solid var(--border-soft);
  border-bottom: 4px solid var(--border-depth);
  border-radius: 18px;
  padding: 8px 11px 9px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}

.hud-ribbon {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-subtle);
  border-radius: 11px;
  padding: 4px 8px;
  gap: 4px;
}

.metric-item {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1px 2px;
  border-radius: 8px;
  transition: background 0.2s ease;
}

.metric-label {
  font-size: 9.5px;
  font-weight: 500;
  color: var(--ink-muted);
  line-height: 1.1;
  white-space: nowrap;
}

.metric-val {
  font-size: 14.5px;
  font-weight: 900;
  color: var(--ink-primary);
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.metric-divider {
  width: 1px;
  height: 20px;
  background: var(--border-soft);
  flex-shrink: 0;
}

.combo-pill.hot {
  background: #fef3c7;
}
.combo-pill.hot .metric-label {
  color: #b45309;
  font-weight: 700;
}
.combo-pill.hot .metric-val {
  color: #d97706;
}

.rule-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.rule-badge {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 6px;
  border-radius: 12px;
  transition: background 0.18s ease, transform 0.18s ease;
}

.rule-badge.rule-text {
  background: #eff6ff;
  color: #1e40af;
}
.rule-badge.rule-text .rule-icon {
  background: var(--rule-text);
}

.rule-badge.rule-bg {
  background: #fdf2f8;
  color: #9d174d;
}
.rule-badge.rule-bg .rule-icon {
  background: var(--rule-bg);
}

.rule-badge.rule-mixed {
  background: #fff7ed;
  color: #9a3412;
}
.rule-badge.rule-mixed .rule-icon {
  background: var(--rule-mixed);
}

.rule-badge.rule-flash {
  animation: rulePop 0.3s cubic-bezier(0.22, 1.3, 0.36, 1);
}

@keyframes rulePop {
  0% { transform: scale(0.95); }
  55% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.rule-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  color: #ffffff;
  flex-shrink: 0;
}

.rule-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.rule-eyebrow {
  font-size: 9.5px;
  font-weight: 700;
  opacity: 0.78;
  line-height: 1.1;
}

.rule-copy strong {
  font-size: 14px;
  font-weight: 900;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timer-readout {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 2px;
  flex-shrink: 0;
}

.speed-chip {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 900;
  color: #ffffff;
  background: #ea580c;
  white-space: nowrap;
}

.timer-number {
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  min-width: 60px;
  text-align: right;
  color: var(--ink-primary);
}

.timer-number small {
  font-size: 11.5px;
  font-weight: 700;
  margin-left: 2px;
  color: var(--ink-muted);
}

.timer-number.urgent {
  color: var(--state-danger);
  animation: urgentPulse 0.35s ease-in-out infinite alternate;
}

@keyframes urgentPulse {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

.timer-track {
  width: 100%;
  height: 9px;
  border-radius: 999px;
  background: var(--surface-subtle);
  overflow: hidden;
}

.timer-fill {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #10b981;
  transform-origin: left center;
  will-change: width;
  transition: background 0.15s ease;
}

.timer-fill.warn {
  background: #f59e0b;
}

.timer-fill.danger {
  background: #e11d48;
}

/* ---------- Hero 3x4 Tactile Keycap Board (Always Portrait 3x4) ---------- */
.board-stage {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  width: 100%;
}

.board-tray {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--tray-bg);
  border: 2px solid var(--tray-border);
  border-bottom: 5px solid #0d111c;
  border-radius: 22px;
  padding: 8px;
  box-shadow: inset 0 4px 14px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
}

.board-tray.shake-wrong {
  animation: bezelShake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes bezelShake {
  10%, 90% { transform: translateX(-4px); }
  20%, 80% { transform: translateX(6px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* Always 3 columns x 4 rows for Mobile Portrait experience */
.stroop-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.stroop-tile {
  position: relative;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.22);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.36),
    inset 0 -5px 0 rgba(0, 0, 0, 0.24),
    0 2px 4px rgba(0, 0, 0, 0.28);
  transition: transform 0.12s ease, opacity 0.15s ease, filter 0.15s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  isolation: isolate;
}

.stroop-word {
  position: relative;
  z-index: 2;
  font-size: clamp(20px, 5.8vw, 27px);
  font-weight: 900;
  letter-spacing: -0.01em;
  line-height: 1.1;
  text-align: center;
  padding: 0 4px 3px;
  white-space: nowrap;
}

.stroop-word.outline-dark {
  text-shadow:
    0 1.4px 0 rgba(12, 16, 28, 0.88),
    -1.1px -1.1px 0 rgba(12, 16, 28, 0.78),
    1.1px -1.1px 0 rgba(12, 16, 28, 0.78),
    -1.1px 1.1px 0 rgba(12, 16, 28, 0.78),
    1.1px 1.1px 0 rgba(12, 16, 28, 0.78),
    0 3px 6px rgba(0, 0, 0, 0.32);
}

.stroop-word.outline-light {
  text-shadow:
    0 1.4px 0 rgba(255, 255, 255, 0.96),
    -1.4px -1.4px 0 rgba(255, 255, 255, 0.92),
    1.4px -1.4px 0 rgba(255, 255, 255, 0.92),
    -1.4px 1.4px 0 rgba(255, 255, 255, 0.92),
    1.4px 1.4px 0 rgba(255, 255, 255, 0.92),
    0 3px 6px rgba(0, 0, 0, 0.22);
}

/* Active Scanner Hop */
.stroop-tile.scanning {
  z-index: 6;
  transform: scale(1.055);
  border: 3px solid #ffffff;
  box-shadow:
    0 0 0 3px #facc15,
    0 0 22px rgba(250, 204, 21, 0.9),
    inset 0 2px 0 rgba(255, 255, 255, 0.6);
}

/* Dim non-target tiles on Lock */
.stroop-grid.has-target .stroop-tile:not(.active-target) {
  opacity: 0.28;
  filter: saturate(0.45) brightness(0.76);
  transform: scale(0.96);
}

.stroop-tile.active-target {
  z-index: 10;
  transform: scale(1.075);
  border: 3.5px solid #ffffff;
  box-shadow:
    0 0 0 4px #facc15,
    0 0 28px rgba(250, 204, 21, 0.95),
    0 10px 24px rgba(0, 0, 0, 0.55);
  animation: targetLockBounce 0.26s cubic-bezier(0.22, 1.4, 0.36, 1);
}

@keyframes targetLockBounce {
  0% { transform: scale(0.95); }
  55% { transform: scale(1.11); }
  100% { transform: scale(1.075); }
}

.stroop-tile.correct-hit {
  z-index: 12;
  border-color: #ffffff;
  box-shadow:
    0 0 0 5px #22c55e,
    0 0 30px rgba(34, 197, 94, 0.95);
}

.stroop-tile.wrong-hit {
  z-index: 12;
  border-color: #ffffff;
  box-shadow:
    0 0 0 5px #e11d48,
    0 0 30px rgba(225, 29, 72, 0.95);
}

.tile-target-tag {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 4;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 9.5px;
  font-weight: 900;
  background: #121826;
  color: #fde047;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

/* Floating Toast inside Board */
.board-toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 25;
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 18px;
  font-weight: 900;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  animation: toastPop 0.24s cubic-bezier(0.22, 1.35, 0.36, 1);
}

.board-toast.ok {
  background: #16a34a;
  color: #ffffff;
  border: 2.5px solid #dcfce7;
}

.board-toast.warn {
  background: #e11d48;
  color: #ffffff;
  border: 2.5px solid #ffe4e6;
}

@keyframes toastPop {
  from { opacity: 0; transform: translate(-50%, -40%) scale(0.82); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ---------- Bottom Control Dock (Tactile Mobile Controls) ---------- */
.control-dock {
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}

.idle-controls {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* Segmented Mode Selector */
.mode-segment {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  background: var(--surface-subtle);
  padding: 4px;
  border-radius: 14px;
  border: 1.5px solid var(--border-soft);
}

.mode-pill {
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  border-radius: 10px;
  padding: 7px 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-pill strong {
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.mp-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-text { background: var(--rule-text); }
.dot-bg { background: var(--rule-bg); }
.dot-mixed { background: var(--rule-mixed); }

.mode-pill.active {
  background: var(--surface-card);
  color: var(--ink-primary);
  box-shadow: 0 2px 6px rgba(18, 24, 38, 0.1), 0 2px 0 var(--border-depth);
}
.mode-pill.active strong {
  font-weight: 900;
}

/* Primary Tactile 3D Arcade CTA */
.btn-primary {
  width: 100%;
  border: none;
  border-bottom: 4.5px solid var(--brand-indigo-dark);
  border-radius: 15px;
  padding: 11px 16px;
  font-family: inherit;
  font-size: 15.5px;
  font-weight: 900;
  color: #ffffff;
  background: var(--brand-indigo);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease, filter 0.15s ease;
}

.btn-primary:hover {
  filter: brightness(1.06);
}
.btn-primary:active {
  transform: translateY(3px);
  border-bottom-width: 1.5px;
}

.btn-svg-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.secondary-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.btn-secondary {
  border: 1.5px solid var(--border-soft);
  border-bottom: 3.5px solid var(--border-depth);
  border-radius: 13px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-primary);
  background: var(--surface-card);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.08s ease, border-bottom-width 0.08s ease, background 0.15s ease;
}

.btn-secondary:hover {
  background: #f8faff;
}
.btn-secondary:active {
  transform: translateY(2px);
  border-bottom-width: 1.5px;
}

/* Playing Controls (Voice Mode) */
.playing-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface-card);
  border: 1.5px solid var(--border-soft);
  border-bottom: 3.5px solid var(--border-depth);
  border-radius: 14px;
  padding: 9px 11px;
}

.voice-prompt-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-primary);
}

.voice-wave {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 18px;
  flex-shrink: 0;
}

.voice-wave span {
  width: 3px;
  height: 6px;
  border-radius: 99px;
  background: var(--brand-indigo);
  transition: height 0.15s ease;
}

.voice-wave.listening span {
  background: var(--state-danger);
  animation: waveBounce 0.68s ease-in-out infinite;
}
.voice-wave.listening span:nth-child(2) { animation-delay: 0.12s; }
.voice-wave.listening span:nth-child(3) { animation-delay: 0.24s; }
.voice-wave.listening span:nth-child(4) { animation-delay: 0.36s; }
.voice-wave.listening span:nth-child(5) { animation-delay: 0.48s; }

@keyframes waveBounce {
  0%, 100% { height: 5px; }
  50% { height: 18px; }
}

.btn-danger {
  border: none;
  border-bottom: 3px solid #9f1239;
  border-radius: 10px;
  padding: 7px 13px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 900;
  color: #ffffff;
  background: var(--state-danger);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-danger:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
}

/* Playing Controls (Tap Fallback Mode) */
.tap-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface-card);
  border: 1.5px solid var(--border-soft);
  border-bottom: 3.5px solid var(--border-depth);
  border-radius: 15px;
  padding: 8px 9px;
}

.tap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-secondary);
}

.btn-danger-mini {
  border: none;
  border-bottom: 2.5px solid #9f1239;
  border-radius: 8px;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 900;
  color: #ffffff;
  background: var(--state-danger);
  cursor: pointer;
}

.tap-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.tap-color-btn {
  border: 1.5px solid var(--border-soft);
  border-bottom: 3.5px solid var(--border-depth);
  border-radius: 11px;
  padding: 7px 5px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 900;
  color: var(--ink-primary);
  background: var(--surface-app);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.08s ease;
}

.tap-color-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}
.tap-color-btn:not(:disabled):active {
  transform: translateY(2px);
  border-bottom-width: 1.5px;
}

.tap-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid rgba(18, 24, 38, 0.25);
  flex-shrink: 0;
}

/* ---------- Live Mic Transcript Strip ---------- */
.transcript-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 12px;
  background: var(--tray-bg);
  color: #f8fafc;
  min-height: 36px;
}

.transcript-left {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex: 1;
}

.tr-badge {
  font-size: 9.5px;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.14);
  color: #cbd5e1;
  flex-shrink: 0;
  white-space: nowrap;
}

.tr-badge.live {
  background: #e11d48;
  color: #ffffff;
}

.transcript-text {
  font-size: 11.5px;
  font-weight: 500;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.transcript-right {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.detected-pill {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 900;
  white-space: nowrap;
  background: #10b981;
  color: #ffffff;
}

.detected-pill.wrong {
  background: #e11d48;
  color: #ffffff;
}

.btn-mic-test {
  border: none;
  background: #334155;
  color: #ffffff;
  border-radius: 8px;
  padding: 4px 9px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.btn-mic-test:hover {
  background: #475569;
}

.btn-mic-test.testing {
  background: #e11d48;
  color: #ffffff;
}

/* ---------- Modals (Contained neatly inside Portrait Frame) ---------- */
.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: rgba(15, 20, 36, 0.62);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-card {
  width: 100%;
  max-width: 372px;
  max-height: 92%;
  overflow-y: auto;
  background: var(--surface-card);
  border: 1.5px solid var(--border-soft);
  border-bottom: 5px solid var(--border-depth);
  border-radius: 22px;
  padding: 16px;
  box-shadow: 0 22px 48px rgba(18, 24, 38, 0.35);
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  font-size: 18px;
  font-weight: 900;
  color: var(--ink-primary);
}

.modal-close {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 1.5px solid var(--border-soft);
  background: var(--surface-subtle);
  color: var(--ink-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.setting-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-primary);
}

.segmented-group {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.seg-btn,
.seg-mini {
  border: 1.5px solid var(--border-soft);
  border-bottom: 3px solid var(--border-depth);
  background: var(--surface-app);
  color: var(--ink-secondary);
  border-radius: 10px;
  padding: 7px 4px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.seg-btn.active,
.seg-mini.active {
  background: var(--brand-indigo);
  border-color: var(--brand-indigo);
  border-bottom-color: var(--brand-indigo-dark);
  color: #ffffff;
}

.segmented-mini {
  display: flex;
  gap: 5px;
  flex-shrink: 0;
}
.seg-mini {
  padding: 6px 9px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 13px;
  background: var(--surface-app);
  border: 1.5px solid var(--border-soft);
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-info strong {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-primary);
}

.setting-info small {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink-muted);
  line-height: 1.3;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  display: inline-block;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}
.toggle-switch input:checked + .slider {
  background: #10b981;
}
.toggle-switch input:checked + .slider::before {
  transform: translateX(20px);
}

.privacy-note-box {
  padding: 9px 11px;
  border-radius: 12px;
  background: #ecfdf5;
  border: 1.5px solid #a7f3d0;
  font-size: 11px;
  line-height: 1.45;
  color: #065f46;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.btn-ghost {
  border: 1.5px solid #fecdd3;
  background: #fff1f2;
  color: #be123c;
  border-radius: 11px;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary-sm {
  border: none;
  border-bottom: 3.5px solid var(--brand-indigo-dark);
  border-radius: 11px;
  padding: 8px 20px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 900;
  color: #ffffff;
  background: var(--brand-indigo);
  cursor: pointer;
}

/* Game Over Modal */
.gameover-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.go-eyebrow {
  font-size: 12px;
  font-weight: 900;
  color: var(--state-danger);
}

.gameover-header h2 {
  font-size: 22px;
  font-weight: 900;
  color: var(--ink-primary);
}

.new-record-badge {
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  background: #fef3c7;
  color: #b45309;
  border: 1.5px solid #fcd34d;
}

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

.go-stat {
  background: var(--surface-app);
  border: 1.5px solid var(--border-soft);
  border-radius: 13px;
  padding: 8px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.go-stat span {
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-muted);
}
.go-stat strong {
  font-size: 20px;
  font-weight: 900;
  color: var(--ink-primary);
}

.go-breakdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 11px;
  border-radius: 15px;
  background: var(--surface-app);
  border: 1.5px solid var(--border-soft);
}

.go-missed-tile {
  width: 112px;
  height: 74px;
  border-radius: 13px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3), inset 0 -4px 0 rgba(0, 0, 0, 0.22), 0 4px 10px rgba(18, 24, 38, 0.16);
  font-size: 23px;
  font-weight: 900;
}

.go-explain {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  width: 100%;
}

.go-ex-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-wrap: wrap;
}
.go-ex-line > span:first-child {
  color: var(--ink-muted);
}

.go-answer-pill {
  padding: 1px 9px;
  border-radius: 7px;
  background: #d1fae5;
  color: #065f46;
  font-weight: 900;
}

.go-privacy-ok {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #065f46;
  background: #ecfdf5;
  border: 1.5px solid #a7f3d0;
  border-radius: 10px;
  padding: 6px 10px;
}

.go-actions {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 8px;
}

.go-actions .btn-primary {
  padding: 10px 12px;
  font-size: 14px;
}

/* ---------- Ultra-Compact Phones (<= 380px width or <= 740px height) ---------- */
@media (max-width: 390px), (max-height: 750px) {
  .app-shell {
    padding: max(7px, env(safe-area-inset-top)) 9px max(7px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
  }

  .brand-title {
    font-size: 16.5px;
  }

  .mic-pill {
    padding: 4px 8px;
    font-size: 10.5px;
  }

  .icon-btn {
    width: 31px;
    height: 31px;
    border-radius: 9px;
  }

  .mission-deck {
    padding: 6px 9px 7px;
    gap: 6px;
    border-radius: 15px;
  }

  .metric-val {
    font-size: 13.5px;
  }

  .rule-icon {
    width: 26px;
    height: 26px;
    font-size: 12px;
  }

  .rule-copy strong {
    font-size: 13px;
  }

  .timer-number {
    font-size: 21px;
    min-width: 54px;
  }

  .board-tray {
    padding: 6px;
    border-radius: 18px;
  }

  .stroop-grid {
    gap: 5.5px;
  }

  .stroop-tile {
    border-radius: 11px;
  }

  .stroop-word {
    font-size: clamp(19px, 5.6vw, 24px);
  }

  .mode-pill {
    padding: 6px 3px;
  }
  .mode-pill strong {
    font-size: 11.5px;
  }

  .btn-primary {
    padding: 10px 12px;
    font-size: 14.5px;
  }

  .btn-secondary {
    padding: 7px 8px;
    font-size: 12px;
  }

  .transcript-bar {
    padding: 4px 7px;
    min-height: 33px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
