/* =========================================================================
   Eduan — Sistema de diseño
   Comunicador CAA por conmutador único (sonido / botón).
   Principios:
     · La accesibilidad ES el producto: alto contraste (AAA), objetivos enormes.
     · Un único color (ÁMBAR) reservado al barrido => el ojo lo encuentra solo.
     · 3 zonas fijas, sin scroll de página. Mobile-first / PWA.
     · Tipografía Atkinson Hyperlegible (Braille Institute, baja visión).
   NOTA: las clases y variables que toca el JS se conservan
   (--accent-2, --warn, --danger, .cell, .highlight, .row-highlight, .dur-*, …).
   ========================================================================= */

:root {
  /* — Superficies (OLED dark) — */
  --bg:        #0B0F14;   /* casi negro, ahorra batería en OLED */
  --bg-soft:   #121925;   /* cabecera / paneles */
  --panel:     #161E2B;   /* tarjetas */
  --panel-2:   #1F2A3A;   /* celdas en reposo */
  --panel-3:   #26344A;   /* hover / foco teclado */
  --border:    #2A3445;

  /* — Texto — */
  --text:      #F5F8FC;   /* AAA sobre --bg */
  --muted:     #9FB0C3;   /* pistas (>4.5:1 sobre --bg) */

  /* — Semánticos (algunos los lee el JS) — */
  --accent:    #4DA3FF;   /* foco, enlaces */
  --accent-2:  #2BD4A0;   /* CONFIRMAR (lo lee app.js para feedback) */
  --warn:      #FFB020;   /* zona "largo" del medidor (lo lee app.js) */
  --danger:    #FF5A5A;   /* borrar / atrás (lo lee app.js) */

  /* — EL color del barrido: exclusivo, no se usa para nada más — */
  --highlight: #FFC400;   /* ámbar: celda activa */
  --on-scan:   #0B0F14;   /* texto sobre ámbar pleno */
  --scan-tint: rgba(255, 196, 0, .14);  /* fila iluminada */
  --scan-ring: rgba(255, 196, 0, .55);  /* anillo de la celda activa */

  --radius:    18px;
  --radius-sm: 12px;
  --shadow:    0 10px 30px rgba(0, 0, 0, .45);

  /* Pilas de espaciado 4/8 */
  --gap: 12px;

  font-size: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

::selection { background: var(--highlight); color: var(--on-scan); }

html { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;

  height: 100vh;
  height: 100dvh;          /* respeta barras del navegador móvil */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;        /* la app no hace scroll; el teclado scrollea por dentro */

  /* Safe areas (notch, isla dinámica, barra de gestos) */
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

/* Salto al contenido para teclado/lectores */
.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--highlight);
  color: var(--on-scan);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  z-index: 1000;
}
.skip-link:focus { left: 8px; }

/* Foco visible y consistente en todo lo interactivo */
:where(button, [role="button"], a, input, [tabindex]):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* =========================================================================
   1) TOPBAR — mínima; los ajustes viven escondidos a la derecha
   ========================================================================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  flex: none;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { display: inline-flex; width: 38px; height: 38px; flex: none; }
.logo svg { width: 100%; height: 100%; display: block; }
.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .2px;
  white-space: nowrap;
}
.tagline {
  margin: 0;
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 8px; flex: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 48px; height: 48px;     /* objetivo táctil >= 44 */
  cursor: pointer;
  transition: background .15s, transform .08s, border-color .15s;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--panel-2); border-color: var(--panel-3); }
.icon-btn:active { transform: scale(.94); }

/* Estado de red (offline) — discreto, no bloquea */
.net-status {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  font-weight: 700;
  color: var(--warn);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.net-status svg { width: 14px; height: 14px; }
body.is-offline .net-status { display: inline-flex; }

/* =========================================================================
   LAYOUT — columna que rellena la altura disponible
   ========================================================================= */
.layout {
  width: 100%;
  max-width: 760px;          /* en escritorio queda centrado y legible */
  margin: 0 auto;
  padding: var(--gap);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* =========================================================================
   2) MENSAJE EN CONSTRUCCIÓN — lo más importante de la pantalla
   ========================================================================= */
.message-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  flex: none;
}
.message-label {
  color: var(--muted);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.message-text {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  font-weight: 700;
  line-height: 1.25;
  min-height: 1.25em;
  max-height: 2.5em;
  overflow-y: auto;
  word-break: break-word;
}
.message-text[data-empty="true"] { color: var(--muted); font-weight: 400; }
.message-text .caret {
  display: inline-block;
  width: 3px; height: 1.05em;
  background: var(--accent);
  margin-left: 3px;
  vertical-align: text-bottom;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* =========================================================================
   3) TABLERO DE BARRIDO — ocupa el grueso de la pantalla
   ========================================================================= */
.board {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.board-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
  flex: none;
  flex-wrap: wrap;
}
.breadcrumb { font-weight: 700; color: var(--accent-2); font-size: 1rem; }
.board-hint { color: var(--muted); font-size: .82rem; }

/* 3 columnas grandes => menos pasos de barrido, objetivos enormes.
   IMPORTANTE: el nº de columnas debe coincidir con COLS en keyboard.js. */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(0, 1fr);   /* las filas se reparten la altura => SIN scroll */
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 4px;            /* aire para que el resaltado (scale) no se recorte */
}

