/* ===== DESIGN TOKENS ===== */
:root {
  /* superficies — chrome calmo */
  --bg: #eef2f7;
  --card: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --text-muted: #475569;   /* ≥4.5:1 sobre --card y --surface-2 */
  --line: #e2e8f0;

  /* marca / acción */
  --primary: #2f6df6;
  --primary-d: #2356d6;
  --primary-soft: #e7eefb;

  /* semánticos de estado */
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --success: #10b981;

  /* forma */
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-2xl: 24px;

  /* tipografía */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-md: 17px;
  --fs-lg: 20px;
  --fs-xl: 26px;
  --fs-display: 34px;

  /* sombras */
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,.10);
  --shadow-lg: 0 12px 34px rgba(15,23,42,.18);

  /* dinámico por categoría — el ÚNICO color "fuerte", set vía JS */
  --cat-color: #2f6df6;
}

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

html, body {
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ===== SVG ICONS ===== */
.icon {
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}
.icon-sm { width: 13px; height: 13px; }
.icon-md { width: 18px; height: 18px; }
.icon-lg { width: 22px; height: 22px; }

/* ===== BUTTONS ===== */
.btn {
  border: none;
  border-radius: var(--r-lg);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px;
  white-space: nowrap;
  font-size: var(--fs-sm);
  touch-action: manipulation;
  transition: transform .08s ease, opacity .08s ease;
}
.btn:active { transform: scale(.96); opacity: .9; }

/* Principal: Activar / Decir */
/* Usa --primary-d (#2356d6) en lugar de --primary (#2f6df6) para alcanzar
   contraste ≥4.5:1 con texto blanco y cumplir WCAG AA. --primary se reserva
   para usos decorativos (anillo de pulso, acento de categoría). */
.btn--primary {
  background: var(--primary-d);
  color: #fff;
  font-size: var(--fs-base);
  min-height: 48px;
  padding: 0 20px;
}
.btn--primary:active { background: var(--primary-d); transform: scale(.97); }

/* Neutral (Probar voz, Reiniciar) */
.btn--neutral {
  background: var(--surface-2);
  color: var(--text-muted);
}

/* Utilidad (Atrás / Limpiar / Ajustes) — mismo contenedor calmo */
.btn--util {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--line);
  min-height: 44px;
}
.btn--util:active { background: var(--line); }
.btn--util.is-danger { color: var(--danger); }
.btn--util.is-danger:active { background: var(--danger-soft); border-color: var(--danger-soft); }

/* Ancho completo */
.btn--wide { width: 100%; min-height: 52px; font-size: var(--fs-base); }

/* Enlace (Cambiar de paciente) */
.btn--link {
  background: none;
  color: var(--primary-d);
  font-size: var(--fs-sm);
  min-height: 44px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ===== MODULE ROW ===== */
.module-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  min-height: 46px;
}
.module-row[hidden] { display: none; }

/* Centro + paciente a la derecha del toggle */
.center-id {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  margin-left: auto;
}
.center-id-text {
  display: flex;
  flex-direction: column;
  line-height: 1.18;
  min-width: 0;
  text-align: right;
}
.center-id-text b {
  font-size: var(--fs-sm);
  color: var(--text);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}
.center-id-text span {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

/* Segmented control (Dímelo | Matriz) */
.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  border: none;
  border-radius: var(--r-sm);
  padding: 5px 13px;
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  background: transparent;
  /* Área táctil mínima WCAG 2.5.8 (≥44×44 px) */
  min-height: 44px;
}
.seg-btn[aria-pressed="true"] {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ===== PHRASE ROW ===== */
.phrase-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  min-height: 72px;
}

/* Chips de frase */
.phrase-chips {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  /* Espacio extra arriba/derecha para que el ✕ de cada chip (top/right: -5px) no
     quede recortado: con overflow-x:auto el navegador fuerza overflow-y a recortar. */
  padding: 8px 8px 2px 2px;
  align-items: center;
  scrollbar-width: none;
}
.phrase-chips::-webkit-scrollbar { display: none; }

/* Placeholder "Toca los dibujos…" */
.phrase-hint {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  padding: 0 6px;
  white-space: nowrap;
  font-style: italic;
}

