:root {
  --bg: #f6f3ec;
  --panel: #fffdf8;
  --ink: #241d14;
  --muted: #7a6a55;
  --line: #e3d9c8;
  --gold: #c9861a;
  --gold-soft: #f6e7c8;
  --green: #2f6f4f;
  --red: #a33a2a;
  --shadow: 0 1px 2px rgba(36, 29, 20, .06), 0 8px 24px rgba(36, 29, 20, .05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17140f;
    --panel: #221d16;
    --ink: #f2ece1;
    --muted: #a0917b;
    --line: #362e23;
    --gold: #e0a63f;
    --gold-soft: #3a2e18;
    --green: #6cc295;
    --red: #e58a76;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

:root[data-theme="dark"] {
  --bg: #17140f;
  --panel: #221d16;
  --ink: #f2ece1;
  --muted: #a0917b;
  --line: #362e23;
  --gold: #e0a63f;
  --gold-soft: #3a2e18;
  --green: #6cc295;
  --red: #e58a76;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

/* el atributo hidden manda sobre cualquier display */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.wrap { max-width: 1000px; margin: 0 auto; padding: 0 16px 56px; }

header {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--gold-soft), transparent);
}

.head {
  position: relative;
  max-width: 1000px;
  margin: 0 auto;
  padding: 18px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: 13px; }

/* Botón de menú (tres líneas) */
.burger {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  width: 42px;
  height: 38px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 4px;
  cursor: pointer;
  flex: none;
}

.burger span { display: block; width: 18px; height: 2px; background: var(--ink); border-radius: 2px; }
.burger:hover { border-color: var(--gold); }
.burger[aria-expanded="true"] { border-color: var(--gold); background: var(--gold-soft); }

nav {
  position: absolute;
  top: calc(100% - 8px);
  right: 16px;
  z-index: 20;
  min-width: 190px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

nav button {
  appearance: none;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

nav button:hover { background: var(--gold-soft); }
nav button[aria-selected="true"] { color: var(--gold); background: var(--gold-soft); }
nav button.admin { border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; margin-top: 4px; padding-top: 12px; }

h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 28px 0 10px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.scroll { overflow-x: auto; }

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

th, td {
  padding: 9px 10px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 600;
}

th:nth-child(-n+3), td:nth-child(-n+3) { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--gold-soft); }

td.pos { color: var(--muted); width: 1%; }
td.name { font-weight: 600; }
td.pts { font-weight: 700; font-size: 16px; }
.top td.pos { color: var(--gold); font-weight: 700; }
.dim { color: var(--muted); font-weight: 400; }
.pos-num { color: var(--muted); font-weight: 400; font-size: 13px; }

.tie {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--gold-soft);
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.tie .grp { font-weight: 600; color: var(--muted); font-size: 12px; }

.match {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  align-items: center;
}

.match:last-child { border-bottom: 0; }
.pair { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.pair .vs { color: var(--muted); font-size: 12px; }
.score { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.score .stb { color: var(--gold); }
.pending { color: var(--muted); font-weight: 400; font-size: 13px; }
.win { color: var(--green); }
.lose { color: var(--muted); }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.team-head { padding: 10px 12px; background: var(--gold-soft); border-bottom: 1px solid var(--line); }
.team-head strong { display: block; }
.team-head span { color: var(--muted); font-size: 12px; }
.cap { color: var(--gold); font-size: 12px; }

.msg { padding: 24px; text-align: center; color: var(--muted); }
.err { color: var(--red); }

footer { color: var(--muted); font-size: 12px; text-align: center; padding: 28px 16px 0; }

@media (max-width: 560px) {
  th, td { padding: 8px 7px; }
  .hide-s { display: none; }
}

/* --- Puerta de entrada ------------------------------------------------ */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: linear-gradient(180deg, var(--gold-soft), var(--bg) 40%);
}

.gate-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.gate-card h1 { font-size: 22px; margin: 0; }
.gate-card .sub { display: block; margin-bottom: 20px; }
.gate-card label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 5px; }

input, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
}

input:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }

