*, *::before, *::after {
  box-sizing: border-box;
  margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: #111;
  color: #fff;
  font-family: 'Segoe UI', system-ui, sans-serif;
  height: 100dvh;
  overflow: hidden;
}

/* ─── SETUP SCREEN ─────────────────────────────── */
#setup-screen {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  height: 100dvh;
  padding: 24px;
  background: #1a1a2e;
}

/* ─── AUTH BAR ─────────────────────────────────── */
#auth-bar {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Auth modal ──────────────────────────── */
#auth-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 40;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#auth-modal.show { display: flex; }

#auth-modal-box {
  background: #1e293b;
  border-radius: 20px;
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

#btn-auth-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  color: #666;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
#btn-auth-close:hover { color: #fff; }

#auth-tabs {
  display: flex;
  gap: 4px;
  background: #0f172a;
  border-radius: 10px;
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: #888;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.auth-tab.selected { background: #1e293b; color: #fff; }

#auth-modal-box input {
  width: 100%;
  background: #0f172a;
  border: 2px solid #334155;
  border-radius: 10px;
  color: #fff;
  font-size: 0.95rem;
  padding: 10px 14px;
  outline: none;
}
#auth-modal-box input:focus { border-color: #4ade80; }

.auth-submit-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: #4ade80;
  color: #1a1a2e;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}
.auth-submit-btn:disabled { opacity: 0.5; }
.auth-submit-btn:active { opacity: 0.85; }

.auth-link-btn {
  background: none;
  border: none;
  color: #64748b;
  font-size: 0.8rem;
  cursor: pointer;
  text-align: center;
  padding: 4px;
  width: 100%;
}
.auth-link-btn:hover { color: #94a3b8; }

.auth-error {
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(248,113,113,0.1);
  color: #f87171;
  margin: 0;
}

.auth-reset-info {
  font-size: 0.85rem;
  color: #94a3b8;
  text-align: center;
  margin: 0;
}

.auth-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.auth-btn:active { opacity: 0.7; }
.auth-btn-primary { background: #4ade80; color: #1a1a2e; }
.auth-btn-ghost   { background: transparent; color: #888; border: 1px solid #334155; }

#auth-user-email {
  font-size: 0.7rem;
  color: #888;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#auth-msg {
  font-size: 0.7rem;
  color: #4ade80;
}

#setup-screen h1 {
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: 5px;
  color: #4ade80;
}

.setup-row {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 360px;
}

.team-setup {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #16213e;
  border-radius: 14px;
  padding: 12px 16px;
}

.team-color-swatch {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.2);
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
  position: relative;
}

.team-color-swatch input[type="color"] {
  position: absolute;
  inset: -8px;
  width: calc(100% + 16px);
  height: calc(100% + 16px);
  opacity: 0;
  cursor: pointer;
}

.team-name-input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid rgba(255,255,255,0.2);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 4px 0;
  outline: none;
}

.team-name-input:focus {
  border-bottom-color: #4ade80;
}

.duration-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.duration-setup label {
  font-size: 0.8rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #888;
}

.time-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.time-inputs input {
  width: 68px;
  text-align: center;
  font-size: 1.8rem;
  font-weight: 700;
  padding: 8px 4px;
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 10px;
  color: #fff;
  outline: none;
}

.time-inputs input:focus { border-color: #4ade80; }
.time-inputs span { font-size: 1.8rem; font-weight: 700; color: #aaa; }

#btn-start-game {
  width: 100%;
  max-width: 360px;
  padding: 18px;
  border: none;
  border-radius: 14px;
  background: #4ade80;
  color: #1a1a2e;
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
#btn-start-game:active { transform: scale(0.97); background: #22c55e; }

/* ─── GAME SCREEN ──────────────────────────────── */
#game-screen {
  display: none;
  height: 100dvh;
  width: 100%;
  flex-direction: row;
}

#game-screen.active { display: flex; }

/* Team panels */
.team-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px 10px 6px;
  gap: 6px;
  overflow: hidden;
  position: relative;
  transition: background 0.3s;
}

.team-panel .team-label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.85;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.team-panel .score {
  font-size: 3rem;
  font-weight: 900;
  line-height: 1;
}

