:root {
  /* Raw Light & Dark Palette Tokens (High Contrast for Day Sunlight & Low Glare for Night Driving) */
  --brand-light: #007a67;
  --brand-dark: #00e5c3;

  --bg-main-light: #f1f5f9;
  --bg-main-dark: #090d14;

  --bg-header-light: rgba(241, 245, 249, 0.94);
  --bg-header-dark: rgba(9, 13, 20, 0.92);

  --bg-card-light: #ffffff;
  --bg-card-dark: #121926;

  --bg-card-hover-light: #f8fafc;
  --bg-card-hover-dark: #192335;

  --bg-elevated-light: #e2e8f0;
  --bg-elevated-dark: #1e293b;

  --text-primary-light: #0f172a;
  --text-primary-dark: #f8fafc;

  --text-secondary-light: #334155;
  --text-secondary-dark: #cbd5e1;

  --text-muted-light: #475569;
  --text-muted-dark: #94a3b8;

  --border-subtle-light: #94a3b8;
  --border-subtle-dark: rgba(255, 255, 255, 0.18);

  --border-active-light: #007a67;
  --border-active-dark: #00e5c3;

  --shadow-card-light: 0 2px 8px rgba(15, 23, 42, 0.08);
  --shadow-card-dark: 0 4px 14px rgba(0, 0, 0, 0.35);

  /* Default Fallback Assignments (Light) */
  --brand-color: var(--brand-light);
  --bg-main: var(--bg-main-light);
  --bg-header: var(--bg-header-light);
  --bg-card: var(--bg-card-light);
  --bg-card-hover: var(--bg-card-hover-light);
  --bg-elevated: var(--bg-elevated-light);
  --text-primary: var(--text-primary-light);
  --text-secondary: var(--text-secondary-light);
  --text-muted: var(--text-muted-light);
  --border-subtle: var(--border-subtle-light);
  --border-active: var(--border-active-light);
  --shadow-card: var(--shadow-card-light);

  /* MANDATORY: Fallback for browsers without light-dark() support */
  @media (prefers-color-scheme: dark) {
    --brand-color: var(--brand-dark);
    --bg-main: var(--bg-main-dark);
    --bg-header: var(--bg-header-dark);
    --bg-card: var(--bg-card-dark);
    --bg-card-hover: var(--bg-card-hover-dark);
    --bg-elevated: var(--bg-elevated-dark);
    --text-primary: var(--text-primary-dark);
    --text-secondary: var(--text-secondary-dark);
    --text-muted: var(--text-muted-dark);
    --border-subtle: var(--border-subtle-dark);
    --border-active: var(--border-active-dark);
    --shadow-card: var(--shadow-card-dark);
  }

  /* Modern CSS light-dark() automatic resolution */
  @supports (color: light-dark(white, black)) {
    --brand-color: light-dark(var(--brand-light), var(--brand-dark));
    --bg-main: light-dark(var(--bg-main-light), var(--bg-main-dark));
    --bg-header: light-dark(var(--bg-header-light), var(--bg-header-dark));
    --bg-card: light-dark(var(--bg-card-light), var(--bg-card-dark));
    --bg-card-hover: light-dark(var(--bg-card-hover-light), var(--bg-card-hover-dark));
    --bg-elevated: light-dark(var(--bg-elevated-light), var(--bg-elevated-dark));
    --text-primary: light-dark(var(--text-primary-light), var(--text-primary-dark));
    --text-secondary: light-dark(var(--text-secondary-light), var(--text-secondary-dark));
    --text-muted: light-dark(var(--text-muted-light), var(--text-muted-dark));
    --border-subtle: light-dark(var(--border-subtle-light), var(--border-subtle-dark));
    --border-active: light-dark(var(--border-active-light), var(--border-active-dark));
  }

  /* MANDATORY: Apply color-scheme to :root and reflect <meta name="color-scheme"> override */
  color-scheme: light dark;

  &:has(> head > meta[name="color-scheme"][content="dark"]) {
    color-scheme: dark;
  }
  &:has(> head > meta[name="color-scheme"][content="light"]) {
    color-scheme: light;
  }

  accent-color: var(--brand-color);
  --ui-scale: 1;
  --accent-amber: #f59e0b;
  --accent-blue: #2563eb;
  --accent-purple: #7c3aed;
  --accent-red: #e11d48;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-main);
  color: var(--text-primary);
  accent-color: var(--brand-color);
  font-family: 'Kantumruy Pro', 'Noto Sans Khmer', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.42;
  padding-bottom: 148px;
  min-height: 100dvh;
  font-size: calc(16px * var(--ui-scale));
}

