:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #ece7dc;
  --text: #1c1f1d;
  --muted: #69706b;
  --brand: #0f3d2e;
  --brand-2: #17694d;
  --on-brand: #f4f1ea;
  --accent: #d7263d;
  --ok: #1f9d55;
  --ok-bg: #dcf5e6;
  --bad: #c62a3a;
  --bad-bg: #fbe1e4;
  --gold: #e0a100;
  --border: #ddd6c8;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 16px rgb(0 0 0 / .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --surface: #17201d;
    --surface-2: #212c28;
    --text: #ecefe9;
    --muted: #9aa49e;
    --brand: #0f3d2e;
    --brand-2: #2f9b74;
    --ok-bg: #133524;
    --bad-bg: #3a1a1f;
    --border: #2b3833;
    --shadow: 0 1px 2px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }

.topbar {
  background: var(--brand);
  color: var(--on-brand);
  padding: calc(env(safe-area-inset-top) + 14px) 16px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar h1 { margin: 0; font-size: 1.25rem; letter-spacing: .02em; }
.topbar h1 span { color: var(--gold); }
.topbar h1 .ver { font-size: .62rem; font-weight: 500; opacity: .6; letter-spacing: 0; color: var(--on-brand); }
.topbar .who { font-size: .9rem; opacity: .85; }
.topbar a { color: inherit; }

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

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 8px; font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 14px 20px;
  background: var(--brand-2); color: #fff; font-weight: 650; font-size: 1.05rem;
  cursor: pointer; text-decoration: none; width: 100%;
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.small { padding: 8px 12px; font-size: .9rem; width: auto; border-radius: 10px; }
.btn.danger { background: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

input[type=text], input[type=password], textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); margin: 8px 0 12px;
}
textarea { min-height: 180px; font-family: ui-monospace, monospace; font-size: .85rem; }

/* Marcador grande */
.score { display: flex; justify-content: space-around; text-align: center; margin: 12px 0 16px; }
.score b { display: block; font-size: 2rem; line-height: 1.1; }
.score small { color: var(--muted); }

/* Pantalla de pregunta */
.quiz-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.badge {
  display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2); color: var(--muted);
}
.badge.kuadrilla { background: var(--accent); color: #fff; }
.badge.gaurkotasuna { background: #2563eb; color: #fff; }
.badge.matematika { background: #7c3aed; color: #fff; }
.badge.geografia { background: #0f766e; color: #fff; }
.qimg { display: block; width: 100%; max-height: 38vh; object-fit: cover; border-radius: 12px; margin: 0 0 14px; background: var(--surface-2); }
/* Los dibujos se ven enteros y sobre blanco también en modo oscuro */
.qimg.matematika { object-fit: contain; background: #fff; padding: 8px; }
.qimg.small { max-height: 200px; margin: 8px 0 4px; }
.credit { font-size: .72rem; color: var(--muted); margin: 0 0 6px; }
.timer { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 18px; }
.timer > div { height: 100%; background: var(--brand-2); width: 100%; transform-origin: left; }
.timer.low > div { background: var(--accent); }
.question { font-size: 1.25rem; font-weight: 650; line-height: 1.35; margin: 0 0 18px; }
.options { display: grid; gap: 10px; }
.option {
  text-align: left; padding: 16px; border-radius: 14px; border: 2px solid var(--border);
  background: var(--surface); font-size: 1.05rem; cursor: pointer; line-height: 1.3;
}
.option:active { background: var(--surface-2); }
.option.ok { border-color: var(--ok); background: var(--ok-bg); }
.option.bad { border-color: var(--bad); background: var(--bad-bg); }
.option:disabled { cursor: default; }
.feedback { text-align: center; font-weight: 750; font-size: 1.2rem; margin-top: 16px; min-height: 1.5em; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }

/* Ranking */
.tabs { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: none; padding: 10px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: grid; grid-template-columns: 2rem 1fr auto; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.rank li:last-child { border-bottom: 0; }
.rank .pos { font-weight: 800; text-align: center; color: var(--muted); }
.rank li:nth-child(1) .pos { color: var(--gold); }
.rank .pts { font-weight: 800; font-variant-numeric: tabular-nums; }
.rank .me { color: var(--brand-2); }
.rank .sub { font-size: .8rem; color: var(--muted); }

/* Resultados */
.result { padding: 14px 0; border-bottom: 1px solid var(--border); }
.result:last-child { border-bottom: 0; }
.result .q { font-weight: 650; margin: 6px 0; }
.result ul { margin: 6px 0; padding-left: 0; list-style: none; }
.result li { padding: 6px 10px; border-radius: 8px; margin: 3px 0; font-size: .95rem; }
.result li.answer { background: var(--ok-bg); }
.result li.wrong { background: var(--bad-bg); text-decoration: line-through; }
.result .note { font-size: .88rem; color: var(--muted); font-style: italic; }

/* Navegación inferior */
nav.bottom {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom);
}
nav.bottom a {
  flex: 1; max-width: 180px; text-align: center; padding: 10px 4px 12px; color: var(--muted);
  text-decoration: none; font-size: .78rem; font-weight: 600;
}
nav.bottom a .ico { display: block; font-size: 1.35rem; margin-bottom: 2px; }
nav.bottom a.on { color: var(--brand-2); }

.hint { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: .9rem; display: flex; gap: 10px; align-items: flex-start; }
.hint > button { margin-left: auto; border: 0; background: none; cursor: pointer; font-size: 1.1rem; color: var(--muted); }
.error { color: var(--bad); font-weight: 600; }
.hidden { display: none !important; }

/* Admin */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
td, th { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.qr-modal { position: fixed; inset: 0; background: rgb(0 0 0 / .6); display: grid; place-items: center; padding: 16px; z-index: 10; }
.qr-modal .card { max-width: 360px; width: 100%; text-align: center; }
.qr-modal img { width: 100%; background: #fff; border-radius: 12px; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
input[type=password] { font-size: 1.4rem; letter-spacing: .3em; text-align: center; }
input[type=password]::placeholder { font-size: 1rem; letter-spacing: normal; }

.logout { border: 1px solid rgb(255 255 255 / .35); background: none; color: var(--on-brand); border-radius: 8px; padding: 2px 8px; margin-left: 6px; cursor: pointer; font-size: .95rem; }
.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.player { padding: 12px 8px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface); font-weight: 600; cursor: pointer; }
.player.on { border-color: var(--brand-2); background: var(--ok-bg); }
