/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Sunset purple — high-contrast for outdoor / bright daylight use */
  --purple:       #5b2a86;
  --purple-dark:  #3f1d5d;
  --purple-light: #efe7f5;
  --red:          #b91c1c;
  --red-light:    #fdecec;
  --amber:        #b45309;
  --gray:         #4b5563;
  --gray-light:   #f3f4f6;
  --border:       #c7c9d1;
  --text:         #0f172a;
  --white:        #ffffff;
  --radius:       10px;
  --shadow:       0 2px 8px rgba(0,0,0,.18);
  --tap:          48px;
  --header-h:     56px;
  --font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: var(--white);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── Screens ──────────────────────────────────────────────────────────── */
.screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
.screen.hidden { display: none; }

/* ── Header ───────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--purple);
  color: var(--white);
  box-shadow: var(--shadow);
}
.app-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Back button ──────────────────────────────────────────────────────── */
.btn-back {
  background: none;
  border: none;
  color: var(--white);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
  min-width: var(--tap);
  min-height: var(--tap);
  flex-shrink: 0;
}

/* ── Main content ─────────────────────────────────────────────────────── */
main {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  min-height: var(--tap);
  padding: 0 20px;
  font-size: 0.95rem;
  transition: filter .15s;
  user-select: none;
}
.btn:active { filter: brightness(.88); }

.btn-primary   { background: var(--purple);      color: var(--white); }
.btn-secondary { background: var(--gray-light);  color: var(--text);  border: 1px solid var(--border); }
.btn-danger    { background: var(--red);         color: var(--white); }

.btn-xl { min-height: 60px; font-size: 1.1rem; width: 100%; }
.btn-lg { min-height: 52px; font-size: 1rem;   width: 100%; }

.hidden { display: none !important; }

/* ── Home screen ──────────────────────────────────────────────────────── */
.home-actions { display: flex; flex-direction: column; gap: 12px; }

.active-game-card {
  background: var(--purple-light);
  border: 1.5px solid var(--purple);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.active-game-card strong { font-size: 1.05rem; }
.active-game-card .meta  { font-size: 0.85rem; color: var(--gray); }

/* ── Form ─────────────────────────────────────────────────────────────── */
.form { display: flex; flex-direction: column; gap: 20px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-weight: 600; font-size: 0.9rem; }
.form-group input {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 0 14px;
  height: var(--tap);
  font-size: 1rem;
  font-family: var(--font);
  background: var(--white);
  color: var(--text);
  width: 100%;
}
.form-group input:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(91,42,134,.18);
}

/* ── Score bar ────────────────────────────────────────────────────────── */
.score-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--purple);
  color: var(--white);
  border-radius: var(--radius);
  padding: 6px 10px;
  gap: 8px;
}
.score-side { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.score-name { font-size: 0.72rem; font-weight: 600; text-align: center; opacity: .85;
              max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-num  { font-size: 1.8rem; font-weight: 800; line-height: 1; }

.score-center { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.period-row { display: flex; align-items: center; gap: 6px; }
.period-btn {
  background: rgba(255,255,255,.25);
  border: none;
  color: var(--white);
  font-size: 1.1rem;
  font-weight: 700;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#period-label { font-size: 0.95rem; font-weight: 700; min-width: 26px; text-align: center; }

/* ── Link row ─────────────────────────────────────────────────────────── */
.link-row {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: -4px;
}
.link-btn {
  background: none;
  border: none;
  padding: 4px 0;
  color: var(--purple);
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}
.link-btn:active { opacity: .7; }

/* ── Event grid ───────────────────────────────────────────────────────── */
.event-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  flex: 1;
}
.event-grid.single-col { grid-template-columns: 1fr; }
.event-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.score-side.tappable { cursor: pointer; user-select: none; }
.score-side.tappable .score-num::after {
  content: " +";
  font-size: 1rem;
  font-weight: 600;
  opacity: .6;
}
.col-label {
  font-size: 0.85rem;
  font-weight: 800;
  text-align: center;
  color: var(--purple);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--purple);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Each column holds 4 sections; each section is a horizontal row of buttons */
.event-section {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
  padding: 6px;
  background: var(--purple-light);
  border-radius: var(--radius);
}

.event-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
  border: 2px solid var(--purple);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--purple-dark);
  cursor: pointer;
  min-height: 56px;
  padding: 0 4px;
  text-align: center;
  line-height: 1.1;
  letter-spacing: .02em;
  transition: background .12s, transform .05s;
}
.event-btn:active {
  background: var(--purple);
  color: var(--white);
  transform: scale(.97);
}

/* ── Bottom bar ───────────────────────────────────────────────────────── */
.bottom-bar {
  display: flex;
  gap: 10px;
  padding-top: 4px;
}
.bottom-bar .btn { flex: 1; }

/* ── Dialog ───────────────────────────────────────────────────────────── */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
}
.dialog-overlay.hidden { display: none; }

