:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --ink: #1f2a44;
  --muted: #5c6478;
  --accent: #ff6b1a;
  --accent-dark: #c94f0c;
  --ok: #1e8a4c;
  --ok-bg: #e2f5ea;
  --ko: #c62828;
  --ko-bg: #fde6e6;
  --line: #ddd6c8;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(31, 42, 68, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Cabecera ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: var(--ink);
  color: #fff;
}
.logo { margin: 0; font-size: 1rem; }
.topbar-actions { display: flex; gap: 8px; }

/* ---------- Logo (ficha) ---------- */
:root {
  --rsb-navy: #1f2a44;
  --rsb-brass: #e3a02a;
  --rsb-p1: #2f6f4f;
  --rsb-p2: #9b3b2f;
  --rsb-p3: #2d5b8e;
  --rsb-p4: #7a4a8c;
  --rsb-p5: #8a6b1f;
  --rsb-p6: #2f6f6f;
  /* por defecto: ficha navy sobre fondo claro */
  --rsb-mark: var(--rsb-navy);
  --rsb-mark-ink: #ffffff;
}
/* sobre la cabecera navy: ficha latón con la R en navy */
.rsb-on-navy { --rsb-mark: var(--rsb-brass); --rsb-mark-ink: var(--rsb-navy); }
/* sobre un bloque latón */
.rsb-on-brass { --rsb-mark: var(--rsb-navy); --rsb-mark-ink: var(--rsb-brass); }
/* una sola tinta */
.rsb-mono { --rsb-mark: currentColor; --rsb-mark-ink: #ffffff; }

.rsb-logo { display: inline-flex; align-items: center; gap: 10px; line-height: 1; }
.rsb-logo__mark { display: block; flex: none; }
.rsb-logo__wordmark {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  white-space: nowrap;
  color: currentColor;
}
/* en la cabecera el logotipo va más pequeño */
.rsb-logo--compact .rsb-logo__wordmark { font-size: 14px; letter-spacing: 0.15em; }
.link-btn { background: none; border: 0; color: #fff; text-decoration: underline; padding: 6px; }

html, body { overflow-x: hidden; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 12px calc(80px + env(safe-area-inset-bottom));
}

/* Respuesta táctil inmediata: sin zoom por doble toque ni selección de texto al tocar */
button, label, select, input { touch-action: manipulation; }
.option, .chip, .btn { -webkit-user-select: none; user-select: none; }

h2 { font-size: 1.25rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 18px 0 8px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.muted { color: var(--muted); font-size: 0.9rem; }

/* ---------- Botones ---------- */
.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 1rem;
  background: var(--accent);
  color: #fff;
  min-height: 48px;
}
.btn:active { background: var(--accent-dark); }
.btn.secondary { background: var(--surface); color: var(--ink); border: 2px solid var(--ink); }
.btn.ok { background: var(--ok); }
.btn.ko { background: var(--ko); }
.btn + .btn { margin-top: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin-top: 0; flex: 1 1 0; min-width: 0; }
.btn.ghost { background: var(--surface); color: var(--muted); border: 2px solid var(--line); }
.btn-row .btn.undo { flex: 0 0 auto; width: auto; padding: 14px 12px; }


/* ---------- Configuración ---------- */
label { display: block; font-weight: 600; margin-bottom: 6px; }

.field { margin-bottom: 16px; }

.text-input {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  min-height: 48px;
}
.text-input:focus { border-color: var(--accent); outline: none; }

.player-inputs { display: grid; gap: 8px; }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0; /* los fieldset tienen min-width: min-content por defecto */
}
.segmented legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  margin: 0;
  text-align: center;
  padding: 12px 0;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-weight: 700;
  min-height: 48px;
}
.segmented input:checked + label { background: var(--ink); border-color: var(--ink); color: #fff; }
.segmented input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; }
.segmented.mode label { padding: 10px 6px; font-size: 0.92rem; }
.segmented label small { display: block; font-size: 0.72rem; font-weight: 600; opacity: 0.8; }
.segmented input:disabled + label { border-style: dashed; color: var(--muted); cursor: not-allowed; }
/* Temáticas (chips activables) */
.themes { display: flex; flex-wrap: wrap; gap: 8px; border: 0; padding: 0; margin: 0; min-width: 0; }
.themes legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.themes input { position: absolute; opacity: 0; pointer-events: none; }
.themes label {
  margin: 0;
  padding: 9px 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.themes .count { font-size: 0.75rem; color: var(--muted); font-weight: 700; }
.themes input:checked + label { background: var(--ink); border-color: var(--ink); color: #fff; }
.themes input:checked + label .count { color: #cfd5e3; }
.themes input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; }
.theme-actions { display: flex; gap: 12px; margin-top: 8px; }
.link-btn.dark { color: var(--ink); padding: 4px 0; }
.btn:disabled { background: #b9b3a6; cursor: not-allowed; }
.badge.theme { background: var(--accent); }

.scale-hint { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--muted); margin-top: 4px; }

/* ---------- Marcador ---------- */
.scoreboard { display: grid; gap: 6px; margin-bottom: 10px; }
.chip {
  min-width: 0;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 4px 8px;
  box-shadow: var(--shadow);
}
.chip .name { font-weight: 700; font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .line { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
.chip .score { font-size: 1.15rem; font-weight: 800; line-height: 1.2; }
.chip .round { font-size: 0.72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* El jugador con el turno se rellena con su color */
.chip.current { background: var(--pc, var(--accent)); border-color: var(--pc, var(--accent)); color: #fff; }
.chip.current .round { color: #fff; }
.chip.current .name::before { background: #fff; }
.chip .name::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--pc, var(--muted));
  margin-right: 5px;
  vertical-align: 1px;
}
.chip.out { opacity: 0.55; }
.chip.out .round { color: var(--ko); }
.chip.passed .round { color: var(--ok); }

/* ---------- Pregunta ---------- */
.badge {
  display: inline-block;
  background: var(--ink);
  color: #fff;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 700;
  margin-right: 6px;
}
.badge.light { background: #ece7dc; color: var(--ink); }
.question { font-size: 1.25rem; font-weight: 800; margin: 10px 0 6px; }

/* Tarjeta de la pregunta en la pantalla de juego (compacta) */
.question-card { padding: 0 12px 10px; overflow: hidden; margin-bottom: 10px; }
.turn-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 0 -12px 8px;
  padding: 6px 12px;
  background: var(--pc, var(--accent));
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
}
.turn-line strong { font-weight: 800; }
.badges { display: flex; gap: 4px; flex-wrap: nowrap; overflow: hidden; }
.badges .badge { margin: 0; font-size: 0.7rem; padding: 2px 8px; white-space: nowrap; flex: none; }
.badges .badge.light { flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; }
.question-card .question { font-size: 1.15rem; margin: 8px 0 0; line-height: 1.25; }
.hint { margin: 4px 0 0; font-size: 0.8rem; color: var(--muted); }

/* Cambio de turno: breve «pop» para que se note sin interrumpir */
.turn-change { animation: turn-pop 0.45s ease-out; }
@keyframes turn-pop {
  0% { transform: scale(0.94); opacity: 0.4; }
  60% { transform: scale(1.04); opacity: 1; }
  100% { transform: scale(1); }
}
.turn-line.turn-change { animation-name: turn-flash; }
@keyframes turn-flash {
  0% { filter: brightness(1.6); }
  100% { filter: none; }
}
@media (prefers-reduced-motion: reduce) {
  .turn-change { animation: none; }
}

/* ---------- Opciones ---------- */
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.option {
  position: relative;
  text-align: left;
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 7px 8px;
  min-height: 48px;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
  box-shadow: var(--shadow);
  transition: transform 0.08s;
}
.option:active:not(:disabled) { border-color: var(--accent); transform: scale(0.97); }
.option:disabled { cursor: default; box-shadow: none; }
.option .num { display: inline-block; min-width: 1.1em; margin-right: 4px; font-size: 0.72rem; color: var(--muted); font-weight: 700; }
.option .ans { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; font-size: 0.82rem; margin-top: 3px; font-weight: 700; }
.option .ans > span:first-child { min-width: 0; }
.option.ok { border-color: var(--ok); background: var(--ok-bg); }
.option.ok .ans { color: var(--ok); }
.option.ko { border-color: var(--ko); background: var(--ko-bg); }
.option.ko .ans { color: var(--ko); }
.option.shown { background: #f0ede6; border-style: dashed; }
.option .tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #ece7dc;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: 1px;
}
.option .by {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--pc, var(--muted));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
  vertical-align: -2px;
  margin-right: 4px;
}

/* ---------- Barra inferior ---------- */
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(244, 241, 234, 0.96);
  border-top: 1px solid var(--line);
}
.bottom-bar .inner { max-width: 560px; margin: 0 auto; }

/* ---------- Hoja inferior ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 10; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
}
.sheet { max-height: 88vh; overflow-y: auto; overscroll-behavior: contain; }
.sheet h2 { margin-bottom: 6px; }

/* Reglas */
.rules { margin: 8px 0 12px; padding-left: 1.3em; line-height: 1.45; }
.rules li { margin-bottom: 6px; }
.rules-example { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; line-height: 1.45; }

/* Reportar tarjeta y tarjetas vistas */
.report-line { text-align: center; margin: 16px 0 4px; font-size: 0.9rem; color: var(--muted); }
.report-line .link-btn { color: var(--muted); font-size: 0.9rem; min-height: 44px; }
.seen-line .link-btn { font-size: inherit; }
.reveal {
  font-size: 1.6rem;
  font-weight: 800;
  text-align: center;
  padding: 18px 10px;
  margin: 12px 0;
  border-radius: 12px;
  background: #f4f1ea;
}
.reveal .swatch { width: 26px; height: 26px; vertical-align: -5px; }
.note { font-size: 0.9rem; color: var(--muted); text-align: center; margin: -4px 0 12px; }

/* ---------- Resumen ---------- */
.summary-list { list-style: none; padding: 0; margin: 0; }
.summary-list li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.summary-list li:last-child { border-bottom: 0; }
.plus { color: var(--ok); font-weight: 700; }
.zero { color: var(--muted); }
.winner { font-size: 1.5rem; font-weight: 800; text-align: center; margin: 8px 0 16px; }

@media (min-width: 480px) {
  .options { grid-template-columns: 1fr 1fr 1fr; }
}
