/* ==========================================================================
   DASHBOARD.CSS — Generic Keyboard Tester
   ==========================================================================
   Layout structure:
   1. Root — .cm-dashboard (flex column, 100vh)
   2. Themes — .cm-style-* (CSS variable overrides per theme)
   3. Header Bar — .cm-header (top nav with branding + status badges)
   4. Metric Cards — .cm-metric-card (Polling, Latency, Active, Max Roll)
   5. Center Stage — .cm-stage (keyboard display area)
      5a. Toolbar — .cm-kb-toolbar (Style/Layout/Sound dropdowns)
      5b. Keyboard Canvas — .cm-keyboard-canvas (scaled keyboard frame)
   6. Side Panels — Left (Event Stream), Right (Control Deck + Typing Test)
   7. Responsive — Media queries for smaller viewports
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. ROOT CONTAINER — Full-screen flex dashboard
   -------------------------------------------------------------------------- */
:root {
  /* Default theme variables (Classic) — overridden by .cm-style-* classes on body */
  --kb-stage-bg: radial-gradient(circle at top, rgba(0, 255, 157, 0.06) 0%, rgba(0, 0, 0, 0.15) 60%);
  --kb-stage-grid:
    radial-gradient(circle at 50% 0%, rgba(0, 255, 157, 0.12), transparent 55%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.02) 0 1px, transparent 1px 120px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.02) 0 1px, transparent 1px 120px);
  --kb-frame: #1a1a1e;
  --kb-frame-border: #0b0b0b;
  --kb-mount: #080808;
  --kb-mount-border: rgba(255, 255, 255, 0.03);
  --kb-key: #2a2a32;
  --kb-key-top: #383842;
  --kb-key-shadow: #000;
  --kb-key-legend: #ffffff;
  /* Shared across components */
  --font-size-section-title: 24px;
  color-scheme: dark;
}

.cm-dashboard {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
  /* Fill viewport but allow scroll to below-fold content */
  /* Fixed height keeps keyboard layout stable */
  background: transparent;
  overflow: hidden;
  /* Keyboard area doesn't scroll internally */
  position: relative;
  font-family: "Space Grotesk", "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

/* --------------------------------------------------------------------------
   2. THEMES — Each .cm-style-* class overrides the CSS variables above.
   Available themes: cyber, mint, classic, carbon, glass, synthwave, retro,
   flat, floating, bubble, mac, arcade, dracula, nord
   -------------------------------------------------------------------------- */

/* Cyber — High-tech, cyberpunk, aggressive angles and neon */
.cm-style-cyber {
  --kb-stage-bg: radial-gradient(ellipse at bottom, #0d0f14 0%, #030406 100%);
  --kb-stage-grid: none;
  --kb-frame: #0b0c10;
  --kb-frame-border: #00ffcc;
  --kb-mount: #050608;
  --kb-key: #11151c;
  --kb-key-top: #1a202a;
  --kb-key-shadow: transparent;
  --kb-key-legend: #e0f8f5;
  --color-primary: #00ffcc;
  --color-surface: #0b0c10;
  --color-border: rgba(0, 255, 204, 0.2);
  --kb-key-text-glow: 0 0 10px rgba(0, 255, 204, 0.6);
}

/* Cyber overrides: aggressive cut corners and glowing accents */
.cm-style-cyber .cm-key {
  border-radius: 0;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  box-shadow: inset 0 0 0 1px rgba(0, 255, 204, 0.15) !important;
  background: var(--kb-key-top);
  border: none;
}

.cm-style-cyber .cm-key::after {
  display: none;
  /* No traditional 3D cap in cyber mode */
}

/* Add a subtle scanline or tech pattern inside the key */
.cm-style-cyber .cm-key-sub {
  font-size: 10px;
  /* Increased from 9px */
  font-weight: 600;
  opacity: 0.6;
  position: absolute;
  bottom: 6px;
  right: 6px;
  pointer-events: none;
  z-index: 2;
}

.cm-style-cyber .cm-key::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0, 255, 204, 0.03) 2px, rgba(0, 255, 204, 0.03) 4px);
  pointer-events: none;
}

.cm-style-cyber .cm-key--active {
  background: var(--color-primary) !important;
  color: #000 !important;
  box-shadow: 0 0 20px rgba(0, 255, 204, 0.4), inset 0 0 10px rgba(0, 0, 0, 0.5) !important;
  transform: translateY(2px) scale(0.97) !important;
}

.cm-style-cyber .cm-key--active .cm-key__label {
  color: #000 !important;
  text-shadow: none;
  font-weight: 800;
}

.cm-style-cyber .cm-key--active::before {
  opacity: 0.3;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0, 0, 0, 0.2) 2px, rgba(0, 0, 0, 0.2) 4px);
}

.cm-style-cyber .cm-keyboard-frame {
  border-radius: 0;
  clip-path: polygon(15px 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%, 0 15px);
  border: none;
  box-shadow: none;
  background: #0b0c10;
  position: relative;
  padding: 16px;
}

.cm-style-cyber .cm-keyboard-frame::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  clip-path: polygon(15px 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%, 0 15px);
  pointer-events: none;
}

.cm-style-cyber .cm-mount-main,
.cm-style-cyber .cm-mount-nav,
.cm-style-cyber .cm-mount-numpad {
  background: rgba(0, 255, 204, 0.02);
  border: 1px solid rgba(0, 255, 204, 0.15);
  border-radius: 0;
  box-shadow: none;
}

/* Perspective Cyber Grid Background */
.cm-style-cyber .cm-stage::before {
  content: '';
  position: absolute;
  top: 40%;
  left: -50%;
  right: -50%;
  bottom: -50%;
  background-image:
    linear-gradient(rgba(0, 255, 204, 0.2) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 255, 204, 0.2) 1px, transparent 1px);
  background-size: 40px 40px;
  background-position: center top;
  transform: perspective(400px) rotateX(60deg);
  opacity: 0.4;
  pointer-events: none;
}