/* Fallback for older browsers without accent-color */
@supports not (accent-color: var(--brand-color)) {
  input[type="checkbox"].visually-hidden {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }

  label.checkbox-fallback-label {
    position: relative;
    padding-left: 2rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
  }

  input[type="checkbox"] + span::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1.3rem;
    height: 1.3rem;
    border: 2px solid var(--border-subtle);
    background: var(--bg-card);
    border-radius: 5px;
    box-sizing: border-box;
  }

  input[type="checkbox"]:focus-visible + span::before {
    outline: 2px solid var(--brand-color);
    outline-offset: 2px;
  }

  input[type="checkbox"]:checked + span::before {
    background-color: var(--brand-color, #00e5c3);
    border-color: var(--brand-color, #00e5c3);
  }

  input[type="checkbox"]:checked + span::after {
    content: "✓";
    position: absolute;
    left: 0.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: #fff;
    font-weight: bold;
    font-size: 0.9rem;
  }

  input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
  }

  input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 10px;
    background: linear-gradient(to right, var(--brand-color, #00e5c3) var(--progress, 50%), #64748b var(--progress, 50%));
    border-radius: 5px;
  }

  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 22px;
    width: 22px;
    border-radius: 50%;
    background: var(--brand-color, #00e5c3);
    cursor: pointer;
    margin-top: -6px;
  }

  input[type="range"]::-moz-range-track {
    width: 100%;
    height: 10px;
    background: #64748b;
    border-radius: 5px;
  }

  input[type="range"]::-moz-range-thumb {
    height: 22px;
    width: 22px;
    border-radius: 50%;
    background: var(--brand-color, #00e5c3);
    cursor: pointer;
  }

  input[type="range"]::-moz-range-progress {
    background-color: var(--brand-color, #00e5c3);
    height: 10px;
    border-radius: 5px;
  }
}

/* Top App Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-header);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1.5px solid var(--border-subtle);
  padding: 10px 14px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  max-width: 920px;
  margin: 0 auto;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 2px solid var(--brand-color);
  display: grid;
  place-items: center;
  color: var(--brand-color);
  font-weight: 800;
  font-size: 1.08rem;
}

.brand-title h1 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-xiaota {
  font-size: 0.78rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--brand-color);
  border: 1.5px solid var(--brand-color);
  font-weight: 700;
}

.brand-subtitle {
  margin: 1px 0 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Enlarged Driving-Safe Header & Action Buttons (min 48px touch target) */
.icon-btn {
  min-height: calc(46px * var(--ui-scale));
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1.5px solid var(--border-subtle);
  border-radius: 12px;
  padding: 8px 13px;
  font-size: calc(0.86rem * var(--ui-scale));
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: var(--shadow-card);
  transition: transform 0.1s ease, border-color 0.18s ease;
}

.icon-btn:active {
  transform: scale(0.95);
}

.icon-btn.primary-outline {
  border-color: var(--brand-color);
  color: var(--brand-color);
}

.settings-main-btn {
  background: var(--bg-elevated);
  border-width: 2px;
}

/* Driving Ergonomics Bar (Size M/L/XL + Wake + Language) */
.control-strip {
  max-width: 920px;
  margin: 10px auto 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ergonomics-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1.5px solid var(--border-subtle);
  border-radius: 13px;
  padding: 7px 11px;
  gap: 10px;
  flex-wrap: wrap;
}

.ergo-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ergo-label {
  font-size: calc(0.82rem * var(--ui-scale));
  font-weight: 700;
  color: var(--text-secondary);
}

.mode-pill-group {
  display: inline-flex;
  background: var(--bg-elevated);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  gap: 3px;
}

.size-pill,
.lang-pill {
  min-height: calc(36px * var(--ui-scale));
  background: transparent;
  border: 1.5px solid transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: calc(0.8rem * var(--ui-scale));
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 8px;
  cursor: pointer;
}

.size-pill.active,
.lang-pill.active {
  background: var(--bg-card);
  color: var(--brand-color);
  border-color: var(--brand-color);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.wake-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: calc(0.84rem * var(--ui-scale));
  font-weight: 700;
  cursor: pointer;
  color: var(--text-primary);
  min-height: 36px;
}

.wake-toggle-label input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 0;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-input-wrap {
  position: relative;
  flex: 1;
}

.search-input {
  width: 100%;
  min-height: calc(44px * var(--ui-scale));
  background: var(--bg-card);
  border: 1.5px solid var(--border-subtle);
  border-radius: 12px;
  padding: 9px 38px 9px 14px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: calc(0.92rem * var(--ui-scale));
  font-weight: 500;
}

.search-input:focus {
  outline: 2px solid var(--brand-color);
  border-color: var(--brand-color);
}

.clear-search-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 6px;
}

/* Category Tabs (Bigger Touch Height for Driving) */
.category-tabs {
  max-width: 920px;
  margin: 10px auto 0;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.cat-tab {
  flex: 0 0 auto;
  min-height: calc(44px * var(--ui-scale));
  background: var(--bg-card);
  border: 1.5px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 8px 15px;
  font-family: inherit;
  font-size: calc(0.86rem * var(--ui-scale));
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: transform 0.1s ease;
}

.cat-tab:active {
  transform: scale(0.96);
}

.cat-tab.active {
  background: var(--bg-elevated);
  color: var(--brand-color);
  border: 2px solid var(--brand-color);
}

.cat-count {
  font-size: 0.74rem;
  background: var(--bg-elevated);
  padding: 2px 7px;
  border-radius: 99px;
  border: 1px solid var(--border-subtle);
}

/* Main Content Container */
.main-container {
  max-width: 920px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Active Voice Banner */
.speaking-banner {
  background: var(--bg-card);
  border: 2px solid var(--brand-color);
  border-radius: var(--radius-md);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-card);
  flex-wrap: wrap;
}

.speaking-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 200px;
  flex: 1;
}

.speaking-status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: calc(0.78rem * var(--ui-scale));
  font-weight: 800;
  color: var(--brand-color);
  text-transform: uppercase;
}

.pulse-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--brand-color);
}

