:root {
  color-scheme: light;
  --ground: #f4f7f1;
  --surface: #ffffff;
  --surface-2: #e8f0e2;
  --ink: #13251a;
  --ink-soft: #4c6350;
  --ink-faint: #8a9c8d;
  --line: #e6ede1;
  --line-soft: #eef2ea;
  --accent: #1f6d3c;
  --accent-ink: #ffffff;
  --accent-wash: #e1f0e6;
  --accent-2: #b5842a;
  --accent-2-ink: #ffffff;
  --danger: #a8402a;
  --danger-wash: #f7e3dd;
  --bar-bg: rgba(244, 247, 241, 0.86);
  --shadow-1: 0 2px 10px rgba(20, 40, 25, 0.07);
  --shadow-2: 0 10px 26px rgba(31, 109, 60, 0.28);
  --radius-sm: 14px;
  --radius-md: 20px;
  --radius-lg: 26px;
  --tap: 52px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#app {
  max-width: 620px; margin: 0 auto;
  padding: 0 16px calc(64px + env(safe-area-inset-bottom));
}
svg { display: block; }

/* header */
.top {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 2px 14px; position: sticky; top: 0; z-index: 20;
  background: var(--bar-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--line);
  margin: 0 -16px; padding-left: 16px; padding-right: 16px;
}
.top h1 { font-size: 1.4rem; margin: 0; letter-spacing: -0.02em; flex: 1; font-weight: 800; text-wrap: balance; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back {
  border: 0; background: none; color: var(--accent); padding: 8px 4px 8px 0; font-size: 20px;
  cursor: pointer; min-height: 44px; display: flex; align-items: center;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 6px 10px 6px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-soft);
  white-space: nowrap;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.pill.queued { color: var(--accent-2); background: #f6ecd8; }
.pill.queued .dot { background: var(--accent-2); }
.pill.offline { color: var(--ink-faint); }
.pill.offline .dot { background: var(--ink-faint); }

/* forms */
input, select, textarea, button { font: inherit; }
.field { margin-top: 16px; }
.field label {
  display: block; font-size: 11.5px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 6px;
}
.field .hint { font-size: 13px; color: var(--ink-faint); margin-top: 6px; line-height: 1.4; }
.field input, .field select, .field textarea {
  width: 100%; padding: 13px 14px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); min-height: var(--tap);
}
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.team-code-row { display: flex; gap: 8px; }
.team-code-row input:first-child { flex: 1; }
.code-input {
  width: 76px !important; flex: 0 0 auto; text-align: center; text-transform: uppercase;
  letter-spacing: 0.04em; font-weight: 700;
}
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 650;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-2); }
.btn.wide { width: 100%; }
.btn.quiet { background: none; color: var(--accent); border-color: transparent; padding: 0 6px; }
.btn.danger { color: var(--danger); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }

/* groups as cards */
.group {
  margin-top: 22px; background: var(--surface); border-radius: var(--radius-md);
  box-shadow: var(--shadow-1); overflow: hidden;
}
.group-head {
  display: flex; align-items: center; gap: 10px; padding: 15px 16px 10px;
}
.group-head h2 { font-size: 1.02rem; margin: 0; flex: 1; font-weight: 700; letter-spacing: -0.01em; }