/* Mint - Light teal/turquoise with high-contrast keys (clean, bright look) */
.cm-style-mint {
  --kb-stage-bg: linear-gradient(180deg, #f0faf7 0%, #e0f5ef 100%);
  --kb-stage-grid: none;
  --kb-frame: #ffffff;
  --kb-frame-border: #d0e8e2;
  --kb-mount: #f5fbf9;
  --kb-key: #9ce0cf;
  --kb-key-top: #b8ede2;
  --kb-key-shadow: #6bc4b0;
  --kb-key-legend: #004d40;
  --color-primary: #00897b;

  /* Global UI Overrides for Light Theme */
  --color-background: #e0f5ef;
  --color-surface: rgba(255, 255, 255, 0.7);
  --color-surface-lighter: rgba(255, 255, 255, 0.95);
  --color-text: #003328;
  --color-text-dim: #00796b;
  --color-border: #bce3d9;
}

/* Mint overrides: rounded keys, lighter feel */
.cm-style-mint .cm-key {
  border-radius: 10px;
  box-shadow: 0 4px 0 var(--kb-key-shadow, #6bc4b0),
    0 6px 12px rgba(0, 0, 0, 0.1);
}

.cm-style-mint .cm-key::after {
  border-radius: 8px;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.8);
}

.cm-style-mint .cm-keyboard-frame {
  border-radius: 18px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* Floating - Borderless keys floating on a clean surface */
.cm-style-floating {
  --kb-stage-bg: linear-gradient(135deg, #1a1d23 0%, #12151a 100%);
  --kb-stage-grid: none;
  --kb-frame: transparent;
  --kb-frame-border: transparent;
  --kb-mount: transparent;
  --kb-key: #2a2d35;
  --kb-key-top: #33363f;
  --kb-key-shadow: transparent;
  --kb-key-legend: #e8e8ec;
  --color-primary: #6c63ff;
  --color-surface: #1a1d23;
  --color-border: #6c63ff;
}

/* Floating overrides: no frame borders, soft glow shadows */
.cm-style-floating .cm-key {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4),
    0 0 1px rgba(255, 255, 255, 0.08);
}

.cm-style-floating .cm-key::after {
  border-radius: 10px;
  bottom: 4px;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.06);
}

.cm-style-floating .cm-keyboard-frame {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.cm-style-floating .cm-keyboard-mount {
  background: transparent !important;
  border: none !important;
}

/* Retro - Chunky rounded typewriter keys on cream background */
.cm-style-retro {
  --kb-stage-bg: linear-gradient(180deg, #f5f0e8 0%, #ebe5d6 100%);
  --kb-stage-grid: none;
  --kb-frame: #e8e0d0;
  --kb-frame-border: #d4cbb8;
  --kb-mount: #f0e8d8;
  --kb-key: #d4c9b0;
  --kb-key-top: #e8ddc5;
  --kb-key-shadow: #b8a888;
  --kb-key-legend: #3e3529;
  --color-primary: #c87941;

  /* Global UI Overrides for Light Theme */
  --color-background: #ebe5d6;
  --color-surface: #fdfaf4;
  --color-surface-lighter: #ffffff;
  --color-text: #3e3529;
  --color-text-dim: #7a6b57;
  --color-border: #dcd4c3;
}

/* Retro overrides: very rounded, chunky 3D depth */
.cm-style-retro .cm-key {
  border-radius: 14px;
  box-shadow: 0 8px 0 var(--kb-key-shadow, #b8a888),
    0 14px 20px rgba(0, 0, 0, 0.15);
}

.cm-style-retro .cm-key::after {
  border-radius: 11px;
  top: 5px;
  left: 5px;
  right: 5px;
  bottom: 10px;
  box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.5);
}

.cm-style-retro .cm-keyboard-frame {
  border-radius: 24px;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.12);
}

/* Flat - Ultra-thin laptop-style keys, no 3D depth */
.cm-style-flat {
  --kb-stage-bg: linear-gradient(180deg, #1e2028 0%, #16181e 100%);
  --kb-stage-grid: none;
  --kb-frame: #22242c;
  --kb-frame-border: #2c2e38;
  --kb-mount: #1a1c24;
  --kb-key: #2e3040;
  --kb-key-top: #363848;
  --kb-key-shadow: transparent;
  --kb-key-legend: #c8cad0;
  --color-primary: #64b5f6;
  --color-surface: #1e2028;
  --color-border: #64b5f6;
}

/* Flat overrides: no box-shadow, thin keys */
.cm-style-flat .cm-key {
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.cm-style-flat .cm-key::after {
  border-radius: 4px;
  top: 2px;
  left: 2px;
  right: 2px;
  bottom: 3px;
  box-shadow: none;
}

.cm-style-flat .cm-key:hover {
  transform: translateY(0px);
  box-shadow: 0 0 12px rgba(100, 181, 246, 0.2);
}

.cm-style-flat .cm-keyboard-frame {
  border-radius: 10px;
}

/* Bubble - Floating keyboard design: keys float individually, no visible frame.
   Inspired by the "floating keys on teal gradient" aesthetic. */
.cm-style-bubble {
  --kb-stage-bg: linear-gradient(145deg, #d4f5f0 0%, #b2ebf2 40%, #e0f7fa 100%);
  --kb-stage-grid: none;
  --kb-frame: transparent;
  /* Frame is invisible — keys float */
  --kb-frame-border: transparent;
  --kb-mount: transparent;
  --kb-key: #b2f0e8;
  /* Soft mint key base */
  --kb-key-top: #ccf5ef;
  /* Slightly lighter top face */
  --kb-key-shadow: #7ecfc2;
  /* Subtle teal shadow */
  --kb-key-legend: #00695c;
  /* Deep teal text for contrast */
  --color-primary: #00897b;

  /* Global UI Overrides for Light Theme */
  --color-background: #d4f5f0;
  --color-surface: rgba(255, 255, 255, 0.65);
  --color-surface-lighter: rgba(255, 255, 255, 0.9);
  --color-text: #004d40;
  --color-text-dim: #00796b;
  --color-border: rgba(0, 150, 136, 0.2);
}

/* Bubble: each key floats with its own individual shadow */
.cm-style-bubble .cm-key {
  border-radius: 22px;
  border: 1px solid rgba(0, 150, 136, 0.15);
  box-shadow:
    0 2px 0 var(--kb-key-shadow),
    /* Bottom edge depth */
    0 4px 12px rgba(0, 120, 110, 0.18);
  /* Soft ambient shadow */
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

/* Subtle hover lift for interactivity */
.cm-style-bubble .cm-key:hover {
  transform: translateY(-1px);
  box-shadow:
    0 3px 0 var(--kb-key-shadow),
    0 6px 18px rgba(0, 120, 110, 0.22);
}

/* Bold, readable key labels */
.cm-style-bubble .cm-key__label {
  text-shadow: none;
  font-weight: 800;
  color: var(--kb-key-legend);
}

/* Flat key top — minimal inner shadow for subtle 3D */
.cm-style-bubble .cm-key::after {
  border-radius: 19px;
  top: 1px;
  left: 1px;
  right: 1px;
  bottom: 3px;
  box-shadow: inset 0 1px 3px rgba(255, 255, 255, 0.5);
}

/* Invisible frame — no case, no border, no shadow */
.cm-style-bubble .cm-keyboard-frame {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  border-radius: 0;
}

/* Override mount plate to be invisible too */
.cm-style-bubble .cm-keyboard-mount {
  background: transparent !important;
  border: none !important;
}

/* Mac - Elegant minimal silver/white flat keys */
.cm-style-mac {
  --kb-stage-bg: linear-gradient(180deg, #f5f5f7 0%, #ebebf0 100%);
  --kb-stage-grid: none;
  --kb-frame: #e5e5ea;
  --kb-frame-border: #d1d1d6;
  --kb-mount: #d1d1d6;
  --kb-key: #ffffff;
  --kb-key-top: #ffffff;
  --kb-key-shadow: #c7c7cc;
  --kb-key-legend: #1c1c1e;
  --color-primary: #007aff;

  /* Global UI Overrides for Light Theme */
  --color-background: #ebebf0;
  --color-surface: #ffffff;
  --color-surface-lighter: #fcfcfc;
  --color-text: #1c1c1e;
  --color-text-dim: #8e8e93;
  --color-border: #d1d1d6;
}

/* Mac overrides: Flat keys with subtle shadow */
.cm-style-mac .cm-key {
  border-radius: 6px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1), 0 2px 0 #c7c7cc;
}

.cm-style-mac .cm-key::after {
  border-radius: 5px;
  top: 1px;
  left: 1px;
  right: 1px;
  bottom: 2px;
  box-shadow: none;
}

.cm-style-mac .cm-keyboard-frame {
  border-radius: 12px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.08);
}

/* Arcade - Chunky, bold, toy-like pop colors */
.cm-style-arcade {
  --kb-stage-bg: radial-gradient(circle at center, #2b1055 0%, #150824 100%);
  --kb-stage-grid:
    repeating-linear-gradient(45deg, rgba(255, 0, 128, 0.05) 0 2px, transparent 2px 20px);
  --kb-frame: #ff0055;
  --kb-frame-border: #cc0044;
  --kb-mount: #222222;
  --kb-key: #ffcc00;
  --kb-key-top: #ffee33;
  --kb-key-shadow: #cc9900;
  --kb-key-legend: #000000;
  --color-primary: #00ffff;
  --color-surface: #150824;
  --color-border: #ff0055;
}

/* Arcade overrides: deep chunky block keys */
.cm-style-arcade .cm-key {
  border-radius: 4px;
  box-shadow: 0 10px 0 var(--kb-key-shadow),
    0 12px 10px rgba(0, 0, 0, 0.4);
  border: 2px solid #000;
}

.cm-style-arcade .cm-key::after {
  border-radius: 2px;
  top: 0px;
  left: 0px;
  right: 0px;
  bottom: 4px;
  border-bottom: 2px solid rgba(0, 0, 0, 0.2);
  box-shadow: none;
}

.cm-style-arcade .cm-keyboard-frame {
  border-radius: 8px;
  border: 4px solid #000;
  box-shadow: 10px 10px 0 #00ffff;
}

.cm-style-arcade .cm-key__label {
  font-weight: 900;
}

.cm-style-arcade .cm-key--active .cm-key__label {
  color: #000 !important;
  /* Keep black text readable on magenta active state */
}

/* Override: Arcade active key should be hot-pink, not cyan (cyan is invisible on yellow) */
.cm-style-arcade .cm-key--active {
  background: #ff0055 !important;
  box-shadow: 0 1px 0 #990033,
    0 0 30px #ff0055,
    0 0 60px rgba(255, 0, 85, 0.3) !important;
}

.cm-style-arcade .cm-key--active::after {
  background: #ff3377 !important;
}

/* Arcade history state: use hot-pink text instead of cyan */
.cm-style-arcade .cm-key--history .cm-key__label {
  color: #ff0055;
  filter: drop-shadow(0 0 8px rgba(255, 0, 85, 0.4));
}

/* Mac toolbar labels need dark color on light background */
.cm-style-mac .cm-setting-group label {
  color: #555;
}

.cm-style-mac .cm-kb-toolbar select {
  background: rgba(240, 240, 245, 0.95);
  border-color: #c7c7cc;
  color: #1c1c1e;
}

/* Dracula - Classic purple-accented dark theme */
/* Dracula - Classic purple-accented dark theme */
.cm-style-dracula {
  --kb-stage-bg: radial-gradient(circle at top, rgba(189, 147, 249, 0.08) 0%, rgba(40, 42, 54, 0.95) 100%);
  --kb-stage-grid:
    radial-gradient(circle at 50% 0%, rgba(189, 147, 249, 0.15), transparent 55%),
    repeating-linear-gradient(90deg, rgba(189, 147, 249, 0.03) 0 1px, transparent 1px 120px),
    repeating-linear-gradient(0deg, rgba(189, 147, 249, 0.03) 0 1px, transparent 1px 120px);
  --kb-frame: #282a36;
  --kb-frame-border: #44475a;
  --kb-mount: #21222c;
  --kb-key: #44475a;
  --kb-key-top: #525670;
  --kb-key-shadow: #191a21;
  --kb-key-legend: #f8f8f2;
  --color-primary: #bd93f9;
  --color-surface: #282a36;
  --color-border: rgba(189, 147, 249, 0.25);
}

/* Nord - Calm arctic blue-grey palette */
/* Nord - Calm arctic blue-grey palette */
.cm-style-nord {
  --kb-stage-bg: radial-gradient(circle at top, rgba(136, 192, 208, 0.1) 0%, rgba(46, 52, 64, 0.95) 100%);
  --kb-stage-grid:
    radial-gradient(circle at 50% 0%, rgba(136, 192, 208, 0.15), transparent 55%),
    repeating-linear-gradient(90deg, rgba(136, 192, 208, 0.03) 0 1px, transparent 1px 120px),
    repeating-linear-gradient(0deg, rgba(136, 192, 208, 0.03) 0 1px, transparent 1px 120px);
  --kb-frame: #3b4252;
  --kb-frame-border: #4c566a;
  --kb-mount: #2e3440;
  --kb-key: #434c5e;
  --kb-key-top: #4c566a;
  --kb-key-shadow: #242933;
  --kb-key-legend: #eceff4;
  --color-primary: #88c0d0;
  --color-surface: #2e3440;
  --color-border: rgba(136, 192, 208, 0.25);
}

/* Synthwave - Neon pink and cyan on deep purple */
.cm-style-synthwave {
  --kb-stage-bg: radial-gradient(circle at top, rgba(255, 0, 157, 0.1) 0%, rgba(0, 0, 0, 0.4) 70%);
  --kb-stage-grid:
    radial-gradient(circle at 50% 0%, rgba(0, 255, 255, 0.2), transparent 50%),
    repeating-linear-gradient(90deg, rgba(255, 0, 157, 0.05) 0 1px, transparent 1px 120px),
    repeating-linear-gradient(0deg, rgba(255, 0, 157, 0.05) 0 1px, transparent 1px 120px);
  --kb-frame: #1b1029;
  --kb-frame-border: #ff009d;
  --kb-mount: #0e051a;
  --kb-key: #251838;
  --kb-key-top: #362252;
  --kb-key-shadow: #000;
  --kb-key-legend: #00ffff;
  --color-primary: #ff009d;
  --color-surface: #1b1029;
  --color-border: rgba(255, 0, 157, 0.3);
}

.cm-size-compact .cm-stage {
  --key-unit: clamp(64px, 5.2vw, 88px);
  --key-gap: 2px;
}

.cm-size-standard .cm-stage {
  --key-unit: clamp(72px, 6vw, 98px);
  --key-gap: 2px;
}

.cm-size-large .cm-stage {
  --key-unit: clamp(80px, 6.6vw, 110px);
  --key-gap: 3px;
}

/* 1. Header & Status */
.cm-hud-header {
  height: 64px;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 32px;
  color: var(--color-text, rgba(255, 255, 255, 0.85));
  /* Dynamic wrapper */
  z-index: 10;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.cm-hud-brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Updated logo/title style for theme support */
.cm-dashboard-title {
  display: flex;
  flex-direction: column;
}

.cm-dashboard-title h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--color-text, #ffffff);
  /* Theme dynamic */
  text-transform: uppercase;
}

.cm-dashboard-title span {
  font-size: 11px;
  color: var(--color-primary, #00ff9d);
  letter-spacing: 1px;
  margin-top: -2px;
  text-transform: uppercase;
}

.cm-hud-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cm-language-mount {
  margin-right: 4px;
}

.cm-language-mount .cm-setting-group--no-label {
  margin: 0;
  padding: 0;
}

.cm-os-toggle {
  display: flex;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.cm-os-toggle__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.cm-os-toggle__btn:hover {
  color: var(--color-text, rgba(255, 255, 255, 0.8));
  background: var(--color-surface, rgba(255, 255, 255, 0.05));
}

.cm-os-toggle__btn.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.05);
  text-shadow: 0 0 10px var(--color-primary);
}

.cm-info-card--support {
  border-color: var(--color-primary, #00ff9d) !important;
  background: var(--color-surface, rgba(20, 20, 28, 0.8)) !important;
  box-shadow: inset 0 0 0 1px var(--color-border, rgba(255, 255, 255, 0.1)), 0 8px 32px rgba(0, 0, 0, 0.4) !important;
}

.cm-language-mount select {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  padding: 0 32px 0 10px;
  height: 32px;
  line-height: 32px;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.9);
  transition: all 0.2s ease;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath stroke='rgba(255,255,255,0.5)' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.cm-language-mount select:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: #fff;
}

.cm-status-pill {
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--color-text, rgba(255, 255, 255, 0.8));
  background: var(--color-surface, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--color-border, rgba(255, 255, 255, 0.05));
  display: flex;
  align-items: center;
  transition: all 0.2s ease;
  min-width: 80px;
  justify-content: center;
}

/* Fixed-width LAST KEY pill so it doesn't jump around */
#last-key {
  min-width: 200px;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
}

.cm-status-pill.is-inactive {
  border-color: rgba(255, 75, 75, 0.5);
  color: #ff9a9a;
  background: rgba(255, 75, 75, 0.1);
}

@media (max-width: 900px) {
  .cm-hud-header {
    padding: 12px 16px;
  }

  .cm-hud-title {
    font-size: 14px;
    letter-spacing: 2px;
  }

  .cm-hud-right {
    gap: 8px;
  }

  .cm-status-pill#last-key {
    display: none;
    /* Hide last key on small screens to save space */
  }

  .cm-language-mount select {
    padding: 4px 18px 4px 6px;
    font-size: 10px;
    width: 100px;
  }
}

.cm-lock-states {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--color-surface, rgba(255, 255, 255, 0.05));
  padding: 2px 4px;
  border-radius: 16px;
  border: 1px solid var(--color-border, rgba(255, 255, 255, 0.05));
}

.cm-kb-icon {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: all 0.2s ease;
}

.cm-kb-icon:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.cm-lock-pill {
  padding: 2px 8px;
  border-radius: 14px;
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-dim, rgba(255, 255, 255, 0.3));
  letter-spacing: 0.5px;
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cm-lock-pill.is-active {
  background: rgba(0, 255, 157, 0.2);
  border-color: var(--color-primary);
  color: var(--color-primary);
  opacity: 1;
  box-shadow: 0 0 12px rgba(0, 255, 157, 0.3);
}

/* 2. Metrics Bar */
.cm-metrics-bar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  padding: 8px 20px;
  background: rgba(5, 5, 5, 0.6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.cm-ad-row {
  display: block;
  text-align: center;
  width: 100%;
  align-self: stretch;
  padding: 8px 24px 4px;
  background: rgba(5, 5, 5, 0.6);
  border-bottom: none;
}

.cm-ad-row .cm-ad-slot {
  margin: 0 auto;
  border-radius: 12px;
}

.cm-metrics-bar .cm-metric-card {
  background: #1a1a1f;
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 8px 10px;
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.cm-metrics-bar .cm-metric-card:hover {
  transform: translateY(-4px);
  border-color: var(--color-primary);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.7);
}

.cm-metrics-bar .cm-sparkline {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 28px;
  pointer-events: none;
  opacity: 0.4;
}

/* 3. Workspace Layout */
.cm-workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr 280px;
  gap: 16px;
  padding: 10px 14px 16px;
  min-height: 0;
  align-items: stretch;
}

.cm-panel {
  background: rgba(10, 10, 12, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}


.cm-panel--left,
.cm-panel--right {
  align-self: stretch;
}

.cm-stage {
  /* Don't stretch to match the tallest column — shrink-wrap to keyboard's natural height */
  align-self: start;
}

.cm-panel--right {
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  scrollbar-gutter: stable;
  padding-bottom: 30px;
  /* Add breathing room for the bottom content */
}

/* 3.1 Inner Panel Scroll Hint */
.cm-panel-scroll-hint {
  position: sticky;
  bottom: 0px;
  left: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--color-primary);
  opacity: 0.9;
  z-index: 20;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  animation: cm-bounce-small 2.2s infinite cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(to top, rgba(10, 10, 12, 0.9) 0%, rgba(10, 10, 12, 0) 100%);
  padding-top: 20px;
  padding-bottom: 5px;
  margin-top: -20px;
}

.cm-panel-scroll-hint.is-hidden {
  opacity: 0;
  transform: translateY(10px);
  animation: none;
}

.cm-panel-scroll-hint__text {
  font-size: 8px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 700;
}

.cm-panel-scroll-hint__icon {
  width: 14px;
  height: 14px;
}

@keyframes cm-bounce-small {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(5px);
  }
}

.cm-panel--right .cm-button {
  font-size: 10px;
  min-width: 0;
  padding: 6px 8px;
}

.cm-panel--right::-webkit-scrollbar {
  width: 6px;
}

.cm-panel--right::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 12px;
}