.speaking-banner.is-speaking .pulse-dot {
  animation: pulseGlow 1s infinite ease-in-out;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.65; }
}

.speaking-zh {
  font-size: calc(1.3rem * var(--ui-scale));
  font-weight: 800;
  color: var(--text-primary);
}

.speaking-meta {
  font-size: calc(0.86rem * var(--ui-scale));
  color: var(--text-secondary);
  font-weight: 600;
}

.speaking-actions {
  display: flex;
  gap: 8px;
}

/* ================= MOST USED WHILE DRIVING HERO GRID ================= */
.driving-quick-section {
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 15px;
  box-shadow: var(--shadow-card);
}

.driving-hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.hero-drive-btn {
  min-height: calc(78px * var(--ui-scale));
  background: var(--bg-elevated);
  border: 2px solid var(--border-subtle);
  border-radius: 15px;
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: transform 0.1s ease, border-color 0.18s ease;
}

.hero-drive-btn:active {
  transform: scale(0.96);
}

.hero-drive-btn.tone-teal {
  border-left: 6px solid var(--brand-color);
}

.hero-drive-btn.tone-purple {
  border-left: 6px solid var(--accent-purple);
}

.hero-drive-btn.tone-amber {
  border-left: 6px solid var(--accent-amber);
}

.hero-drive-btn.tone-blue {
  border-left: 6px solid var(--accent-blue);
}

.hero-icon {
  font-size: calc(1.75rem * var(--ui-scale));
  line-height: 1;
  flex-shrink: 0;
}

.hero-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hero-zh {
  font-size: calc(0.8rem * var(--ui-scale));
  font-weight: 800;
  color: var(--brand-color);
}

/* ================= INTERACTIVE STUDIOS (Massage, Mirrors, Climate) ================= */
.studio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 14px;
}

.studio-card {
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-card);
}

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

.studio-title {
  margin: 0;
  font-size: calc(1rem * var(--ui-scale));
  font-weight: 800;
}

