:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #273449;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #10b981;
  --primary-hover: #059669;
  --secondary: #3b82f6;
  --secondary-hover: #2563eb;
  --win-bg: rgba(16, 185, 129, 0.16);
  --win-text: #34d399;
  --loss-bg: rgba(239, 68, 68, 0.16);
  --loss-text: #f87171;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.9rem;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.3rem;
}

.tab {
  color: var(--muted);
  text-decoration: none;
  padding: 0.5rem 0.95rem;
  border-radius: 7px;
  font-size: 0.92rem;
  font-weight: 600;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-alt);
}

.tab.active {
  background: var(--primary);
  color: #052e16;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.25rem;
}

.card-narrow {
  max-width: 580px;
}

.card h2 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.section-label {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 600;
}

.form-inline {
  display: flex;
  gap: 0.6rem;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

input:focus,
select:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.btn {
  border: none;
  border-radius: 8px;
  min-height: 44px;
  padding: 0.65rem 1.15rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #052e16;
  width: 100%;
  margin-top: 1rem;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary);
  color: #ffffff;
}

.btn-secondary:hover {
  background: var(--secondary-hover);
}

.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.88rem;
  padding: 0.25rem 0;
  min-height: 36px;
}

.btn-link:hover {
  color: var(--loss-text);
  text-decoration: underline;
}

.inline-link {
  color: var(--primary);
  text-decoration: none;
}

.inline-link:hover {
  text-decoration: underline;
}

.player-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pill {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.9rem;
}

.matchup-row {
  display: flex;
  gap: 0.75rem;
}

.field {
  flex: 1;
}

.score-field {
  flex: 0 0 92px;
}

.field label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.vs-divider {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0.7rem 0;
}

.flash-list {
  margin-bottom: 1rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.flash-success {
  background: var(--win-bg);
  color: var(--win-text);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.flash-error {
  background: var(--loss-bg);
  color: var(--loss-text);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-win {
  background: var(--win-bg);
  color: var(--win-text);
}

.badge-loss {
  background: var(--loss-bg);
  color: var(--loss-text);
}

.pos {
  color: var(--win-text);
}

.neg {
  color: var(--loss-text);
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Mobile-first usability & layout */
@media (max-width: 640px) {
  .container {
    padding: 1.25rem 0.9rem calc(5.5rem + env(safe-area-inset-bottom));
  }

  .header {
    margin-bottom: 1.1rem;
  }

  .header h1 {
    font-size: 1.55rem;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  /* Sticky bottom thumb-friendly navigation bar */
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom));
    background: rgba(15, 23, 42, 0.96);
    backdrop-filter: blur(8px);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.35);
  }

  .tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.5rem 0.4rem;
    font-size: 0.9rem;
    text-align: center;
  }

  .card {
    padding: 1rem;
    border-radius: 10px;
  }

  .form-inline {
    flex-direction: column;
  }

  .form-inline .btn {
    width: 100%;
  }

  .score-field {
    flex: 0 0 84px;
  }

  /* Convert tables into zero-scroll stacked cards on mobile */
  .table-wrap {
    overflow-x: visible;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tbody tr {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.75rem;
  }

  tbody tr:last-child {
    margin-bottom: 0;
  }

  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    text-align: right;
  }

  tbody td:last-child {
    border-bottom: none;
  }

  tbody td::before {
    content: attr(data-label);
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    margin-right: 0.75rem;
  }
}