/* Acciones de frase */
.phrase-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Speak: icon-only square — overrides .btn--primary padding/height */
#speak {
  width: 54px;
  height: 54px;
  min-height: 54px;
  padding: 0;
}

/* Clear: soft-red background so it reads clearly as destructive */
#clear {
  background: var(--danger-soft);
  border-color: var(--danger-soft);
}
#clear:active { background: #fecaca; border-color: #fecaca; }

/* === Estado "hablando" (speaking celebration) === */
.phrase-row.is-speaking {
  box-shadow: 0 0 0 2.5px var(--primary), 0 0 18px rgba(47,109,246,.28);
  animation: phrase-pulse .9s ease-in-out infinite;
}
@keyframes phrase-pulse {
  0%, 100% { box-shadow: 0 0 0 2.5px var(--primary), 0 0 0px rgba(47,109,246,0); }
  50%       { box-shadow: 0 0 0 2.5px var(--primary), 0 0 18px rgba(47,109,246,.35); }
}
.btn--primary.is-speaking {
  background: var(--primary-d);
  box-shadow: 0 0 0 4px rgba(47,109,246,.35);
}

/* ===== CHIPS (pictogramas en la tira de frase) ===== */
.chip {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 58px;
  height: 56px;
  border: none;
  border-radius: var(--r-md);
  background: var(--surface-2);
  cursor: pointer;
  padding: 5px 8px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  animation: chip-pop .15s ease;
}
@keyframes chip-pop {
  from { transform: scale(.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.chip-face { font-size: 22px; line-height: 1; }
.chip-img { width: 28px; height: 28px; object-fit: contain; }
.chip-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-muted);
  max-width: 54px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Botón ✕ permanente en cada chip (affordance de quitar) */
.chip-remove {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-muted);
  color: #fff;
  border: 2px solid var(--card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
}

/* ===== CATEGORÍAS ===== */
.categories-strip {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg);
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
  min-height: 52px;
  align-items: center;
  position: relative;
}
/* Fade en el borde derecho (hay más categorías) */
.categories-strip::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 36px;
  background: linear-gradient(to right, transparent, var(--bg));
  pointer-events: none;
  z-index: 1;
}
.categories-strip::-webkit-scrollbar { display: none; }

.cat-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--card);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-muted);
  min-height: 38px;
  box-shadow: var(--shadow);
}
.cat-tab-icon { font-size: 17px; line-height: 1; }
img.cat-tab-icon { width: 17px; height: 17px; object-fit: contain; vertical-align: middle; }
.cat-tab.is-active { color: var(--text); }

/* ===== CUERPO DÍMELO (categorías + tablero) ===== */
.dimelo-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ===== TABLERO DE PICTOGRAMAS ===== */
.board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
  padding: 10px;
  overflow-y: auto;
  align-content: start;
}

