/* AXONFAS · componentes compartidos del HUD Biónico (TD-35).
 * Los tokens (colores, tipografía, geometría) vienen de docs/design-system/tokens.css, que cada página carga antes.
 * Aquí van los componentes que usan todas las páginas: base, cabecera, botones, tarjetas, controles, tablas,
 * etiquetas, diálogo del QR, navegación, formularios, tarjetas de ejercicio, mapa corporal, indicadores, avisos y el
 * escenario de cámara (index.html y seguimiento.html). Lo propio de cada pantalla (tacómetros, guía) queda en su HTML. */

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

body {
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--ink);
  font: 400 1rem/1.55 var(--font-body);
  min-height: 100vh;
  overflow-x: hidden;
}

header.top-header {
  position: sticky;
  top: 0;
  z-index: 900;
  background: rgba(3, 7, 18, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--surface-border);
  padding: 12px clamp(16px, 3vw, 36px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #00F2FE 0%, #4FACFE 100%);
  border-radius: var(--radius-sm);
  display: grid;
  place-content: center;
  color: #030712;
  font: 900 1.1rem var(--font-display);
  box-shadow: var(--accent-glow);
}

.brand-info h1 {
  font: 800 1.35rem/1.1 var(--font-display);
  letter-spacing: -0.02em;
  color: #FFFFFF;
  margin: 0;
}

.brand-info h1 span {
  color: var(--tape);
  font-weight: 500;
  font-size: 0.95rem;
}

.brand-info p {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 2px 0 0;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 242, 254, 0.12);
  border: 1px solid var(--tape);
  color: var(--tape);
  font: 700 0.75rem var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: var(--accent-glow);
}

.header-badge .pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--tape);
  box-shadow: 0 0 8px var(--tape);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.wrap {
  max-width: 90rem;
  margin-inline: auto;
  padding: 20px clamp(16px, 2.5vw, 36px) 64px;
}

.btn {
  border: 1px solid var(--surface-border);
  background: var(--surface-2);
  color: #FFFFFF;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  min-height: 40px;                       /* objetivo táctil (WCAG 2.5.8) */
  font: 700 0.875rem/1.25 var(--font-display);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;                /* el texto queda centrado aunque pase a dos líneas */
  text-align: center;
  gap: 8px;
  max-width: 100%;
}

.btn:hover {
  border-color: var(--tape);
  box-shadow: var(--accent-glow);
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--tape);
  border-color: var(--tape);
  color: #030712;
  box-shadow: var(--accent-glow);
}

.btn.primary:hover {
  background: var(--tape-hover);
  color: #030712;
}

.btn.danger {
  background: var(--alert-strong);
  border-color: var(--alert);
  color: #FFFFFF;
}

.btn.danger:hover {
  box-shadow: var(--alert-glow);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.status-line {
  font: 500 0.85rem var(--font-mono);
  color: var(--muted);
}

.panel-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-card h2 {
  font: 800 0.85rem/1.2 var(--font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tape);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.control {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.control:last-child { margin-bottom: 0; }

.control label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font: 600 0.85rem var(--font-body);
  color: var(--ink-secondary);
}

.control output {
  font: 700 0.85rem var(--font-mono);
  background: rgba(0, 242, 254, 0.1);
  color: var(--tape);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(0, 242, 254, 0.2);
}

.control input[type="range"] {
  width: 100%;
  accent-color: var(--tape);
  cursor: pointer;
}

.control .hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  margin-top: 6px;
}

.check input[type="checkbox"] {
  accent-color: var(--tape);
  width: 16px;
  height: 16px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

th {
  text-align: left;
  vertical-align: bottom;
  font: 800 0.75rem/1.3 var(--font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tape);
  background: rgba(11, 19, 37, 0.95);
  padding: 12px 14px;
}

/* Las celdas de texto se ajustan dentro de la columna en vez de empujar la tabla a un scroll lateral; las cifras no se
   cortan. Solo una tabla con muchas columnas en celular usa el scroll de .table-wrap. */
td {
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  vertical-align: top;
  overflow-wrap: anywhere;
  min-width: 6ch;
}

td.num, th.num { font-family: var(--font-mono); white-space: nowrap; }

.tag {
  font: 800 0.75rem var(--font-mono);
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
  letter-spacing: 0.04em;
}

.tag.ok { color: var(--safe); background: var(--safe-soft); border: 1px solid rgba(0, 255, 136, 0.3); }

.tag.bad { color: var(--alert-ink); background: var(--alert-soft); border: 1px solid rgba(255, 0, 85, 0.3); }

.tag.warn { color: var(--hold); background: var(--hold-soft); border: 1px solid rgba(255, 184, 0, 0.3); }

.tag.cal { color: var(--tape); background: var(--tape-soft); border: 1px solid rgba(0, 242, 254, 0.3); }

.empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 24px;
  text-align: center;
}

.share-dialog {
  margin: auto;
  width: min(94vw, 48rem);
  max-height: 92vh;
  overflow-y: auto;
  padding: 22px 24px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--tape);
  box-shadow: var(--accent-glow), var(--shadow-lg);
}

.share-dialog::backdrop { background: rgba(2, 6, 23, 0.78); backdrop-filter: blur(6px); }

.share-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }

.share-head h2 { font: 800 1.15rem/1.2 var(--font-display); letter-spacing: -0.01em; color: #FFFFFF; }

.share-body { display: grid; grid-template-columns: minmax(0, 16rem) minmax(0, 1fr); gap: 20px 24px; align-items: start; }

@media (max-width: 640px) { .share-body { grid-template-columns: minmax(0, 1fr); } }

.share-qr {
  background: #FFFFFF;
  border-radius: var(--radius);
  padding: 12px;
  width: min(100%, 16rem);
  margin: 0 auto;
  box-shadow: var(--accent-glow);
}

.share-qr svg { display: block; width: 100%; height: auto; }

.share-qr-missing { color: #030712; font-size: 0.85rem; text-align: center; padding: 24px 8px; }

.share-url-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin: 14px 0 4px; }

.share-url {
  font: 700 0.84rem var(--font-mono);
  color: var(--tape);
  background: var(--tape-soft);
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  padding: 6px 10px;
  overflow-wrap: anywhere;
  user-select: all;
}

.share-steps { padding-left: 1.3em; display: grid; gap: 6px; font-size: 0.9rem; color: var(--ink-secondary); }

.share-note { font-size: 0.8rem; color: var(--muted); margin-top: 12px; }

.share-note code { font-family: var(--font-mono); color: var(--ink-secondary); }

footer {
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--surface-border);
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.6;
}