.cm-panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cm-panel-section .cm-ad-slot {
  margin: 0;
}

.cm-panel-section--grow {
  flex: 1;
  min-height: 0;
}

.cm-panel-title {
  font-size: 9px;
  font-weight: 800;
  color: var(--color-primary);
  font-family: var(--font-accent, var(--font-family));
  text-transform: uppercase;
  letter-spacing: 2px;
}

.cm-terminal--panel {
  flex: 1;
  min-height: 0;
}

.cm-accuracy-note {
  font-size: 12px;
  color: var(--color-text-dim);
  line-height: 1.5;
  margin: 0;
}

.cm-accuracy-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cm-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 4px 8px;
  border-radius: 10px;
  color: var(--color-primary);
  border: 1px solid rgba(0, 255, 157, 0.15);
  background: rgba(0, 255, 157, 0.05);
}

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

.cm-control-grid--two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cm-control-grid--three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cm-control-grid .cm-button {
  width: auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.cm-settings-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cm-settings-grid .cm-button {
  width: 100%;
}

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

.cm-setting-group label {
  font-size: 11px;
  font-weight: 700;
  color: var(--color-primary);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.cm-setting-group select,
.cm-setting-group input[type="range"] {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 12px;
  color: #fff;
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.2;
}

select option {
  background-color: #1a1a1f;
  color: #fff;
  padding: 8px;
}

.cm-diag-status {
  font-size: 11px;
  color: var(--color-text);
  padding: 10px;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.cm-diag-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  overflow: visible;
}

.cm-badges {
  display: flex;
  gap: 12px;
}

.cm-badge {
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--color-surface, rgba(255, 255, 255, 0.05));
  /* Theme dynamic */
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--color-text, rgba(255, 255, 255, 0.6));
  /* Theme dynamic */
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cm-diag-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--color-text-dim);
  overflow: visible;
}

