/* Colors are semantic tokens so each theme only swaps values:
   a = left team, b = right team, accent = highlights (watch button, status pill), brand = UI chrome. */

/* Theme "rosa" (default): light, pink / violet / yellow */
:root {
  --bg: #fff5fa;
  --bg-2: #f4ecff;
  --surface: #ffffff;
  --surface-2: #fffbfd;
  --ink: #2b1a3d;
  --muted: #574669;
  --line: #eadcf3;
  --line-strong: #9a7cc4; /* borders that must be visible in the sun (>= 3:1) */

  --a: #e0367a;
  --a-ink: #b3195a;
  --a-soft: #ffe3ef;
  --a-flash: #ffc2dc;
  --on-a: #ffffff;
  --b: #7c4ddb;
  --b-ink: #5a2fb5;
  --b-soft: #efe7ff;
  --b-flash: #dccbff;
  --on-b: #ffffff;

  --accent: #ffc83d;
  --accent-on: #2b1a3d;
  --accent-ink: #7a4f00;
  --accent-soft: #fff4c7;
  --accent-glow: 0 8px 22px rgb(255 200 61 / 0.45);

  --brand: #7c4ddb;
  --brand-ink: #5a2fb5;
  --brand-soft: #efe7ff;
  --on-brand: #ffffff;
  --primary-bg: linear-gradient(135deg, #e0367a, #7c4ddb);
  --primary-on: #ffffff;

  --danger: #a51d2d;
  --danger-soft: #ffe4e7;
  --scrim: rgb(43 26 61 / 0.5);
  --shadow: 0 8px 24px rgb(124 77 219 / 0.13);
  --watch-face: radial-gradient(circle at 50% 40%, #3b2553, #1d1029 72%);
  --watch-rim: #e9c46a;
  --watch-rim-inner: #b8913c;

  --radius: 22px;
  color-scheme: only light; /* keep Chrome's auto dark mode from repainting this theme */
}

/* Theme "negro": black, grays and neon green */
:root[data-theme="negro"] {
  --bg: #0a0c0b;
  --bg-2: #111513;
  --surface: #171b19;
  --surface-2: #1f2522;
  --ink: #f1f5f3;
  --muted: #9ba7a1;
  --line: #2b3330;
  --line-strong: #6f7b75;

  --a: #2fe38a;
  --a-ink: #4ff2a0;
  --a-soft: #0f2a1c;
  --a-flash: #1a4a31;
  --on-a: #04130b;
  --b: #aeb8b3;
  --b-ink: #e1e8e4;
  --b-soft: #222826;
  --b-flash: #3a433f;
  --on-b: #0a0c0b;

  --accent: #c6f45a;
  --accent-on: #0a0c0b;
  --accent-ink: #c6f45a;
  --accent-soft: #23301a;
  --accent-glow: 0 8px 22px rgb(198 244 90 / 0.22);

  --brand: #2fe38a;
  --brand-ink: #5cf2a8;
  --brand-soft: #14271d;
  --on-brand: #04130b;
  --primary-bg: linear-gradient(135deg, #2fe38a, #14a866);
  --primary-on: #03110a;

  --danger: #ff7272;
  --danger-soft: #3a1717;
  --scrim: rgb(0 0 0 / 0.65);
  --shadow: 0 8px 24px rgb(0 0 0 / 0.5);
  --watch-face: radial-gradient(circle at 50% 40%, #27302c, #0a0d0c 72%);
  --watch-rim: #59615d;
  --watch-rim-inner: #2f3532;

  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { font-size: 112.5%; } /* 18px base, still follows the phone's font size setting */

html, body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%) fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.sprite { position: absolute; }
svg { width: 1.3em; height: 1.3em; fill: currentColor; flex: none; }

.view { display: flex; flex-direction: column; gap: 14px; }
h1, h2, p { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 20px; min-height: 58px; padding: 12px 20px;
  font: inherit; font-size: 1.1rem; font-weight: 800; color: var(--ink);
  cursor: pointer; touch-action: manipulation;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .icon-btn:focus-visible, .side:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; }
.btn-xl { min-height: 74px; font-size: 1.35rem; flex-direction: column; gap: 2px; }
.btn-xl small { font-size: 0.95rem; font-weight: 650; opacity: 0.9; }
.btn-lg { min-height: 62px; font-size: 1.15rem; }
.btn-primary { background: var(--primary-bg); color: var(--primary-on); box-shadow: var(--shadow); }
.btn-yellow { background: var(--accent); color: var(--accent-on); box-shadow: var(--accent-glow); }
.btn-soft { background: var(--brand-soft); color: var(--brand-ink); border: 2px solid var(--brand); }
.btn-outline { background: var(--surface); color: var(--brand-ink); border: 2px solid var(--brand); }
.btn-outline:disabled { opacity: 0.45; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border: 2px solid var(--danger); }

.icon-btn {
  width: 52px; height: 52px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--surface); color: var(--brand-ink); box-shadow: var(--shadow); cursor: pointer;
}
.icon-btn svg { width: 28px; height: 28px; }

.bar { display: grid; grid-template-columns: 52px 1fr 52px; align-items: center; gap: 8px; }
.bar h1 { text-align: center; font-size: 1.2rem; font-weight: 850; }
.bar-spacer { width: 52px; }
.match .bar { grid-template-columns: 52px 1fr auto; }
.menu-btn { min-height: 52px; padding: 8px 14px; font-size: 1.05rem; gap: 6px; }
#match-format {
  font-size: 1rem; line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }

/* ---------- Theme switch ---------- */
.theme-switch { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.theme-switch > span { font-weight: 800; font-size: 1.05rem; }
.theme-switch .options { display: flex; gap: 8px; flex: 1; }
.theme-switch label { flex: 1; }
.theme-switch input { position: absolute; opacity: 0; pointer-events: none; }
.theme-switch .swatch {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 8px 12px;
  border-radius: 16px; border: 2px solid var(--line); background: var(--surface-2); font-weight: 800; cursor: pointer;
}
.theme-switch .swatch i { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.theme-switch .sw-rosa i { background: conic-gradient(#e0367a 0 33%, #7c4ddb 0 66%, #ffc83d 0); }
.theme-switch .sw-negro i { background: conic-gradient(#0a0c0b 0 33%, #aeb8b3 0 66%, #2fe38a 0); box-shadow: 0 0 0 2px #2b3330; }
.theme-switch input:checked + .swatch { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-ink); }
.theme-switch input:focus-visible + .swatch { outline: 3px solid var(--brand); outline-offset: 2px; }

/* ---------- Home ---------- */
.hero { display: flex; align-items: center; gap: 14px; margin: 10px 0 6px; }
.hero img { border-radius: 22px; box-shadow: var(--shadow); }
.hero h1 { font-size: 2.1rem; font-weight: 900; letter-spacing: -0.02em; }
.hero p { color: var(--muted); font-size: 1.2rem; font-weight: 650; }

.how { display: flex; flex-direction: column; gap: 14px; }
.how h2 { font-size: 1.35rem; font-weight: 850; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: step; display: flex; flex-direction: column; gap: 10px; }
.steps li { counter-increment: step; position: relative; padding-left: 46px; min-height: 34px; font-size: 1.1rem; line-height: 1.4; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: -2px; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 900; color: var(--primary-on); background: var(--primary-bg);
}
.note { color: var(--muted); font-size: 1.05rem; line-height: 1.4; }
.note b { color: var(--ink); }
.tips summary { cursor: pointer; font-weight: 800; color: var(--brand-ink); font-size: 1.05rem; padding: 13px 0; }
.tips ul { margin: 8px 0 0; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; color: var(--muted); line-height: 1.4; }
.tips b { color: var(--ink); }

/* Watch legend: a drawing of the watch's music screen */
.watch-legend { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.wl-watch {
  width: min(250px, 72vw); aspect-ratio: 1; border-radius: 50%; background: var(--watch-face);
  border: 7px solid var(--watch-rim); box-shadow: 0 10px 26px rgb(0 0 0 / 0.3), inset 0 0 0 3px var(--watch-rim-inner);
  display: flex; align-items: center; justify-content: center; gap: 6%;
}
.wl-btn { width: 27%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; }
.wl-btn svg { width: 55%; height: 55%; }
.wl-btn.wl-a { background: var(--a); color: var(--on-a); }
.wl-btn.wl-b { background: var(--b); color: var(--on-b); }
.wl-btn.wl-undo { background: var(--accent); color: var(--accent-on); width: 23%; }
.wl-labels { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; text-align: center; gap: 6px; }
.wl-labels span { display: flex; flex-direction: column; overflow-wrap: anywhere; }
.wl-labels b { font-size: 1.1rem; font-weight: 900; }
.wl-labels small { font-size: 0.9rem; font-weight: 700; color: var(--muted); }
.wl-labels .wl-a { color: var(--a-ink); }
.wl-labels .wl-b { color: var(--b-ink); }
.wl-labels .wl-undo { color: var(--accent-ink); }

/* ---------- Setup ---------- */
.setup { display: flex; flex-direction: column; gap: 14px; }
.team-field {
  display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); border-left: 8px solid;
}
.team-field.team-a { border-color: var(--a); }
.team-field.team-b { border-color: var(--b); }
.team-label { display: flex; align-items: center; gap: 8px; font-weight: 850; font-size: 1.1rem; }
.team-label small { color: var(--muted); font-weight: 650; }
.team-a .team-label { color: var(--a-ink); }
.team-b .team-label { color: var(--b-ink); }
.team-field input {
  font: inherit; font-size: 1.4rem; font-weight: 800; color: var(--ink);
  border: 2px solid var(--line-strong); border-radius: 14px; padding: 12px 14px; background: var(--surface-2); width: 100%;
}
.team-field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand); }

.rules { display: block; }
.rules summary { list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; cursor: pointer; }
.rules summary::-webkit-details-marker { display: none; }
.rules-title { font-weight: 850; font-size: 1.15rem; }
.rules-summary { flex: 1 1 100%; order: 3; color: var(--muted); font-size: 1.02rem; line-height: 1.35; }
.rules-change { margin-left: auto; background: var(--brand-soft); color: var(--brand-ink); border: 2px solid var(--brand); font-weight: 800; padding: 6px 14px; border-radius: 999px; }
.rules-change::before { content: "Cambiar"; }
.rules[open] .rules-change::before { content: "Listo ✓"; }
.rules[open] .rules-summary { display: none; }
.rules[open] fieldset:first-of-type { margin-top: 14px; }
.segmented { border: 0; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.segmented:last-child { margin-bottom: 0; }
.segmented legend { font-weight: 800; margin-bottom: 8px; padding: 0; font-size: 1.05rem; }
.segmented label { flex: 1 1 0; min-width: 96px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; gap: 6px; text-align: center; min-height: 54px; padding: 8px; border-radius: 16px;
  background: var(--surface-2); border: 2px solid var(--line-strong); font-weight: 750; cursor: pointer; line-height: 1.2;
}
.segmented input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.segmented input:checked + span::before { content: "✓"; font-weight: 900; }
.segmented input:focus-visible + span { outline: 3px solid var(--a); outline-offset: 2px; }

/* ---------- Match ---------- */
.status-banner { min-height: 46px; display: flex; justify-content: center; align-items: center; }
.status-banner:not(:empty) {
  width: fit-content; margin: 0 auto; padding: 8px 22px; border-radius: 999px;
  background: var(--accent); color: var(--accent-on); font-size: 1.25rem; font-weight: 900; text-align: center;
  box-shadow: var(--accent-glow);
}
.board { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.side {
  position: relative; min-width: 0; min-height: 46dvh; padding: 18px 8px 58px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border-radius: 28px; border: 3px solid; color: var(--ink); font: inherit; cursor: pointer;
  touch-action: manipulation; transition: transform 0.08s ease, background-color 0.2s ease;
}
.side[data-side="a"] { background: var(--a-soft); border-color: var(--a); }
.side[data-side="b"] { background: var(--b-soft); border-color: var(--b); }
.side:active { transform: scale(0.98); }
.side.flash-a { background: var(--a-flash); }
.side.flash-b { background: var(--b-flash); }
/* Long names ("Marta y Susana") wrap to two lines instead of widening the board. */
.team {
  font-size: 1.35rem; font-weight: 900; max-width: 100%; text-align: center; line-height: 1.15; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.side[data-side="a"] .team, .side[data-side="a"] .points { color: var(--a-ink); }
.side[data-side="b"] .team, .side[data-side="b"] .points { color: var(--b-ink); }
.points { font-size: clamp(4.5rem, 26vw, 8rem); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.tally { display: flex; gap: 10px; }
.tally-item { display: flex; flex-direction: column; align-items: center; }
.tally-item b { font-size: 2rem; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tally-item small { color: var(--muted); font-size: 0.95rem; font-weight: 750; }
.side-key {
  position: absolute; bottom: 12px; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
}
.side[data-side="a"] .side-key { background: var(--a); color: var(--on-a); }
.side[data-side="b"] .side-key { background: var(--b); color: var(--on-b); }
.sets-line { text-align: center; color: var(--muted); font-size: 1.1rem; font-weight: 700; min-height: 1.4em; font-variant-numeric: tabular-nums; }

.btn-watch { flex-direction: row; gap: 12px; }
.btn-watch[data-status="off"] { background: var(--accent); color: var(--accent-on); box-shadow: var(--accent-glow); }
.btn-watch[data-status="on"] { background: var(--brand-soft); color: var(--brand-ink); border: 2px solid var(--brand); }
.btn-watch[data-status="paused"] { background: var(--danger-soft); color: var(--danger); border: 2px solid var(--danger); }
.last-point { text-align: center; color: var(--muted); font-size: 1rem; min-height: 1.3em; }

/* Options sheet */
.sheet { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: flex-end; z-index: 20; }
.sheet-card {
  width: 100%; max-width: 560px; margin: 0 auto; background: var(--surface); max-height: 92dvh; overflow-y: auto;
  border-radius: 28px 28px 0 0; padding: 22px 18px max(18px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}
.sheet-card h2 { font-size: 1.35rem; font-weight: 900; margin-bottom: 4px; }
.sheet-card .theme-switch { padding: 6px 4px 12px; border-bottom: 1px solid var(--line); }
.toggle { display: flex; align-items: center; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--line); font-size: 1.08rem; font-weight: 700; }
.toggle input { width: 28px; height: 28px; accent-color: var(--brand); flex: none; }
.toggle small { display: block; color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.sheet-card .btn { margin-top: 6px; }

/* Winner */
.winner { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: var(--scrim); overflow: hidden; }
.confetti {
  position: absolute; inset: -40px 0 0; pointer-events: none;
  background-image:
    radial-gradient(circle, var(--a) 0 5px, transparent 6px),
    radial-gradient(circle, var(--accent) 0 4px, transparent 5px),
    radial-gradient(circle, var(--b) 0 5px, transparent 6px),
    radial-gradient(circle, #fff 0 3px, transparent 4px);
  background-size: 90px 110px, 70px 90px, 120px 80px, 60px 70px;
  background-position: 0 0, 30px 20px, 50px 40px, 10px 60px;
  animation: confetti 6s linear infinite;
  opacity: 0.85;
}
@keyframes confetti { to { background-position: 0 440px, 30px 380px, 50px 520px, 10px 340px; } }
.winner-card {
  position: relative; width: min(420px, 100%); background: var(--surface); border-radius: 30px; padding: 26px 20px 20px;
  display: flex; flex-direction: column; gap: 12px; text-align: center; box-shadow: 0 20px 50px rgb(0 0 0 / 0.35);
}
.trophy { font-size: 4.2rem; line-height: 1; }
.winner-card h2 { font-size: 1.9rem; font-weight: 900; }
.winner-card.winner-a h2 { color: var(--a-ink); }
.winner-card.winner-b h2 { color: var(--b-ink); }
.winner-card p { font-size: 1.5rem; font-weight: 850; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- History ---------- */
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.history button {
  width: 100%; text-align: left; font: inherit; color: var(--ink); cursor: pointer; border: 2px solid var(--line-strong);
  background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center;
}
.h-date { color: var(--muted); font-size: 0.95rem; font-weight: 650; }
.h-teams { font-weight: 850; font-size: 1.15rem; }
.ta { color: var(--a-ink); }
.tb { color: var(--b-ink); }
.h-score { grid-column: 2; grid-row: 1 / span 2; font-weight: 900; font-size: 1.2rem; font-variant-numeric: tabular-nums; text-align: right; }
.badge { justify-self: start; font-size: 0.95rem; font-weight: 800; padding: 4px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); }
.empty { color: var(--muted); text-align: center; margin-top: 50px; font-size: 1.15rem; }

/* ---------- Detail ---------- */
.detail { display: flex; flex-direction: column; gap: 14px; }
.detail h2 { font-size: 1.35rem; font-weight: 900; }
.detail .meta { color: var(--muted); margin-top: 6px; font-size: 1.02rem; }
.score-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 1.15rem; }
.score-table th, .score-table td { padding: 10px 6px; text-align: center; }
.score-table th { color: var(--muted); font-weight: 750; font-size: 0.9rem; }
.score-table td:first-child, .score-table th:first-child { text-align: left; font-weight: 850; }
.score-table tr.ta td:first-child, .score-table tr.ta td.won { color: var(--a-ink); }
.score-table tr.tb td:first-child, .score-table tr.tb td.won { color: var(--b-ink); }
.score-table td.won { font-weight: 900; }
.score-table sup { color: var(--muted); font-size: 0.8em; }
.stats { display: grid; grid-template-columns: 1fr auto auto; gap: 10px 18px; font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.stats span:nth-child(3n+1) { color: var(--muted); font-weight: 650; }
.stats .ta, .stats .tb { font-weight: 850; }
.detail .actions { display: flex; flex-direction: column; gap: 10px; }
.detail [data-action="delete"] { margin-top: 24px; } /* keep the destructive action away from the main one */

@media (prefers-reduced-motion: reduce) {
  .confetti { animation: none; }
  .btn, .side { transition: none; }
}
