:root {
  --green: #1a5c2e;
  --green-dark: #0d3d1e;
  --gold: #f4c842;
  --gold-dark: #c9a200;
  --bg: #111;
  --card: #1e1e1e;
  --text: #f0f0f0;
  --muted: #888;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }

/* ── Setup ── */
#setup-screen {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px 20px;
  background: linear-gradient(160deg, #0d3d1e 0%, #111 60%);
  overflow-y: auto;
}
.setup-logo { font-size: 3rem; margin-bottom: 8px; }
.setup-title { font-size: 1.5rem; font-weight: 800; color: var(--gold); margin-bottom: 4px; }
.setup-sub { font-size: 0.85rem; color: var(--muted); margin-bottom: 28px; }
.setup-card { background: #1e1e1e; border-radius: 20px; padding: 24px 20px; width: 100%; max-width: 420px; box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
.setup-card label { display: block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin-bottom: 5px; margin-top: 14px; }
.setup-card label:first-child { margin-top: 0; }
.setup-card input { width: 100%; background: #2a2a2a; border: 1.5px solid #333; border-radius: 10px; padding: 12px 14px; font-size: 1rem; color: var(--text); outline: none; -webkit-appearance: none; appearance: none; }
.setup-card input:focus { border-color: var(--gold); }
.btn-start { width: 100%; margin-top: 22px; background: var(--gold); color: var(--green-dark); border: none; border-radius: 12px; padding: 16px; font-size: 1.05rem; font-weight: 800; cursor: pointer; transition: background 0.15s, transform 0.1s; }
.btn-start:active { transform: scale(0.97); }

/* ── Record screen layout ── */
#record-screen { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }

/* ── Header ── */
.game-header { background: linear-gradient(90deg, var(--green-dark) 0%, #1a5c2e 100%); }
.header-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px 8px; }

.live-badge { display: flex; align-items: center; gap: 6px; font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; color: #ff6b6b; flex-shrink: 0; }
.live-dot { width: 8px; height: 8px; background: #ff6b6b; border-radius: 50%; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity:1; transform:scale(1); } 50% { opacity:0.4; transform:scale(0.7); } }

/* Scoreboard */
.scoreboard { flex: 1; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4px; min-width: 0; padding: 0 4px; }
.sb-team { display: flex; flex-direction: column; align-items: flex-end; min-width: 0; }
.sb-right { align-items: flex-start; }
.sb-name { font-size: 0.6rem; font-weight: 700; color: rgba(255,255,255,0.6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; text-transform: uppercase; letter-spacing: 0.3px; }
.sb-score { font-size: 1.05rem; font-weight: 900; letter-spacing: 0.5px; line-height: 1.15; }
.sb-score.us   { color: var(--gold); }
.sb-score.them { color: rgba(255,255,255,0.85); }
.sb-sep { font-size: 0.6rem; font-weight: 700; color: rgba(255,255,255,0.35); text-align: center; flex-shrink: 0; }

.btn-finish { background: rgba(255,255,255,0.12); color: white; border: 1px solid rgba(255,255,255,0.25); border-radius: 8px; padding: 7px 13px; font-size: 0.75rem; font-weight: 700; cursor: pointer; flex-shrink: 0; transition: background 0.15s, transform 0.1s; }
.btn-finish:active { transform: scale(0.95); background: rgba(255,255,255,0.2); }

/* Quarter progress bar */
.quarter-bar { display: flex; align-items: center; padding: 6px 14px 8px; gap: 0; }
.q-pip {
  font-size: 0.65rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px;
  color: rgba(255,255,255,0.3); background: rgba(255,255,255,0.08);
  border-radius: 20px; padding: 3px 9px; flex-shrink: 0;
  transition: all 0.3s;
}
.q-pip.active { color: var(--gold); background: rgba(244,200,66,0.2); }
.q-pip.done { color: #4ade80; background: rgba(74,222,128,0.15); }
.q-line { flex: 1; height: 1px; background: rgba(255,255,255,0.15); margin: 0 4px; }
.q-scores { margin-left: 10px; display: flex; gap: 8px; overflow: hidden; }
.q-score-chip { font-size: 0.62rem; font-weight: 700; color: #4ade80; white-space: nowrap; }

/* ── Stats grid ── */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; overflow: hidden; }
.stat-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: var(--radius); border: none; cursor: pointer; transition: transform 0.08s, filter 0.08s; min-height: 0; padding: 8px 4px; user-select: none; -webkit-user-select: none; }
.stat-btn:active { transform: scale(0.93); filter: brightness(1.15); }
.stat-btn.flash { animation: btnflash 0.2s ease; }
@keyframes btnflash { 0% { transform:scale(1); } 40% { transform:scale(0.88); filter:brightness(1.3); } 100% { transform:scale(1); } }

.stat-btn[data-stat="goals"]     { background: linear-gradient(145deg,#c9a200,#f4c842); color:#1a1a00; }
.stat-btn[data-stat="behinds"]   { background: linear-gradient(145deg,#78716c,#a8a29e); color:#fff; }
.stat-btn[data-stat="kicks"]     { background: linear-gradient(145deg,#1d4ed8,#3b82f6); color:#fff; }
.stat-btn[data-stat="handballs"] { background: linear-gradient(145deg,#6d28d9,#8b5cf6); color:#fff; }
.stat-btn[data-stat="marks"]     { background: linear-gradient(145deg,#065f46,#10b981); color:#fff; }
.stat-btn[data-stat="tackles"]   { background: linear-gradient(145deg,#991b1b,#ef4444); color:#fff; }
.stat-btn[data-stat="smothers"]  { background: linear-gradient(145deg,#c2410c,#f97316); color:#fff; }
.stat-btn[data-stat="hitouts"]   { background: linear-gradient(145deg,#0e7490,#06b6d4); color:#fff; }

.stat-name { font-size: 0.62rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.8px; opacity: 0.85; margin-bottom: 2px; }
.stat-count { font-size: 2.8rem; font-weight: 900; line-height: 1; }
.stat-plus { font-size: 0.9rem; opacity: 0.7; margin-top: 1px; }

/* ── Footer ── */
.game-footer { padding: 8px; display: grid; grid-template-columns: 1fr 1.6fr; gap: 8px; }
.btn-undo { background: #2a2a2a; border: 1.5px solid #444; color: var(--text); border-radius: 12px; padding: 14px; font-size: 0.95rem; font-weight: 700; cursor: pointer; transition: background 0.1s, transform 0.08s; display: flex; align-items: center; justify-content: center; gap: 6px; }
.btn-undo:active { background: #3a3a3a; transform: scale(0.97); }
.btn-undo:disabled { opacity: 0.35; pointer-events: none; }
.btn-qbreak { background: var(--green); color: white; border: none; border-radius: 12px; padding: 14px; font-size: 0.95rem; font-weight: 800; cursor: pointer; transition: background 0.1s, transform 0.08s; display: flex; align-items: center; justify-content: center; }
.btn-qbreak:active { background: var(--green-dark); transform: scale(0.97); }
.btn-qbreak.fulltime { background: #f4c842; color: #1a1a00; }
.btn-qbreak.save { background: #16a34a; }

/* ── Quarter break bottom sheet ── */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: all; }

.qbreak-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #1c1c1c;
  border-radius: 24px 24px 0 0;
  padding: 12px 20px 32px;
  z-index: 51;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.34,1.2,0.64,1);
  max-width: 480px;
  margin: 0 auto;
}
.qbreak-sheet.open { transform: translateY(0); }

.sheet-handle { width: 40px; height: 4px; background: #444; border-radius: 4px; margin: 0 auto 16px; }
.sheet-title { font-size: 1rem; font-weight: 800; color: var(--gold); margin-bottom: 18px; text-align: center; }

.sheet-score-row { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 10px; align-items: end; margin-bottom: 20px; }
.sheet-field { display: flex; flex-direction: column; gap: 5px; }
.sheet-field label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.sheet-field input { background: #2a2a2a; border: 1.5px solid #444; border-radius: 10px; padding: 12px; font-size: 1.4rem; font-weight: 800; color: white; text-align: center; outline: none; -webkit-appearance: none; appearance: none; width: 100%; }
.sheet-field input:focus { border-color: var(--gold); }
.sheet-dot { font-size: 1.8rem; color: var(--muted); padding-bottom: 10px; }
.sheet-result { font-size: 1rem; font-weight: 800; color: #4ade80; text-align: right; padding-bottom: 10px; white-space: nowrap; }

.btn-sheet-confirm { width: 100%; background: var(--gold); color: #1a1a00; border: none; border-radius: 13px; padding: 16px; font-size: 1rem; font-weight: 800; cursor: pointer; transition: background 0.15s, transform 0.1s; }
.btn-sheet-confirm:active { transform: scale(0.98); }
.btn-sheet-confirm.final { background: #16a34a; color: white; }

/* ── Saving overlay ── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: none; align-items: center; justify-content: center; z-index: 100; }
.overlay.show { display: flex; }
.overlay-box { background: var(--card); border-radius: 20px; padding: 32px 40px; text-align: center; font-size: 1.1rem; font-weight: 700; }

@media (min-width: 600px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .stat-count { font-size: 3.2rem; }
}

.sheet-qtr-label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 8px; }
.sheet-qtr-label.opp-label { color: rgba(255,255,255,0.45); margin-top: 14px; }
.sheet-result.opp { color: rgba(255,255,255,0.7); }
.sheet-running {
  background: rgba(74,222,128,0.1);
  border: 1px solid rgba(74,222,128,0.25);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 18px;
  font-size: 0.85rem;
  color: #4ade80;
  font-weight: 700;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.sheet-running.hidden { display: none; }

/* Worm hint on scoreboard */
.worm-hint {
  position: absolute; bottom: -1px; left: 50%; transform: translateX(-50%);
  font-size: 0.55rem; font-weight: 700; color: rgba(255,255,255,0.3);
  letter-spacing: 0.3px; white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity 0.3s;
}
.worm-hint.visible { opacity: 1; }
#scoreboard-tap { cursor: pointer; position: relative; }
#scoreboard-tap:active { opacity: 0.8; }

/* Worm modal */
.worm-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  z-index: 70; display: none; align-items: center; justify-content: center; padding: 16px;
}
.worm-overlay.open { display: flex; }
.worm-box {
  background: #181818; border-radius: 20px; padding: 20px;
  width: 100%; max-width: 440px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.worm-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.worm-title { font-size: 1rem; font-weight: 800; color: var(--gold); }
.worm-close {
  background: none; border: none; color: var(--muted); font-size: 1.2rem;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.worm-close:hover { color: white; }
.worm-legend {
  display: flex; justify-content: space-between;
  font-size: 0.7rem; font-weight: 700; margin-bottom: 12px;
}
.worm-us-leg   { color: #f4c842; }
.worm-even-leg { color: rgba(255,255,255,0.35); }
.worm-them-leg { color: #f87171; }
.worm-chart-wrap { position: relative; min-height: 200px; }
.worm-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem; color: var(--muted); font-style: italic;
}

/* ── Setup tabs ── */
.setup-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  width: 100%;
  max-width: 420px;
}
.setup-tab {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border: 1.5px solid rgba(255,255,255,0.13);
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  transition: all 0.15s;
}
.setup-tab.active {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--green-dark);
}

.join-error {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.35);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #f87171;
  margin-top: 10px;
}
.join-error.hidden { display: none; }

/* ── Parent lobby ── */
#lobby-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  background: linear-gradient(160deg, #0d3d1e 0%, #111 60%);
}

.lobby-parent-wrap {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.lobby-game-badge {
  background: rgba(244,200,66,0.12);
  border: 1px solid rgba(244,200,66,0.3);
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 24px;
  display: inline-block;
}

.lobby-status {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.55);
  margin-bottom: 24px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.lobby-pulse {
  display: inline-block;
  width: 8px; height: 8px;
  background: #4ade80;
  border-radius: 50%;
  animation: pulse 1.2s infinite;
  flex-shrink: 0;
}

.lobby-players-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--muted);
  margin-bottom: 10px;
}

.lp-player-list {
  background: #1e1e1e;
  border-radius: 14px;
  padding: 4px 16px;
  margin-bottom: 20px;
  min-height: 52px;
}

.lp-player-item {
  padding: 9px 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: white;
  border-bottom: 1px solid #2a2a2a;
}
.lp-player-item:last-child { border-bottom: none; }
.lp-player-item.is-you { color: var(--gold); }

.lobby-your-name {
  font-size: 0.78rem;
  color: var(--muted);
}

/* ── Session mode (parent recording screen) ── */
.session-mode .btn-qbreak { display: none; }
.session-mode .game-footer { grid-template-columns: 1fr; }

/* ── Quarter notification overlay ── */
.qtr-notif {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 20px;
  padding: 22px 32px;
  text-align: center;
  z-index: 80;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  min-width: 240px;
}
.qtr-notif.show { opacity: 1; }
.qtr-notif-title {
  font-size: 0.68rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--muted); margin-bottom: 10px;
}
.qtr-notif-score { font-size: 1.1rem; font-weight: 800; color: var(--gold); margin-bottom: 2px; }
.qtr-notif-them  { color: rgba(255,255,255,0.7); }

/* Player select in setup card */
.setup-card select {
  width: 100%; background: #2a2a2a; border: 1.5px solid #333; border-radius: 10px;
  padding: 12px 14px; font-size: 1rem; color: var(--text); outline: none;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  cursor: pointer;
}
.setup-card select:focus { border-color: var(--gold); }
.setup-card select option { background: #2a2a2a; }
.setup-card input.player-manual-input { margin-top: 6px; }

/* Disposals bar */
.disposals-bar {
  text-align: center;
  padding: 4px 8px;
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.disposals-bar strong { color: var(--gold); font-size: 1rem; margin: 0 2px; }
.disposals-sub { opacity: 0.55; font-size: 0.72rem; }
