:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #646d78;
  --border: #dde1e6;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #16a34a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --text: #e7eaee;
    --muted: #9aa3ad;
    --border: #2c323a;
    --accent: #4f8cff;
    --ok: #22c55e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
header, footer { padding: 16px; max-width: 1200px; margin: 0 auto; }
h1 { margin: 0; font-size: 1.6rem; }
h2 { margin: 0; font-size: 1.1rem; }
.sub { margin: 4px 0 0; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  padding: 0 16px;
  max-width: 1200px;
  margin: 0 auto;
}
@media (max-width: 860px) {
  main { grid-template-columns: minmax(0, 1fr); }
}

.video-wrap {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
}
video, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* efecto espejo */
}
.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #fff;
  text-align: center;
  padding: 16px;
}
.placeholder .muted { color: #c8ced6; }
.caption {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 8px 18px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: clamp(1.3rem, 4vw, 2.2rem);
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.caption.show { opacity: 1; }
.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.live {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
}
.meter {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
#holdBar { height: 100%; width: 0; background: var(--ok); transition: width 0.08s linear; }

.transcript-box, .panel details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.transcript { min-height: 3em; font-size: 1.2rem; margin: 8px 0 0; word-wrap: break-word; }

.panel { display: flex; flex-direction: column; gap: 12px; }
.panel summary { font-weight: 700; cursor: pointer; margin-bottom: 8px; }
.panel label { display: block; margin: 8px 0; }
.panel label.check { display: flex; gap: 8px; align-items: center; }
.panel select, .panel input[type="range"] { width: 100%; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
input[type="text"], input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
button, .file-btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:disabled { opacity: 0.5; cursor: not-allowed; }


.sign-list { list-style: none; padding: 0; margin: 10px 0; }
.sign-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.sign-list button { padding: 2px 10px; }

/* ---------- Pestañas ---------- */
.tabs {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  font-weight: 600;
  padding: 10px;
}
.tab.active { background: var(--accent); color: var(--accent-text); }

/* ---------- Voz → Señas ---------- */
.sign-stage {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
#signCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.sign-big {
  position: absolute;
  inset: 0 0 25% 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(5rem, 22vw, 11rem);
  font-weight: 800;
  line-height: 1;
}
.sign-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  text-align: center;
  padding: 0 12px;
}
.sign-word { font-size: clamp(1.3rem, 5vw, 2rem); font-weight: 700; }
button.big { font-size: 1.1rem; padding: 12px 22px; }
button.listening { background: #dc2626; border-color: #dc2626; }
.interim { min-height: 1.5em; font-style: italic; margin: 0 0 12px; }
#typeForm { margin-bottom: 12px; }

/* ---------- Móvil ---------- */
@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  .sub { font-size: 0.9rem; }
  main { padding: 0 12px; gap: 12px; }
  header, footer { padding: 12px; }
  button, .file-btn { padding: 10px 14px; } /* objetivos táctiles más grandes */
  .tab { font-size: 0.85rem; padding: 10px 4px; }
  .live { flex-wrap: wrap; }
}
.interim:empty { display: none; }

/* ---------- Deletreo ---------- */
.spell-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.spelling { flex: 1; font-size: 1.6rem; font-weight: 800; letter-spacing: 0.12em; min-width: 4ch; }
.spelling::after { content: "▏"; color: var(--accent); animation: blink 1s steps(1) infinite; }
.spell-row.empty .spelling::after { opacity: 0.4; }
@keyframes blink { 50% { opacity: 0; } }

.hint {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 34%;
  max-width: 200px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: #1b1f24;
  border-radius: 10px;
  text-align: center;
  font-weight: 700;
}
.hint canvas { width: 100%; height: auto; display: block; }

/* ---------- Abecedario ---------- */
.alpha-detail {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
#alphaCanvas { width: min(45%, 240px); height: auto; flex-shrink: 0; }
.alpha-key { font-size: 3rem; font-weight: 800; line-height: 1; }
.alpha-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
}
.alpha-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px;
  font-weight: 700;
}
.alpha-card canvas { width: 100%; height: auto; }
.alpha-card.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
@media (max-width: 600px) {
  .alpha-detail { flex-direction: column; text-align: center; }
  #alphaCanvas { width: 60%; }
}

/* ---------- Conversación ---------- */
.transcript-box { margin-bottom: 12px; }
.they-box { border-color: var(--accent); }
.they-say { font-size: clamp(1.4rem, 5.5vw, 2rem); font-weight: 700; line-height: 1.3; margin: 10px 0 4px; }
.they-say.muted { font-size: 1rem; font-weight: 400; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0; scrollbar-width: thin; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip.done { border-color: var(--ok); }
.phrase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin: 4px 0 10px;
}
.phrase {
  position: relative;
  min-height: 52px;
  font-weight: 600;
  text-align: left;
  line-height: 1.25;
}
.phrase .del {
  position: absolute;
  top: 2px;
  right: 6px;
  font-weight: 400;
  color: var(--muted);
}
.say-form { margin-top: 6px; }
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
  margin-top: 8px;
}
.msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  line-height: 1.35;
}
.msg small { display: block; font-size: 0.75rem; opacity: 0.75; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg.them { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
a { color: var(--accent); }
.search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
  margin-top: 6px;
}
.word-grid button.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