button.primary {
  background: var(--gold);
  color: #fff;
  border: 0;
  border-radius: 9px;
  font: inherit;
  font-weight: 700;
  padding: 10px 16px;
  cursor: pointer;
}

.gate-card button.primary { width: 100%; margin-top: 18px; }
button.primary:hover { filter: brightness(1.07); }
button.small { padding: 7px 12px; font-size: 13px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font-weight: 600; cursor: pointer; }
button.small:hover { border-color: var(--gold); }

/* --- Carga de resultados ---------------------------------------------- */
.card.pad { padding: 14px; }
.card.pad label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.card.pad .sub { display: block; margin-top: 8px; }
select.wide { width: auto; min-width: 190px; max-width: 100%; }

.match.edit { grid-template-columns: 1fr; gap: 8px; }
.inputs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.setbox { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
select.g { width: auto; padding: 7px 8px; font-variant-numeric: tabular-nums; }
select.g:disabled { opacity: .45; }

.save-msg { font-size: 12px; color: var(--muted); }
.save-msg.ok { color: var(--green); font-weight: 600; }
.save-msg.err { color: var(--red); }
.foot-note { margin-top: 14px; }

/* --- Reglamento -------------------------------------------------------- */
.prose p { margin: 0 0 10px; }
.prose p:last-child { margin-bottom: 0; }

.rule {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.rule:last-child { border-bottom: 0; }
.rule-n { font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
.center { text-align: center; }

.rule.sub { padding-left: 42px; background: color-mix(in srgb, var(--gold-soft) 40%, transparent); }
.rule.sub .rule-n { font-weight: 600; font-size: 13px; }

/* --- Título de sección -------------------------------------------------- */
.page-title {
  font-size: 22px;
  letter-spacing: -.01em;
  margin: 24px 0 4px;
}

.page-title + h2 { margin-top: 18px; }

/* --- Penalizaciones ----------------------------------------------------- */
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 12px; }
.form-grid label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.form-grid label > select, .form-grid label > input { margin-top: 5px; }
.form-grid .wide-cell { grid-column: 1 / -1; }
input.qty { width: 100%; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); font-weight: 700; }
.neg { color: var(--red); font-weight: 700; }

@media (max-width: 820px) { .hide-m { display: none; } }

/* Aportaciones / caja */
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.caja-badge { background: var(--gold-soft); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.caja-resumen { font-size: 18px; margin-bottom: 14px; }
.caja-total { font-variant-numeric: tabular-nums; }
input.euro { max-width: 90px; text-align: right; }
.caja-add { padding: 10px 12px; border-top: 1px dashed var(--line); }
.caja-add .form-grid { grid-template-columns: 1fr 1.4fr 80px; gap: 6px; margin-bottom: 8px; }
.caja-add input.euro { max-width: none; }
td .small, .dim.small { font-size: 11px; }
input.team-name { width: 100%; font-weight: 700; margin-bottom: 4px; }
.team-edit { min-width: 0; }
.team-edit table { table-layout: fixed; }
.team-edit th:nth-child(1), .team-edit td:nth-child(1) { width: 26px; }
.team-edit th:nth-child(3), .team-edit td:nth-child(3) { width: 42px; text-align: center; }
.team-edit th:nth-child(4), .team-edit td:nth-child(4) { width: 66px; }
.team-edit select.wide { width: 100%; min-width: 0; text-overflow: ellipsis; }
.team-edit input.rank { width: 100%; padding-left: 6px; padding-right: 4px; text-align: center; }
.cap-btn { padding: 4px 8px; border-radius: 8px; font-size: 16px; line-height: 1; color: var(--line); background: transparent; }
.cap-btn.on { color: var(--gold); border-color: var(--gold); background: var(--gold-soft); }
.cap-btn:disabled { opacity: .3; }