.cm-diag-value {
  font-size: 14px;
  font-weight: 800;
  color: var(--color-primary);
}

.cm-focus-badge {
  position: absolute;
  top: 65px;
  /* Moved down to avoid overlapping the sound dropdown */
  right: 20px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(0, 255, 157, 0.12);
  border: 1px solid rgba(0, 255, 157, 0.35);
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--color-primary);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  cursor: pointer;
}

/* 4. Center Stage */
.cm-stage {
  --key-unit: clamp(72px, 6vw, 110px);
  --key-gap: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  /* Keep toolbar pinned at top */
  overflow: hidden;
  position: relative;
  border-radius: 18px;
  border: none;
  background: transparent;
  padding-top: 4px;
  padding-bottom: 0;
  gap: 2px;
}

.cm-kb-toolbar {
  width: min(100%, 1240px);
  padding: 6px 8px;
  border-radius: 12px;
  background: rgba(10, 10, 12, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
}

.cm-kb-toolbar__row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.cm-kb-toolbar__left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.cm-kb-toolbar__right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.cm-kb-toolbar .cm-setting-group {
  gap: 4px;
  min-width: 0;
  flex: 1 1 auto;
}

.cm-kb-toolbar label {
  font-size: 8px;
  letter-spacing: 1px;
}

.cm-kb-toolbar select {
  font-size: 11px;
  padding: 6px 4px;
  /* Reduced right padding to fix gap */
  min-width: 110px;
  max-width: 180px;
  text-overflow: ellipsis;
  /* Reduced to fit neatly without wrapping */
  /* Uniform dropdown width */
  width: auto;
  background: rgba(15, 15, 20, 0.9);
  border-color: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  border-radius: 4px;
}

@media (max-width: 1200px) {
  .cm-kb-toolbar__right {
    gap: 8px;
  }
}


.cm-keyboard-canvas {
  width: 100%;
  max-width: 2000px;
  padding: 4px;
  padding-top: 16px;
  position: relative;
  top: 0;
  margin-top: 0;
  z-index: 1;
  /* Fill remaining space after toolbar */
  display: flex;
  justify-content: center;
  align-items: flex-start;
  /* Push keyboard up against toolbar instead of dead-centering it */
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  perspective: none;
  transform-origin: top center;
}

@media (max-width: 1400px) {
  .cm-kb-toolbar__row {
    flex-wrap: wrap;
    justify-content: center;
  }

  .cm-kb-toolbar__right {
    justify-content: center;
  }
}

@media (max-width: 980px) {
  .cm-kb-toolbar__left {
    width: 100%;
    justify-content: center;
  }

  .cm-kb-toolbar__right {
    width: 100%;
  }
}

.cm-keyboard-frame {
  background: var(--kb-frame);
  padding: 10px;
  border-radius: 12px;
  box-shadow: 0 40px 100px rgba(0, 0, 0, 0.9),
    inset 0 1px 1px rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: auto;
  position: relative;
  transform: none;
  border: none;
}

.cm-keyboard-frame::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 1px solid var(--kb-frame-border);
  border-radius: 12px;
  pointer-events: none;
  opacity: 0.2;
}

