/* ============================================================
   TablerosCAA — hoja de estilos
   Temas: claro / oscuro / alto contraste. Diseño accesible.
   ============================================================ */

:root {
  /* La paleta viene del mundo físico de la CAA: tarjetas plastificadas
     sobre papel cálido, contornos de tinta y los brillantes planos de
     los pictogramas de ARASAAC. */
  --font: "Nunito", "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-display: "Baloo 2", "Nunito", system-ui, sans-serif;
  --font-scale: 1;

  --bg: #faf7f1;
  --bg-panel: #ffffff;
  --bg-sunken: #f1ede4;
  --text: #26313b;
  --text-soft: #67707c;
  --brand: #26313b;
  --brand-contrast: #ffffff;
  --accent: #2563ae;
  --accent-soft: #e8f0fa;
  --speak: #2f8f3c;
  --sun: #ffc94d;
  --danger: #b3261e;
  --border: #e6e1d5;
  --border-strong: #cfc9bb;
  --ink: #26313b;
  --focus: #ff8f00;
  --shadow: 0 1px 3px rgba(60, 50, 30, 0.08), 0 6px 18px rgba(60, 50, 30, 0.07);
  --shadow-lift: 0 4px 10px rgba(60, 50, 30, 0.12), 0 12px 32px rgba(60, 50, 30, 0.12);
  --radius: 14px;

  --cell-bg: #ffffff;
  --cell-min: 110px;
  --scan-highlight: #ffd54f;

  color-scheme: light;
}

:root[data-contrast="high"] {
  --bg: #000000;
  --bg-panel: #000000;
  --bg-sunken: #000000;
  --text: #ffffff;
  --text-soft: #ffff00;
  --brand: #ffff00;
  --brand-contrast: #000000;
  --accent: #00e5ff;
  --accent-soft: #003340;
  --danger: #ff5252;
  --border: #ffffff;
  --focus: #ffff00;
  --shadow: none;
  --cell-bg: #000000;
  --scan-highlight: #ffff00;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { font-size: calc(100% * var(--font-scale)); }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
:root[data-contrast="high"] body { background: #000; }

/* ---------- Utilidades ---------- */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

.skip-link {
  position: absolute; left: 8px; top: -60px;
  background: var(--brand); color: var(--brand-contrast);
  padding: 10px 18px; border-radius: 0 0 8px 8px;
  z-index: 100; transition: top 0.15s;
  font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: 0; }

:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

kbd {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-bottom-width: 3px;
  border-radius: 6px;
  padding: 1px 7px;
  font-size: 0.85em;
  font-family: inherit;
}

.hint { color: var(--text-soft); font-size: 0.9rem; }
.hint-inline { color: var(--text-soft); font-weight: 400; font-size: 0.85em; }
.spacer { flex: 1; }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 8px rgba(15, 35, 60, 0.06);
  position: sticky; top: 0; z-index: 20;
}

.brand {
  display: flex; align-items: center; gap: 8px;
  color: var(--brand); text-decoration: none;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem; letter-spacing: 0.1px;
}
.brand strong { font-weight: 800; color: var(--accent); }
.brand-icon { width: 34px; height: 34px; }

.main-nav ul {
  display: flex; gap: 2px;
  list-style: none; margin: 0; padding: 0;
  flex-wrap: wrap;
}
.main-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 14px 6px;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.78rem;
  line-height: 1.2;
  min-width: 64px;
}
.nav-ico { margin: 0; font-size: 1.25rem; }
.main-nav a:hover { background: var(--bg-sunken); }
.main-nav a[aria-current="page"] {
  background: var(--sun);
  color: var(--ink);
  box-shadow: inset 0 -3px 0 rgba(60, 40, 0, 0.18);
}