/* ===== TILE (átomo base) ===== */
.tile {
  min-width: 0;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: var(--r-xl);
  background: var(--card);
  cursor: pointer;
  padding: 6px;
  box-shadow: var(--shadow);
  border: 2.5px solid transparent;
  transition: transform .08s ease;
}
.tile:active { transform: scale(.94); }
.tile-emoji { font-size: 38px; line-height: 1; }
.tile-img { width: 60%; height: 60%; object-fit: contain; }
.tile-img--placeholder { display: flex; align-items: center; justify-content: center; color: var(--line); }
.tile-label {
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== VISTAS DE MÓDULO ===== */
.module-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.module-view[hidden] { display: none; }

/* ===== APPBAR (oculto; compatible con JS de refreshTitle) ===== */
.appbar[hidden] { display: none; }

/* ===== MÓDULO MATRIZ ===== */
.matrix-header {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.matrix-select {
  flex: 1;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: var(--fs-sm);
  background: var(--card);
  color: var(--text);
  min-height: 44px;
}
.matrix-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.matrix-grid {
  display: grid;
  /* columnas fijadas por JS según m.cols; el CSS pone el mínimo */
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: 10px;
  padding: 12px;
  flex: 1;
  align-content: start;
}

/* Celdas de matriz */
.mcell {
  min-width: 0;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  padding: 4px;
  box-shadow: var(--shadow);
  position: relative;
  min-height: 44px;
  /* La celda es su propio container → imagen, emoji y tick escalan con su tamaño
     (cqmin = % del lado menor de la celda). App para niños: cuanto más grande, mejor. */
  container-type: size;
}
/* Emoji y tick escalan con la celda en vez de un tamaño fijo */
.mcell-emoji { font-size: 52cqmin; line-height: 1; flex: 0 0 auto; }
/* La imagen rellena todo el espacio disponible de la celda (menos la etiqueta) */
.mcell img { flex: 1 1 0; min-height: 0; width: 100%; object-fit: contain; }
.mcell-label { font-size: max(11px, 13cqmin); font-weight: 600; color: var(--text-muted); text-align: center; flex: 0 0 auto; }

/* Estado "completado" (marcado) */
.mcell.is-off .mcell-emoji,
.mcell.is-off .mcell-label,
.mcell.is-off img { opacity: .25; }
.mcell.is-off::after {
  content: '✓';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 64cqmin;
  color: var(--success);
  background: rgba(255,255,255,.55);
  border-radius: calc(var(--r-lg) - 2px);
}

/* Celda vacía (relleno de grid) */
.mcell.is-empty { border-style: dashed; background: transparent; box-shadow: none; cursor: default; }
.matrix-empty {
  grid-column: 1 / -1;
  color: var(--text-muted);
  text-align: center;
  padding: 40px 16px;
  font-size: var(--fs-md);
}

/* ===== PANTALLA DE ACTIVACIÓN ===== */
.code-view[hidden] { display: none; }
.code-view {
  flex: 1;
  display: flex;
}
.code-screen {
  flex: 1;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.code-card {
  background: var(--card);
  border-radius: var(--r-2xl);
  padding: 32px 28px;
  width: 100%;
  max-width: 334px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--shadow-lg);
  align-items: center;
}
.code-logo { width: 72px; height: 72px; }
.code-card-title { font-size: var(--fs-lg); font-weight: 800; color: var(--text); text-align: center; }
.code-card-sub { font-size: var(--fs-sm); color: var(--text-muted); text-align: center; line-height: 1.6; width: 100%; }

/* Nombre del centro en la pantalla de código */
.code-accent {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--primary-d);
  text-transform: uppercase;
  letter-spacing: .6px;
}
.code-accent:empty { display: none; }

/* Input del código */
.code-input {
  font-size: var(--fs-display);
  font-weight: 800;
  text-align: center;
  letter-spacing: 8px;
  text-transform: uppercase;
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: var(--r-lg);
  font-family: ui-monospace, monospace;
  color: var(--text);
  background: var(--card);
  width: 100%;
  outline: none;
}
.code-input:focus { border-color: var(--primary); }
.code-input.is-error { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }

/* Mensaje de error */
.code-error-msg {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  color: var(--danger);
  font-size: var(--fs-sm);
  font-weight: 700;
  background: var(--danger-soft);
  padding: 9px 12px;
  border-radius: var(--r-sm);
  width: 100%;
}
.code-error-msg::before { content: "⚠ "; flex-shrink: 0; }
.code-error-msg[hidden] { display: none; }

/* Ayuda offline */
.code-hint { font-size: var(--fs-xs); color: var(--text-muted); text-align: center; line-height: 1.6; width: 100%; }
.code-hint[hidden] { display: none; }

/* Error de estado (revocado/expulsado) vs. error de entrada */
.code-error-msg.is-state-error { background: var(--warn-soft); color: var(--warn); border-left: 3px solid var(--warn); }

/* ===== AJUSTES (bottom sheet) ===== */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}
.settings-overlay[hidden] { display: none; }

.settings-panel {
  background: var(--card);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  padding: 12px 20px 28px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 -8px 40px rgba(15,23,42,.2);
  max-height: 92vh;
  overflow-y: auto;
}
.settings-handle {
  width: 38px;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 0 auto;
}
.settings-head { display: flex; align-items: center; justify-content: space-between; }
.settings-head h2 { font-size: var(--fs-lg); font-weight: 800; }
.settings-divider { height: 1px; background: var(--line); }
.settings-info {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: 10px 13px;
  line-height: 1.6;
}
.settings-info strong {
  color: var(--text);
  display: block;
  font-size: var(--fs-sm);
}