.cm-mount-main,
.cm-mount-nav,
.cm-mount-numpad {
  background: var(--kb-mount);
  padding: 4px;
  border-radius: 8px;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.8);
}

.cm-keyboard-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.cm-spacer {
  background: var(--kb-frame);
  border-radius: 4px;
}

.cm-mount-main {
  display: grid;
  column-gap: var(--key-gap);
  row-gap: var(--key-gap);
  grid-template-columns: repeat(60, calc(var(--key-unit) / 4));
  grid-auto-rows: var(--key-unit);
}

.cm-mount-nav {
  display: grid;
  grid-template-columns: repeat(3, var(--key-unit));
  grid-auto-rows: var(--key-unit);
  gap: var(--key-gap);
  padding: 6px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.cm-mount-numpad {
  display: grid;
  grid-template-columns: repeat(4, var(--key-unit));
  grid-auto-rows: var(--key-unit);
  gap: var(--key-gap);
  padding: 6px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 12px;
  border: 1px solid var(--kb-mount-border);
}

/* Tactile Key Animations */
.cm-key {
  position: relative;
  background: var(--kb-key-top);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 6px;
  /* slightly more padding */
  box-shadow: 0 4px 0 var(--kb-key-shadow), 0 6px 14px rgba(0, 0, 0, 0.8), inset 0 1px 1px rgba(255, 255, 255, 0.1);
  color: var(--kb-key-legend);
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  user-select: none;
  cursor: default;
  border: 1px solid rgba(255, 255, 255, 0.03);
  /* Subtle glass edge */
  transition: transform 0.05s ease, background-color 0.1s ease, box-shadow 0.1s ease !important;
}

.cm-key--active {
  transform: translateY(3px) scale(0.97) !important;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5) !important;
}

