:root {
  --bg: #0f1420;
  --bg-elev: #171d2c;
  --bg-elev-2: #1f2739;
  --border: #2a3348;
  --text: #e7ebf3;
  --text-muted: #8b93a7;
  --accent: #5b8def;
  --green: #35c98f;
  --light-green: #8de8bd;
  --red: #f2545b;
  --amber: #f5a623;
  --blue: #4dabf7;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: 0 24px 48px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.app-header h1 { font-size: 20px; margin: 0; }

.header-actions { display: flex; align-items: center; gap: 12px; }

.muted { color: var(--text-muted); font-size: 13px; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: #4a7bdc; }
.btn-secondary { background: var(--bg-elev-2); color: var(--text); }
.btn-secondary:hover { background: #29334a; }
.btn-ghost { background: transparent; color: var(--text-muted); font-size: 20px; padding: 0 6px; }
.btn-danger { background: transparent; color: var(--red); }
.btn-small { padding: 4px 8px; font-size: 12px; }

.summary-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.tile-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.tile-value { font-size: 20px; font-weight: 700; }

.leaderboard {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.leaderboard-title { font-weight: 700; margin-bottom: 10px; }
.leaderboard-table { display: flex; flex-direction: column; }
.leaderboard-row {
  display: grid;
  grid-template-columns: 28px 1fr 130px 70px 90px 90px;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.leaderboard-row:first-child { border-top: none; }
.leaderboard-head {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-bottom: 6px;
}
.leaderboard-rank { text-align: center; font-size: 15px; }
.leaderboard-person { font-weight: 600; }

.filter-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }

.filter-selects { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.filter-select {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}

.segmented-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.segmented-toggle .segment {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.segmented-toggle .segment.active { background: var(--accent); color: white; }
.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}
.tab.active { background: var(--accent); color: white; border-color: var(--accent); }

.trash-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  margin-left: auto;
}
.trash-toggle:hover { color: var(--text); border-color: var(--text-muted); }

.trash-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  padding: 4px 18px;
}
.trash-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  gap: 10px;
}
.trash-row:first-of-type { border-top: none; }

.game-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.game-card-header {
  padding: 12px 18px;
  background: var(--bg-elev-2);
  font-weight: 600;
}
.game-card-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.game-status { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.game-status.live { color: var(--amber); font-weight: 700; }
.game-situation {
  margin-top: 4px;
  text-align: right;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
}

.field-bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: -8px 0 16px;
  font-size: 12px;
  color: var(--text-muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.legend-swatch-marker { background: var(--accent); }
.legend-swatch-firstdown { background: #f5d90a; }
.legend-swatch-redzone { background: rgba(242, 84, 91, 0.5); }

.field-bar {
  position: relative;
  height: 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-top: 6px;
}
.field-bar-redzone {
  position: absolute;
  top: -1px; bottom: -1px; right: -1px;
  width: 20%;
  background: rgba(242, 84, 91, 0.25);
  border-radius: 0 4px 4px 0;
}
.field-bar-marker {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
}
.field-bar-firstdown {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 14px;
  background: #f5d90a;
  transform: translateX(-50%);
}

.bet-row {
  display: grid;
  grid-template-columns: 90px 1fr 140px 90px 90px 110px 70px;
  gap: 10px;
  align-items: center;
  padding: 12px 18px 12px 14px;
  border-top: 1px solid var(--border);
  border-left: 4px solid var(--border);
}
.bet-row:first-of-type { border-top: none; }

.bet-type-badge {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  line-height: 1.6;
}

.bet-desc { font-size: 14px; }
.selection-text { font-weight: 700; }
.collapse-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 0 8px 0 0;
  vertical-align: middle;
}
.collapse-toggle:hover { color: var(--text); }
.bet-desc .progress-wrap {
  margin-top: 6px;
  height: 5px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  width: 100%;
}
.bet-desc .progress-bar { height: 100%; background: var(--accent); }
.bet-desc .progress-text { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

.bet-current { font-size: 13px; color: var(--text-muted); }
.time-chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.bet-odds, .bet-stake { font-size: 13px; }

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  text-align: center;
}
.status-pending { background: #2a3348; color: var(--text-muted); }
.status-live {
  background: rgba(245,166,35,0.15);
  color: var(--amber);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.status-live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 0 rgba(242,84,91,0.7);
  animation: live-ping 1.6s infinite;
}
.status-won { background: rgba(53,201,143,0.15); color: var(--green); }
.status-lost { background: rgba(242,84,91,0.15); color: var(--red); }
.status-push { background: rgba(77,171,247,0.15); color: var(--blue); }
.status-void { background: #2a3348; color: var(--text-muted); }
.status-unknown { background: #2a3348; color: var(--text-muted); }

@keyframes live-ping {
  0% { box-shadow: 0 0 0 0 rgba(242,84,91,0.6); }
  70% { box-shadow: 0 0 0 6px rgba(242,84,91,0); }
  100% { box-shadow: 0 0 0 0 rgba(242,84,91,0); }
}

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.no-game-label { color: var(--text-muted); font-style: italic; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 20;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  padding: 20px 24px 24px;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-header h2 { font-size: 18px; margin: 0; }

.form-fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 14px 0;
  padding: 10px 14px 14px;
  min-width: 0;
}
.form-fieldset legend { font-size: 12px; color: var(--text-muted); padding: 0 6px; }

.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.form-row label { width: 100px; flex-shrink: 0; font-size: 13px; color: var(--text-muted); }
.form-row input, .form-row select {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 14px;
}
.form-actions { margin-top: 16px; display: flex; justify-content: flex-end; }
.form-error { color: var(--red); font-size: 13px; min-height: 18px; }

.hidden { display: none !important; }

.leg-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bg);
}
.leg-row .form-row:last-of-type { margin-bottom: 8px; }
.leg-row-title { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }

.acca-card { border: 1px solid var(--accent); }
.acca-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: var(--bg-elev-2);
}
.acca-header-main { font-weight: 600; }
.acca-header-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.acca-leg-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.acca-leg-summary .status-badge { font-size: 10px; padding: 2px 8px; }
.leg-person-row {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}
.leg-line-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 160px 70px 90px;
  gap: 10px;
  align-items: center;
  padding: 10px 34px 10px 14px;
  border-top: 1px solid var(--border);
  border-left: 4px solid var(--border);
}
.leg-remove-x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.leg-remove-x:hover { color: var(--red); border-color: var(--red); }
.leg-line-row:first-of-type { border-top: none; }
.leg-game-label { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.injury-badge {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.injury-out { background: rgba(242,84,91,0.15); color: var(--red); }
.injury-doubtful { background: rgba(242,84,91,0.12); color: #e08a5b; }
.injury-questionable { background: rgba(245,166,35,0.15); color: var(--amber); }
.injury-other { background: #2a3348; color: var(--text-muted); }

.box-line { font-size: 13px; font-weight: 600; color: var(--text); margin-top: 5px; }

select.override-select, select.person-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
}

.person-badge {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
}

@media (max-width: 900px) {
  .summary-bar { grid-template-columns: repeat(2, 1fr); }
  .bet-row { grid-template-columns: 1fr; }
  .row-actions { justify-content: flex-start; }
  .leaderboard-row { grid-template-columns: 24px 1fr 90px; font-size: 13px; }
  .leaderboard-row > div:nth-child(3), .leaderboard-row > div:nth-child(4), .leaderboard-row > div:nth-child(5) { display: none; }
}

@media (max-width: 640px) {
  /* Extra clearance so iOS Safari's floating minimal-UI bar (URL/security
     pill) never sits on top of the last card when scrolled to the bottom. */
  body { padding: 0 14px calc(64px + env(safe-area-inset-bottom, 0px)); }

  .app-header {
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .game-card-header-top {
    flex-wrap: wrap;
    row-gap: 4px;
  }
  .game-situation { text-align: left; }

  .acca-header {
    flex-direction: column;
    align-items: flex-start;
    row-gap: 8px;
  }
  .acca-header .row-actions { width: 100%; }

  .leg-line-row { grid-template-columns: 1fr; row-gap: 6px; }
  .leg-line-row > div:not(.bet-desc) { justify-self: flex-start; }

  .row-actions { flex-wrap: wrap; }

  .form-row { flex-direction: column; align-items: stretch; gap: 4px; }
  .form-row label { width: auto; }
}