.studio-badge {
  font-size: calc(0.74rem * var(--ui-scale));
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 700;
  border: 1px solid var(--border-subtle);
}

.segmented-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: var(--bg-elevated);
  padding: 5px;
  border-radius: 12px;
  border: 1.5px solid var(--border-subtle);
}

.seg-btn {
  min-height: calc(44px * var(--ui-scale));
  background: transparent;
  border: 1.5px solid transparent;
  color: var(--text-secondary);
  padding: 8px 6px;
  border-radius: 9px;
  font-family: inherit;
  font-size: calc(0.84rem * var(--ui-scale));
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.seg-btn.active {
  background: var(--bg-card);
  color: var(--brand-color);
  border-color: var(--brand-color);
  box-shadow: var(--shadow-card);
}

.studio-subgrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
}

.studio-subgrid.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.studio-action-btn {
  min-height: calc(68px * var(--ui-scale));
  background: var(--bg-elevated);
  border: 1.5px solid var(--border-subtle);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  transition: transform 0.1s ease, border-color 0.18s ease;
}

.studio-action-btn:active {
  transform: scale(0.96);
}

.studio-action-btn.primary-action {
  border: 2px solid var(--brand-color);
}

.studio-action-btn.danger-action {
  border: 2px solid var(--accent-red);
}

.btn-km {
  font-size: calc(0.92rem * var(--ui-scale));
  font-weight: 700;
  color: var(--text-primary);
}

.btn-en {
  font-size: calc(0.79rem * var(--ui-scale));
  color: var(--text-secondary);
  font-weight: 600;
}

.btn-zh-mini {
  font-size: calc(0.77rem * var(--ui-scale));
  color: var(--brand-color);
  font-weight: 800;
  margin-top: 2px;
}

/* Climate Stepper Row */
.climate-control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  padding: 10px 13px;
  border-radius: 13px;
  border: 1.5px solid var(--border-subtle);
  gap: 10px;
  flex-wrap: wrap;
}

.stepper-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-circle-btn {
  width: calc(44px * var(--ui-scale));
  height: calc(44px * var(--ui-scale));
  border-radius: 11px;
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: calc(1.25rem * var(--ui-scale));
  font-weight: 800;
  cursor: pointer;
}

.step-value {
  font-size: calc(1.18rem * var(--ui-scale));
  font-weight: 800;
  min-width: 58px;
  text-align: center;
  color: var(--brand-color);
}

/* ================= COMMAND CARDS GRID & BUTTON SIZE MODES ================= */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 11px;
  gap: 8px;
}

.section-title {
  margin: 0;
  font-size: calc(1.04rem * var(--ui-scale));
  font-weight: 800;
  color: var(--text-primary);
}

.commands-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 11px;
}

.cmd-card {
  position: relative;
  min-height: calc(92px * var(--ui-scale));
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow-card);
  transition: transform 0.1s ease, border-color 0.18s ease;
  user-select: none;
}

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

.cmd-card:active {
  transform: scale(0.96);
}

.cmd-card.playing {
  border-color: var(--brand-color);
  border-width: 3px;
  background: var(--bg-elevated);
}

.cmd-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.cmd-icon-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cmd-emoji {
  font-size: calc(1.55rem * var(--ui-scale));
  line-height: 1;
}