.cm-focus-mode .cm-panel {
  opacity: 0.12;
  filter: blur(1px);
  pointer-events: none;
}

.cm-focus-mode .cm-stage {
  box-shadow: 0 0 60px rgba(0, 255, 157, 0.12);
}

.cm-focus-mode .cm-focus-badge {
  display: none;
}

/* ESC exit hint button — hidden by default, shown in focus mode */
.cm-focus-esc-hint {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  margin: 8px auto;
  border-radius: 8px;
  background: rgba(0, 255, 157, 0.08);
  border: 1px solid rgba(0, 255, 157, 0.25);
  color: var(--color-primary, #00ff9d);
  font-family: "Space Grotesk", sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 2px;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 5;
}

.cm-key-legend {
  font-size: 13px;
  /* Increased from 11px per user UI/UX explicit req */
  font-weight: 700;
  line-height: 1;
  text-shadow: var(--kb-key-text-glow);
  pointer-events: none;
  z-index: 2;
}

.cm-focus-mode .cm-focus-esc-hint {
  display: flex;
}


.cm-focus-esc-hint:hover {
  background: rgba(0, 255, 157, 0.15);
  border-color: var(--color-primary, #00ff9d);
  box-shadow: 0 0 15px rgba(0, 255, 157, 0.15);
}

.cm-focus-esc-hint__key {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(0, 255, 157, 0.15);
  border: 1px solid rgba(0, 255, 157, 0.4);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
}

/* Focus Guard */
.cm-focus-guard {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.cm-focus-guard.is-visible {
  opacity: 1;
  pointer-events: all;
}

.cm-focus-guard__content {
  text-align: center;
  padding: 40px;
  background: rgba(13, 13, 13, 0.9);
  border: 1px solid var(--color-error);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 50px rgba(255, 62, 62, 0.2);
  max-width: 400px;
}

.cm-focus-guard__icon {
  font-size: 48px;
  color: var(--color-error);
  margin-bottom: 16px;
  animation: pulse 2s infinite;
}

.cm-focus-guard__title {
  font-size: 24px;
  color: var(--color-error);
  letter-spacing: 4px;
  margin-bottom: 8px;
}

.cm-focus-guard__text {
  font-size: 12px;
  color: var(--color-text-dim);
  text-transform: uppercase;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.1);
    opacity: 0.7;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

body {
  padding-bottom: 0;
}

@media (max-height: 900px) {
  .cm-hud-header {
    padding: 10px 20px;
  }

  .cm-hud-title {
    font-size: 16px;
  }

  .cm-metrics-bar {
    padding: 6px 16px;
    gap: 6px;
  }

  .cm-metrics-bar .cm-metric-card {
    padding: 6px 8px;
  }

  .cm-ad-row {
    padding: 4px 16px;
  }

  .cm-ad-row .cm-ad-slot {
    height: 60px !important;
    min-height: 60px !important;
  }

  .cm-workspace {
    padding: 8px 12px 12px;
  }

  .cm-panel {
    padding: 10px;
  }
}

@media (max-height: 760px) {
  .cm-hud-header {
    padding: 8px 16px;
  }

  .cm-metrics-bar {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .cm-metrics-bar .cm-metric-card {
    padding: 6px 8px;
  }

  .cm-workspace {
    gap: 12px;
    padding: 6px 10px 10px;
  }

}

/* Panel-Specific Max Height logic ensures the sidebars scroll internally.
   Truncates the right panel just after DIAGNOSTICS, hiding INPUT_TUNING and below.
   The left panel syncs to the same height for visual symmetry. */
@media (min-width: 901px) {

  .cm-panel--left,
  .cm-panel--right {
    max-height: 530px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  }
}

/* Force AdSense placeholder containers to match the dark theme background.
   Without this, the <ins> element defaults to white before ads resolve. */
.adsbygoogle,
.adsbygoogle *,
#stage-ad-mount,
#stage-ad-mount * {
  background: transparent !important;
  background-color: transparent !important;
}

/* Responsive adjustments */
@media (max-width: 1500px) {
  .cm-workspace {
    grid-template-columns: 260px minmax(520px, 1fr) 300px;
  }
}

@media (max-width: 1300px) {
  .cm-workspace {
    grid-template-columns: 220px minmax(480px, 1fr) 260px;
  }

  .cm-metrics-bar {
    grid-template-columns: repeat(4, 1fr);
  }
}

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

  .cm-panel--left,
  .cm-panel--right {
    order: 2;
  }

  .cm-stage {
    order: 1;
    min-height: 360px;
  }
}

@media (max-width: 900px) {
  .cm-ad-row {
    padding: 6px 12px;
  }
}

/* Visually Hidden (Screen Reader Only) but valid for SEO indexers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ==========================================================================
   Scroll-to-Top Floating Button
   ========================================================================== */
.cm-scroll-top {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 9000;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #1e1e24;
  color: rgba(255, 255, 255, 0.85);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px);
  transition: opacity 0.3s ease, transform 0.3s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  /* Scroll progress ring */
  --scroll-progress: 0;
  outline: 2.5px solid rgba(255, 255, 255, 0.08);
  outline-offset: 3px;
}

/* Scroll progress ring via pseudo-element */
.cm-scroll-top::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: conic-gradient(rgba(255, 255, 255, 0.6) calc(var(--scroll-progress) * 1%),
      rgba(255, 255, 255, 0.1) calc(var(--scroll-progress) * 1%));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2.5px));
  z-index: -1;
  transition: background 0.1s linear;
}