.top-actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- Botones e inputs ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: #efebe1;
  border: none;
  box-shadow: inset 0 0 0 1px rgba(70, 60, 35, 0.08);
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  transition: background 0.12s, box-shadow 0.12s, color 0.12s;
}
.btn:hover { background: #e5dfd0; box-shadow: inset 0 0 0 1px rgba(70, 60, 35, 0.14); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn[disabled]:hover { background: #efebe1; }

.btn-primary {
  background: linear-gradient(180deg, #3173c2, var(--accent));
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 174, 0.35), inset 0 -2px 0 rgba(0, 25, 60, 0.18);
}
.btn-primary:hover { background: #1c4f8e; color: #fff; box-shadow: 0 2px 8px rgba(37, 99, 174, 0.45); }

.btn-danger { background: #fbeae7; color: #a8231b; box-shadow: none; }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-ghost { background: transparent; box-shadow: none; }
.btn-ghost:hover { background: #efebe1; }
.btn-ghost[aria-pressed="true"] {
  background: var(--brand);
  color: var(--brand-contrast);
}

.btn-big { font-size: 1.1rem; padding: 12px 20px; }

.input {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1.5px solid #ddd7c9;
  border-radius: 12px;
  padding: 9px 12px;
  min-height: 44px;
  width: 100%;
  transition: border-color 0.12s;
}
.input:hover { border-color: var(--border-strong); }
.input:focus-visible { outline: 4px solid var(--focus); outline-offset: 1px; border-color: var(--accent); }

:root[data-contrast="high"] .sentence-chip { background: #000; border-color: #fff; color: #fff; }
:root[data-contrast="high"] .main-nav a[aria-current="page"] { background: #ffff00; color: #000; }

/* Alto contraste: los controles recuperan bordes fuertes */
:root[data-contrast="high"] .btn { background: #000; color: #fff; box-shadow: inset 0 0 0 2px #fff; }
:root[data-contrast="high"] .btn:hover { background: #222; }
:root[data-contrast="high"] .btn-primary { background: #00e5ff; color: #000; box-shadow: none; }
:root[data-contrast="high"] .btn-danger { background: #000; color: #ff5252; box-shadow: inset 0 0 0 2px #ff5252; }
:root[data-contrast="high"] .input { background: #000; color: #fff; border: 2px solid #fff; }
.input-num { width: 76px; }
.input-title { font-size: 1.15rem; font-weight: 700; min-width: 220px; }

input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 32px; }
input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--accent); }

/* ---------- Vistas ---------- */
main { padding: 12px 16px 40px; max-width: 1500px; margin: 0 auto; }
.view-narrow { max-width: 820px; margin: 0 auto; }

.view-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.view-head h1 { margin: 0; }
.view-head-actions { margin-left: auto; display: flex; gap: 8px; }

h1, h2, .board-title {
  font-family: var(--font-display);
}
h1 { font-size: 1.7rem; font-weight: 800; letter-spacing: 0; }
h2 { font-size: 1.2rem; font-weight: 700; }

/* ---------- Bienvenida (primer uso) ---------- */
.welcome {
  max-width: 680px;
  margin: 7vh auto 0;
  text-align: center;
  background: var(--bg-panel);
  border: 2.5px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 6px 0 rgba(38, 49, 59, 0.18), var(--shadow-lift);
  padding: 44px 30px;
}
.welcome h1 { margin-top: 0; font-size: 2.1rem; }
.welcome > p { font-size: 1.05rem; }
.welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
  max-width: 440px;
  margin: 24px auto;
}
.welcome-actions .btn {
  justify-content: center;
  font-family: var(--font-display);
  padding: 16px 22px;
  border-radius: 16px;
}
.welcome-actions .btn:not(.btn-primary) {
  background: #fff;
  box-shadow: inset 0 0 0 2.5px var(--ink);
}
.welcome-actions .btn:not(.btn-primary):hover { background: var(--accent-soft); }

/* ---------- Tira de frase (como una tira de velcro real) ---------- */
.sentence-bar {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--bg-panel);
  border: none;
  border-radius: 20px;
  padding: 12px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.sentence {
  flex: 1;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 8px;
  min-height: 92px;
  background: var(--bg-sunken);
  border: 2px dashed var(--border-strong);
  border-radius: 16px;
  min-width: 240px;
}

.sentence:empty::after {
  content: "Pulsa los pictogramas para construir una frase…";
  color: var(--text-soft);
  padding: 0 12px;
  font-weight: 600;
}

/* Cada palabra es una tarjeta que se «pega» en la tira */
.sentence-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  padding: 5px 9px;
  max-width: 110px;
  box-shadow: 0 2.5px 0 rgba(38, 49, 59, 0.25);
  animation: chip-pop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes chip-pop {
  from { transform: scale(0.6) rotate(-4deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}
.sentence-chip img { width: 50px; height: 50px; object-fit: contain; }
.sentence-chip .chip-label {
  font-size: 0.8rem;
  font-weight: 800;
  text-align: center;
  overflow-wrap: anywhere;
}

.sentence-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* La tecla de hablar: grande, redonda y verde, como en un comunicador físico */
#btnSpeakSentence {
  background: linear-gradient(180deg, #3aa347, var(--speak));
  color: #fff;
  border-radius: 999px;
  font-size: 1.15rem;
  font-family: var(--font-display);
  font-weight: 700;
  padding: 14px 26px;
  box-shadow: 0 3px 10px rgba(47, 143, 60, 0.4), inset 0 -3px 0 rgba(0, 40, 10, 0.2);
}
#btnSpeakSentence:hover {
  background: #23732e;
  box-shadow: 0 3px 10px rgba(47, 143, 60, 0.5), inset 0 -3px 0 rgba(0, 40, 10, 0.25);
}
#btnBackspace, #btnClearSentence { background: transparent; box-shadow: none; color: var(--text-soft); }
#btnBackspace:hover, #btnClearSentence:hover { background: var(--bg-sunken); color: var(--text); }

/* ---------- Navegación de tablero ---------- */
.board-nav {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.board-title { margin: 0; font-size: 1.3rem; }
.board-nav-right { margin-left: auto; display: flex; gap: 8px; }

/* ---------- Cuadrícula del tablero ---------- */
.board-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(var(--cols, 6), 1fr);
  grid-auto-rows: minmax(var(--cell-min), auto);
}

.board-row { display: contents; }

.cell {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: var(--cell-min);
  padding: 8px 6px;
  background: var(--cell-bg);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  position: relative;
  box-shadow: 0 1px 3px rgba(15, 35, 60, 0.1);
  transition: transform 0.08s, box-shadow 0.12s;
}
.cell:hover { box-shadow: var(--shadow-lift); }
:root[data-big-cells="1"] .cell { min-height: 160px; }
.cell:hover { transform: scale(1.03); border-color: var(--accent); z-index: 2; }
.cell:active { transform: scale(0.97); }

.cell img {
  width: min(72px, 100%);
  height: 72px;
  object-fit: contain;
  pointer-events: none;
}
:root[data-big-cells="1"] .cell img { width: min(110px, 100%); height: 110px; }

.cell .cell-label {
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
  text-transform: var(--text-case, uppercase);
}

/* Preferencias: posición del texto y escritura */
:root[data-label-pos="top"] .cell,
:root[data-label-pos="top"] .sentence-chip,
:root[data-label-pos="top"] .seq-card,
:root[data-label-pos="top"] .picto-result {
  flex-direction: column-reverse;
}
:root[data-case="none"] { --text-case: none; }
:root[data-case="lower"] { --text-case: lowercase; }
.sentence-chip .chip-label,
.player-step .player-label,
.seq-card .seq-label,
.picto-card .picto-word {
  text-transform: var(--text-case, uppercase);
}

.cell-empty {
  background: transparent;
  border: 2px dashed #d3dde7;
  color: #b0bfce;
  cursor: default;
  box-shadow: none;
}
.cell-empty:hover { box-shadow: none; }
.board-grid-edit .cell-empty { cursor: pointer; }
.board-grid-edit .cell-empty::after {
  content: "＋";
  font-size: 1.5rem;
  font-weight: 400;
  color: #b0bfce;
  transition: color 0.12s;
}
.board-grid-edit .cell-empty:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: none;
}
.board-grid-edit .cell-empty:hover::after { color: var(--accent); }

.cell-link::before {
  content: "⇱";
  position: absolute;
  top: 4px; right: 8px;
  font-size: 1rem;
  color: var(--text-soft);
}

.cell.dragging { opacity: 0.4; }
.cell.drop-target { border-color: var(--focus); border-style: dashed; }

/* Colores de categorías (clave de Fitzgerald) */
.cat-persona     { background: #ffe082; border-color: #f9a825; color: #16202b; }
.cat-accion      { background: #a5d6a7; border-color: #2e7d32; color: #16202b; }
.cat-sustantivo  { background: #ffcc80; border-color: #ef6c00; color: #16202b; }
.cat-descriptivo { background: #90caf9; border-color: #1565c0; color: #16202b; }
.cat-social      { background: #f8bbd0; border-color: #c2185b; color: #16202b; }
.cat-importante  { background: #ef9a9a; border-color: #c62828; color: #16202b; }
.cat-misc        { background: #ffffff; border-color: #9e9e9e; color: #16202b; }

:root[data-contrast="high"] .cell[class*="cat-"] {
  background: #000; color: #fff; border-width: 5px;
}

.cat-dot {
  display: inline-block;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  vertical-align: middle;
  margin-right: 4px;
}
.cat-dot[data-cat="persona"]     { background: #ffe082; border-color: #f9a825; }
.cat-dot[data-cat="accion"]      { background: #a5d6a7; border-color: #2e7d32; }
.cat-dot[data-cat="sustantivo"]  { background: #ffcc80; border-color: #ef6c00; }
.cat-dot[data-cat="descriptivo"] { background: #90caf9; border-color: #1565c0; }
.cat-dot[data-cat="social"]      { background: #f8bbd0; border-color: #c2185b; }
.cat-dot[data-cat="importante"]  { background: #ef9a9a; border-color: #c62828; }
.cat-dot[data-cat="misc"]        { background: #ffffff; border-color: #9e9e9e; }

/* ---------- Barrido ---------- */
.scan-highlight-row .cell,
.cell.scan-highlight,
.scan-highlight-row .btn,
.btn.scan-highlight {
  box-shadow: 0 0 0 6px var(--scan-highlight);
  border-color: var(--scan-highlight) !important;
  z-index: 5;
}

body.scanning-active .cell:hover { transform: none; }

/* ---------- Editor: lienzo + panel lateral ---------- */
.editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 18px;
  align-items: start;
}

/* Lienzo con rieles para añadir fila / columna */
.editor-canvas {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  grid-template-rows: auto 40px;
  gap: 10px;
}
.editor-canvas .board-grid { grid-area: 1 / 1; }
.add-strip {
  font: inherit;
  border: 2px dashed #d3dde7;
  background: transparent;
  color: #b0bfce;
  border-radius: 12px;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.add-strip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.rail { display: flex; gap: 8px; }
.rail .add-strip { flex: 1; }
.rail-col { grid-area: 1 / 2; flex-direction: column; }
.rail-row { grid-area: 2 / 1; flex-direction: row; }

/* Secciones plegables del panel */
.panel-sect {
  border-top: 1px solid var(--bg-sunken);
  padding: 4px 0;
  margin-bottom: 4px;
}
.panel-sect summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 4px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.panel-sect summary::-webkit-details-marker { display: none; }
.panel-sect summary::before {
  content: "▸";
  font-size: 0.85rem;
  transition: transform 0.15s;
}
.panel-sect[open] summary::before { transform: rotate(90deg); }
.panel-sect summary:hover { background: var(--bg-sunken); color: var(--text); }
.panel-sect > *:not(summary) { margin-top: 6px; }

.cell-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
}
.cell-panel-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px;
}
.cell-panel-head h2 { margin: 0; flex: 1; font-size: 1.02rem; }
.btn-close { padding: 6px 12px; min-height: 38px; border-radius: 50%; width: 38px; justify-content: center; }

.cell-panel .field { margin-bottom: 18px; }
.cell-panel fieldset.field {
  border: none;
  border-radius: 0;
  padding: 0;
  margin: 0 0 18px;
}
.cell-panel legend,
.cell-panel .field > label {
  display: block;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
  padding: 0;
  margin-bottom: 7px;
}
.cell-panel .hint-inline { text-transform: none; letter-spacing: 0; }
.cell-panel .picto-results { max-height: 200px; }
.cell-panel hr { border: none; border-top: 1px solid var(--bg-sunken); margin: 16px 0; }
#btnCellClear { width: 100%; justify-content: center; margin-top: 4px; }

/* Selector segmentado (contenido de la celda) */
.mode-picker {
  display: flex;
  gap: 4px;
  background: #efebe1;
  padding: 4px;
  border-radius: 12px;
}
.mode-picker .btn {
  flex: 1;
  justify-content: center;
  background: transparent;
  box-shadow: none;
  min-height: 38px;
  padding: 6px 6px;
  font-size: 0.82rem;
  border-radius: 9px;
}
.mode-picker .btn:hover { background: #e5dfd0; }
.mode-picker .btn:has(input:checked) {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(15, 35, 60, 0.18);
}
.mode-picker input { position: absolute; opacity: 0; pointer-events: none; }
.mode-picker .btn:has(input:focus-visible) { outline: 4px solid var(--focus); outline-offset: 1px; }
.img-preview-panel { margin: 0 auto 10px; }

.cell.cell-selected {
  outline: 4px solid var(--accent);
  outline-offset: 3px;
  z-index: 4;
}

@media (max-width: 980px) {
  .editor-layout { grid-template-columns: 1fr; }
  .cell-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(380px, 94vw);
    max-height: none;
    border-radius: 16px 0 0 16px;
    box-shadow: var(--shadow-lift);
    transform: translateX(105%);
    transition: transform 0.25s ease;
    z-index: 40;
  }
  .cell-panel.open { transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
  .cell-panel { transition: none; }
}

.editor-toolbar {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
}
.editor-toolbar-group { display: flex; gap: 8px; align-items: center; }
.editor-hint { color: var(--text-soft); margin: 4px 0 10px; font-size: 0.9rem; }

/* ---------- Lista de tableros ---------- */
.boards-list {
  list-style: none;
  margin: 0; padding: 0;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.board-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.12s, box-shadow 0.12s;
}
.board-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.board-card h2 { margin: 0; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.board-card .home-badge {
  font-size: 0.72rem;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 700;
}
:root[data-contrast="high"] .board-card .home-badge { color: #000; }
.board-card .board-meta { color: var(--text-soft); font-size: 0.85rem; }
.board-card .board-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.board-card .btn { padding: 6px 10px; min-height: 38px; font-size: 0.9rem; }

/* ---------- Ajustes ---------- */
.settings-group {
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
}
.settings-group legend {
  font-weight: 800;
  font-size: 1.05rem;
  padding: 0 8px;
}
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field-check { display: flex; align-items: center; gap: 10px; }
.field-check label { margin: 0; }
.settings-actions { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }

/* ---------- Diálogos ---------- */
.dialog {
  border: 3px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-panel);
  color: var(--text);
  padding: 0;
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
}
.dialog-small { width: min(440px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(5, 15, 25, 0.6); }
.dialog-form { padding: 20px; }
.dialog h2 { margin-top: 0; }
.dialog-actions {
  display: flex; gap: 8px; align-items: center;
  margin-top: 16px;
  position: sticky; bottom: 0;
  background: var(--bg-panel);
  padding-top: 8px;
}

/* Selector de imagen */
.img-picker { display: flex; gap: 12px; align-items: flex-start; }
.img-preview {
  width: 92px; height: 92px;
  flex: none;
  border: 2px dashed var(--border);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: #fff;
}
.img-preview img { max-width: 86px; max-height: 86px; object-fit: contain; }
.img-picker-controls { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.search-row { display: flex; gap: 8px; }
.search-row .input { flex: 1; }

.picto-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 8px;
}
.picto-result {
  font: inherit;
  background: #fff;
  border: 1.5px solid #e3e9f0;
  border-radius: 12px;
  padding: 6px 4px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.picto-result img { width: 56px; height: 56px; object-fit: contain; }
.picto-result span { font-size: 0.72rem; overflow-wrap: anywhere; text-align: center; color: #16202b; }
.picto-result[aria-selected="true"], .picto-result:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Selector de categoría */
.cat-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.cat-swatch {
  font: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  border-radius: 999px;
  border: 2px solid transparent;
  padding: 7px 13px;
  cursor: pointer;
  color: #16202b;
  transition: box-shadow 0.12s;
}
.cat-swatch:hover { box-shadow: 0 0 0 2px rgba(20, 40, 70, 0.15); }
.cat-swatch[aria-checked="true"] {
  border-color: var(--text);
  box-shadow: 0 0 0 3px var(--focus);
}

/* Exportar */
.export-grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
.export-opt {
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 2px;
}
.export-opt strong { font-size: 1.02rem; }
.export-opt span { font-weight: 400; color: var(--text-soft); font-size: 0.88rem; }
.share-box {
  margin-top: 14px;
  padding: 12px;
  background: var(--bg-sunken);
  border-radius: 10px;
}

/* ---------- Traductor a pictogramas ---------- */
.trans-input {
  width: 100%;
  min-height: 110px;
  resize: vertical;
  font-size: 1.1rem;
}
.trans-controls {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin: 10px 0 18px;
}
.trans-line {
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
}
.trans-line-words {
  display: flex; gap: 10px; flex-wrap: wrap;
  list-style: none; margin: 0 0 8px; padding: 0;
}
.picto-card {
  font: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  gap: 4px;
  width: 108px; min-height: 120px;
  background: #fff;
  border: 3px solid var(--border);
  border-radius: 12px;
  padding: 8px 4px;
  cursor: pointer;
  color: #16202b;
}
.picto-card img { width: 76px; height: 76px; object-fit: contain; }
.picto-card .picto-word {
  font-weight: 800; font-size: 0.92rem; text-transform: uppercase;
  text-align: center; overflow-wrap: anywhere;
}
.picto-card .picto-alt {
  font-size: 0.68rem; color: var(--text-soft); font-weight: 600;
}
.picto-card.text-only { justify-content: center; background: var(--bg-sunken); cursor: default; }
.picto-card:hover { border-color: var(--accent); }
.trans-line-actions { display: flex; gap: 8px; }
.trans-status { margin: 8px 0; }

/* ---------- Rutinas ---------- */
.routine-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.step-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  flex-wrap: wrap;
}
.step-num {
  font-weight: 800; font-size: 1.2rem;
  min-width: 36px; text-align: center;
  color: var(--accent);
}
.step-thumb {
  width: 72px; height: 72px; flex: none;
  border: 2px dashed var(--border);
  border-radius: 10px;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 1.4rem;
  padding: 0;
}
.step-thumb img { max-width: 64px; max-height: 64px; object-fit: contain; }
.step-fields { flex: 1; display: flex; gap: 8px; flex-wrap: wrap; min-width: 200px; }
.step-fields .input { flex: 2; min-width: 140px; }
.step-fields input[type="time"] { flex: 0; min-width: 110px; }
.step-tools { display: flex; gap: 4px; }
.step-tools .btn { padding: 6px 10px; min-height: 40px; }

/* Reproductor de rutina */
.player {
  max-width: 720px; margin: 0 auto; text-align: center;
}
.player-progress {
  display: flex; gap: 8px; justify-content: center; align-items: center;
  margin: 14px 0;
  flex-wrap: wrap;
}
.player-dot {
  width: 46px; height: 46px;
  border-radius: 10px;
  border: 3px solid var(--border);
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  position: relative;
}
.player-dot img { width: 38px; height: 38px; object-fit: contain; }
.player-dot.done::after {
  content: "✓";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(46, 125, 50, 0.85);
  color: #fff; font-size: 1.6rem; font-weight: 800;
}
.player-dot.current { border-color: var(--focus); box-shadow: 0 0 0 4px var(--scan-highlight); }
.player-step {
  background: var(--bg-panel);
  border: 4px solid var(--accent);
  border-radius: 20px;
  padding: 26px;
  margin: 12px 0 18px;
}
.player-step img { width: min(240px, 60vw); height: auto; max-height: 240px; object-fit: contain; }
.player-step .player-label {
  font-size: 2rem; font-weight: 800; text-transform: uppercase; margin-top: 8px;
}
.player-step .player-time { font-size: 1.2rem; color: var(--text-soft); }
.player-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn-done {
  font-size: 1.4rem; padding: 16px 34px;
  background: #2e7d32; border-color: #2e7d32; color: #fff;
}
.btn-done:hover { background: #1b5e20; border-color: #1b5e20; color: #fff; }
.player-finished { font-size: 1.5rem; padding: 30px 0; }
.player-finished .big { font-size: 4rem; }

/* ---------- Secuencias (páginas imprimibles) ---------- */
.seq-layout {
  display: grid;
  grid-template-columns: 1fr 290px;
  gap: 18px;
  align-items: start;
}
@media (max-width: 980px) { .seq-layout { grid-template-columns: 1fr; } }

.seq-page-wrap { overflow-x: auto; padding: 6px; }

.seq-page {
  background: #ffffff;
  box-shadow: var(--shadow-lift);
  border-radius: 6px;
  margin: 0 auto;
  padding: 4%;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  box-sizing: border-box;
  min-height: 200px;
  width: 100%;
  max-width: 1050px;
}
.seq-page.landscape { aspect-ratio: 297 / 210; }
.seq-page.portrait  { aspect-ratio: 210 / 297; max-width: 740px; }

.seq-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #fff;
  border: 3px solid var(--border-strong);
  border-radius: 16px;
  padding: 8px;
  position: relative;
  cursor: grab;
  width: calc(90px * var(--card-size, 1.4));
  box-shadow: 0 1px 3px rgba(15, 35, 60, 0.1);
}
.seq-card:active { cursor: grabbing; }
.seq-card.cat-persona     { border-color: #f9a825; }
.seq-card.cat-accion      { border-color: #2e7d32; }
.seq-card.cat-sustantivo  { border-color: #ef6c00; }
.seq-card.cat-descriptivo { border-color: #1565c0; }
.seq-card.cat-social      { border-color: #c2185b; }
.seq-card.cat-importante  { border-color: #c62828; }

.seq-card img {
  width: calc(66px * var(--card-size, 1.4));
  height: calc(66px * var(--card-size, 1.4));
  object-fit: contain;
  pointer-events: none;
}
.seq-card .seq-label {
  font: inherit;
  font-weight: 700;
  font-size: calc(0.62rem * var(--card-size, 1.4));
  text-align: center;
  border: none;
  background: transparent;
  width: 100%;
  min-width: 0;
  color: #17222e;
}
.seq-label:focus-visible { outline: 3px solid var(--focus); border-radius: 6px; }

.seq-card .seq-tools {
  position: absolute;
  top: -12px; right: -10px;
  display: none;
  gap: 4px;
}
.seq-card:hover .seq-tools,
.seq-card:focus-within .seq-tools { display: flex; }
.seq-tool {
  font: inherit;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: #fff;
  cursor: pointer;
  font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.seq-tool:hover { border-color: var(--accent); background: var(--accent-soft); }
.seq-card.dragging { opacity: 0.35; }
.seq-card.drop-before { box-shadow: -6px 0 0 0 var(--focus); }

.seq-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 76px;
}
.seq-panel h2 { margin: 0; font-size: 1rem; }
.seq-add-row { display: flex; gap: 8px; }
.seq-add-row .input { flex: 1; }
.align-group, .orient-group { display: flex; gap: 6px; }
.align-group .btn, .orient-group .btn { padding: 8px 12px; min-height: 40px; }
.align-group .btn[aria-pressed="true"], .orient-group .btn[aria-pressed="true"] {
  background: var(--brand); color: var(--brand-contrast); border-color: var(--brand);
}

/* ---------- Agarre de redimensionado de celdas ---------- */
.board-grid-edit .cell { touch-action: manipulation; }
.resize-handle {
  position: absolute;
  right: -2px; bottom: -2px;
  width: 26px; height: 26px;
  border-radius: 12px 4px 12px 4px;
  background: var(--accent);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  cursor: nwse-resize;
  touch-action: none;
  z-index: 3;
  border: 2px solid #fff;
  box-shadow: var(--shadow);
}
.board-grid-edit .cell:hover .resize-handle,
.board-grid-edit .cell:focus .resize-handle,
.board-grid-edit .cell:focus-within .resize-handle { display: flex; }
.cell.resizing { opacity: 0.85; outline: 4px dashed var(--focus); outline-offset: 2px; z-index: 6; }

/* ---------- Cámara ---------- */
.camera-video {
  width: 100%; max-height: 420px;
  background: #000;
  border-radius: 10px;
}

/* ---------- Atribución ---------- */
.attribution {
  margin-top: 18px;
  color: var(--text-soft);
  font-size: 0.8rem;
  text-align: center;
}
.attribution a { color: inherit; }

/* ---------- Impresión ---------- */
.print-area { display: none; }

@media print {
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; }
  .print-area .print-sentence {
    font-size: 13pt; font-weight: 700; margin: 10pt 0 4pt;
  }
  .print-area .seq-page {
    box-shadow: none; border-radius: 0; max-width: none;
    width: 100%; padding: 0; aspect-ratio: auto;
  }
  .print-area .seq-card { break-inside: avoid; box-shadow: none; }
  .print-area .seq-tools, .print-area .resize-handle { display: none !important; }
  .print-area .print-author { text-align: right; color: #55677a; font-size: 10pt; }
  .print-area h1 { text-align: center; font-size: 20pt; margin: 0 0 12pt; }
  .print-area .board-grid { gap: 8pt; }
  .print-area .cell {
    border-width: 2pt;
    min-height: 90pt;
    break-inside: avoid;
    transform: none !important;
  }
  .print-area .attribution { margin-top: 14pt; font-size: 8pt; }
}

/* ---------- Adaptaciones ---------- */
@media (max-width: 760px) {
  .topbar { gap: 8px; }
  .main-nav a { padding: 8px 10px; }
  .sentence-actions { width: 100%; justify-content: stretch; }
  .sentence-actions .btn { flex: 1; justify-content: center; }
  :root { --cell-min: 88px; }
  .cell img { height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .cell:hover { transform: none; }
}