/* Campos de ajustes */
.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: var(--fs-sm); font-weight: 700; color: var(--text-muted); }
.field select {
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: var(--fs-base);
  background: var(--card);
  color: var(--text);
  min-height: 44px;
}

/* Slider de velocidad */
.speed-row { display: flex; align-items: center; gap: 10px; }
.speed-label { font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted); white-space: nowrap; }
.speed-cur { font-size: var(--fs-sm); color: var(--text); }
.speed-range { flex: 1; accent-color: var(--primary); cursor: pointer; }

/* Toggle "Hablar al tocar" */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 0; }
.toggle-text { font-size: var(--fs-sm); font-weight: 600; color: var(--text); flex: 1; }
.toggle {
  width: 46px;
  height: 28px;
  background: var(--primary);
  border-radius: 14px;
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
  border: none;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: right .2s;
}
.toggle[aria-checked="false"] { background: var(--line); }
.toggle[aria-checked="false"]::after { right: calc(100% - 24px); }

/* ===== LAYOUT APAISADO (de lado) =====
   En landscape, categorías pasan a columna izquierda y el tablero domina.
   Activado vía media query en Lane 4; las clases CSS se definen aquí. */
.land-compact .phrase-row { min-height: auto; padding: 6px 10px; }
.land-compact .module-row { min-height: 40px; }
.body-split { flex: 1; display: flex; min-height: 0; }
.body-split .board { flex: 1; }
.categories-col {
  flex-direction: column;
  flex-wrap: nowrap;
  width: 92px;
  flex-shrink: 0;
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
  align-items: stretch;
  border-right: 1px solid var(--line);
  padding: 8px;
}
.categories-col::after { display: none; }
.categories-col .cat-tab {
  flex-direction: column;
  width: 100%;
  gap: 3px;
  padding: 8px 4px;
  text-align: center;
  min-height: 56px;
  justify-content: center;
}
.categories-col .cat-tab-icon { font-size: 22px; }