.cm-scroll-top svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cm-scroll-top--visible {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

.cm-scroll-top:hover {
  background: #2a2a32;
  color: #fff;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.6);
  transform: translateY(-2px);
}

.cm-scroll-top:active {
  transform: translateY(0);
}

/* --------------------------------------------------------------------------
   GLOBAL JS TOOLTIP — Appended to body to prevent clipping
   -------------------------------------------------------------------------- */
.cm-global-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  background: rgba(10, 12, 18, 0.96);
  color: #fff;
  border: 1px solid rgba(0, 255, 157, 0.2);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.5;
  max-width: 260px;
  white-space: normal;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 12px rgba(0, 255, 157, 0.08);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 10000;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.cm-global-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

[data-cm-tooltip],
[data-tooltip] {
  cursor: help;
}

/* --------------------------------------------------------------------------
   RESET HINT — Subtle hotkey hint next to the Reset button
   -------------------------------------------------------------------------- */
.cm-reset-hint {
  font-size: 10px;
  color: var(--color-text-dim, rgba(255, 255, 255, 0.3));
  letter-spacing: 0.5px;
  margin-left: 8px;
  font-family: "IBM Plex Mono", monospace;
}

/* ==========================================================================
   LIGHT THEME OVERRIDES (Generic — triggered by .cm-theme-light class)
   ==========================================================================
   These themes use light backgrounds with dark text. Many UI elements have
   hardcoded dark-mode values (rgba(0,0,0,*) backgrounds, rgba(255,255,255,*)
   borders/text). This block overrides ALL of them for a consistent light feel.
   ========================================================================== */

.cm-theme-light {
  color-scheme: light;
}

/* Header */
.cm-theme-light .cm-hud-header {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
}

/* Metrics Bar */
.cm-theme-light .cm-metrics-bar {
  background: rgba(255, 255, 255, 0.4);
  border-bottom: 1px solid var(--color-border);
}

.cm-theme-light .cm-metrics-bar .cm-metric-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.cm-theme-light .cm-metrics-bar .cm-metric-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* Ad Row */
.cm-theme-light .cm-ad-row {
  background: rgba(255, 255, 255, 0.3);
}

/* Side Panels */
.cm-theme-light .cm-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.cm-theme-light .cm-panel-scroll-hint {
  background: linear-gradient(to top, var(--color-surface) 0%, transparent 100%);
}

.cm-theme-light .cm-panel--right {
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.cm-theme-light .cm-panel--right::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
}

/* Toolbar icons */
.cm-theme-light .cm-kb-icon {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--color-border);
  color: var(--color-text-dim);
}