.cmd-labels {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cmd-km {
  font-size: calc(0.98rem * var(--ui-scale));
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.35;
}

.cmd-en {
  font-size: calc(0.84rem * var(--ui-scale));
  font-weight: 600;
  color: var(--text-secondary);
}

.fav-star-btn {
  min-width: 38px;
  min-height: 38px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 9px;
  display: grid;
  place-items: center;
}

.fav-star-btn.is-fav {
  color: var(--accent-amber);
  border-color: var(--accent-amber);
}

.cmd-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.cmd-chinese-box {
  display: flex;
  flex-direction: column;
}

.cmd-zh {
  font-size: calc(1rem * var(--ui-scale));
  font-weight: 800;
  color: var(--brand-color);
}

.cmd-pinyin {
  font-size: calc(0.75rem * var(--ui-scale));
  color: var(--text-muted);
  font-weight: 600;
}

.speak-badge {
  width: calc(36px * var(--ui-scale));
  height: calc(36px * var(--ui-scale));
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1.5px solid var(--brand-color);
  color: var(--brand-color);
  display: grid;
  place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
}

/* ================= SIZE PRESETS (M / L / XL DRIVING MODE) ================= */
body[data-btn-size="normal"] .commands-grid {
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
}

body[data-btn-size="large"] .commands-grid {
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
}

/* XL Driving Mode: Giant touch buttons, larger text & icons for zero-squint tapping */
body[data-btn-size="xl"] .driving-hero-grid {
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 13px;
}

body[data-btn-size="xl"] .hero-drive-btn {
  min-height: calc(102px * var(--ui-scale));
  padding: 16px 18px;
  border-width: 2.5px;
  border-left-width: 8px;
}

body[data-btn-size="xl"] .hero-icon {
  font-size: calc(2.2rem * var(--ui-scale));
}

body[data-btn-size="xl"] .commands-grid {
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 14px;
}

body[data-btn-size="xl"] .cmd-card {
  min-height: calc(114px * var(--ui-scale));
  padding: 16px 18px;
  border-width: 2.5px;
}

body[data-btn-size="xl"] .cmd-km,
body[data-btn-size="xl"] .btn-km {
  font-size: calc(1.14rem * var(--ui-scale));
}

body[data-btn-size="xl"] .cmd-en,
body[data-btn-size="xl"] .btn-en {
  font-size: calc(0.95rem * var(--ui-scale));
}

body[data-btn-size="xl"] .cmd-zh {
  font-size: calc(1.16rem * var(--ui-scale));
}

body[data-btn-size="xl"] .studio-action-btn {
  min-height: calc(84px * var(--ui-scale));
  padding: 13px 14px;
}

/* Language Filter Visibility Modes */
body[data-lang-mode="km"] .cmd-en,
body[data-lang-mode="km"] .btn-en {
  display: none;
}

body[data-lang-mode="en"] .cmd-km,
body[data-lang-mode="en"] .btn-km {
  display: none;
}

body[data-lang-mode="en"] .cmd-en,
body[data-lang-mode="en"] .btn-en {
  font-size: calc(0.98rem * var(--ui-scale));
  font-weight: 700;
  color: var(--text-primary);
}

/* Bottom Sticky Quick Dock (Enlarged for Driving) */
.bottom-dock {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--bg-header);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 2px solid var(--border-subtle);
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
}

.dock-inner {
  max-width: 920px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.45fr 1fr 1fr 1fr;
  gap: 9px;
}

.dock-btn {
  min-height: calc(56px * var(--ui-scale));
  border: 2px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: 14px;
  padding: 9px 10px;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: var(--shadow-card);
  transition: transform 0.1s ease;
}

.dock-btn:active {
  transform: scale(0.95);
}

.dock-btn.wake-main {
  background: var(--brand-color);
  color: #04120f;
  border-color: var(--brand-color);
  font-weight: 800;
}

.dock-btn.wake-main .dock-sub {
  color: #04120f;
  opacity: 0.85;
}

.dock-top {
  font-size: calc(0.86rem * var(--ui-scale));
  font-weight: 800;
  white-space: nowrap;
}

.dock-sub {
  font-size: calc(0.73rem * var(--ui-scale));
  color: var(--brand-color);
  font-weight: 700;
}

/* Native Modal Dialogs (Compliant with modern-web-guidance) */
dialog {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 2px solid var(--brand-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 480px;
  width: calc(100% - 28px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background-color: rgba(4, 7, 12, 0.72);
  backdrop-filter: blur(4px);
}

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

.dialog-header h2 {
  margin: 0;
  font-size: 1.08rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.form-field label {
  font-size: 0.84rem;
  color: var(--text-secondary);
  font-weight: 700;
}

.form-field input[type="text"],
.form-field select {
  min-height: 44px;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border-subtle);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.92rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

@media (max-width: 520px) {
  .dock-inner {
    grid-template-columns: 1.35fr 1fr 1fr 1fr;
    gap: 6px;
  }
  body[data-btn-size="normal"] .commands-grid,
  body[data-btn-size="large"] .commands-grid {
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }
  body[data-btn-size="xl"] .commands-grid,
  body[data-btn-size="xl"] .driving-hero-grid {
    grid-template-columns: 1fr;
  }
}