.cell {
  position: relative;
  background: var(--panel-2);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 0;             /* deja que minmax(0,1fr) encoja la fila si hace falta */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: clamp(1.15rem, 4.2vw, 1.6rem);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  text-align: center;
  padding: 6px 8px;
  transition: transform .1s ease-out, border-color .12s, background .12s, box-shadow .12s;
}
.cell:hover { background: var(--panel-3); }
.cell:active { transform: scale(.97); }
.cell-main { line-height: 1.2; }
.cell-sub { font-size: .72rem; font-weight: 600; color: var(--muted); }
.cell-ico { font-size: 1.6rem; line-height: 1; }

.cell.action { background: #16223a; }
.cell.suggestion { font-size: clamp(1.05rem, 4vw, 1.3rem); }
.cell.suggestion .cell-sub { color: var(--accent-2); }

/* — EL RESALTADO DEL BARRIDO — */
/* Fila entera iluminada (fase "row"): tinte ámbar tenue */
.cell.row-highlight {
  border-color: var(--scan-ring);
  background: var(--scan-tint);
}
/* Casilla concreta dentro de la fila activa (fase "col") */
.cell.in-active-row { border-color: rgba(255, 196, 0, .35); }
/* Celda ACTIVA: ámbar pleno, texto oscuro, anillo + leve realce. Imposible de fallar. */
.cell.highlight {
  background: var(--highlight);
  color: var(--on-scan);
  border-color: var(--highlight);
  box-shadow: 0 0 0 4px var(--scan-ring), 0 10px 24px rgba(0, 0, 0, .4);
  transform: translateY(-2px) scale(1.04);
  z-index: 2;
}
.cell.highlight .cell-sub,
.cell.highlight .cell-ico { color: var(--on-scan); opacity: .85; }

/* Frase completa predicha: ocupa toda la fila, destacada en verde */
.cell.phrase {
  grid-column: 1 / -1;
  min-height: 64px;
  flex-direction: row;
  gap: 12px;
  font-size: clamp(1.05rem, 4vw, 1.25rem);
  text-align: left;
  justify-content: flex-start;
  padding: 12px 18px;
  background: #15302a;
  border-color: var(--accent-2);
}
.cell.phrase::before {
  content: "";
  width: 22px; height: 22px;
  flex: none;
  background: var(--highlight);
  -webkit-mask: var(--icon-spark) center / contain no-repeat;
  mask: var(--icon-spark) center / contain no-repeat;
}
.cell.phrase .cell-sub { color: var(--accent-2); margin-left: auto; white-space: nowrap; }
/* Frase como FILA ACTIVA del barrido: ámbar inequívoco (igual que el resto).
   Anillo INTERIOR (inset) para que el resaltado no se derrame al hueco entre filas
   y no deje esos "arcos" verdes a medias. El destello se queda ámbar (fondo oscuro). */
.cell.phrase.row-highlight {
  border-color: var(--highlight);
  background: #1b3f33;
}

/* Destello al ELEGIR (lo dispara app.js con .flash) */
.cell.flash { animation: flash .35s ease-out; }
@keyframes flash {
  0%   { background: var(--accent-2); color: var(--on-scan); box-shadow: 0 0 0 6px rgba(43, 212, 160, .35); }
  100% { }
}

/* Icono "destello" como máscara (sin emoji) */
:root {
  --icon-spark: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M12 2l1.8 5.5a4 4 0 0 0 2.7 2.7L22 12l-5.5 1.8a4 4 0 0 0-2.7 2.7L12 22l-1.8-5.5a4 4 0 0 0-2.7-2.7L2 12l5.5-1.8a4 4 0 0 0 2.7-2.7L12 2z'/></svg>");
}

/* =========================================================================
   4) BARRA DE MICRÓFONO FUSIONADA (ancho = duración, alto = volumen)
   ========================================================================= */
.input-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  flex: none;
}
.dur-meter { margin: 0; }
.dur-track {
  position: relative;
  height: 56px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--border);
  background: var(--bg);     /* las 3 zonas las pinta el JS encima */
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.dur-track:hover { border-color: var(--accent); }
.dur-track.mic-on {
  cursor: default;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(43, 212, 160, .2);
}
.dur-zone-label {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
  font-size: .74rem;
  font-weight: 700;
  color: rgba(255, 255, 255, .92);
  text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
  pointer-events: none;
  white-space: nowrap;
  z-index: 2;
}
.dur-zone-label .za { font-size: .58rem; font-weight: 600; opacity: .82; }
.dur-divider {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: rgba(255, 255, 255, .35);
  z-index: 2;
}
/* Relleno: el ANCHO crece con la duración; la ALTURA refleja el volumen */
.dur-fill {
  position: absolute;
  left: 0; bottom: 0;
  width: 0%;
  height: 25%;
  background: rgba(255, 255, 255, .34);
  z-index: 3;
  transition: width .04s linear, height .06s linear;
}
.dur-fill.idle { width: 0%; }
/* Marcador en el borde de avance */
.dur-marker {
  position: absolute;
  top: 0; bottom: 0;
  left: 0%;
  width: 3px;
  background: #fff;
  box-shadow: 0 0 10px rgba(255, 255, 255, .85);
  z-index: 4;
  opacity: 0;
  transition: left .04s linear, opacity .15s;
}
.dur-label {
  margin-top: 6px;
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
  min-height: 1.2em;
  color: var(--muted);
}