/* Event log on each side */
.events-log {
  flex: 1;
  width: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: none;
}
.events-log::-webkit-scrollbar { display: none; }

.event-item {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  opacity: 0.9;
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  padding: 4px 5px;
}

.event-icon { font-size: 0.9rem; flex-shrink: 0; }
.event-detail { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-time { font-size: 0.6rem; opacity: 0.7; flex-shrink: 0; }

/* Team action buttons */
.team-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.action-btn {
  width: 100%;
  padding: 10px 4px;
  border: none;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  background: rgba(0,0,0,0.3);
  color: inherit;
  transition: background 0.1s, transform 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.action-btn .action-icon { font-size: 1.3rem; }
.action-btn:active { transform: scale(0.95); background: rgba(0,0,0,0.5); }

/* ─── CENTER PANEL ─────────────────────────────── */
#center-panel {
  width: 108px;
  flex-shrink: 0;
  background: #111827;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 12px 6px;
  box-shadow: 0 0 24px rgba(0,0,0,0.7);
  z-index: 2;
}

#center-panel .app-title {
  font-size: 0.55rem;
  font-weight: 900;
  letter-spacing: 3px;
  color: #4ade80;
  text-transform: uppercase;
}

#clock {
  font-size: 1.7rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  color: #4ade80;
  transition: color 0.3s;
  text-align: center;
}

#clock.warning { color: #facc15; }
#clock.danger  { color: #f87171; animation: pulse 0.8s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

#period-label {
  font-size: 0.6rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #666;
  text-align: center;
}

#status-label {
  font-size: 0.6rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #888;
  text-align: center;
}

.center-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.ctrl-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
}

.ctrl-btn:active { transform: scale(0.9); }
.ctrl-btn:disabled { opacity: 0.3; pointer-events: none; }

#btn-play { background: #16a34a; color: #fff; }
#btn-pause { background: #dc2626; color: #fff; }

.stoppage-controls {
  display: flex;
  align-items: center;
  gap: 3px;
  width: 100%;
}

.stoppage-btn {
  flex: 1;
  padding: 6px 2px;
  border: none;
  border-radius: 7px;
  font-size: 0.48rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
}
.stoppage-btn:active { transform: scale(0.92); }
.stoppage-btn:disabled { opacity: 0.3; pointer-events: none; }

#btn-stoppage { background: #0e7490; color: #fff; }
#btn-retract  { background: #374151; color: #fff; }

#stoppage-secs {
  width: 34px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 5px 2px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #fff;
  outline: none;
}
#stoppage-secs:focus { border-color: #4ade80; }

#btn-end-game {
  width: 100%;
  padding: 10px 4px;
  border: none;
  border-radius: 10px;
  background: #7c3aed;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
#btn-end-game:active { transform: scale(0.96); background: #6d28d9; }

/* ─── MODAL ────────────────────────────────────── */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 20;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#modal-overlay.show { display: flex; }

#modal {
  background: #1e293b;
  border-radius: 20px;
  padding: 24px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

#modal h2 {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-field label {
  font-size: 0.75rem;
  color: #888;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.modal-field input {
  background: #0f172a;
  border: 2px solid #334155;
  border-radius: 10px;
  color: #fff;
  font-size: 1.4rem;
  font-weight: 700;
  padding: 10px 14px;
  outline: none;
  text-align: center;
}

.modal-field input:focus { border-color: #4ade80; }

/* Card type selector */
.card-type-row {
  display: flex;
  gap: 10px;
}

.card-type-btn {
  flex: 1;
  padding: 14px;
  border: 3px solid transparent;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: border-color 0.15s, transform 0.1s;
}

.card-type-btn .card-icon { font-size: 1.6rem; }
.card-type-btn.yellow-card { background: rgba(234,179,8,0.15); color: #facc15; }
.card-type-btn.red-card    { background: rgba(239,68,68,0.15);  color: #f87171; }
.card-type-btn.selected    { border-color: currentColor; }
.card-type-btn:active      { transform: scale(0.96); }

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.modal-btn:active { transform: scale(0.96); }

#modal-cancel { background: #334155; color: #ccc; }
#modal-confirm { background: #4ade80; color: #1a1a2e; }

/* ─── END GAME OVERLAY ─────────────────────────── */
#endgame-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 30;
  flex-direction: column;
  overflow-y: auto;
  padding: 24px;
  gap: 20px;
  align-items: center;
}
#endgame-overlay.show { display: flex; }

#endgame-overlay h2 {
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #f87171;
  text-align: center;
  margin-top: 8px;
}

.final-scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 100%;
  max-width: 380px;
  border-radius: 16px;
  overflow: hidden;
}

