:root {
  --bg: #0f1822;
  --bg2: #16212e;
  --card: #1a2735;
  --line: #243648;
  --text: #e6eef7;
  --sub: #8aa0b6;
  --accent: #22c55e;
  --accent2: #16a34a;
  --warn: #f59e0b;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 14px;
  --pad: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
body { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }

#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
#topbar h1 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; text-align: center; }
.iconbtn { background: transparent; color: var(--text); border: 0; font-size: 22px; padding: 6px 10px; border-radius: 10px; }
.iconbtn:active { background: var(--card); }

#update-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: var(--accent); color: #08120a; font-weight: 600; font-size: 14px; }
#update-banner[hidden] { display: none; }
#update-banner button { background: #08120a; color: var(--accent); border: 0; padding: 8px 14px; border-radius: 8px; font-weight: 700; font-size: 14px; }

#view { flex: 1; padding: 12px 12px 96px; overflow-y: auto; }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bg2); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 6;
}
.tab { background: transparent; color: var(--sub); border: 0; padding: 14px 6px; font-size: 13px; }
.tab.active { color: var(--accent); font-weight: 600; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 16px; }
.card h4 { margin: 12px 0 6px; font-size: 14px; color: var(--sub); }
.title { font-weight: 600; }
.sub { color: var(--sub); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.gap { gap: 10px; flex-wrap: wrap; }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.list { display: flex; flex-direction: column; }
.empty { text-align: center; padding: 40px 20px; color: var(--sub); }
.empty-cell { text-align: center; color: var(--sub); padding: 12px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--sub); flex: 1; margin-bottom: 8px; }
input, select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  width: 100%;
  font-family: inherit;
}
input[type=number] { max-width: 100%; }
/* iOS Safari renders date inputs with extra intrinsic padding/min-width and
   centers their text. Normalize so they match the other fields. */
