:root {
  --bg: #0f2016;
  --bg2: #132a1e;
  --panel: #1a3728;
  --panel2: #204634;
  --line: #2c5a41;
  --ink: #eaf5ee;
  --muted: #9db9a9;
  --accent: #c8ff3c;      /* tennis-ball green-yellow */
  --check: #3ddc84;
  --x: #ff6b6b;
  --danger: #e5484d;
  --radius: 12px;
  --tap: 44px;            /* min touch target */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior-y: contain;
}
#app { max-width: 720px; margin: 0 auto; min-height: 100vh; }

/* Court background on the opening (home) screen. A dark gradient overlay keeps
   the buttons and history cards readable over the photo. Match/stat screens
   stay on solid dark for maximum legibility. */
body.screen-home {
  background:
    linear-gradient(180deg, rgba(15,32,22,0.72) 0%, rgba(15,32,22,0.86) 55%, rgba(15,32,22,0.96) 100%),
    url('../img/background.jpg') top center / cover no-repeat fixed;
}
body.screen-home .topbar { background: transparent; border-bottom-color: transparent; }
body.screen-home #app { background: transparent; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--bg2); position: sticky; top: 0; z-index: 10;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.05rem; margin: 0; flex: 1; text-align: center; }
.topbar .btn.ghost { min-width: 72px; }

.pad { padding: 12px; padding-bottom: calc(env(safe-area-inset-bottom) + 24px); }
h2 { font-size: 1rem; margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* Buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); border-radius: var(--radius); padding: 10px 14px;
  font-size: 0.95rem; min-height: var(--tap); cursor: pointer;
}
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.4; }
.btn.primary { background: var(--accent); color: #10240f; border-color: var(--accent); font-weight: 700; }
.btn.big { width: 100%; font-size: 1.1rem; padding: 16px; margin: 8px 0 16px; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; min-height: 36px; font-size: 0.85rem; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger.armed { background: var(--danger); color: #fff; font-weight: 700; }
.btn.undo { width: 100%; margin: 10px 0; background: var(--panel2); }

/* Home / history */
.history .card, #resume-slot .card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px; display: flex; justify-content: space-between; gap: 10px;
}
.card-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

/* Setup */
.setup .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.setup .field span { font-size: 0.85rem; color: var(--muted); }
.setup input[type="text"] {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); padding: 12px; font-size: 1rem; min-height: var(--tap);
}
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 14px; padding: 10px 12px 6px; }
legend { color: var(--muted); font-size: 0.85rem; padding: 0 4px; }
.radio { display: flex; align-items: center; gap: 8px; padding: 8px 0; min-height: var(--tap); }
.radio.sel span { color: var(--accent); font-weight: 600; }
.radio input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Scoreboard */
.scoreboard {
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; position: sticky; top: 54px; z-index: 5;
}
.score-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.score-row.winner .pname { color: var(--accent); }
.serve, .serve-sp { width: 14px; display: inline-block; text-align: center; color: var(--accent); }
.pname { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sets { display: flex; gap: 6px; }
.setcell { min-width: 20px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.setcell.live { color: var(--ink); font-weight: 700; }
.gamecell {
  min-width: 44px; text-align: center; font-weight: 800; font-size: 1.2rem;
  background: var(--panel); border-radius: 8px; padding: 2px 6px; font-variant-numeric: tabular-nums;
}
.gamecell.tb { color: var(--accent); }
.game-label { text-align: center; color: var(--accent); font-size: 0.85rem; margin-top: 4px; }
.final-banner {
  background: var(--accent); color: #10240f; border-radius: 8px; padding: 10px;
  text-align: center; font-weight: 700; margin-top: 8px;
}
.fmt { text-align: center; font-size: 0.75rem; margin-top: 6px; }

/* Player panels (point logging grid) */
.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
@media (max-width: 420px) { .panels { grid-template-columns: 1fr; } }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px;
}
.panel.serving { border-color: var(--accent); }
.panel-head {
  font-weight: 700; text-align: center; padding: 4px 0 8px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.pill { background: var(--accent); color: #10240f; font-size: 0.65rem; padding: 2px 6px; border-radius: 999px; vertical-align: middle; }
.grp { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 6px 2px 2px; }
.catrow { display: grid; grid-template-columns: 1fr auto auto; gap: 4px; align-items: center; margin-bottom: 4px; }
.catlabel { font-size: 0.8rem; line-height: 1.1; }
.mk {
  min-width: var(--tap); min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line);
  font-size: 1.1rem; font-weight: 800; cursor: pointer; background: var(--panel2); color: var(--ink);
}
.mk:active { transform: scale(0.94); }
.mk.check { color: var(--check); }
.mk.check:active { background: var(--check); color: #08240f; }
.mk.x { color: var(--x); }
.mk.x:active { background: var(--x); color: #2a0000; }
.mk.none { visibility: hidden; }
.mk[disabled] { opacity: 0.35; }

/* Notes */
.notes textarea {
  width: 100%; min-height: 64px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--ink); padding: 10px; font-size: 1rem; resize: vertical;
}
.note-actions { display: flex; gap: 8px; margin: 8px 0; }
.note-actions .btn { flex: 1; }
.note { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; }
.note .muted { font-size: 0.72rem; display: block; }

/* Stat sheet */
.statwrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); }
table.statsheet { border-collapse: collapse; width: 100%; min-width: 640px; font-size: 0.8rem; }
.statsheet th, .statsheet td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; vertical-align: top; }
.statsheet thead th { background: var(--bg2); position: sticky; top: 0; font-size: 0.72rem; }
.statsheet .rowh { text-align: left; background: var(--panel); white-space: nowrap; }
.seq { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; max-width: 120px; }
.mk-sm { font-size: 0.75rem; }
.mk-sm.check { color: var(--check); }
.mk-sm.x { color: var(--x); }
.sub { font-weight: 700; margin-top: 2px; }
.tot { background: var(--panel2); }
.score-line td { background: var(--bg2); text-align: left; font-size: 0.8rem; }
.pointlog { font-size: 0.85rem; padding-left: 18px; }
.pointlog li { margin-bottom: 3px; }
