:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --home: #2563eb;
  --away: #db2777;
  --live: #16a34a;
  --warn: #b45309;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #141c2f;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #243049;
    --accent: #60a5fa;
    --home: #3b82f6;
    --away: #ec4899;
    --live: #22c55e;
    --warn: #f59e0b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1rem; margin: 1.5rem 0 .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.muted { color: var(--muted); }
.center { text-align: center; padding: 2rem 1rem; }
.warn { color: var(--warn); font-weight: 600; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem max(16px, env(safe-area-inset-right)) .75rem max(16px, env(safe-area-inset-left));
  padding-top: max(.75rem, env(safe-area-inset-top));
  background: #0f172a; color: #fff;
  position: sticky; top: 0; z-index: 5;
}
.topbar .brand { font-weight: 800; text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; }
.topbar nav a { text-decoration: none; opacity: .85; font-size: .95rem; }

main {
  max-width: 960px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
body.modal-open { overflow: hidden; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.meta { color: var(--muted); font-size: .9rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; touch-action: manipulation;
}
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn:disabled { opacity: .4; cursor: default; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700;
  background: var(--border); color: var(--muted); }
.badge.live { background: var(--live); color: #fff; }
.badge.final { background: var(--text); color: var(--bg); }
.mini-score { font-variant-numeric: tabular-nums; font-weight: 700; }

/* Fixtures list */
.fixtures { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.fixture {
  display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem;
}
.fx-court { font-size: .8rem; color: var(--muted); }
.fx-teams { margin: .15rem 0 .35rem; }
.fx-actions { display: flex; gap: .5rem; }

/* Scorer */
.game-label { text-align: center; margin: .25rem 0 .75rem; font-size: 1.05rem; }
.game-row { display: flex; align-items: center; justify-content: center; gap: .5rem .75rem; flex-wrap: wrap; margin: .25rem 0 .75rem; }
.game-row .game-label { margin: 0; }
.swap-btn { padding: .35rem .7rem; font-size: .85rem; }
.court { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.panel {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
  min-height: 56vh; min-height: 56dvh; padding: 1rem .5rem; border: 0; border-radius: var(--radius);
  color: #fff; font: inherit; cursor: pointer; user-select: none; touch-action: manipulation;
  transition: transform .06s ease, filter .1s;
}
.panel.home { background: var(--home); }
.panel.away { background: var(--away); }
button.panel:active:not(:disabled) { transform: scale(.98); filter: brightness(1.1); }
.panel:disabled { cursor: default; opacity: .75; }
.panel.won { opacity: 1; outline: 4px solid #facc15; }
.panel .team { font-weight: 700; font-size: 1.2rem; text-align: center; }
.panel .score { font-size: clamp(5rem, 24vw, 10rem); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.panel .pair { font-size: 1.05rem; text-align: center; opacity: .95; }
.panel .game-pts { font-size: .9rem; opacity: .8; }
.panel .tap { font-size: .75rem; opacity: .7; text-transform: uppercase; letter-spacing: .08em; margin-top: .25rem; }
.court.big .panel { min-height: 40vh; min-height: 40dvh; cursor: default; }
.watch .court { margin-bottom: .9rem; }

.controls { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; margin: .9rem 0; }

.sync { font-size: .8rem; font-weight: 600; }
.sync.ok { color: var(--live); }
.sync.pending { color: var(--muted); }
.sync.error { color: var(--warn); }

table.games { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; font-size: .9rem; }
table.games th, table.games td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; }
table.games th { color: var(--muted); font-weight: 600; font-size: .8rem; }
table.games .num { text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.games .gno { width: 1.8rem; color: var(--muted); }
table.games .right { text-align: right; }
table.games .pair-cell { line-height: 1.35; }
table.games .cum { display: block; font-weight: 700; }
table.games .seg { display: block; font-size: .75rem; }
table.games tr.current { background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 600; }
table.games tr:not(.done):not(.current) { color: var(--muted); }

/* Lineup modal */
.modal {
  position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 16px;
}
.sheet { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 680px; padding: 1rem 1rem 0; }
.sheet h2 { margin: 0 0 .25rem; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.2rem; }
.sheet h3 { font-size: .85rem; color: var(--muted); margin: 1rem 0 .4rem; }
.sheet-head p { margin: 0 0 .75rem; font-size: .9rem; }
.lineups { display: grid; gap: .6rem; }
.lu-game {
  display: grid; grid-template-columns: 1fr 1fr; gap: .5rem;
  border: 1px solid var(--border); border-radius: 12px; padding: .5rem .6rem .6rem; margin: 0; min-width: 0;
}
.lu-game legend { font-weight: 700; font-size: .85rem; padding: 0 .3rem; }
.lu-side { display: grid; gap: .35rem; min-width: 0; padding-left: .5rem; border-left: 3px solid; }
.lu-side.home { border-color: var(--home); }
.lu-side.away { border-color: var(--away); }
.lu-team { font-size: .75rem; font-weight: 700; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lu-side select {
  width: 100%; min-width: 0; padding: .5rem .45rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  font: inherit; font-size: 16px; /* ≥16px stops iOS zooming on focus */
}
.lu-side select.bad { border-color: var(--warn); outline: 2px solid var(--warn); }
.counts { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.chip { display: inline-block; font-size: .72rem; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: .1rem .45rem; margin: .1rem; }
.sheet-actions {
  position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: .5rem;
  margin: 1rem -1rem 0; padding: .75rem 1rem max(.75rem, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
}

/* Board */
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .75rem; }
.card { display: block; text-decoration: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.card-head { display: flex; justify-content: space-between; color: var(--muted); font-size: .85rem; margin-bottom: .5rem; }
.card .row { display: flex; justify-content: space-between; align-items: baseline; padding: .2rem 0; font-size: 1.05rem; }
.card .row strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.card .row.won span { font-weight: 800; }
.bar { height: 4px; background: var(--border); border-radius: 2px; margin-top: .5rem; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }
.live-dot { color: var(--live); font-weight: 800; font-size: .8rem; letter-spacing: .1em; }
.live-dot::before { content: "● "; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.toast {
  position: fixed; left: 50%; bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px)); transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: .9rem; width: max-content;
  background: #0f172a; color: #fff; padding: .55rem .6rem .55rem 1.1rem; border-radius: 12px; max-width: calc(100% - 32px);
  box-shadow: 0 8px 24px rgba(0,0,0,.25); font-weight: 600;
}
.toast[hidden] { display: none; }
.toast span:only-child { padding-right: .5rem; }
.toast-action {
  flex: none; background: #facc15; color: #0f172a; border: 0; border-radius: 9px;
  font: inherit; font-weight: 800; padding: .5rem .9rem; cursor: pointer; touch-action: manipulation;
}

@media (max-width: 520px) {
  h1 { font-size: 1.2rem; }
  .topbar nav { gap: .8rem; font-size: .9rem; }
  .btn { padding: .5rem .8rem; }
  .fixture { flex-direction: column; align-items: stretch; }
  .fx-actions .btn { flex: 1; padding: .7rem; }

  .scorer .toolbar, .watch .toolbar { gap: .4rem; margin-bottom: .4rem; }
  .meta { font-size: .8rem; }
  .court { gap: .5rem; }
  .panel { min-height: 54vh; min-height: 54dvh; padding: .75rem .35rem; }
  .panel .team { font-size: 1.1rem; }
  .panel .pair { font-size: .95rem; }
  .game-row { margin: 0 0 .5rem; }
  .controls .btn { flex: 1; white-space: nowrap; padding-left: .4rem; padding-right: .4rem; }

  table.games { font-size: .8rem; }
  table.games th, table.games td { padding: .45rem .4rem; }

  /* Lineup editor goes full screen; home and away stack so names aren't cut off. */
  .modal { padding: 0; background: var(--surface); }
  .sheet { border-radius: 0; min-height: 100%; padding-top: max(1rem, env(safe-area-inset-top)); }
  .sheet-actions { border-radius: 0; }
  .sheet-actions .btn { flex: 1; padding: .75rem; }
  .lu-game { grid-template-columns: 1fr; }
  .counts { grid-template-columns: 1fr; }
}

/* Phone held sideways: keep the score panels on screen. */
@media (max-height: 500px) and (orientation: landscape) {
  .panel, .court.big .panel { min-height: 70vh; min-height: 70dvh; }
  .panel .score { font-size: clamp(3.5rem, 18vh, 7rem); }
  .game-label, .game-row { margin: 0 0 .4rem; }
}

/* Lineup warnings */
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.notice {
  background: var(--surface); border: 1px solid var(--warn); border-radius: var(--radius);
  padding: 1.5rem 1.25rem; text-align: center; margin-bottom: 1rem;
}
.notice-icon { font-size: 2rem; }
.notice h2 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.2rem; margin: .4rem 0 .6rem; }
.notice p { margin: 0 0 .6rem; line-height: 1.45; }
.notice-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin: 1rem 0 .5rem; }
.linkish { background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; font-size: .85rem; cursor: pointer; padding: .5rem; }
.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem;
  border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--surface));
  border-radius: 12px; padding: .6rem .75rem; margin-bottom: .6rem; font-size: .9rem;
}
.banner.urgent { border-width: 2px; }
.banner-actions { display: flex; gap: .4rem; }
.banner-actions .btn { padding: .4rem .7rem; font-size: .85rem; }
.hint { color: var(--warn); font-size: .85rem; margin: .4rem 0 0; }
#lineup-error:empty { display: none; }

@media (max-width: 520px) {
  .notice-actions .btn { flex: 1 1 100%; padding: .75rem; }
  .banner-actions { width: 100%; }
  .banner-actions .btn { flex: 1; }
}

/* Sign in */
.topbar nav { align-items: center; }
.who-btn { background: none; border: 0; color: inherit; font: inherit; opacity: .85; cursor: pointer; padding: 0; }
.login { max-width: 380px; margin: 1.5rem auto; display: grid; gap: .8rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.login p { margin: 0; }
.login label { display: grid; gap: .3rem; font-weight: 600; font-size: .9rem; }
.login input { font: inherit; font-size: 16px; padding: .65rem .7rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.login .btn { padding: .75rem; }
#login-error:empty { display: none; }
.sync.auth { color: var(--warn); }

@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; row-gap: .3rem; }
  .topbar nav { gap: .7rem; font-size: .85rem; flex-wrap: wrap; }
}
.team-status { list-style: none; padding: 0; margin: .25rem auto .8rem; display: inline-grid; gap: .35rem; text-align: left; }
.team-status .ok { color: var(--live); }
.team-status .bad { color: var(--warn); }
.team-status strong { color: var(--text); }

/* Refresh icon */
.icon-btn { gap: .4rem; }
.icon { width: 1.05em; height: 1.05em; flex: none; }
.spinning .icon { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinning .icon { animation-duration: 2.4s; } }

/* Between-games popup */
.popup {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.popup-card {
  background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 420px;
  padding: 1.25rem; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.popup-card h2 { margin: .1rem 0 1rem; font-size: 1.4rem; }
.ng-done { margin: 0; font-size: .9rem; }
.ng-teams { display: grid; gap: .5rem; }
.ng-team { border-radius: 12px; padding: .7rem .8rem; color: #fff; display: grid; gap: .2rem; }
.ng-team.home { background: var(--home); }
.ng-team.away { background: var(--away); }
.ng-name { font-weight: 700; font-size: .95rem; opacity: .9; }
.ng-players { font-size: 1.25rem; font-weight: 800; line-height: 1.3; }
.ng-vs { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.popup-actions { display: flex; gap: .5rem; margin-top: 1.1rem; }
.popup-actions .btn { flex: 1; padding: .8rem; font-size: 1rem; }

/* Bonus points */
.panel .bonus-tag { font-size: .8rem; font-weight: 700; background: rgba(255,255,255,.22); border-radius: 999px; padding: .15rem .55rem; }
.bonus-mini { font-size: .72rem; font-weight: 700; color: var(--accent); }
.bonus-rows { display: grid; gap: .6rem; margin: 1rem 0 .25rem; text-align: left; }
.bonus-row { display: grid; gap: .3rem; padding-left: .6rem; border-left: 4px solid; font-weight: 700; }
.bonus-row.home { border-color: var(--home); }
.bonus-row.away { border-color: var(--away); }
.bonus-row select { font: inherit; font-size: 16px; font-weight: 400; padding: .55rem .5rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text, inherit); }
.bonus-err { color: var(--warn); font-size: .85rem; margin: .5rem 0 0; }