/* rows */
.row {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px;
  padding: 13px 16px; border-top: 1px solid var(--line-soft); min-height: var(--tap); cursor: pointer;
}
.group-head + .row, .group > .row:first-child { border-top: 0; }
.row-main { min-width: 0; }
.row-name {
  font-weight: 650; letter-spacing: -0.01em; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.row-meta { font-size: 12px; color: var(--ink-faint); margin-top: 5px; }
.count {
  font-variant-numeric: tabular-nums; font-size: 1.1rem;
  font-weight: 800; text-align: right; letter-spacing: -0.02em; color: var(--accent); white-space: nowrap;
}

/* misc */
.empty { color: var(--ink-faint); padding: 40px 20px; text-align: center; line-height: 1.55; }
.note {
  background: var(--accent-wash); border-left: 4px solid var(--accent);
  padding: 14px 16px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 14.5px; line-height: 1.5; margin-top: 18px;
  color: #204a2e;
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--ground); padding: 12px 18px; border-radius: 999px;
  font-size: 13.5px; display: flex; align-items: center; gap: 14px; z-index: 25;
  box-shadow: 0 10px 26px rgba(20, 40, 25, 0.35); max-width: calc(100vw - 28px);
}
.toast span { overflow-wrap: anywhere; white-space: pre-line; }
.fab {
  position: fixed; right: max(16px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  font-size: 1.9rem; line-height: 1; cursor: pointer; box-shadow: var(--shadow-2); z-index: 15;
  transition: transform 0.12s ease;
}
.fab:active { transform: scale(0.92); }
.icon-btn {
  border: 0; background: none; color: var(--ink-soft); font-size: 13px; font-weight: 700;
  min-height: 40px; min-width: 40px; cursor: pointer; border-radius: 999px; padding: 0 8px;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.danger { color: var(--danger); font-size: 20px; }

.log { list-style: none; padding: 0; margin: 4px 0 0; }
.log li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 13px; color: var(--ink); padding: 10px 16px; border-top: 1px solid var(--line-soft);
}
.log li:first-child { border-top: 0; }
.log .what { flex: 1; line-height: 1.4; white-space: pre-line; }
.log-actions { display: flex; gap: 0; flex-shrink: 0; }

/* scoreboard */
.scoreboard {
  margin-top: 18px; background: linear-gradient(160deg, #17402a, #0e2717);
  color: #f4ead3; border-radius: var(--radius-lg); padding: 20px 18px 18px;
  box-shadow: var(--shadow-2); text-align: center;
}
.score-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.side { flex: 1; min-width: 0; }
.side-name {
  font-size: 12.5px; font-weight: 700; letter-spacing: 0.02em; opacity: 0.85;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.side-score { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin-top: 2px; }
.clock { font-family: var(--mono); font-size: 1.05rem; font-weight: 700; opacity: 0.9; padding: 0 6px; white-space: nowrap; }
.venue { margin-top: 12px; font-size: 12.5px; opacity: 0.7; }

.status-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase; padding: 5px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-soft);
}
.status-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); }
.status-pill.live { background: #fde3de; color: #a8402a; }
.status-pill.live .dot { background: #e8543c; animation: pulse 1.4s ease-in-out infinite; }
.status-pill.break { background: #fbf1cf; color: #8a6a00; }
.status-pill.done { background: var(--surface-2); color: var(--ink-faint); }
.scoreboard .status-pill { background: rgba(255, 255, 255, 0.14); color: #f4ead3; }
.scoreboard .status-pill.live { background: rgba(232, 84, 60, 0.24); color: #ffcabe; }
.scoreboard .status-pill.break { background: rgba(255, 255, 255, 0.18); color: #f4ead3; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* event grid */
.event-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.event-btn {
  min-height: 64px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 700; font-size: 14px;
  box-shadow: var(--shadow-1); cursor: pointer;
}
.event-btn:active { transform: scale(0.96); }
.event-btn.yellow { background: #fff3c4; border-color: #e9c74a; color: #6b5200; }
.event-btn.red { background: #f8d9d1; border-color: #d97a63; color: #7a2a17; }

/* team + number picker */
.backdrop { position: fixed; inset: 0; background: rgba(15, 25, 20, 0.42); z-index: 30; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 76vh; overflow-y: auto; box-shadow: 0 -10px 30px rgba(20, 40, 25, 0.2);
}
.sheet-head { display: flex; align-items: center; gap: 4px; margin-bottom: 12px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 1.05rem; font-weight: 750; letter-spacing: -0.01em; }

.chip-row { display: flex; gap: 12px; }
.chip {
  flex: 1; min-height: 66px; border-radius: var(--radius-sm); border: 2px solid var(--accent);
  background: var(--accent-wash); color: var(--accent); font-weight: 800; font-size: 16px; cursor: pointer;
}
.chip.away { border-color: var(--accent-2); background: #f6ecd8; color: #8a641f; }

.player-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.player-btn {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface);
  font-weight: 650; font-size: 15px; cursor: pointer; text-align: left;
}
.player-btn:active { background: var(--surface-2); }
.pn {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent-2); color: var(--accent-2-ink);
  display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 800; flex-shrink: 0;
}
.manual-toggle { margin-top: 12px; }
.manual-toggle summary { font-size: 13px; color: var(--accent); font-weight: 650; cursor: pointer; padding: 8px 0; list-style: none; }
.manual-toggle summary::-webkit-details-marker { display: none; }

/* team sheet editor */
.player-row { display: grid; grid-template-columns: 56px 1fr 84px 40px; gap: 8px; align-items: center; margin-top: 10px; }
.player-row input {
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  min-height: 44px; width: 100%;
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
