:root {
  --court: #173d33;      /* header / primary */
  --court-2: #21584a;
  --ball: #c8e04a;       /* highlight */
  --clay: #c9562c;       /* live / attention */
  --bg: #f3f4f1;
  --card: #ffffff;
  --ink: #1b2420;
  --muted: #5f6b65;
  --line: #dde2dc;
  --win: #e7f2d0;
  --tie: #fbe9df;
  --primary: #1f5c4b;
  --primary-ink: #ffffff;
  --danger: #b3261e;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --card: #18201c; --ink: #e8eee9; --muted: #9aa8a0; --line: #2a3530;
    --win: #2b3a17; --tie: #3d2418; --primary: #6fbf9f; --primary-ink: #0f1412; --danger: #ff8a80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --card: #18201c; --ink: #e8eee9; --muted: #9aa8a0; --line: #2a3530;
  --win: #2b3a17; --tie: #3d2418; --primary: #6fbf9f; --primary-ink: #0f1412; --danger: #ff8a80;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* Header + tabs */
.top { background: var(--court); color: #fff; position: sticky; top: 0; z-index: 5; padding-top: env(safe-area-inset-top, 0); }
.top-in { max-width: 1100px; margin: 0 auto; padding: .8rem 16px .5rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.brand { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.logo { width: 48px; height: 48px; flex: none; border-radius: 10px; background: #fff; padding: 2px; }
.top h1 { margin: 0; font-size: 1.15rem; line-height: 1.2; overflow-wrap: anywhere; }
.top p { margin: .1rem 0 0; font-size: .82rem; opacity: .8; }
.top p:empty { display: none; }
.top-right { display: flex; align-items: center; gap: .8rem; flex: none; }
.lang { display: inline-flex; align-items: center; gap: 2px; padding: 3px 3px 3px 8px; border: 1px solid rgb(255 255 255 / .45); border-radius: 999px; background: rgb(255 255 255 / .08); }
.lang svg { width: 16px; height: 16px; margin-right: 3px; fill: none; stroke: #fff; stroke-width: 1.8; }
.lang button { border: 0; background: none; color: #fff; padding: .28rem .65rem; border-radius: 999px; cursor: pointer; font-size: .82rem; font-weight: 600; }
.lang button:hover { background: rgb(255 255 255 / .14); }
.lang button[aria-pressed="true"] { background: var(--ball); color: #173d33; }
.lang .short { display: none; }
.lock { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgb(255 255 255 / .45); background: rgb(255 255 255 / .08); cursor: pointer; padding: 0; }
.lock[hidden] { display: none; }
.lock:hover { background: rgb(255 255 255 / .18); }
.lock svg { width: 16px; height: 16px; fill: none; stroke: #fff; stroke-width: 1.8; }
input.pin { font-size: 1.6rem; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; }
.err { color: var(--danger, #c0392b); min-height: 1.2em; margin: .2rem 0 0; }
@media (max-width: 560px) {
  .lang .long { display: none; }
  .lang .short { display: inline; }
}
.live[hidden] { display: none; }
@media (max-width: 420px) { .live { font-size: 0; gap: 0; } }
.live { flex: none; font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; display: inline-flex; align-items: center; gap: .35rem; opacity: .9; }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ball); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .live::before { animation: none; } }

.tabs { max-width: 1100px; margin: 0 auto; padding: 0 12px; display: flex; gap: .2rem; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: 0; color: #fff; opacity: .72; padding: .6rem .8rem .7rem; cursor: pointer;
  font-weight: 600; white-space: nowrap; border-bottom: 3px solid transparent;
}
.tabs button:hover { opacity: 1; }
.tabs button[aria-current="page"] { opacity: 1; border-bottom-color: var(--ball); }

main { max-width: 1100px; margin: 0 auto; padding: 16px 16px 4rem; }

/* Banners */
.notice { background: var(--clay); color: #fff; padding: .65rem .85rem; border-radius: var(--radius); font-weight: 600; margin-bottom: .9rem; white-space: pre-line; }
.event { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.4rem; padding: .7rem .9rem; margin-bottom: .9rem; }
.event.card { border-left: 4px solid var(--primary); }
.ev-item { display: flex; align-items: center; gap: .5rem; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.ev-item svg { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--primary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ev-item a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
.ev-item a:hover { text-decoration-color: currentColor; }
.ev-status { font-size: .75rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.ev-status.on { background: var(--clay); border-color: var(--clay); color: #fff; }
.ev-status.done { opacity: .8; }
.ev-edit { margin-left: auto; }
.empty-event { width: 100%; text-align: left; background: none; border: 1px dashed var(--line); color: var(--muted); cursor: pointer; font-weight: 600; }
.adminbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .9rem;
  padding: .55rem .7rem; border: 1px dashed var(--primary); border-radius: var(--radius); background: var(--card);
}
.adminbar .tag { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; background: var(--primary); color: var(--primary-ink); padding: .15rem .5rem; border-radius: 999px; }
.adminbar .grow { flex: 1; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; gap: .35rem; border: 1px solid transparent; border-radius: 9px;
  background: var(--primary); color: var(--primary-ink); padding: .45rem .85rem; font-weight: 600; cursor: pointer; text-decoration: none; font-size: .9rem;
}
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--danger); border-color: currentColor; }
.btn.sm { padding: .25rem .6rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: default; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .9rem; }
.toolbar .grow { flex: 1 1 200px; }
.search { width: 100%; padding: .5rem .75rem; border: 1px solid var(--line); border-radius: 9px; background: var(--card); }
.chips { display: flex; gap: .35rem; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .3rem .75rem; cursor: pointer; font-size: .85rem; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--court); border-color: var(--court); color: #fff; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: none; padding: .4rem .8rem; cursor: pointer; font-weight: 600; font-size: .85rem; }
.seg button[aria-pressed="true"] { background: var(--court); color: #fff; }

h2.sec { font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 1.3rem 0 .55rem; display: flex; align-items: center; gap: .5rem; }
h2.sec:first-child { margin-top: .2rem; }
h2.sec .now { color: var(--clay); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); }

/* Pairs */
.pairs { display: grid; gap: .5rem; }
.pair { display: grid; grid-template-columns: 2.4rem 1fr auto; gap: .2rem .75rem; align-items: center; padding: .6rem .8rem; }
.seed { width: 2.2rem; height: 2.2rem; border-radius: 50%; background: var(--bg); border: 1px solid var(--line); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.pname { font-weight: 600; overflow-wrap: anywhere; }
.pname .amp { color: var(--muted); font-weight: 400; }
.club { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.meta { display: flex; flex-wrap: wrap; gap: .3rem .8rem; font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); color: var(--ink); }
.badge.none { color: var(--muted); font-weight: 400; }
.pair .acts { display: flex; gap: .35rem; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 560px) {
  .pair { grid-template-columns: 2.4rem 1fr; }
  .pair .acts { grid-column: 2; justify-content: flex-start; }
}

/* Courts */
.courts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: .8rem; }
.court { overflow: hidden; }
.court-h { background: var(--court-2); color: #fff; padding: .55rem .8rem; display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.court-h b { font-size: 1rem; }
.court-h small { opacity: .85; font-size: .75rem; text-align: right; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: .72rem; padding: .4rem .45rem; border-bottom: 1px solid var(--line); }
td { padding: .45rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; width: 2.2rem; }
table.final tr.tie td { background: var(--tie); }
tr.podium td { background: var(--win); }
.why { font-size: .72rem; color: var(--muted); }
.warn { padding: .55rem .8rem; font-size: .82rem; background: var(--tie); display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.legend { font-size: .8rem; color: var(--muted); margin-top: .8rem; }

/* Matches */
.matches { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: .6rem; }
.match { padding: .55rem .7rem .6rem; border-left: 4px solid var(--line); }
.match.done { border-left-color: var(--primary); }
.match.current { border-left-color: var(--clay); }
.match.tap { cursor: pointer; }
.match.tap:hover { border-color: var(--primary); }
.mh { display: flex; justify-content: space-between; font-size: .74rem; color: var(--muted); margin-bottom: .25rem; gap: .5rem; }
.mh b { color: var(--ink); }
.side { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .22rem .35rem; border-radius: 7px; }
.side.win { background: var(--win); font-weight: 600; }
.side .g { font-weight: 700; min-width: 1.5rem; text-align: right; }
.ph { color: var(--muted); font-style: italic; }
.note { font-size: .72rem; color: var(--muted); margin-top: .25rem; }
.note.bad { color: var(--danger); }

/* Rules */
.rules { align-items: start; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: .8rem; }
.rule { padding: .85rem 1rem; border-top: 4px solid var(--court-2); }
.rule.key { border-top-color: var(--clay); }
.rule h3 { margin: 0 0 .35rem; font-size: 1rem; }
.rule ul { margin: 0; padding-left: 1.1rem; }
.rule li { margin: .25rem 0; }

footer { margin-top: 2.5rem; font-size: .78rem; color: var(--muted); text-align: center; }

/* Modal: bottom sheet on phones, dialog on wider screens */
#modal { position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
#modal[hidden] { display: none; }
.sheet { background: var(--card); color: var(--ink); width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 1.1rem 16px calc(1.2rem + env(safe-area-inset-bottom, 0)); }
@media (min-width: 640px) { #modal { align-items: center; } .sheet { border-radius: 16px; padding: 1.3rem 1.4rem; } }
.sheet h3 { margin: 0 0 .3rem; }
.field { display: block; margin: .7rem 0; }
.field > span { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
.field input, .field select, .field textarea { width: 100%; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
.field textarea { min-height: 9rem; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.field.check { display: flex; gap: .5rem; align-items: center; }
.field.check input { width: auto; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.score { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin: .8rem 0; }
.score .who { min-width: 0; overflow-wrap: anywhere; }
.stepper { display: flex; align-items: center; flex: none; }
.stepper button { width: 2.6rem; height: 2.6rem; border: 1px solid var(--line); background: var(--bg); font-size: 1.2rem; cursor: pointer; }
.stepper button:first-child { border-radius: 9px 0 0 9px; }
.stepper button:last-child { border-radius: 0 9px 9px 0; }
.stepper input { width: 3.4rem; height: 2.6rem; text-align: center; font-size: 1.25rem; font-weight: 700; border: 1px solid var(--line); border-left: 0; border-right: 0; background: var(--card); -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.dec { background: var(--tie); border-radius: 9px; padding: .6rem .8rem; }
.dec label { display: flex; gap: .5rem; align-items: center; margin: .35rem 0; }
.acts-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1.1rem; }
.acts-row .grow { flex: 1; }
.err { color: var(--danger); font-size: .85rem; min-height: 1.2em; }

#toast { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom, 0)); transform: translateX(-50%); background: #1b2420; color: #fff; padding: .55rem 1rem; border-radius: 999px; font-size: .85rem; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 30; max-width: calc(100vw - 32px); text-align: center; }
#toast.on { opacity: 1; }
