/* Palette and shapes follow tennis.ntnui.no: deep green, off-white, yellow accent, Public Sans, pills. */
:root {
  --bg: #081800;
  --surface: #0c1e04;
  --surface-2: #17290f;
  --text: #f0e8dd;
  --muted: #a6a294;
  --border: rgba(240, 232, 221, 0.12);
  --border-strong: rgba(240, 232, 221, 0.25);
  --accent: #ffea6f;
  --accent-strong: #ffea6f;
  --accent-soft: rgba(255, 234, 111, 0.14);
  --on-accent: #081800;
  --green: #5fca92;
  --green-soft: rgba(95, 202, 146, 0.16);
  --danger: #f65155;
  --danger-soft: rgba(246, 81, 85, 0.16);
  --warn: #ffea6f;
  --info: #60a5fa;
  --info-soft: rgba(30, 58, 138, 0.55);
  --gold: #e5b92e;
  --silver: #9aa5ad;
  --bronze: #b0703a;
  --radius: 16px;
  --font: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(95, 202, 146, 0.1), transparent 70%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--text); text-underline-offset: 3px; transition: color 0.2s; }
a:hover { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- top bar (floating pill like NTNUI) ---------- */
.topbar {
  position: sticky; top: max(10px, env(safe-area-inset-top)); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  max-width: 1100px; margin: 10px auto 0; padding: 6px 8px 6px 14px;
  width: calc(100% - 32px);
  background: rgba(8, 24, 0, 0.6); backdrop-filter: blur(16px) saturate(1.25); -webkit-backdrop-filter: blur(16px) saturate(1.25);
  border: 2px solid var(--border); border-radius: 48px;
  box-shadow: inset 0 0 30px rgba(95, 202, 146, 0.05);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--accent); }
.topbar-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.topbar-actions button, .topbar-actions .btn { border-color: transparent; background: transparent; }
.topbar-actions button:hover, .topbar-actions .btn:hover { color: var(--accent); background: transparent; border-color: transparent; }

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