.cm-theme-light .cm-kb-icon:hover {
  background: rgba(0, 0, 0, 0.08);
  border-color: var(--color-primary);
  color: var(--color-text);
}

/* OS Toggle */
.cm-theme-light .cm-os-toggle {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--color-border);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
}

.cm-theme-light .cm-os-toggle__btn {
  color: var(--color-text-dim);
}

.cm-theme-light .cm-os-toggle__btn.is-active {
  background: rgba(0, 0, 0, 0.08);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.cm-theme-light .cm-os-toggle__btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--color-text);
}

/* Language Select */
.cm-theme-light .cm-language-mount select {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath stroke='rgba(0,0,0,0.4)' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.cm-theme-light .cm-language-mount select:hover {
  background-color: rgba(0, 0, 0, 0.06);
  border-color: var(--color-primary);
  color: var(--color-text);
}

/* Toolbar selects & labels */
.cm-theme-light .cm-setting-group label {
  color: var(--color-text-dim);
}

.cm-theme-light .cm-kb-toolbar select {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
}

/* Lock states */
.cm-theme-light .cm-lock-states {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--color-border);
}

/* Status Pill */
.cm-theme-light .cm-status-pill {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--color-border);
}

/* Lock Pills */
.cm-theme-light .cm-lock-pill.is-active {
  background: rgba(0, 150, 100, 0.15);
  box-shadow: none;
}

/* Tag pills */
.cm-theme-light .cm-tag {
  border: 1px solid var(--color-border);
  background: rgba(0, 0, 0, 0.03);
}

/* Diagnostic items */
.cm-theme-light .cm-diag-grid .cm-diag-item {
  color: var(--color-text);
}

/* Global tooltip */
.cm-theme-light .cm-global-tooltip {
  background: rgba(255, 255, 255, 0.96);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

/* Focus Guard overlay */
.cm-theme-light .cm-focus-guard__content {
  background: var(--color-surface);
  color: var(--color-text);
}

/* Button outlines */
.cm-theme-light .cm-button--outline {
  border-color: var(--color-border);
  color: var(--color-text);
}

.cm-theme-light .cm-button--outline:hover {
  background: rgba(0, 0, 0, 0.06);
  border-color: var(--color-primary);
}

/* Settings range / slider */
.cm-theme-light .cm-settings-grid input[type="range"] {
  accent-color: var(--color-primary);
}

/* Diag status */
.cm-theme-light .cm-diag-status {
  color: var(--color-text);
}

/* Footer logo — CSS filter to invert the white logo to dark on light themes */
.cm-theme-light footer img[alt="Cytific Labs"] {
  filter: brightness(0) saturate(100%);
}

/* Footer text & links */
.cm-theme-light footer {
  color: var(--color-text-dim) !important;
}

.cm-theme-light footer a {
  color: var(--color-text) !important;
}

.cm-theme-light footer a[style*="color-primary"] {
  color: var(--color-primary) !important;
}

/* Toolbar bar above keyboard */
.cm-theme-light .cm-kb-toolbar {
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(12px);
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.cm-theme-light .cm-kb-toolbar select {
  background: var(--color-surface);
  border-color: var(--color-border);
  color: var(--color-text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.cm-theme-light .cm-kb-toolbar label {
  color: var(--color-text-dim);
}

/* Event Stream / Terminal Log */
.cm-theme-light .cm-terminal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.cm-theme-light .cm-terminal__header {
  background: rgba(0, 0, 0, 0.03);
  border-bottom: 1px solid var(--color-border);
}

.cm-theme-light .cm-terminal__body {
  color: var(--color-text);
  scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
}

.cm-theme-light .cm-terminal__body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
}

.cm-theme-light .cm-terminal__item {
  color: var(--color-text);
}

/* Diag strip - hidden by user request */
.cm-diag-strip {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  height: 0 !important;
  border: none !important;
}

/* ── Premium Diagnostic Status Chip ────────────────────────── */
.cm-diag-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.7);
  transition: all 0.3s ease;
  margin-bottom: 6px;
}

.cm-diag-status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-accent, #00f0a0);
  box-shadow: 0 0 6px var(--color-accent, #00f0a0), 0 0 12px rgba(0, 240, 160, 0.3);
  flex-shrink: 0;
  animation: diag-pulse 2s ease-in-out infinite;
}

.cm-diag-status__dot--error {
  background: var(--color-error, #ff4444);
  box-shadow: 0 0 6px var(--color-error, #ff4444), 0 0 12px rgba(255, 68, 68, 0.3);
  animation: diag-pulse-error 1s ease-in-out infinite;
}

.cm-diag-status__dot--accent {
  background: var(--color-accent, #00f0a0);
  box-shadow: 0 0 6px var(--color-accent, #00f0a0), 0 0 12px rgba(0, 240, 160, 0.3);
  animation: diag-pulse 1.5s ease-in-out infinite;
}

.cm-diag-status__label {
  word-break: break-word;
  line-height: 1.3;
  font-size: 0.75rem;
}

.cm-diag-status--error {
  border-color: rgba(255, 68, 68, 0.25);
  background: rgba(255, 68, 68, 0.06);
  color: var(--color-error, #ff4444);
}

.cm-diag-status--accent {
  border-color: rgba(0, 240, 160, 0.2);
  background: rgba(0, 240, 160, 0.04);
  color: var(--color-accent, #00f0a0);
}

@keyframes diag-pulse {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.5;
    transform: scale(0.85);
  }
}

@keyframes diag-pulse-error {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.4;
    transform: scale(0.7);
  }
}

.cm-theme-light .cm-diag-status {
  background: rgba(0, 0, 0, 0.03);
  border-color: rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.6);
}

.cm-theme-light .cm-diag-status--error {
  background: rgba(255, 68, 68, 0.06);
  border-color: rgba(255, 68, 68, 0.2);
  color: var(--color-error, #cc0000);
}

.cm-theme-light .cm-diag-strip {
  display: none !important;
}