/* Columnas del tablero por tamaño de pantalla */
.board-5col { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.board-6col { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.board-8col { grid-template-columns: repeat(8, minmax(0, 1fr)); }

/* ===== RESPONSIVE LAYOUTS =====
   Portrait estrecho (por defecto): frase apilada en 2 filas, categorías en tira,
   tablero en 4 columnas.
   Tablet/ancho: frase en 1 fila.
   Landscape (de lado): categorías como columna izquierda, barras compactas,
   tablero domina el espacio restante. */

/* Teléfono portrait → frase siempre apilada (ya es el default en .phrase-row--stack) */

/* Tableta o pantalla ≥600px de ancho */
@media (min-width: 600px) {
  /* Tablero: auto-fit en pantallas medianas (mín 120px → ~4-5 cols) */
  .board { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}

/* Tableta grande ≥820px de ancho: auto-fit mín 140px */
@media (min-width: 820px) {
  .board { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

/* LANDSCAPE: categorías → columna izquierda + tablero protagonista.
   Aplica tanto en teléfono de lado como en tablet de lado. */
@media (orientation: landscape) and (max-height: 500px) {
  /* Barras superiores compactas */
  .land-compact-auto .module-row { min-height: 40px; }
  .land-compact-auto .phrase-row { min-height: auto; padding: 6px 10px; }

  /* dimelo-body se convierte en body-split (fila) */
  #dimelo-body {
    flex-direction: row;
  }
  /* Categorías → columna izquierda */
  #categories {
    flex-direction: column;
    flex-wrap: nowrap;
    width: 88px;
    flex-shrink: 0;
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 0;
    align-items: stretch;
    border-right: 1px solid var(--line);
    padding: 8px;
  }
  #categories::after { display: none; }
  #categories .cat-tab {
    flex-direction: column;
    width: 100%;
    gap: 3px;
    padding: 8px 4px;
    text-align: center;
    min-height: 56px;
    justify-content: center;
  }
  #categories .cat-tab-icon { font-size: 20px; }

  /* Tablero: auto-fit en landscape de teléfono (mín 110px) */
  .board { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
}

/* Landscape tableta (altura mayor) */
@media (orientation: landscape) and (min-height: 500px) {
  #dimelo-body { flex-direction: row; }
  #categories {
    flex-direction: column;
    flex-wrap: nowrap;
    width: 100px;
    flex-shrink: 0;
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 0;
    align-items: stretch;
    border-right: 1px solid var(--line);
    padding: 8px;
  }
  #categories::after { display: none; }
  #categories .cat-tab {
    flex-direction: column;
    width: 100%;
    gap: 3px;
    padding: 8px 4px;
    text-align: center;
    min-height: 64px;
    justify-content: center;
  }
  #categories .cat-tab-icon { font-size: 22px; }

  /* Tablero: auto-fit en landscape tablet (mín 140px → ~8+ cols según ancho disponible) */
  .board { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

/* ===== SAFE-AREA INSETS (notch / home indicator en iOS) ===== */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.board {
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.settings-panel {
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}
.toast {
  bottom: calc(24px + env(safe-area-inset-bottom));
}
.module-row {
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
}

/* ===== BREAKPOINTS ADICIONALES ===== */

/* Pantalla muy angosta (360px, teléfonos pequeños) */
@media (max-width: 360px) {
  .code-card { padding: 24px 16px; }
  .code-input { font-size: var(--fs-xl); letter-spacing: 5px; }
  .chip { min-width: 50px; height: 50px; }
  .chip-face { font-size: 18px; }
  .tile-emoji { font-size: 30px; }
  .board { grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); }
}

/* Pantalla grande desktop (≥900px) — centrado con max-width cómodo */
@media (min-width: 900px) {
  body { max-width: 1280px; margin: 0 auto; box-shadow: var(--shadow-lg); }
  .settings-panel { max-width: 560px; margin: 0 auto; border-radius: var(--r-2xl); }
  .settings-overlay { align-items: center; }
  .tts-banner { max-width: 1280px; left: 50%; transform: translateX(-50%); right: auto; width: 1280px; }
  /* Tiles más generosos en desktop */
  .board { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .tile-emoji { font-size: 46px; }
  .tile-label { font-size: 12px; }
}

/* Hover sutil para dispositivos con puntero fino (mouse/trackpad) */
@media (hover: hover) and (pointer: fine) {
  .tile:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
  }
}

/* ===== ACCESIBILIDAD ===== */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ===== BANNERS / TOASTS ===== */
.tts-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--fs-sm);
  font-weight: 700;
  padding: 10px 16px;
  text-align: center;
  z-index: 200;
  border-bottom: 1px solid rgba(180,83,9,.2);
}
.tts-banner[hidden] { display: none; }

/* ===== UNDO TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 200;
  white-space: nowrap;
}
.toast[hidden] { display: none; }
.toast .btn--link { color: #93c5fd; min-height: auto; text-decoration: underline; font-size: var(--fs-sm); font-weight: 700; }

/* ===== MODAL DE CONFIRMACIÓN (reemplaza confirm()) ===== */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 20px;
}
.confirm-overlay[hidden] { display: none; }
.confirm-panel {
  background: var(--card);
  border-radius: var(--r-2xl);
  padding: 24px 20px;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--shadow-lg);
}
.confirm-msg {
  font-size: var(--fs-base);
  color: var(--text);
  line-height: 1.5;
  text-align: center;
}
.confirm-actions { display: flex; flex-direction: column; gap: 10px; }

/* ===== LOADING SKELETON para matrices ===== */
.skeleton-cell {
  aspect-ratio: 1 / 1;
  border-radius: var(--r-lg);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== MOTION REDUCE ===== */
@media (prefers-reduced-motion: reduce) {
  .chip { animation: none; }
  .phrase-row.is-speaking { animation: none; }
  .skeleton-cell { animation: none; }
  .tile { transition: none; }
  .toggle::after { transition: none; }
}