input[type=date] {
  -webkit-appearance: none;
  appearance: none;
  text-align: left;
  min-height: 44px;
  display: block;
}
input[type=date]::-webkit-date-and-time-value { text-align: left; }
button {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  padding: 12px 16px; border-radius: 10px; font-size: 15px; font-weight: 500;
  cursor: pointer;
}
button:active { transform: scale(0.98); }
button.primary { background: var(--accent); border-color: var(--accent); color: #08120a; font-weight: 700; }
button.primary:active { background: var(--accent2); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.link { background: transparent; border: 0; color: var(--accent); padding: 6px 0; }
button.link.danger { color: var(--danger); }
button.big { padding: 16px 22px; font-size: 17px; }
button[disabled] { opacity: 0.4; }

.fab {
  position: fixed; right: 18px; bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #08120a; border: 0; font-size: 28px; font-weight: 800;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  z-index: 5;
}

.match { cursor: pointer; }
.status { font-size: 12px; padding: 4px 8px; border-radius: 999px; background: var(--bg); color: var(--sub); }
.status-live { background: #14361b; color: var(--accent); }
.status-finished { background: #1a2735; color: var(--sub); }
.status-ready { background: #1d2a3a; color: #7fb6ff; }

.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.chk { flex: 1 1 45%; background: var(--bg); border: 1px solid var(--line); padding: 8px 10px; border-radius: 10px; flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.chk.inline { flex-basis: auto; width: 100%; margin-bottom: 6px; }
.chk input { width: auto; }
.chk .sub { display: block; font-size: 11px; }

.keepers > label { background: var(--bg); border: 1px solid var(--line); padding: 8px 12px; border-radius: 10px; margin-bottom: 6px; flex-direction: row; align-items: center; }
.keepers select { max-width: 60%; }

.quarter { border-top: 1px solid var(--line); padding: 8px 0; }
.qhead { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.qhead .keeper { margin-left: auto; color: var(--accent); }
.slot { display: flex; gap: 12px; padding: 4px 0; font-size: 14px; }
.slot .sub { min-width: 50px; font-variant-numeric: tabular-nums; }

.stats { width: 100%; border-collapse: collapse; }
.table-scroll { max-width: 100%; overflow-x: auto; }
.table-scroll .stats { min-width: 580px; }
.stats th, .stats td { text-align: left; padding: 6px 4px; font-size: 14px; border-bottom: 1px solid var(--line); }
.stats th { color: var(--sub); font-weight: 500; }
.stats td:nth-child(n+2), .stats th:nth-child(n+2) { text-align: right; font-variant-numeric: tabular-nums; }

.stick-bottom { position: sticky; bottom: 60px; background: var(--bg); padding: 10px 0; }

/* Live screen */
.clock { text-align: center; padding: 12px 0 18px; }
.clock-row { display: flex; align-items: center; justify-content: center; gap: 14px; }
.live-controls { justify-content: center; margin-top: 10px; }
.live-controls button { flex: 1; max-width: 140px; }
.iconbtn.jump { font-size: 26px; color: var(--accent); padding: 8px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.iconbtn.jump:active { background: var(--bg2); }
.big-time { font-size: 64px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--accent); letter-spacing: 1px; }
.big-time.small { font-size: 36px; }
.next-sub { text-align: center; }
.next-sub.soon .big-time { color: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }
.bigname { font-size: 22px; font-weight: 600; padding: 6px 0; }
.pname { padding: 8px 6px; border-bottom: 1px solid var(--line); border-radius: 6px; }
.pname:last-child { border-bottom: 0; }
.pname.tappable { cursor: pointer; }
.pname.tappable:active { background: var(--bg2); }
.pname.injured { color: var(--sub); text-decoration: line-through; }
.card-action { width: 100%; margin-top: 10px; }
#view > .card-action { display: block; margin: 0 0 10px; }
.injured-card { border-color: #5a3a1a; background: #2a1f12; }
.injured-card h3 { color: var(--warn); }

.player-row { display: flex; align-items: center; gap: 10px; }
.player-row .player-name-input { flex: 1; background: var(--bg); }
.player-row .player-name-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Swipe-to-delete (match list) */
.swipe-wrap { position: relative; overflow: hidden; border-radius: 12px; }
.swipe-wrap .swipe-card { position: relative; z-index: 2; transform: translateX(0); touch-action: pan-y; will-change: transform; }
.swipe-wrap .swipe-card.swiped { box-shadow: 0 0 0 1px var(--danger) inset; }
.swipe-action {
  position: absolute; right: 0; top: 0; bottom: 0; width: 72px;
  display: flex; align-items: center; justify-content: center;
  background: var(--danger); color: #fff; border: 0; border-radius: 0 12px 12px 0;
  font-size: 22px; z-index: 1; cursor: pointer;
}

/* Score card */
.score-card { text-align: center; }
.finished-banner { text-align: center; padding: 12px; border: 1px solid var(--accent); background: rgba(34,197,94,0.08); border-radius: 12px; margin-bottom: 10px; }
.finished-banner .big-time { color: var(--accent); }
.score-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-bottom: 8px; }
.score-side { display: flex; flex-direction: column; align-items: center; }
.score-label { font-size: 12px; color: var(--sub); text-transform: uppercase; letter-spacing: 0.5px; }
.score-num { font-size: 48px; font-weight: 700; line-height: 1.1; color: var(--accent); }
.score-sep { font-size: 32px; color: var(--sub); }
.score-actions { justify-content: center; margin-bottom: 8px; }
.goals-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.goal-row { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 8px; }
.goal-row:nth-child(odd) { background: rgba(255,255,255,0.03); }
.goal-time { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--sub); }
.goal-us { color: var(--accent); font-weight: 600; }
.goal-opp { color: var(--danger); font-weight: 600; }
.goal-actions { display: flex; gap: 2px; }
.goal-actions .link { padding: 4px 8px; font-size: 14px; }

/* Action sheet */
.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-end; justify-content: center; z-index: 200; padding: 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.sheet { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 8px; animation: pop 0.15s ease-out; }
.sheet-title { color: var(--sub); text-align: center; padding: 6px 0 4px; font-size: 13px; }
.sheet button { width: 100%; padding: 14px; font-size: 16px; }

/* Timeline */
.tl-head { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; padding: 4px 0; color: var(--sub); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.tl-head > :nth-child(1) { text-align: right; padding-right: 6px; }
.tl-head > :nth-child(2) { text-align: center; min-width: 70px; }
.tl-head > :nth-child(3) { text-align: left; padding-left: 6px; }
.timeline { position: relative; }
.timeline::before { content: ''; position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: var(--line); transform: translateX(-50%); }
.tl-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; padding: 10px 0; position: relative; }
.tl-off { text-align: right; padding-right: 14px; color: #fca5a5; line-height: 1.3; font-size: 14px; }
.tl-on  { text-align: left;  padding-left: 14px; color: #86efac; line-height: 1.3; font-size: 14px; }
.tl-time { position: relative; z-index: 1; min-width: 70px; text-align: center; padding: 4px 10px; border-radius: 999px; background: #2b2150; color: #c4b5fd; font-weight: 600; font-variant-numeric: tabular-nums; font-size: 13px; }
.tl-row.past .tl-off, .tl-row.past .tl-on { opacity: 0.4; text-decoration: line-through; }
.tl-row.past .tl-time { background: var(--line); color: var(--sub); }
.tl-row.next .tl-time { background: var(--accent); color: #08120a; box-shadow: 0 0 0 4px rgba(34,197,94,0.2); }

/* Alert overlay */
#alert-overlay[hidden] { display: none; }
#alert-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.alert-card {
  background: var(--card); border: 2px solid var(--accent); border-radius: var(--radius);
  padding: 20px; max-width: 380px; width: 100%; text-align: center;
  animation: pop 0.2s ease-out;
}
.alert-card h2 { margin: 0 0 12px; color: var(--accent); }
.alert-card #alert-body { margin-bottom: 16px; line-height: 1.7; text-align: left; }
.alert-card button { width: 100%; padding: 14px; }
@keyframes pop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