/* ==========================================================================
   NAVEGACIÓN ENTRE PÁGINAS (prototipo · galería · fisioterapeuta · paciente)
   ========================================================================== */
.top-nav { display: flex; flex-wrap: wrap; gap: 6px; }
.top-nav a {
  font: 700 0.8rem var(--font-display);
  letter-spacing: 0.04em;
  color: var(--ink-secondary);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.top-nav a:hover { color: var(--tape); border-color: var(--surface-border); }
.top-nav a[aria-current="page"] { color: #030712; background: var(--tape); box-shadow: var(--accent-glow); }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--tape); outline-offset: 2px; }

/* Selector de idioma de la cabecera (i18n.js, ADR-030): un botón por idioma; el activo lleva aria-pressed="true" */
.lang-switch { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--surface-border); border-radius: 999px; }
.lang-btn {
  font: 700 0.75rem var(--font-mono); letter-spacing: 0.06em; color: var(--ink-secondary);
  background: transparent; border: 0; border-radius: 999px; min-width: 40px; min-height: 32px; padding: 4px 10px; cursor: pointer;
}
.lang-btn:hover { color: var(--tape); }
.lang-btn[aria-pressed="true"] { color: #030712; background: var(--tape); }

/* ==========================================================================
   FORMULARIOS Y AVISOS
   ========================================================================== */
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font: 600 0.85rem var(--font-body); color: var(--ink-secondary); }
.field input[type="text"], .field input[type="number"], .field select, .field textarea, .search {
  font: 500 0.95rem var(--font-body);
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus, .search:focus { outline: 2px solid var(--tape); outline-offset: 1px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: 10px; }
.muted { color: var(--muted); font-size: 0.82rem; }
.notice {
  border-left: 3px solid var(--hold);
  background: var(--hold-soft);
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--ink-secondary);
}
.page-title { font: 900 clamp(1.4rem, 3vw, 2rem)/1.15 var(--font-display); letter-spacing: -0.02em; color: #FFFFFF; margin-bottom: 6px; }
.page-lede { color: var(--ink-secondary); max-width: 70ch; margin-bottom: 18px; }
.stack { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }   /* una tabla ancha no estira la columna */
.row-between { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }

/* ==========================================================================
   FILTROS Y TARJETAS DE EJERCICIO
   ========================================================================== */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn {
  font: 700 0.8rem var(--font-display);
  color: var(--ink-secondary);
  background: var(--surface-2);
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  min-height: 36px;
}
.chip-btn[aria-pressed="true"] { color: #030712; background: var(--tape); border-color: var(--tape); box-shadow: var(--accent-glow); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr)); gap: 16px; }
/* Simetría (ADR-017): las tarjetas de una misma fila comparten las filas de la grilla (subgrid), así las etiquetas,
   el título, la figura, el mapa y los botones quedan a la misma altura aunque un texto ocupe dos líneas. */
@supports (grid-template-rows: subgrid) {
  .card-grid > .ex-card:not(.patient-card) { grid-row: span 11; grid-template-rows: subgrid; row-gap: 10px; }
  .kpis { grid-auto-rows: auto; }
  .kpis > .kpi { grid-row: span 3; grid-template-rows: subgrid; row-gap: 2px; }
}
.ex-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 10px;
  align-content: start;
  box-shadow: var(--shadow);
  min-width: 0;
}
.ex-card h3 { font: 800 1.05rem/1.2 var(--font-display); color: #FFFFFF; }

.ex-card .dose { font: 600 0.8rem/1.4 var(--font-mono); color: var(--tape); }
.ex-card details summary { cursor: pointer; font: 700 0.85rem var(--font-display); color: var(--tape); }
.ex-card ol, .ex-card ul { padding-left: 1.2em; display: grid; gap: 4px; font-size: 0.88rem; color: var(--ink-secondary); margin-top: 6px; }
.ex-card .source { font-size: 0.78rem; color: var(--muted); }
.ex-card .source a, .link { color: var(--tape); }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ==========================================================================
   MAPA CORPORAL 2D (body-map.js · ADR-013)
   ========================================================================== */
.bodymap-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bodymap-view { margin: 0; text-align: center; }
.bodymap-view figcaption { font: 600 0.7rem var(--font-mono); color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
.bodymap-svg { width: 100%; height: auto; max-height: 280px; }
/* Mismos tokens de músculo que las figuras de los ejercicios (tokens.css: --muscle-*) */
.bodymap-muscle polygon { fill: var(--muscle); fill-opacity: var(--muscle-fill); stroke: var(--muscle); stroke-opacity: var(--muscle-edge); stroke-width: 4; transition: fill-opacity 0.15s, fill 0.15s; }
.bodymap-muscle.neutral polygon { fill-opacity: var(--muscle-neutral-fill); }
.bodymap-muscle.active polygon { fill: var(--fig-active); fill-opacity: calc(var(--muscle-active-min) + var(--muscle-active-range) * var(--level, 0)); stroke: var(--fig-active); stroke-opacity: 0.6; }
.bodymap-muscle.alert polygon { fill: var(--alert); fill-opacity: 0.9; stroke: var(--alert); }
.bodymap-muscle.focus polygon { stroke: #FFFFFF; stroke-opacity: 1; stroke-width: 12; }
.bodymap-muscle:hover polygon { stroke: #FFFFFF; stroke-opacity: 0.8; }
.bodymap-muscle:focus { outline: none; }
.bodymap-muscle:focus-visible polygon { stroke: #FFFFFF; stroke-opacity: 1; stroke-width: 16; fill-opacity: 0.6; }
.bodymap-note { font-size: 0.75rem; color: var(--muted); margin-top: 6px; }
.facts { display: grid; gap: 4px; font-size: 0.85rem; color: var(--ink-secondary); }
.facts strong { color: #FFFFFF; font-weight: 700; }

/* ==========================================================================
   INDICADORES DE CUMPLIMIENTO Y EFECTIVIDAD
   ========================================================================== */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 10px; }
.kpi { background: var(--surface-2); border: 1px solid var(--surface-border); border-radius: var(--radius-sm); padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.kpi .k { font: 700 0.7rem var(--font-display); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.kpi .v { font: 800 1.5rem/1.1 var(--font-mono); color: #FFFFFF; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 0.75rem; color: var(--muted); }
.meter { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--tape); }
.meter.warn > span { background: var(--hold); }
.meter.bad > span { background: var(--alert); }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.live-dot.on { background: var(--safe); box-shadow: 0 0 10px var(--safe); animation: pulse 1.5s infinite; }

/* ==========================================================================
   AVISO FLOTANTE (el fisioterapeuta señala un músculo al paciente)
   ========================================================================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 1000;
  width: min(94vw, 28rem);
  background: var(--surface);
  border: 1px solid var(--tape);
  box-shadow: var(--accent-glow), var(--shadow-lg);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: grid;
  gap: 8px;
  max-height: calc(100svh - 32px);   /* con figura y mapa puede ser alto: se desplaza dentro, no se corta */
  overflow-y: auto;
}
.toast .bodymap-svg { max-height: 180px; }
.toast h3 { font: 800 1rem var(--font-display); color: var(--tape); }

@media (max-width: 640px) {
  header.top-header { padding: 10px 12px; gap: 8px; }
  .brand-icon { width: 30px; height: 30px; font-size: 0.95rem; }
  .brand-info h1 { font-size: 1.1rem; }
  .brand-info h1 span { font-size: 0.8rem; }
  .brand-info p { font-size: 0.72rem; }
  .header-badge { padding: 4px 10px; font-size: 0.65rem; }
  .top-nav { width: 100%; }
  .top-nav a { padding: 8px 10px; font-size: 0.75rem; }
  .lang-switch { position: absolute; top: 10px; right: 12px; }   /* arriba a la derecha, junto a la marca */
  .header-brand { padding-right: 96px; }
  .wrap { padding: 10px 12px 40px; }
  .panel-card { padding: 16px; }
  th, td { padding: 8px 10px; }
  .bodymap-svg { max-height: 220px; }
}

/* ==========================================================================
   ESCENARIO DE CÁMARA (index.html y seguimiento.html): video, esqueleto, avisos, contador y botonera
   ========================================================================== */
.stage-wrapper {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 24px;
}

/* Viewport de Video / Esqueleto */
.viewport {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--stage);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.viewport > video, .viewport > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.viewport.mirror > video, .viewport.mirror > canvas {
  transform: scaleX(-1);
}

/* Malla Táctica de Coordenadas Holográficas */
.hud-grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, rgba(0, 242, 254, 0.04) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(to bottom, rgba(0, 242, 254, 0.04) 1px, transparent 1px) 0 0 / 48px 48px;
  z-index: 2;
}
.hud-corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--tape);
  pointer-events: none;
  z-index: 3;
}
.hud-corner.tl { top: 12px; left: 12px; border-right: none; border-bottom: none; }
.hud-corner.tr { top: 12px; right: 12px; border-left: none; border-bottom: none; }
.hud-corner.bl { bottom: 12px; left: 12px; border-right: none; border-top: none; }
.hud-corner.br { bottom: 12px; right: 12px; border-left: none; border-top: none; }

/* Placeholder */
.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
  padding: 32px;
  color: var(--stage-ink);
  z-index: 5;
  background: radial-gradient(circle, rgba(11, 25, 51, 0.8) 0%, rgba(2, 6, 23, 0.95) 100%);
}
.placeholder strong {
  font: 800 1.8rem/1.2 var(--font-display);
  letter-spacing: -0.01em;
  color: #FFFFFF;
}
.placeholder span {
  font-size: 0.95rem;
  color: var(--muted);
  max-width: 52ch;
}

/* Chip Superior de Estado */
.hud-status-badge {
  position: absolute;
  top: 18px;
  left: 20px;
  background: rgba(11, 19, 37, 0.85);
  border: 1px solid var(--tape);
  box-shadow: var(--accent-glow);
  padding: 6px 14px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--tape);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Alerta Biomecánica <250ms */
.alert {
  position: absolute;
  left: 18px;
  right: 18px;
  top: 18px;
  padding: 16px 24px;
  border-radius: var(--radius-sm);
  font: 900 clamp(1.3rem, 3.2vw, 2.1rem)/1.15 var(--font-display);
  letter-spacing: -0.02em;
  color: #FFFFFF;
  background: var(--alert);
  box-shadow: var(--alert-glow);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  z-index: 30;
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.alert small {
  font: 700 0.85rem/1 var(--font-mono);
  opacity: 0.95;
  letter-spacing: 0.04em;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 10px;
  border-radius: 4px;
}
.alert.sev1 { background: var(--hold); color: #030712; box-shadow: 0 0 25px rgba(255, 184, 0, 0.5); }
.alert.info { background: #1E3A8A; box-shadow: 0 0 25px rgba(30, 58, 138, 0.5); }
.alert.stop { background: #030712; border: 2px solid var(--alert); box-shadow: var(--alert-glow); }

/* Indicador de Fase (Calibración / Ejercicio) */
.phase-indicator {
  position: absolute;
  right: 20px;
  bottom: 20px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: rgba(3, 7, 18, 0.88);
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(14px);
  z-index: 10;
  max-width: min(22rem, 60%);
  text-align: right;
}
.phase-label {
  font: 800 clamp(0.8rem, 1.5vw, 0.95rem)/1.2 var(--font-display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tape);
}
.phase-sub {
  font: 500 0.82rem var(--font-body);
  color: var(--muted);
  margin-top: 3px;
}

/* HUD Gigante a 2-3 Metros */
.hud {
  position: absolute;
  left: 20px;
  bottom: 20px;
  padding: 16px 24px;
  border-radius: var(--radius);
  background: rgba(3, 7, 18, 0.88);
  border: 1px solid var(--surface-border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(14px);
  color: #FFFFFF;
  display: grid;
  gap: 6px;
  min-width: min(18rem, 65%);
  z-index: 10;
}
.hud-phase {
  font: 800 clamp(0.85rem, 1.8vw, 1.05rem)/1.2 var(--font-display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tape);
}
.hud-count {
  font: 900 clamp(3.2rem, 8vw, 5.2rem)/1 var(--font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  color: #FFFFFF;
  text-shadow: var(--accent-glow);
}
.hud-count .hud-total {
  font-size: 0.48em;
  opacity: 0.65;
  margin-left: 6px;
  font-weight: 600;
  color: var(--muted);
}
.hud-bar {
  display: flex;
  gap: 4px;
  height: 10px;
}
.hud-bar span {
  flex: 1;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.18);
  transition: all 0.3s ease;
}
.hud-bar span.cal { background: rgba(0, 242, 254, 0.45); }
.hud-bar span.done { background: var(--tape); box-shadow: var(--accent-glow); }
.hud-bar span.done.flag { background: var(--alert); box-shadow: var(--alert-glow); }

/* Cartel Grande Central */
.announce {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(90%, 42rem);
  text-align: center;
  padding: 24px 32px;
  border-radius: var(--radius);
  background: rgba(3, 7, 18, 0.92);
  border: 1px solid var(--tape);
  box-shadow: var(--accent-glow);
  color: #FFFFFF;
  backdrop-filter: blur(16px);
  font: 900 clamp(1.8rem, 4.5vw, 3.2rem)/1.15 var(--font-display);
  letter-spacing: -0.02em;
  z-index: 35;
}
.announce.done { background: rgba(0, 255, 136, 0.92); color: #030712; }

.pilot-dock {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
  padding: 12px 18px;
  background: rgba(11, 19, 37, 0.75);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
}
.dock-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* Pantalla completa: escenario entero (video, lecturas y botonera con "Dolor: detener") */
.stage-wrapper:fullscreen {
  margin: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  padding: 12px;
  overflow-y: auto;
  background: var(--bg-gradient);
}
.stage-wrapper:fullscreen .viewport { flex: 1 1 auto; aspect-ratio: auto; min-height: 0; max-height: none; }

@media (max-height: 560px) and (orientation: landscape) {
  .viewport { max-height: 78svh; }                        /* celular girado: que entren video y botones */
}
@media (max-width: 640px) {
  .stage-wrapper { padding: 8px; border-radius: var(--radius); margin-bottom: 16px; }
  /* el video toma la forma de la cámara (vertical en celular) sin pasar del 70% de la altura */
  .viewport { aspect-ratio: var(--src-ratio, 3 / 4); max-height: 70svh; border-radius: var(--radius-sm); }
  .hud-status-badge, .hud-grid-overlay { display: none; }
  .hud-corner { width: 10px; height: 10px; }
  .hud-corner.tl, .hud-corner.tr { top: 6px; }
  .hud-corner.bl, .hud-corner.br { bottom: 6px; }
  .hud-corner.tl, .hud-corner.bl { left: 6px; }
  .hud-corner.tr, .hud-corner.br { right: 6px; }
  .placeholder { padding: 16px; }
  .placeholder strong { font-size: 1.25rem; }
  .placeholder span { font-size: 0.85rem; }
  .phase-indicator { left: 8px; right: 8px; top: 8px; bottom: auto; max-width: none; text-align: left; padding: 6px 10px; }
  .phase-label { font-size: 0.78rem; }
  .phase-sub { font-size: 0.72rem; margin-top: 1px; }
  .hud { left: 8px; bottom: 8px; padding: 6px 10px; min-width: 0; gap: 3px; }
  .hud-phase { display: none; }                           /* la fase ya está arriba, en el indicador */
  .hud-count { font-size: 1.9rem; }
  .hud-bar { height: 5px; width: 8rem; gap: 3px; }
  .alert { left: 8px; right: 8px; top: 8px; padding: 10px 12px; font-size: 1.15rem; flex-wrap: wrap; gap: 6px; }
  .alert small { font-size: 0.72rem; }
  .announce { width: 92%; padding: 14px 16px; font-size: 1.35rem; }
  /* botonera: botones grandes para el dedo; cámara y "Dolor" a todo el ancho */
  .pilot-dock { padding: 10px; gap: 10px; margin-top: 10px; }
  .dock-group { display: grid; grid-template-columns: 1fr 1fr; width: 100%; gap: 8px; }
  .dock-group .btn { justify-content: center; min-height: 44px; padding: 10px 12px; font-size: 0.85rem; }
  .dock-group .btn.primary, .dock-group .btn.danger, .dock-group .status-line { grid-column: 1 / -1; }
  .status-line { font-size: 0.75rem; }
}

/* ==========================================================================
   FIGURA DE REFERENCIA DE UN EJERCICIO (.fig · guide-figure.js · design system §4)
   Marco con malla táctica y esquinas del HUD, lienzo con la figura, etiqueta de fase, vista y texto.
   Variantes: --card (galería y planes), --large (guías), --pip (sobre el video del seguimiento).
   ========================================================================== */
.fig { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 8px; min-width: 0; }
.fig-stage {
  grid-column: 1 / -1;
  position: relative;
  aspect-ratio: 3 / 2;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--surface-border);
  background:
    linear-gradient(to right, var(--fig-grid) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(to bottom, var(--fig-grid) 1px, transparent 1px) 0 0 / 24px 24px,
    radial-gradient(circle at 50% 35%, rgba(0, 242, 254, 0.06), transparent 65%),
    var(--fig-bg);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.65);
}
.fig-stage::before, .fig-stage::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid var(--tape);
  opacity: 0.75;
  pointer-events: none;
}
.fig-stage::before { top: 6px; left: 6px; border-right: none; border-bottom: none; }
.fig-stage::after { bottom: 6px; right: 6px; border-left: none; border-top: none; }
.fig-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.fig-chip {
  position: absolute;
  top: 10px;
  left: 24px;
  max-width: 54%;
  padding: 4px 8px;
  border-radius: 4px;
  font: 700 0.62rem/1.2 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink-secondary);
  background: rgba(3, 7, 18, 0.85);
  border: 1px solid var(--muted);
  transition: color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.fig[data-phase="go"] .fig-chip { color: var(--fig-active); border-color: var(--fig-active); box-shadow: 0 0 12px var(--tape-soft); }
.fig[data-phase="hold"] .fig-chip { color: var(--fig-hold); border-color: var(--fig-hold); box-shadow: 0 0 14px var(--hold-soft); }
.fig[data-phase="top"] .fig-chip { color: var(--fig-done); border-color: var(--fig-done); box-shadow: 0 0 14px var(--safe-soft); }
.fig[data-phase="back"] .fig-chip { color: var(--tape-hover); border-color: var(--tape-hover); }
.fig-view {
  position: absolute;
  top: 13px;
  right: 24px;
  max-width: 40%;
  font: 600 0.56rem var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}
/* Animar o pausar esta figura, bajo el dibujo y junto al texto (TD-59). En las tarjetas también anima el mouse encima
   o un toque en el dibujo, y la que se anima se resalta con el borde de --tape. */
.fig-play {
  min-height: 32px;
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 4px;
  font: 700 0.62rem/1 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-secondary);
  background: rgba(3, 7, 18, 0.85);
  border: 1px solid var(--muted);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.fig-play:hover { color: var(--tape-hover); border-color: var(--tape-hover); }
.fig-play:focus-visible { outline: 2px solid var(--tape); outline-offset: 2px; }
.fig[data-motion="on"] .fig-play { color: var(--tape); border-color: var(--tape); }
.fig[data-play="hover"] .fig-stage { cursor: pointer; transition: border-color 0.2s ease, box-shadow 0.2s ease; }
.fig[data-play="hover"][data-motion="on"] .fig-stage {
  border-color: var(--tape);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.65), 0 0 14px var(--tape-soft);
}
.fig-cap { grid-column: 2; font: 600 0.85rem/1.35 var(--font-body); color: var(--ink); min-height: 2.7em; }
.fig--large .fig-chip { font-size: 0.72rem; top: 12px; }
.fig--large .fig-play { font-size: 0.7rem; min-height: 36px; }
.fig--large .fig-view { font-size: 0.64rem; top: 15px; }
.fig--large .fig-cap { font-size: 0.95rem; }
.fig--pip { gap: 4px; }
.fig--pip .fig-stage { border-radius: 6px; }
.fig--pip .fig-stage::before, .fig--pip .fig-stage::after { width: 8px; height: 8px; top: 4px; left: 4px; }
.fig--pip .fig-stage::after { top: auto; left: auto; bottom: 4px; right: 4px; }
.fig--pip .fig-chip { top: 6px; left: 16px; font-size: 0.55rem; padding: 3px 6px; }
.fig--pip .fig-view { display: none; }
.fig--pip { grid-template-columns: minmax(0, 1fr); }
.fig--pip .fig-play { display: none; }                  /* sobre el video: se anima o pausa desde la figura grande */
.fig--pip .fig-cap { grid-column: 1; }
.fig--pip .fig-cap { font-size: 0.76rem; min-height: 0; color: #FFFFFF; }
@media (max-width: 640px) {
  .fig-view { display: none; }
  .fig-cap { font-size: 0.8rem; }
}
@media (pointer: coarse) {
  .fig-play { min-height: 40px; padding: 8px 12px; }
}

/* ==========================================================================
   PREPARAR LA CÁMARA (camera-setup.js · ADR-015): elegir la posición y chequeo en vivo sobre el video
   ========================================================================== */
.cam-setup { margin-bottom: 16px; display: grid; gap: 8px; }
.cam-setup h2 { font: 800 1.05rem var(--font-display); color: #FFFFFF; }
.cam-hint { font-size: 0.78rem; }
.cam-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.cam-option {
  display: grid; gap: 6px; align-content: start; text-align: left; min-width: 0;
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--surface-border); border-radius: var(--radius-sm);
  padding: 10px 12px; cursor: pointer; font: 500 0.82rem/1.3 var(--font-body);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.cam-option:hover { border-color: var(--surface-border-bright); }
.cam-option[aria-checked="true"] { border-color: var(--tape); box-shadow: var(--accent-glow); }
.cam-option strong { font: 800 0.92rem var(--font-display); color: #FFFFFF; }
.cam-option em { font: 700 0.62rem var(--font-mono); font-style: normal; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--safe); border: 1px solid var(--safe); border-radius: 4px; padding: 1px 5px; margin-left: 4px; }
.cam-option svg { width: 100%; max-height: 72px; }
.cam-person { fill: var(--muscle); fill-opacity: var(--muscle-fill); stroke: var(--muscle); stroke-opacity: var(--muscle-edge); }
.cam-nose { fill: var(--muted); }
.cam-body { fill: var(--tape); }
.cam-sight { stroke: var(--tape); stroke-opacity: 0.6; stroke-width: 1.2; stroke-dasharray: 3 3; }
.cam-q { display: flex; flex-wrap: wrap; gap: 4px; }
.cam-q span { font: 600 0.64rem/1.4 var(--font-mono); padding: 1px 6px; border-radius: 4px; border: 1px solid currentColor; }
.cam-q .good { color: var(--safe); }
.cam-q .fair { color: var(--hold); }
.cam-q .poor { color: var(--alert-ink); }
.cam-check {
  position: absolute; left: 18px; bottom: 18px; z-index: 33; width: min(26rem, 62%);
  display: grid; gap: 6px; padding: 12px 14px; border-radius: var(--radius);
  background: rgba(3, 7, 18, 0.92); border: 1px solid var(--tape); box-shadow: var(--accent-glow); color: #FFFFFF;
  font: 500 0.85rem/1.35 var(--font-body);
}
.cam-check strong { font: 800 0.95rem var(--font-display); color: var(--tape); text-transform: uppercase; letter-spacing: 0.04em; }
.cam-check ul { list-style: none; display: grid; gap: 3px; }
.cam-check li::before { display: inline-block; width: 1.3em; font-weight: 800; }
.cam-check li.ok::before { content: '✓'; color: var(--safe); }
.cam-check li.bad::before { content: '✗'; color: var(--alert-ink); }
.cam-check li.warn::before { content: '!'; color: var(--hold); }
.cam-check small { color: var(--muted); }
.cam-check .meter > span { background: var(--safe); transition: width 0.15s linear; }
.cam-check .btn { justify-self: start; }
@media (max-width: 900px) { .cam-options { grid-template-columns: minmax(0, 1fr); } .cam-option svg { max-height: 56px; } }
@media (max-width: 640px) {
  .cam-check { left: 8px; right: 8px; bottom: 8px; width: auto; padding: 8px 10px; font-size: 0.76rem; }
}

/* ==========================================================================
   SUGERENCIAS POR ROL Y PERFIL DEL PACIENTE (suggestions.js · ADR-017 · design system §6)
   ========================================================================== */
.suggest { display: grid; gap: 10px; min-width: 0; }
.suggest-title { font: 800 0.85rem/1.2 var(--font-display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--tape); }
.suggest-note { font-size: 0.8rem; color: var(--muted); }
.suggest-list { list-style: none; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr)); }
.suggest-item {
  display: flex; flex-direction: column; gap: 6px; min-width: 0;   /* el botón queda al fondo: alineado en toda la fila */
  background: var(--surface-2); border: 1px solid var(--surface-border); border-left: 4px solid var(--tape);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.suggest-item[data-kind="safety"], .suggest-item[data-kind="dose"] { border-left-color: var(--hold); }
.suggest-item[data-priority="1"] { border-left-color: var(--alert); }
.suggest-kind { font: 700 0.68rem/1.3 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.suggest-item[data-priority="1"] .suggest-kind { color: var(--alert-ink); }
.suggest-head { font: 800 0.95rem/1.3 var(--font-display); color: #FFFFFF; overflow-wrap: anywhere; }
.suggest-text { font-size: 0.88rem; line-height: 1.45; color: var(--ink); overflow-wrap: anywhere; }
.suggest-why { font-size: 0.8rem; line-height: 1.4; color: var(--muted); overflow-wrap: anywhere; }
.suggest-item .btn { align-self: flex-start; margin-top: auto; }
.ai-summary { border: 1px dashed var(--surface-border-bright); border-radius: var(--radius-sm); padding: 12px 14px; display: grid; gap: 8px; }
.ai-summary p { font-size: 0.9rem; line-height: 1.5; }

.profile-form { display: grid; gap: 14px; }
.profile-group { border: 1px solid var(--surface-border); border-radius: var(--radius-sm); padding: 10px 14px 12px; display: grid; gap: 4px; min-width: 0; }
.profile-group legend { font: 700 0.85rem var(--font-display); color: var(--tape); padding: 0 6px; }
.profile-group .check { align-items: flex-start; min-height: 32px; margin-top: 2px; }
.profile-group .check input { margin-top: 3px; flex: none; }
.profile-form textarea { width: 100%; resize: vertical; min-height: 3.2em; font: inherit; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--surface-border); border-radius: var(--radius-sm); padding: 8px 10px; }
.profile-form .btn { justify-self: start; }
.profile-form .hint { font-size: 0.75rem; color: var(--muted); }
.profile-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.fit-note { font-size: 0.8rem; line-height: 1.4; color: var(--hold); overflow-wrap: anywhere; }
.plan-ex.suggested { outline: 2px solid var(--hold); outline-offset: 4px; border-radius: var(--radius-sm); }

/* ==========================================================================
   ACCESIBILIDAD (WCAG 2.2 AA · ADR-017)
   ========================================================================== */
/* Texto largo (nombres de ejercicios, notas) nunca rompe su contenedor */
p, li, h1, h2, h3, dd, dt, label, legend, summary { overflow-wrap: break-word; }
.kpi .s, .kpi .k, .facts span, .muted, .status-line, .ex-card p { overflow-wrap: anywhere; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Saltar al contenido: oculto hasta que se llega con Tab (WCAG 2.4.1) */
.skip-link {
  position: absolute; left: 12px; top: -80px; z-index: 2000;
  background: var(--tape); color: #030712; font: 800 0.95rem var(--font-display);
  padding: 10px 16px; border-radius: var(--radius-sm); text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* Foco del teclado siempre visible y con contraste sobre cualquier fondo (WCAG 2.4.7 y 2.4.11) */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(0, 242, 254, 0.55);
}
main:focus, [tabindex="-1"]:focus { outline: none; }

/* Movimiento reducido: se quitan los adornos (pulsos, brillos, desplazamientos). Las figuras de los ejercicios
   siguen animadas dentro del ejercicio porque enseñan cómo se hace, y tienen su botón de pausa (WCAG 2.2.2). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .header-badge .pulse, .live-dot.on { animation: none !important; }
  .btn:hover { transform: none; }
}

/* Alto contraste de Windows: bordes visibles en controles y tarjetas */
@media (forced-colors: active) {
  .btn, .chip-btn, .ex-card, .panel-card, .kpi, .suggest-item, .fig-play, .tag { border: 1px solid CanvasText; }
  .top-nav a[aria-current="page"] { outline: 2px solid Highlight; }
}
details.panel-card > summary, .panel-card details > summary { cursor: pointer; font: 800 0.85rem/1.3 var(--font-display); letter-spacing: 0.06em; color: var(--tape); min-height: 32px; display: list-item; }

/* ==========================================================================
   INICIO DE SESIÓN Y ADMINISTRACIÓN (login.html · admin.html · ADR-019 · design system §8)
   ========================================================================== */
.auth-wrap { display: grid; justify-items: center; gap: 18px; }
.auth-card { width: min(100%, 46rem); display: grid; gap: 12px; }
.auth-google { min-height: 44px; display: flex; align-items: center; }
.auth-sep { border: 0; border-top: 1px solid var(--surface-border); margin: 6px 0; }
.auth-roles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); gap: 14px; }
.auth-role { display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm); padding: 14px 16px; min-width: 0; }
.auth-role h3 { font: 800 1rem var(--font-display); color: #FFFFFF; }
.auth-role .btn { margin-top: auto; align-self: flex-start; }
.code-input { text-transform: uppercase; letter-spacing: 0.2em; font-family: var(--font-mono); }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr)); gap: 18px; align-items: start; }
.check-list { list-style: none; display: grid; gap: 8px; }
.check-list li { padding-left: 1.6em; position: relative; font-size: 0.9rem; overflow-wrap: anywhere; }
.check-list li::before { position: absolute; left: 0; font-weight: 800; }
.check-list li.ok::before { content: '✓'; color: var(--safe); }
.check-list li.bad::before { content: '✗'; color: var(--alert-ink); }
.admin-grid select { background: var(--surface-2); color: var(--ink); border: 1px solid var(--surface-border); border-radius: 6px; padding: 6px 8px; min-height: 36px; }
td select { background: var(--surface-2); color: var(--ink); border: 1px solid var(--surface-border); border-radius: 6px; padding: 6px 8px; min-height: 36px; font: inherit; }

/* ==========================================================================
   TRIAJE DEL NIVEL 1 (triage.js · ADR-023)
   ========================================================================== */
.triage { display: grid; gap: 14px; max-width: 46rem; margin: 0 auto 18px; }
.triage .page-title:focus { outline: none; }
.triage .page-title:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.triage-list { display: grid; gap: 8px; padding-left: 1.2em; color: var(--ink-secondary); font-size: 0.92rem; line-height: 1.45; }
.triage-sub { font: 700 0.95rem var(--font-display); color: var(--ink); margin-top: 6px; }
.triage-q legend { color: var(--ink); font-size: 0.9rem; font-weight: 600; line-height: 1.4; }
.triage-q.missing { border-color: var(--alert); }
.triage-yn { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.triage-yn .check { min-height: 40px; min-width: 4.5rem; }
.triage-yn input[type="radio"] { accent-color: var(--tape); width: 18px; height: 18px; }
.triage .check input[type="checkbox"] { width: 20px; height: 20px; flex: none; }
.triage .btn { justify-self: start; min-height: 44px; }
.triage-status { color: var(--alert-ink); font-size: 0.9rem; font-weight: 600; min-height: 1.2em; }
.triage-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.triage-alert { border-left: 4px solid var(--alert); background: var(--alert-soft); border-radius: 4px; padding: 12px 14px; }
.triage-alert p { color: var(--ink); font-size: 0.95rem; line-height: 1.5; }
.triage a { color: var(--tape); }
.triage-tone { margin-bottom: 16px; }

/* ==========================================================================
   PLAN DEL DÍA Y DOLOR AL TERMINAR (care-plan.js, pain-scale.js · ADR-025)
   ========================================================================== */
.today-head { display: grid; gap: 4px; }
.today-status { font: 700 0.8rem var(--font-display); color: var(--ink-secondary); letter-spacing: 0.02em; }
.today-status.done { color: var(--safe); }
.rest-plan > summary { font: 700 1rem var(--font-display); color: var(--ink); cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.rest-plan[open] > summary { margin-bottom: 14px; }
.eva-card { border-left: 4px solid var(--tape); }
div.eva-card { padding-left: 14px; margin: 12px 0; }
.eva-form, .eva-group { display: grid; gap: 12px; border: 0; padding: 0; margin: 0; min-width: 0; }
.eva-group legend { font: 700 1.05rem var(--font-display); color: var(--ink); margin-bottom: 4px; }
.eva-group legend:focus { outline: none; }
.eva-group legend:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.eva-scale { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.9rem, 1fr)); gap: 6px; }
.eva-option {
  position: relative; display: grid; place-items: center; min-height: 48px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--surface-border); border-radius: 8px;
}
.eva-option input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.eva-num { font: 800 1.1rem var(--font-mono); color: var(--ink); font-variant-numeric: tabular-nums; }
.eva-option:has(input:checked) { background: var(--tape); border-color: var(--tape); box-shadow: var(--accent-glow); }
.eva-option:has(input:checked) .eva-num { color: #030712; }
.eva-option:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.eva-ends { display: flex; justify-content: space-between; gap: 10px; color: var(--ink-secondary); font-size: 0.82rem; }
.eva-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.eva-actions .btn { min-height: 44px; }
.eva-high { color: var(--alert-ink); font-weight: 700; }
@media (forced-colors: active) {
  .eva-option { border: 1px solid CanvasText; }
  .eva-option:has(input:checked) { border: 3px solid Highlight; }
}

/* ==========================================================================
   PRÁCTICA DEL SEGUIMIENTO: TUTORIAL Y RUTINA SIN CÁMARA (practice.js · TD-109, TD-110)
   ========================================================================== */
.practice {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 18px; align-items: center;
  background: var(--stage); border: 1px solid var(--surface-border); border-radius: var(--radius); padding: 18px;
}
.practice-fig { min-width: 0; }
.practice-panel { display: grid; gap: 12px; min-width: 0; }
.practice-title { font: 900 clamp(1.2rem, 2.6vw, 1.6rem)/1.2 var(--font-display); color: var(--stage-ink); }
.practice-title:focus { outline: none; }
.practice-title:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.practice-text { color: var(--ink); font-size: 1rem; line-height: 1.5; }
.practice-note { border-left: 3px solid var(--hold); background: var(--hold-soft); color: var(--ink-secondary);
  padding: 8px 12px; border-radius: 4px; font-size: 0.88rem; }
.practice-count { font: 800 clamp(1.1rem, 3vw, 1.6rem)/1.3 var(--font-mono); color: var(--tape); }
.practice-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.practice-actions .btn { min-height: 44px; }
.practice-actions .practice-done { min-height: 64px; min-width: 9rem; font-size: 1.15rem; }
:fullscreen .practice { min-height: 70vh; }
@media (max-width: 760px) {
  .practice { grid-template-columns: minmax(0, 1fr); padding: 14px; }
  .practice-actions .btn { flex: 1 1 100%; }
}

/* ==========================================================================
   INVITADO, MURO DE AUTENTICACIÓN Y DEMO PÚBLICA (auth-wall.js, demo-telemetry.js · ADR-028)
   ========================================================================== */
.guest-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 16px; }
.guest-bar span { flex: 1 1 22rem; color: var(--ink); }
.guest-bar .btn { min-height: 40px; }
.wall-dialog { max-width: min(30rem, calc(100vw - 32px)); border: 1px solid var(--surface-border-bright); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); padding: 20px; }
.wall-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.wall-dialog h2 { font: 800 1.15rem var(--font-display); margin-bottom: 8px; }
.wall-dialog p { color: var(--ink-secondary); line-height: 1.5; margin-bottom: 14px; }
.wall-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.wall-actions .btn { min-height: 44px; }
.guest-entry { display: grid; gap: 10px; }
.guest-entry .btn { justify-self: start; min-height: 44px; }
.demo-share { margin-top: 10px; display: grid; gap: 4px; }

/* ==========================================================================
   AUDITORÍA UI/UX 2026-10-18 (ADR-033): cabecera estable, tarjetas que caben, cámara sin deformar y aviso de entorno
   ========================================================================== */
/* Cabecera en grilla: marca | menú | idioma. La marca se encoge (su texto se corta con "…") y el menú queda siempre en el
   mismo lugar, sin importar el largo del subtítulo de cada página. Ningún estado (hover, foco, actual) cambia medidas. */
header.top-header { border-bottom-width: 2px; }       /* mismo alto con y sin el color de entorno */
html { scrollbar-gutter: stable; }                     /* la barra de scroll no corre la página entre una vista y otra */
header.top-header { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; column-gap: 16px; row-gap: 8px; }
.header-brand, .brand-info { min-width: 0; }
.brand-info h1, .brand-info p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-nav { flex-wrap: nowrap; }
.top-nav a { white-space: nowrap; display: inline-flex; align-items: center; min-height: 36px;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease; }
.top-header .header-badge { display: none; }          /* el aviso de entorno (env-banner.js) dice en qué entorno estás */
.lang-switch { justify-self: end; }
@media (max-width: 1024px) {                            /* tablet: el menú baja a su propia fila, siempre igual */
  header.top-header { grid-template-columns: minmax(0, 1fr) auto; }
  .top-nav { grid-column: 1 / -1; grid-row: 2; overflow-x: auto; scrollbar-width: none; }
  .top-nav::-webkit-scrollbar { display: none; }
}
@media (max-width: 640px) {                             /* celular: cabecera de ~100 px en vez de 160–230 px */
  header.top-header { padding: 8px 12px; row-gap: 6px; }
  .header-brand { padding-right: 0; }
  .brand-info p { display: none; }
  .lang-switch { position: static; }
  .top-nav { width: auto; scroll-snap-type: x proximity; padding-bottom: 2px; }
  .top-nav a { scroll-snap-align: start; padding: 8px 12px; font-size: 0.78rem; }
}

/* Tarjetas de ejercicio en celular: una columna sin subgrid (no hay otra tarjeta con la que alinear), y la figura y el
   mapa muscular lado a lado. Pasan de ~1000 px a menos de una pantalla. */
@media (max-width: 640px) {
  .card-grid > .ex-card, .card-grid > .ex-card:not(.patient-card) { grid-row: auto; grid-template-rows: none; }
  .ex-card { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 10px; row-gap: 8px; padding: 14px; }
  .ex-card > * { grid-column: 1 / -1; }
  .ex-card > .ex-fig { grid-column: 1; align-self: center; }
  .ex-card > .ex-map { grid-column: 2; align-self: center; }
  .ex-card > .ex-map .bodymap-svg { max-height: 190px; }
  .ex-card > .ex-map .bodymap-note, .ex-card > .ex-map .bodymap-view { font-size: 0.7rem; }
  .ex-card .facts { font-size: 0.8rem; }
  /* En media columna, la figura apila escena, botón y leyenda a todo el ancho (antes la leyenda iba en 65 px). */
  .ex-card > .ex-fig .fig { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .ex-card > .ex-fig .fig-cap { grid-column: 1; min-height: 0; font-size: 0.74rem;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .ex-card > .ex-fig .fig-play { justify-self: start; }
  .ex-card .badge-row { gap: 6px; }
  .ex-card .badge-row .tag { font-size: 0.66rem; padding: 2px 8px; }
  .ex-card .dose { font-size: 0.74rem; }
  .ex-card > .row-between { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  .ex-card > .row-between .btn { padding: 8px 10px; font-size: 0.8rem; min-height: 44px; }
  .ex-card > .row-between > :only-child { grid-column: 1 / -1; }
}

/* Cámara: el cuadro toma la forma real de la cámara también en escritorio (4:3, 16:9 o vertical), centrado y sin pasar
   del 75 % de la altura. El video y el esqueleto usan el mismo `contain`, así que no se deforman ni se desalinean. */
.viewport.mirror { aspect-ratio: var(--src-ratio, 16 / 9); max-height: 75svh; margin-inline: auto; }
.viewport > video { background: var(--stage); }

/* Aviso de entorno (env-banner.js): Demo pública en ámbar, Plataforma clínica en verde. La línea de la cabecera repite el
   color para que se note en cualquier página. */
:root[data-env="demo"] header.top-header { border-bottom: 2px solid var(--hold); }
:root[data-env="clinical"] header.top-header { border-bottom: 2px solid var(--safe); }
.env-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 16px; padding: 10px 14px;
  border-radius: var(--radius-sm); border-left: 4px solid currentColor; font-size: 0.9rem; line-height: 1.45; }
.env-banner .env-label { font: 800 0.72rem var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.env-banner .env-text { flex: 1 1 18rem; color: var(--ink); }
.env-banner .btn { min-height: 40px; }
.env-banner.env-demo { color: var(--hold); background: var(--hold-soft); }
.env-banner.env-clinical { color: var(--safe); background: var(--safe-soft); }
:root[data-env="demo"] .guest-bar { border-left-color: var(--hold); background: var(--hold-soft); }
