*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
}

a { color: #60a5fa; text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* Nav */
nav {
  background: #1e293b;
  border-bottom: 1px solid #334155;
  padding: 0 1rem;
}
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 2rem;
}
.nav-brand { font-weight: 700; font-size: 1.2rem; color: #e2e8f0; }
.nav-links { display: flex; align-items: center; gap: 1.5rem; margin-left: auto; }
.nav-links a { color: #94a3b8; font-size: 0.9rem; }
.nav-links a:hover { color: #e2e8f0; }
.nav-username { color: #60a5fa; font-size: 0.85rem; font-weight: 600; }
.nav-toggle { display: none; background: none; border: none; color: #94a3b8; font-size: 1.5rem; cursor: pointer; padding: 0.25rem; line-height: 1; }

@media (max-width: 640px) {
  .nav-toggle { display: block; margin-left: auto; }
  .nav-links { display: none; flex-direction: column; position: absolute; top: 56px; left: 0; right: 0; background: #1e293b; border-bottom: 1px solid #334155; padding: 0.5rem 1rem 1rem; gap: 0.75rem; z-index: 100; }
  .nav-links.open { display: flex; }
  .nav-inner { position: relative; }
  .nav-links a, .nav-username { font-size: 1rem; padding: 0.25rem 0; }
}

/* Pages */
.page { padding: 2rem 1rem; }
.container { max-width: 1100px; margin: 0 auto; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }

/* Card */
.card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.register-card {
  max-width: 400px;
  margin: 4rem auto;
  text-align: center;
}
.register-card h1 { font-size: 1.8rem; margin-bottom: 0.5rem; }
.subtitle { color: #94a3b8; margin-bottom: 2rem; }

/* Form */
.form-group { margin-bottom: 1rem; text-align: left; }
.form-group label { display: block; font-size: 0.85rem; color: #94a3b8; margin-bottom: 0.3rem; }
.form-group input, .form-group select {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus { border-color: #60a5fa; }
.form-group select option { background: #1e293b; }

.inline-form {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  max-width: 400px;
}
.inline-form input, .inline-form select { flex: 1; padding: 0.6rem 0.8rem; background: #0f172a; border: 1px solid #334155; border-radius: 8px; color: #e2e8f0; font-size: 0.95rem; outline: none; }
.inline-form select option { background: #1e293b; }
.inline-form input:focus, .inline-form select:focus { border-color: #60a5fa; }

.btn {
  padding: 0.65rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-sm { padding: 0.4rem 1rem; font-size: 0.8rem; }

.error { color: #f87171; font-size: 0.85rem; margin-top: 0.5rem; }
.restore { margin-top: 1.5rem; font-size: 0.85rem; }

.card h3 { margin-bottom: 0.5rem; }
.hint { color: #64748b; font-size: 0.85rem; margin-bottom: 1rem; }

/* Group picks */
.group-section { margin-bottom: 1.5rem; }
.group-section h4 {
  background: #334155;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.group-pick-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.pick-field {
  flex: 1;
  min-width: 200px;
}
.pick-field label {
  display: block;
  font-size: 0.8rem;
  color: #94a3b8;
  margin-bottom: 0.3rem;
}
.pick-select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #e2e8f0;
  font-size: 0.95rem;
  outline: none;
}
.pick-select:focus { border-color: #60a5fa; }
.pick-select option { background: #1e293b; }

.status-msg { font-size: 0.85rem; margin-top: 0.5rem; color: #22c55e; }
.save-status { font-size: 0.85rem; color: #22c55e; }

/* Standings grid */
#standings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.status-card {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 1rem;
}
.status-card-me {
  border-color: #60a5fa;
  background: #172554;
}
.status-name { font-weight: 700; font-size: 1rem; margin-bottom: 0.5rem; }
.status-bar {
  height: 6px;
  background: #1e293b;
  border-radius: 3px;
  margin-bottom: 0.5rem;
  overflow: hidden;
}
.status-fill {
  height: 100%;
  background: #22c55e;
  border-radius: 3px;
  transition: width 0.3s;
}
.status-detail { font-size: 0.8rem; color: #94a3b8; margin-bottom: 0.3rem; display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; }
.status-detail .done { color: #22c55e; }
.status-detail .todo { color: #64748b; }

/* Table wrap (horizontal scroll on mobile) */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Leaderboard */
#leaderboard-table { width: 100%; border-collapse: collapse; }
#leaderboard-table th {
  text-align: left;
  padding: 0.75rem 0.5rem;
  font-size: 0.8rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #334155;
}
#leaderboard-table td {
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid #1e293b;
  font-size: 0.9rem;
}
.rank-1 { color: #fbbf24; font-weight: 700; }
.rank-2 { color: #94a3b8; font-weight: 700; }
.rank-3 { color: #d97706; font-weight: 700; }
.pred-none { color: #f87171; }
.pred-some { color: #fbbf24; }
.pred-all { color: #22c55e; }

/* Group table */
.group-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.group-table th { text-align: left; padding: 0.5rem 0.4rem; font-size: 0.7rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid #334155; }
.group-table td { padding: 0.5rem 0.4rem; border-bottom: 1px solid #1e293b; }
.group-table tbody tr:hover { background: #0f172a; }
.group-table .no-matches { opacity: 0.5; }
.group-table .rank-1 { color: #22c55e; font-weight: 700; }
.group-table .rank-2 { color: #60a5fa; font-weight: 700; }
.group-table .rank-3 { color: #f87171; font-weight: 700; }

/* Leaderboard breakdown */
.leaderboard-row { cursor: pointer; }
#leaderboard-table tbody .leaderboard-row:hover { background: #0f172a; }
.breakdown-row td { padding: 0 !important; border: none !important; }
.breakdown-content {
  background: #0f172a;
  padding: 2rem 1.5rem 1rem;
  border-bottom: 1px solid #334155;
  position: relative;
}
.breakdown-close {
  position: absolute;
  top: 0.4rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: #64748b;
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
}
.breakdown-close:hover { color: #e2e8f0; }
.breakdown-close:hover { color: #e2e8f0; }
.breakdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0;
  font-size: 0.85rem;
  border-bottom: 1px solid #1e293b;
}
.breakdown-item:last-child { border-bottom: none; }
.breakdown-label { color: #e2e8f0; }
.breakdown-pts { color: #22c55e; font-weight: 700; font-size: 0.9rem; }

/* Standings card */
#page-standings .card {
  padding: 0.8rem 1.5rem 1.5rem;
}

/* Pivot table (players as columns, predictions as rows) */
.pivot-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.pivot-table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.pivot-table th,
.pivot-table td {
  border: 1px solid #1e293b;
  padding: 0;
  text-align: center;
  white-space: nowrap;
}
.pivot-table thead { border-bottom: 2px solid #334155; }

.pivot-corner {
  min-width: 90px;
  border: none;
}

.pivot-name {
  height: 160px;
  vertical-align: bottom;
  padding: 0 !important;
  font-weight: 600;
  font-size: 0.7rem;
  color: #94a3b8;
  position: relative;
  overflow: visible;
}
.pivot-anchor {
  position: absolute;
  bottom: 10px;
  left: 50%;
}
.pivot-name-inner {
  display: block;
  transform-origin: bottom left;
  transform: rotate(-45deg);
  white-space: nowrap;
  z-index: 10;
}
.pivot-name.pivot-me .pivot-name-inner {
  color: #60a5fa;
}

.pivot-label {
  text-align: left;
  font-weight: 600;
  font-size: 0.65rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.4rem 0.6rem !important;
  border-left: none !important;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pivot-cell {
  font-size: 1.1rem;
  color: #94a3b8;
  min-width: 28px;
  padding: 0.3rem 0.15rem !important;
  position: relative;
  cursor: default;
}
.pivot-cell .pivot-val {
  display: inline-block;
}
.pivot-cell[title]:hover::after,
.pivot-cell[title]:focus::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #e2e8f0;
  padding: 0.3rem 0.6rem;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  z-index: 20;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.pivot-cell[title]:focus {
  outline: none;
}
.pivot-cell.pivot-dissenter {
  background: #334155;
}
.pivot-sep td {
  padding: 0 !important;
  height: 10px;
  background: #1e293b;
  border: none;
}

.pivot-cell.pivot-me,
.pivot-name.pivot-me {
  background: #172554;
}

/* Loading */
.loading { text-align: center; color: #64748b; padding: 4rem; font-size: 1.1rem; }
