/* =========================================================
   Narrador de Castronegro — estilos
   - Modo DÍA: pergamino claro, legible para toda la mesa.
   - Modo NOCHE: negro absoluto, texto rojo apagado, sin brillo,
     botones enormes para tocar a ciegas y en silencio.
   ========================================================= */

:root {
  --bg: #f4ecdc;
  --surface: #fffaf0;
  --surface-2: #efe4cd;
  --ink: #2a1f17;
  --ink-soft: #6b5a4a;
  --line: #d9c8a8;
  --accent: #8f1d1d;
  --accent-ink: #fff6ea;
  --ok: #2f6b3a;
  --warn: #9a5b00;
  --wolf: #8f1d1d;
  --village: #2f5d7a;
  --solo: #6a3f8a;
  --amb: #8a6a1f;
  --radius: 14px;
  --gap: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(60,40,20,.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  color-scheme: light;
}

/* Paleta nocturna: se activa con body.mode-night (lo controla app.js). */
body.mode-night {
  --bg: #000;
  --surface: #0a0606;
  --surface-2: #140a0a;
  --ink: #b33a3a;
  --ink-soft: #6e2a2a;
  --line: #2a1212;
  --accent: #5a1414;
  --accent-ink: #e0a0a0;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  transition: background .6s ease, color .6s ease;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-weight: 700; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  min-width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 20px; cursor: pointer;
}
/* De noche la barra casi desaparece para no deslumbrar. */
body.mode-night .topbar { opacity: .35; border-color: transparent; }
body.mode-night .brand span { display: none; }

/* ---------- Contenedor ---------- */
main {
  max-width: 920px; margin: 0 auto;
  padding: 16px 16px 120px;
}
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0 0 8px; }
h1 { font-size: clamp(26px, 5vw, 38px); }
h2 { font-size: clamp(21px, 4vw, 28px); }
h3 { font-size: 18px; }
p { margin: 0 0 10px; }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }
.center { text-align: center; }
.stack > * + * { margin-top: var(--gap); }
.row { display: flex; gap: var(--gap); flex-wrap: wrap; align-items: center; }
.row.spread { justify-content: space-between; }
.grow { flex: 1 1 auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: var(--gap); }

/* ---------- Botones ---------- */
.btn {
  appearance: none; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink);
  border-radius: 12px; padding: 12px 18px; min-height: 48px;
  font: 600 17px var(--font); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-align: center;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { background: #fbe9e7; border-color: #e5b4ae; color: #7a1a12; }
.btn.block { display: flex; width: 100%; }
.btn.xl { min-height: 64px; font-size: 21px; }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Rejilla de jugadores: botones grandes para tocar sin mirar mucho. */
.grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.grid .btn { min-height: 72px; font-size: 19px; }
.grid .btn.selected { outline: 4px solid var(--accent); background: var(--accent); color: var(--accent-ink); }
.grid .btn.dead { opacity: .4; text-decoration: line-through; }

/* ---------- Formularios ---------- */
label { display: block; font-weight: 600; margin-bottom: 4px; }
input[type=text], input[type=number], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); font: 17px var(--font);
}
textarea { min-height: 90px; resize: vertical; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-weight: 500; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }

/* Lista de nombres */
.names { display: grid; gap: 8px; }
.name-row { display: flex; gap: 8px; align-items: center; }
.name-row .seat { width: 28px; text-align: right; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.name-row input { flex: 1; }

/* ---------- Editor de mazo ---------- */
.deck-group h3 { margin-top: 14px; }
.deck-row {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  padding: 8px 0; border-bottom: 1px dashed var(--line);
}
.deck-row:last-child { border-bottom: 0; }
.deck-row .name { font-weight: 600; }
.deck-row .desc { font-size: 13px; color: var(--ink-soft); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); font-size: 22px; cursor: pointer; color: var(--ink); }
.stepper output { min-width: 26px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

.meter { height: 10px; border-radius: 6px; background: linear-gradient(90deg, var(--wolf), #d8c7a0 50%, var(--village)); position: relative; }
.meter .needle { position: absolute; top: -5px; width: 4px; height: 20px; background: var(--ink); border-radius: 2px; transform: translateX(-2px); }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); }
.team-lobo { color: var(--wolf); }
.team-aldeano { color: var(--village); }
.team-solitario { color: var(--solo); }
.team-ambiguo { color: var(--amb); }

.status-bar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--line); margin-top: 16px; }