/* ---------- building blocks ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px;
}
@media (min-width: 860px) { .card { padding: 24px; } }
.card > h2:first-child { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 16px; }
@media (min-width: 860px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3-2 { grid-template-columns: 3fr 2fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.spacer { flex: 1; }

button, .btn {
  font: inherit; font-weight: 500; cursor: pointer;
  border: 2px solid var(--border-strong); background: transparent; color: var(--text);
  border-radius: 999px; padding: 6px 16px; min-height: 38px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
  transition: color 0.2s, background-color 0.2s, border-color 0.2s;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:disabled:hover { border-color: var(--border-strong); color: var(--text); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.primary:hover { background: #fff3a8; border-color: #fff3a8; color: var(--on-accent); }
.danger { color: var(--danger); }
.danger:hover { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.ghost { background: transparent; border-color: transparent; }
.ghost:hover { background: var(--surface-2); border-color: transparent; }
.big { font-size: 1.05rem; padding: 10px 22px; min-height: 48px; white-space: nowrap; }
.icon-btn { padding: 4px 8px; min-height: 32px; min-width: 32px; }
.btn-group { display: inline-flex; gap: 4px; padding: 3px; border: 1px solid var(--border); border-radius: 999px; flex-wrap: wrap; }
.btn-group button { border: 0; min-height: 32px; padding: 4px 14px; }
.btn-group button:hover { background: var(--surface-2); }
.btn-group button.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }

input[type='text'], input[type='number'], input[type='date'], input[type='search'], select, textarea {
  font: inherit; color: var(--text); background: rgba(240, 232, 221, 0.04);
  border: 1px solid var(--border-strong); border-radius: 12px; padding: 8px 12px; min-height: 40px; width: 100%;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }
select option { background: var(--surface); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 120px; resize: vertical; }
label.field { display: block; }
label.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--green); }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }

.badge { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.accent { background: var(--green-soft); color: var(--green); border-color: rgba(95, 202, 146, 0.4); }
.badge.warn { background: var(--accent-soft); color: var(--accent); border-color: rgba(255, 234, 111, 0.4); }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li input[type='text'] { flex: 1; min-height: 34px; padding: 4px 10px; }
.list li.inactive .name, .list li.inactive input { opacity: 0.5; text-decoration: line-through; }
.num { width: 26px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }

.ntnui-list { columns: 2 200px; column-gap: 16px; margin: 8px 0; }
.ntnui-list label { display: flex; gap: 8px; align-items: center; padding: 3px 0; break-inside: avoid; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 18px; padding-bottom: 2px; scrollbar-width: none; }
.tabs button { border: 2px solid var(--border); background: transparent; padding: 6px 16px; color: var(--muted); white-space: nowrap; }
.tabs button:hover { color: var(--accent); border-color: rgba(255, 234, 111, 0.5); }
.tabs button.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---------- matches ---------- */
.matches { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); }
.match { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.match.done { border-color: rgba(95, 202, 146, 0.55); }
.match-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--border); background: rgba(240, 232, 221, 0.03); font-weight: 600; font-size: 0.9rem; }
.match-body { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px 10px; padding: 14px; }
.side { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.side.win .pname { font-weight: 700; }
.pname {
  border: 0; background: none; padding: 2px 6px; margin: 0 -6px; min-height: 0; border-radius: 8px;
  font-weight: 400; text-align: left; justify-content: flex-start; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; max-width: 100%;
}
.pname:hover { background: var(--surface-2); color: var(--accent); }
.vs { grid-column: 1 / -1; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.score {
  width: 64px; height: 48px; font-size: 1.4rem; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums;
  border-radius: 14px; border: 1px solid var(--border-strong); background: rgba(240, 232, 221, 0.05); color: var(--text); padding: 0;
}
button.score:hover { border-color: var(--accent); color: var(--accent); }
input.score { -moz-appearance: textfield; }
input.score::-webkit-inner-spin-button { display: none; }
.score.empty { color: var(--muted); font-weight: 400; }
.side.win + .score, .score.win { background: var(--green-soft); border-color: var(--green); color: var(--green); }

/* Court seen from above: net down the middle, service lines and the centre line on each half. */
.court-card { border: 0; background: none; }
.court-view {
  --line: rgba(255, 255, 255, 0.5);
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch; gap: 8px;
  min-height: 150px; padding: 34px 10px 12px; border-radius: var(--radius);
  background:
    linear-gradient(to right, transparent calc(50% - 1.5px), rgba(255, 255, 255, 0.85) calc(50% - 1.5px), rgba(255, 255, 255, 0.85) calc(50% + 1.5px), transparent calc(50% + 1.5px)),
    linear-gradient(to right, transparent calc(22% - 0.5px), var(--line) calc(22% - 0.5px), var(--line) calc(22% + 0.5px), transparent calc(22% + 0.5px)),
    linear-gradient(to right, transparent calc(78% - 0.5px), var(--line) calc(78% - 0.5px), var(--line) calc(78% + 0.5px), transparent calc(78% + 0.5px)),
    linear-gradient(160deg, var(--c1, #2f6fe0), var(--c2, #1d4fb8));
  box-shadow: inset 0 0 0 6px var(--c2, #1d4fb8), inset 0 0 0 8px var(--line);
}
.court-view::before { /* centre service line, between the service lines */
  content: ''; position: absolute; left: 22%; right: 22%; top: 50%; height: 1px; background: var(--line);
}
.court-card.done .court-view { box-shadow: inset 0 0 0 6px var(--c2, #1d4fb8), inset 0 0 0 8px var(--line), 0 0 0 2px var(--green); }
.court-tag {
  position: absolute; top: 9px; left: 50%; transform: translateX(-50%); z-index: 1; max-width: calc(100% - 24px);
  padding: 1px 10px; border-radius: 99px; background: rgba(8, 24, 0, 0.55); color: #fff; font-size: 0.78rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.court-view .side { position: relative; z-index: 1; justify-content: space-between; align-items: flex-start; gap: 8px; }
.court-view .side-b { align-items: flex-end; }
.court-view .side .pname, .court-view .side span.pname {
  margin: 0; padding: 3px 9px; border-radius: 99px; background: rgba(8, 24, 0, 0.55); color: #fff; font-weight: 600; max-width: 100%;
}
.court-view .side .pname:hover { background: rgba(8, 24, 0, 0.8); color: var(--accent); }
.court-view .side.win .pname { background: var(--green); color: #081800; }
.court-scores { position: relative; z-index: 1; display: flex; gap: 8px; align-self: center; }
.court-view .score { width: 50px; height: 50px; background: rgba(8, 24, 0, 0.45); border-color: rgba(255, 255, 255, 0.35); color: #fff; }
.court-view .score.empty { color: rgba(255, 255, 255, 0.6); }
.court-view .score.win { background: var(--green); border-color: var(--green); color: #081800; }
.court-view button.score:hover { border-color: var(--accent); color: var(--accent); }
@media (max-width: 380px) { .court-view { gap: 4px; padding-inline: 8px; } .court-view .score { width: 48px; height: 46px; font-size: 1.2rem; } .court-scores { gap: 6px; } }

.list li:has(.swatches) { flex-wrap: wrap; row-gap: 4px; }
.swatches { display: flex; gap: 6px; order: 10; flex-basis: 100%; padding-left: 28px; }
.swatch { width: 22px; height: 22px; min-height: 0; padding: 0; border-radius: 6px; border: 2px solid transparent; }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg) inset; }
.cdot { display: inline-block; width: 0.7em; height: 0.7em; border-radius: 3px; margin-right: 6px; vertical-align: 0.05em; }
.resting { margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 12px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.9rem; }
button.chip { min-height: 0; font-weight: 400; }

.round-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.round-title { font-size: 1.4rem; font-weight: 800; }
.actions-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }

/* ---------- timer ---------- */
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.3rem; padding: 4px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); }
.timer.over { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 0.75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; position: sticky; top: 0; background: var(--surface); }
th.sorted, td.sorted { color: var(--accent); font-weight: 700; }
td.left, th.left { text-align: left; }
td.player { text-align: left; font-weight: 500; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
tr.inactive td { opacity: 0.5; }
.pos { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-weight: 700; font-size: 0.85rem; background: var(--surface-2); }
.pos.p1 { background: var(--gold); color: var(--on-accent); }
.pos.p2 { background: var(--silver); color: var(--on-accent); }
.pos.p3 { background: var(--bronze); color: var(--on-accent); }

/* ---------- points grid (imported results) ---------- */
.round-pills { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 12px; }
.round-pills button { min-width: 40px; padding: 4px 10px; }
.round-pills button.on { color: var(--on-accent); border-color: var(--accent); background: var(--accent); font-weight: 700; }
.grid-table td, .grid-table th { padding: 7px 6px; }
.grid-table .g-win { color: var(--green); font-weight: 700; }
.grid-table .g-loss { color: var(--muted); }
.grid-table .g-rest, .g-key.g-rest { color: var(--muted); font-style: italic; }
.grid-table td.g-rest { background: var(--surface-2); }
.g-key { font-weight: 600; margin-right: 6px; }
.g-key.g-win { color: var(--green); }
.g-key.g-loss { color: var(--muted); }

/* ---------- history ---------- */
.hist-round { margin-bottom: 14px; }
.hist-match { display: grid; grid-template-columns: 90px 1fr auto auto auto 1fr; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.hist-match .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-match .t.r { text-align: right; }
.hist-match input { width: 56px; text-align: center; padding: 4px; min-height: 34px; }
.bulk-scores .hist-match { grid-template-columns: minmax(0, 1fr) auto auto auto minmax(0, 1fr); row-gap: 2px; }
.bulk-scores .hist-match .court { grid-column: 1 / -1; }
.bulk-scores .hist-match .t.r { text-align: right; }
.bulk-scores .hist-match .t:last-child { grid-column: auto; }
@media (max-width: 600px) {
  .hist-match { grid-template-columns: 1fr auto auto auto; }
  .hist-match .court { grid-column: 1 / -1; }
  .hist-match .t.r { text-align: left; }
  .hist-match .t:last-child { grid-column: 1 / -1; }
}

/* ---------- podium ---------- */
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 16px 0 24px; }
.podium .step { text-align: center; width: 30%; max-width: 200px; }
.podium .block { border-radius: 14px 14px 0 0; display: grid; place-items: center; font-size: 2rem; font-weight: 900; color: var(--on-accent); }
.podium .p1 .block { height: 130px; background: var(--accent); }
.podium .p2 .block { height: 95px; background: var(--silver); }
.podium .p3 .block { height: 70px; background: var(--bronze); }
.podium .who { font-weight: 700; margin-bottom: 6px; overflow-wrap: anywhere; }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--border-strong); border-radius: 24px; padding: 0; background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), inset 0 0 30px rgba(95, 202, 146, 0.05); }
dialog::backdrop { background: rgba(4, 12, 0, 0.7); backdrop-filter: blur(4px); }
#dialog-body { padding: 22px; }
#dialog-body h2 { margin-bottom: 12px; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px; margin: 10px 0; }
.picker button { font-size: 1.1rem; min-height: 48px; padding: 0; border-radius: 14px; }
.picker button.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.picker-preview { text-align: center; font-size: 1.1rem; margin: 6px 0; }
.picker-type { justify-content: center; margin: 8px 0 4px; }
.picker-type input { width: 90px; text-align: center; font-size: 1.2rem; }
.picker-result { min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.sub-list button { width: 100%; justify-content: space-between; margin-bottom: 6px; border-radius: 14px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none; transition: 0.2s; z-index: 100; max-width: calc(100vw - 32px); display: flex; gap: 12px; align-items: center; font-weight: 500; }
.toast.show { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.toast button { background: transparent; color: var(--bg); border: 0; min-height: 0; padding: 0; font-weight: 700; text-decoration: underline; }

/* ---------- home ---------- */
.t-item { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.t-item:last-child { border-bottom: 0; }
.t-item a { font-weight: 600; text-decoration: none; }
.hero { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.notice { padding: 12px 16px; border-radius: 20px; border: 1px solid var(--info); background: var(--info-soft); color: var(--info); margin: 8px 0; }
.notice.warn { border-color: var(--accent); background: rgba(255, 234, 111, 0.1); color: var(--accent); }
.err { color: var(--danger); }

/* ---------- display / live mode ---------- */
.qr-wrap { display: flex; justify-content: center; margin: 8px 0 12px; }
.qr { display: block; border-radius: 12px; max-width: 100%; height: auto; }
.screen-qr { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; padding: 14px; }
.screen-qr .qr { flex: none; width: 130px; }
.screen-qr p { margin: 4px 0 0; }
body.display .topbar { display: none; }
body.display main { max-width: none; padding: 20px 28px; }
.display-wrap { display: grid; gap: 24px; grid-template-columns: 1fr; }
@media (min-width: 1100px) { .display-wrap { grid-template-columns: 2fr 1fr; } }
.display-wrap .match-body { font-size: 1.35rem; }
.display-wrap .score { width: 84px; height: 64px; font-size: 2rem; }
.display-wrap .court-view { min-height: 190px; padding-top: 46px; font-size: 1.3rem; }
.display-wrap .court-tag { font-size: 1rem; }
.display-wrap .round-title { font-size: 2.2rem; }
.display-wrap table { font-size: 1.1rem; }
.display-wrap .matches { grid-template-columns: repeat(auto-fill, minmax(min(360px, 100%), 1fr)); }
.display-wrap > * { min-width: 0; }
@media (max-width: 700px) {
  body.display main { padding: 56px 16px 12px; }
  .display-wrap .round-title { font-size: 1.4rem; }
  .display-wrap .match-body { font-size: 1.05rem; }
  .display-wrap .score { width: 60px; height: 48px; font-size: 1.4rem; }
  .display-wrap .court-view { min-height: 150px; font-size: 1rem; }
  .display-wrap table { font-size: 0.95rem; }
}
/* TV: courts and standings sized to fill one screen, no scrolling. */
body.display main:has(.tv-wrap) { padding: 14px 20px; }
.tv-wrap { display: grid; grid-template-columns: minmax(0, 1fr) clamp(220px, 21vw, 340px); gap: 16px; height: calc(100vh - 28px); }
.tv-main { display: flex; flex-direction: column; gap: 10px; min-height: 0; min-width: 0; }
.tv-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tv-head .round-title { font-size: clamp(1.2rem, 2vw, 2.3rem); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-head button { flex: none; font-size: clamp(0.85rem, 0.95vw, 1.2rem); }
.tv-head .spacer { flex: 1; }
.tv-courts { flex: 1; min-height: 0; display: flex; flex-wrap: wrap; justify-content: center; align-content: stretch; gap: 14px; }
.tv-court {
  display: flex; flex-direction: column; min-width: 0;
  width: calc((100% - (var(--cols) - 1) * 14px) / var(--cols)); height: calc((100% - (var(--rows) - 1) * 14px) / var(--rows));
}
.tv-court-name { font-size: clamp(0.9rem, 1.3vw, 1.6rem); font-weight: 700; text-align: center; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tv-court .court-card { flex: 1; min-height: 0; display: flex; }
/* One name in each corner, each with half the court's width; the scores in the middle, either side of the net. */
.tv-court .court-view { flex: 1; min-height: 0; grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr auto; column-gap: 14px; font-size: clamp(0.95rem, 1.35vw, 1.7rem); }
.tv-court .court-view .side { display: contents; }
.tv-court .court-view .pname { position: relative; z-index: 1; align-self: start; justify-self: start; }
.tv-court .side-a .pname:nth-child(1) { grid-area: 1 / 1; }
.tv-court .side-a .pname:nth-child(2) { grid-area: 3 / 1; align-self: end; }
.tv-court .side-b .pname:nth-child(1) { grid-area: 1 / 2; justify-self: end; }
.tv-court .side-b .pname:nth-child(2) { grid-area: 3 / 2; justify-self: end; align-self: end; }
.tv-court .court-scores { grid-area: 2 / 1 / 3 / 3; justify-self: center; gap: 14px; }
.tv-court .score { width: clamp(44px, 3.8vw, 88px); height: clamp(40px, 3.6vw, 76px); font-size: clamp(1.2rem, 2vw, 2.4rem); }
.court-view.no-tag { padding-top: 12px; }
.rk { display: inline-block; min-width: 1.3em; margin-right: 5px; padding: 0 4px; border-radius: 6px; background: rgba(255, 255, 255, 0.18); font-size: 0.8em; text-align: center; font-variant-numeric: tabular-nums; }
.tv-rest { font-size: clamp(0.95rem, 1.3vw, 1.4rem); }
.tv-rest b { color: var(--accent); font-weight: 600; }
.tv-wait { font-size: 1.6rem; }
.tv-keys { text-align: right; }
@media (pointer: coarse) { .tv-keys { display: none; } }
.tv-side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.tv-side .card { margin: 0; }
.tv-qr { display: flex; gap: 12px; align-items: center; padding: 12px; }
.tv-qr .qr { flex: none; width: 96px; }
.tv-qr p { margin: 2px 0 0; }
.tv-standings { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 14px 16px; }
.tv-standings h2 { margin: 0 0 6px; }
.tv-standings ol {
  list-style: none; margin: 0; padding: 0; flex: 1; min-height: 0; display: grid; grid-template-rows: repeat(var(--n), minmax(0, 1fr));
  font-size: clamp(0.7rem, calc((100vh - 300px) / var(--n) * 0.55), 1.3rem);
}
.tv-standings li { display: grid; grid-template-columns: 2.2em minmax(0, 1fr) auto; gap: 6px; align-items: center; border-bottom: 1px solid var(--border); min-height: 0; }
.tv-standings li:last-child { border-bottom: 0; }
.tv-standings .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-standings b { color: var(--accent); font-variant-numeric: tabular-nums; }
.tv-standings li.inactive { opacity: 0.5; }
.tv-standings .pos { width: 1.6em; height: 1.6em; font-size: 0.8em; }
/* Narrow windows: stack and scroll like a normal page. */
@media (max-width: 800px) {
  .tv-wrap { grid-template-columns: 1fr; height: auto; }
  .tv-courts { display: grid; grid-template-columns: 1fr; }
  .tv-court { width: auto; height: auto; }
  .tv-court .court-view { min-height: 150px; }
  .tv-court .court-view .score { width: 50px; height: 50px; font-size: 1.4rem; }
  .tv-standings ol { display: block; font-size: 1rem; }
  .tv-standings li { padding: 6px 0; }
}

@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f2f2f2; --text: #000; --muted: #555; --border: #ccc; --border-strong: #999; --accent: #000; --green: #000; color-scheme: light; }
  .topbar, .tabs, .actions-bar, button { display: none !important; }
  body { background: #fff; }
  .card { border: 0; }
}

@media (max-width: 600px) {
  .brand span, .topbar .lbl { display: none; }
  .topbar { width: calc(100% - 24px); padding: 4px 6px 4px 10px; }
  main { padding: 14px 12px; }
  h1 { font-size: 1.3rem; }
  .card { padding: 16px; }
  .actions-bar .big { flex: 1 1 140px; }
  .actions-bar button:not(.big) { flex: 1 1 auto; }
}

/* ---------- tour ---------- */
.tour-results { font-variant-numeric: tabular-nums; letter-spacing: 0.02em; color: var(--muted); }
.tour-results span { display: inline-block; min-width: 1.4em; text-align: center; color: var(--text); }
.tour-results .tour-win { color: var(--accent); font-weight: 700; }
.tour-results .muted { color: var(--muted); }
@media (max-width: 600px) { .tour-table .opt { display: none; } }
.tour-results a { display: inline-block; min-width: 1.4em; text-align: center; text-decoration: none; color: var(--text); }
.tour-results a.tour-win { color: var(--accent); font-weight: 700; }
a.plink { text-decoration: none; color: inherit; }
a.plink:hover { color: var(--accent); text-decoration: underline; }
.delta { font-size: 0.75rem; font-weight: 600; }
.delta.up { color: var(--green); }
.delta.down { color: var(--danger); }

/* ---------- week & player pages ---------- */
.week-nav { margin-bottom: 12px; }
.week-nav .btn, .week-nav button { min-height: 34px; }
.week-top { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.week-top-item { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); }
.hist-match .win { font-weight: 700; }
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.tile { border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; background: rgba(240, 232, 221, 0.03); }
.tile-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.tile-value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; }
.tile-sub { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.form-row { display: flex; gap: 4px; flex-wrap: wrap; }
.form { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; font-size: 0.75rem; font-weight: 700; border: 1px solid var(--border); }
.form.W { background: var(--green-soft); color: var(--green); border-color: rgba(95, 202, 146, 0.5); }
.form.L { background: var(--danger-soft); color: var(--danger); border-color: rgba(246, 81, 85, 0.4); }
.form.D { color: var(--muted); }
.chart-wrap { position: relative; overflow: hidden; }
.chart { display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .base { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.6; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--border-strong); stroke-width: 1; }
.chart-tip { position: absolute; transform: translateX(-50%); pointer-events: none; background: var(--text); color: var(--bg); font-size: 0.8rem; padding: 6px 10px; border-radius: 10px; white-space: nowrap; text-align: center; line-height: 1.3; }
@media (max-width: 600px) { table .opt { display: none; } }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(246, 81, 85, 0.45); }
.icon-btn.on-danger { background: var(--danger-soft); }
.notice a { color: inherit; }

/* ---------- help page ---------- */
.topbar > .btn.ghost { border-color: transparent; background: transparent; }
.topbar > .btn.ghost:hover { color: var(--accent); }
.topbar-cta { min-height: 0; padding: 6px 16px; border-radius: 99px; }
.help { max-width: 820px; }
.help h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); line-height: 1.2; margin: 8px 0 12px; }
.help .lead { font-size: 1.1rem; }
.help section { scroll-margin-top: 90px; }
.help li { margin: 6px 0; }
.help .toc ol { margin: 8px 0 0; padding-left: 22px; columns: 2 220px; }
.help .keys { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.help details { border-top: 1px solid var(--border); padding: 10px 0; }
.help details:first-of-type { border-top: 0; }
.help summary { cursor: pointer; font-weight: 600; }
.help details p { margin: 8px 0 0; color: var(--muted); }
kbd { display: inline-block; min-width: 1.6em; padding: 1px 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; font: 600 0.85em var(--font); text-align: center; background: var(--surface-2); }