/* =========================================================================
   Botones tipo "pill"
   ========================================================================= */
.pill {
  background: var(--accent);
  color: #06122e;
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: filter .15s, transform .08s;
}
.pill:hover { filter: brightness(1.08); }
.pill:active { transform: scale(.97); }
.pill.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.pill.ghost:hover { background: var(--panel-2); }

/* =========================================================================
   DRAWERS (Ajustes / Ayuda) — escondidos; no alcanzables durante el barrido
   ========================================================================= */
.drawer {
  position: fixed;
  top: 0; right: 0;
  width: min(440px, 92vw);
  height: 100vh;
  height: 100dvh;
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
  box-shadow: -20px 0 60px rgba(0, 0, 0, .55);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform .25s ease-out;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer.hidden { transform: translateX(105%); }
.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}
.drawer-head h2 { margin: 0; font-size: 1.2rem; }
.drawer-body { padding: 18px; overflow-y: auto; }
.drawer-body h3 { margin: 22px 0 10px; color: var(--accent-2); font-size: .95rem; }
.drawer-body h3:first-child { margin-top: 0; }

.slider-row, .select-row, .check-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
  color: var(--text);
  font-size: .95rem;
  font-weight: 600;
}
.check-row { flex-direction: row; align-items: center; gap: 12px; font-weight: 400; }
.check-row input[type="checkbox"] { width: 22px; height: 22px; flex: none; accent-color: var(--accent-2); }
.slider-row input[type="range"] { width: 100%; height: 28px; accent-color: var(--accent); }
.slider-row output {
  color: var(--highlight);
  font-weight: 800;
  font-variant-numeric: tabular-nums;  /* cifras que no "bailan" */
}
.set-note { color: var(--muted); font-size: .84rem; line-height: 1.55; margin: 4px 0 14px; font-weight: 400; }
.help-content p { line-height: 1.65; }
.help-content ul { line-height: 1.75; padding-left: 20px; }
.help-content b { color: var(--text); }

.scrim {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .55);   /* scrim fuerte: aísla el panel */
  z-index: 30;
  backdrop-filter: blur(2px);
}
.scrim.hidden { display: none; }
.hidden { }

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 620px) {
  :root { font-size: 16px; }
  .topbar { padding: 8px 12px; }
  .topbar h1 { font-size: 1.05rem; }
  .tagline { display: none; }
  .logo { width: 32px; height: 32px; }
  .icon-btn { width: 44px; height: 44px; }

  .layout { padding: 10px; gap: 10px; }
  .message-card { padding: 12px 14px; }
  .board { padding: 10px; }
  .grid { gap: 7px; }
  /* Sub-etiquetas "palabra/frase" fuera en móvil: ganan altura sin perder claridad.
     (Las sub-etiquetas de las acciones SÍ se quedan: son su nombre.) */
  .cell.suggestion .cell-sub,
  .cell.phrase .cell-sub { display: none; }
}

/* Pantallas muy bajas / horizontal: comprime lo accesorio */
@media (max-height: 560px) {
  .message-label { display: none; }
  .board-hint { display: none; }
  .dur-track { height: 46px; }
}

/* Accesibilidad: el resaltado del barrido es FUNCIONAL (no se desactiva),
   pero se sustituye el movimiento por más contraste de color. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .cell.highlight { transform: none; }
  .message-text .caret { animation: none; opacity: 1; }
}