/* ---------- Pass & Play ---------- */
.handoff { min-height: 62vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 18px; }
.handoff .who { font-family: var(--serif); font-size: clamp(30px, 8vw, 54px); font-weight: 700; }
.secret { font-family: var(--serif); font-size: clamp(28px, 7vw, 46px); font-weight: 700; color: var(--accent); }

/* ---------- Día ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.timer { font: 700 clamp(44px, 12vw, 80px) var(--font); font-variant-numeric: tabular-nums; text-align: center; letter-spacing: 1px; }
.timer.low { color: var(--accent); }
.deaths li { margin: 4px 0; }
details.tools summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
details.tools .row .btn { flex: 1 1 200px; }
.log { max-height: 280px; overflow: auto; font-size: 14px; color: var(--ink-soft); padding-left: 18px; }

/* ---------- Noche ---------- */
body.mode-night main { padding-top: 24px; }
.night-role { text-align: center; font-family: var(--serif); font-size: clamp(26px, 7vw, 44px); letter-spacing: 1px; margin-bottom: 4px; }
.night-q { text-align: center; color: var(--ink-soft); font-size: 18px; margin-bottom: 18px; }
.night-big { text-align: center; font-family: var(--serif); font-size: clamp(34px, 10vw, 64px); margin: 22px 0; }
body.mode-night .btn { background: #0d0707; border-color: #2a1212; color: var(--ink); }
body.mode-night .btn.primary { background: #2a0c0c; border-color: #4a1616; color: #d07a7a; }
body.mode-night .grid .btn { min-height: 86px; font-size: 22px; }
body.mode-night .grid .btn.selected { background: #4a1212; color: #ffb0b0; outline-color: #7a1e1e; }
body.mode-night .card { background: #070404; border-color: #1c0c0c; }
body.mode-night input, body.mode-night select { background: #0d0707; color: var(--ink); border-color: #2a1212; }
.sleeping { min-height: 60vh; display: grid; place-items: center; text-align: center; color: #3a1515; font-family: var(--serif); font-size: 22px; }
.moon { width: 70px; height: 70px; border-radius: 50%; box-shadow: -16px 6px 0 0 #2a1010; margin: 0 auto 18px; }

/* Botón discreto para saltar/pausar de noche */
.night-tools { position: fixed; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 8px; opacity: .5; }

/* ---------- Subtítulos de la voz ---------- */
.caption {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(92vw, 720px); padding: 10px 16px; border-radius: 12px;
  background: rgba(30,20,12,.88); color: #f6ead2; font-size: 16px; text-align: center;
  pointer-events: none; opacity: 0; transition: opacity .3s;
}
.caption.show { opacity: 1; }
body.mode-night .caption { background: rgba(20,4,4,.9); color: #8a3a3a; }

/* ---------- Diálogos ---------- */
dialog.sheet {
  border: 1px solid var(--line); border-radius: 18px; padding: 0;
  width: min(560px, calc(100vw - 32px)); max-height: 86vh;
  background: var(--surface); color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(0,0,0,.55); }
.sheet-body { padding: 18px; overflow: auto; max-height: 86vh; }
.sheet-body .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }

/* ---------- Fin de partida ---------- */
.winner { font-family: var(--serif); font-size: clamp(30px, 8vw, 52px); color: var(--accent); text-align: center; }
table.roles { width: 100%; border-collapse: collapse; }
table.roles td { padding: 8px 6px; border-bottom: 1px solid var(--line); }

@media (max-width: 520px) {
  body { font-size: 16px; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .btn.xl { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