.final-team {
  flex: 1;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.final-team .final-team-name {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.9;
}

.final-team .final-score {
  font-size: 3.5rem;
  font-weight: 900;
  line-height: 1;
}

.final-vs {
  font-size: 1rem;
  font-weight: 900;
  color: #666;
  padding: 0 8px;
  background: #1a1a2e;
  align-self: stretch;
  display: flex;
  align-items: center;
}

.stats-section {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stats-section h3 {
  font-size: 0.75rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #888;
  border-bottom: 1px solid #333;
  padding-bottom: 6px;
}

.stats-row {
  display: flex;
  gap: 10px;
}

.stats-team-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.stats-team-col .col-header {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.7;
  text-align: center;
}

.stats-event-item {
  font-size: 0.75rem;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stats-event-item .s-icon { font-size: 1rem; }
.stats-event-item .s-detail { flex: 1; font-weight: 600; }
.stats-event-item .s-time { font-size: 0.65rem; color: #888; }

.no-events { font-size: 0.75rem; color: #555; text-align: center; padding: 8px; }

#btn-new-game {
  width: 100%;
  max-width: 380px;
  padding: 18px;
  border: none;
  border-radius: 14px;
  background: #4ade80;
  color: #1a1a2e;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  cursor: pointer;
  margin-top: 8px;
  margin-bottom: 16px;
}
#btn-new-game:active { opacity: 0.85; }

/* ─── NOTES ────────────────────────────────────── */
#notes-details {
  width: 100%;
  margin-top: 4px;
}

#notes-summary {
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #666;
  cursor: pointer;
  user-select: none;
  text-align: center;
  padding: 4px 0;
  list-style: none;
}
#notes-summary::-webkit-details-marker { display: none; }
#notes-details[open] #notes-summary { color: #4ade80; }

#notes-ingame {
  width: 100%;
  margin-top: 6px;
  background: #0d1117;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #ccc;
  font-size: 0.75rem;
  padding: 8px;
  resize: none;
  outline: none;
  font-family: inherit;
}
#notes-ingame:focus { border-color: #4ade80; }

.notes-endgame-section {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notes-label {
  font-size: 0.7rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #888;
}

#notes-endgame {
  width: 100%;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 10px;
  color: #ccc;
  font-size: 0.85rem;
  padding: 10px 12px;
  resize: none;
  outline: none;
  font-family: inherit;
}
#notes-endgame:focus { border-color: #4ade80; }

/* ─── SAVED BADGE ──────────────────────────────── */
#saved-badge {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #4ade80;
  color: #1a1a2e;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 8px 20px;
  border-radius: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 40;
}
#saved-badge.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── HISTORY BUTTON ───────────────────────────── */
#btn-history {
  width: 100%;
  max-width: 360px;
  padding: 12px;
  border: 1px solid #334155;
  border-radius: 14px;
  background: transparent;
  color: #888;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
#btn-history:hover { border-color: #4ade80; color: #4ade80; }

/* ─── HISTORY OVERLAY ──────────────────────────── */
#history-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #0f0f1a;
  z-index: 40;
  flex-direction: column;
}
#history-overlay.show { display: flex; }

#history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

#history-title {
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #4ade80;
}

#btn-history-close {
  background: transparent;
  border: none;
  color: #666;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
#btn-history-close:hover { color: #fff; }

#history-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: #16213e;
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 1rem;
  font-weight: 900;
}

.history-item-teams {
  font-size: 0.75rem;
  color: #aaa;
  font-weight: 600;
}

.history-item-meta {
  font-size: 0.65rem;
  color: #555;
  letter-spacing: 1px;
}

.history-item-notes {
  font-size: 0.75rem;
  color: #888;
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-empty {
  text-align: center;
  color: #555;
  font-size: 0.85rem;
  margin-top: 40px;
}

.history-loading {
  text-align: center;
  color: #555;
  font-size: 0.8rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 40px;
}