.dialog-box {
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 16px 16px 24px;
  width: 100%;
  height: 92dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dialog-box h2 { font-size: 1.05rem; flex-shrink: 0; }
.optional { font-size: 0.8rem; color: var(--gray); font-weight: 400; }
.dialog-actions { display: flex; gap: 10px; flex-shrink: 0; }
.dialog-actions .btn { flex: 1; }

.player-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
}
.player-btn {
  background: var(--gray-light);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  min-height: var(--tap);
  padding: 6px 8px;
  text-align: center;
  line-height: 1.2;
}
.player-btn:active { background: var(--purple-light); border-color: var(--purple); }

/* ── Summary ──────────────────────────────────────────────────────────── */
.summary-scoreboard {
  background: var(--purple);
  color: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.summary-teams {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
  opacity: .9;
}
.summary-score-row {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 14px;
}
.summary-goals   { font-size: 3rem; font-weight: 800; line-height: 1; }
.summary-dash    { font-size: 2rem; font-weight: 300; opacity: .7; }
.summary-status  { font-size: 0.8rem; opacity: .75; margin-top: 4px; }

.event-log { display: flex; flex-direction: column; gap: 6px; }

.event-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--gray-light);
  font-size: 0.88rem;
}
.event-item.home-event { border-left: 3px solid var(--purple); }
.event-item.away-event { border-left: 3px solid #1a56db; }

.event-meta   { color: var(--gray); font-size: 0.8rem; min-width: 52px; flex-shrink: 0; }
.event-type   { font-weight: 600; flex: 1; }
.event-player { color: var(--gray); font-size: 0.82rem; }

/* ── History ──────────────────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 10px; }

.history-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--white);
  cursor: pointer;
  transition: background .12s;
}
.history-item:active { background: var(--gray-light); }
.history-teams { font-weight: 700; font-size: 1rem; }
.history-meta  { font-size: 0.83rem; color: var(--gray); }
.history-status-final      { color: var(--purple); }
.history-status-in_progress { color: #d97706; }

.empty-state {
  text-align: center;
  color: var(--gray);
  padding: 40px 16px;
  font-size: 0.95rem;
}

/* ── Status banners ───────────────────────────────────────────────────── */
.sync-indicator {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  right: 12px;
  background: var(--purple);
  color: var(--white);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  z-index: 50;
}

.offline-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #92400e;
  color: var(--white);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  padding: 10px;
  z-index: 50;
}

/* ── Stats table ──────────────────────────────────────────────────────── */
.stats-meta {
  font-size: 0.85rem;
  color: var(--gray);
  margin-bottom: 8px;
}
.stats-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.stats-table th, .stats-table td {
  padding: 8px 10px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.stats-table thead th {
  background: var(--purple-light);
  color: var(--purple-dark);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: .03em;
  position: sticky;
  top: 0;
}
.stats-table tbody th.player-name {
  text-align: left;
  font-weight: 600;
}
.stats-table tfoot th, .stats-table tfoot td {
  background: var(--gray-light);
  font-weight: 700;
  border-bottom: none;
}

/* ── Event log (with undo) ────────────────────────────────────────────── */
.event-log-list { display: flex; flex-direction: column; gap: 6px; }
.log-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--gray-light);
  border-left: 3px solid var(--purple);
}
.log-row.away-event { border-left-color: #1a56db; }
.log-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.log-line1 { display: flex; gap: 8px; align-items: baseline; }
.log-type { font-weight: 700; font-size: 0.95rem; }
.log-team { font-size: 0.8rem; color: var(--gray); }
.log-line2 { display: flex; gap: 8px; font-size: 0.8rem; color: var(--gray); }
.log-period { font-weight: 600; }
.log-undo {
  background: var(--red-light);
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: 8px;
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 12px;
  min-height: 36px;
  cursor: pointer;
  flex-shrink: 0;
}
.log-undo:active { background: var(--red); color: var(--white); }
