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

:root {
  --bg: #0a0a0f;
  --surface: #151520;
  --surface2: #1e1e2e;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-dim: #888899;
  --accent: #6c5ce7;
  --accent-glow: #7c6cf7;
  --green: #00e676;
  --red: #ff5252;
  --gold: #ffd740;
  --radius: 12px;
  --font: 'Space Grotesk', system-ui, sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* === Splash === */
#splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#splash img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.8s ease-out;
}

#splash.dimmed img { opacity: 0.3; }
#splash.hidden { display: none; }

/* === Screens === */
.screen { display: flex; flex-direction: column; min-height: 100dvh; }
.screen[hidden] { display: none !important; }

/* === Login === */
#login-screen {
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: transparent;
  position: relative;
  z-index: 1001;
}

#login-screen .login-card {
  opacity: 0;
  transition: opacity 0.6s ease-in;
}

#login-screen.show-card .login-card {
  opacity: 1;
}

.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-card h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

/* === User Picker === */
.user-picker { text-align: center; }

.picker-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 1.25rem;
}

.picker-buttons {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
}

.picker-btn {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  transition: border-color 0.2s, transform 0.1s;
}

.picker-btn:hover { border-color: var(--accent); }
.picker-btn:active { transform: scale(0.96); }

.picker-btn img {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
}

.picker-btn span {
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

/* === Password step === */
.pw-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  justify-content: center;
}

.pw-user .avatar { width: 40px; height: 40px; }

.pw-user span {
  font-size: 1.1rem;
  font-weight: 600;
}

.btn-back {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  margin-bottom: 1rem;
  align-self: flex-start;
}

.btn-back:hover { color: var(--text); }

/* Fade transitions for login steps */
#user-picker, #login-form {
  transition: opacity 0.25s ease;
}

#user-picker.fade-out, #login-form.fade-out {
  opacity: 0;
}

/* === Password field with toggle === */
.pw-field {
  position: relative;
}

.pw-field input { padding-right: 3rem; }

.pw-toggle {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
}

.pw-toggle:hover { color: var(--text); }

/* === Forms === */
form { display: flex; flex-direction: column; gap: 0.75rem; }
form[hidden] { display: none !important; }

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input, select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 0.75rem 1rem;
  width: 100%;
  transition: border-color 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

select { appearance: none; cursor: pointer; }

/* === Buttons === */
.btn {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 0.8rem 1.5rem;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}

.btn:active { transform: scale(0.97); }

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover { background: var(--accent-glow); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem;
}

.btn-icon:hover { color: var(--text); }

/* === Error / Message === */
.error { color: var(--red); font-size: 0.85rem; }
.msg { font-size: 0.85rem; }
.msg.success { color: var(--green); }
.msg.error { color: var(--red); }

/* === Header === */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.btn-logout:hover { color: var(--text); border-color: var(--text-dim); }

.logged-in-as {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.header-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

/* === Cards === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0.75rem 1rem;
  padding: 1.25rem;
}

.card h2 {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

/* === Banner === */
.banner-wrap {
  position: relative;
  width: 100%;
  overflow: hidden;
}

.banner-img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.banner-fade {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: linear-gradient(to bottom, transparent, var(--bg));
}

/* === Avatars === */
.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  margin-bottom: 0.35rem;
}

.winning .avatar { border-color: var(--green); }

/* === Scoreboard === */
.player-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
}

/* === Avatar wrap (for stars) === */
.avatar-wrap {
  position: relative;
  display: inline-block;
}

.stars {
  position: absolute;
  inset: -12px;
  pointer-events: none;
}

.star {
  position: absolute;
  font-size: 0.75rem;
  animation: star-pop 0.8s ease-out forwards;
  opacity: 0;
}

@keyframes star-pop {
  0% { opacity: 0; transform: scale(0) rotate(0deg); }
  30% { opacity: 1; transform: scale(1.3) rotate(15deg); }
  100% { opacity: 0; transform: scale(0.6) rotate(45deg) translateY(-10px); }
}

/* === Vertical Score Bars === */
.vbars {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  margin-top: 1rem;
}

.vbar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.vbar-value {
  font-size: 1.1rem;
  font-weight: 700;
}

.vbar-track {
  width: 48px;
  height: 100px;
  background: var(--surface2);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.vbar-fill {
  width: 100%;
  border-radius: 8px 8px 0 0;
  transition: height 0.6s ease-out;
  min-height: 3px;
}

.vbar-fill-1 { background: #3b82f6; }
.vbar-fill-2 { background: #fd79a8; }

.score-unit {
  text-align: center;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #aaaabc;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* === Week Progress Bar === */
.week-progress {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.week-progress-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 0.4rem;
}

.week-progress-track {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.week-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease-out;
}

.leader-banner {
  text-align: center;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gold);
}

.leader-banner[hidden] { display: none; }

.star-burst {
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
  pointer-events: none;
  animation: stars-fade 5s ease-out forwards;
}

.star-burst .star {
  position: absolute;
  font-size: 0.7rem;
  animation: star-twinkle 0.6s ease-in-out infinite alternate;
}

.star-burst .star:nth-child(1) { top: -4px; left: 50%; }
.star-burst .star:nth-child(2) { top: 10%; right: -4px; }
.star-burst .star:nth-child(3) { bottom: 10%; right: -2px; }
.star-burst .star:nth-child(4) { bottom: -4px; left: 50%; }
.star-burst .star:nth-child(5) { bottom: 10%; left: -4px; }
.star-burst .star:nth-child(6) { top: 10%; left: -2px; }

@keyframes star-twinkle {
  from { opacity: 0.4; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1.2); }
}

@keyframes stars-fade {
  0%, 80% { opacity: 1; }
  100% { opacity: 0; }
}

/* === Stats Grid === */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.stat-card {
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
}

.stat-card .stat-player {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.stat-card .stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  padding: 0.2rem 0;
}

.stat-card .stat-label { color: var(--text-dim); }

.stat-card .stat-value { font-weight: 600; }
.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }

/* === History === */
.history-list { display: flex; flex-direction: column; gap: 0.5rem; }
.history-list .empty { color: var(--text-dim); font-size: 0.85rem; text-align: center; }

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  background: var(--surface2);
  border-radius: 8px;
  font-size: 0.85rem;
}

.history-item .hi-left { display: flex; flex-direction: column; gap: 0.15rem; }
.history-item .hi-name { font-weight: 600; }
.history-item .hi-week { font-size: 0.75rem; color: var(--text-dim); }
.history-item .hi-right { text-align: right; font-size: 0.75rem; color: var(--text-dim); line-height: 1.4; }

/* === Loading Spinner === */
.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* === Score Info === */
.score-info-row {
  text-align: center;
  margin-top: 0.75rem;
}

.btn-info {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  transition: color 0.15s;
}

.btn-info:hover { color: var(--text); }

/* === Charts === */
.chart-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.chart-wrap {
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.75rem;
  cursor: pointer;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.chart-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn-expand {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.25rem;
  transition: color 0.15s;
}

.btn-expand:hover { color: var(--text); }

.chart-wrap--info {
  background: #1a1a28;
  border: 1px dashed var(--border);
}

.chart-note {
  font-size: 0.65rem;
  color: var(--text-dim);
  font-style: italic;
  flex: 1;
  text-align: center;
}

/* === Modal Overlay === */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay[hidden] { display: none; }

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 400px;
  width: 100%;
  position: relative;
}

.modal-content h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.modal-content p, .modal-content li {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 0.75rem;
}

.modal-content ul {
  padding-left: 1.25rem;
  margin-bottom: 0.75rem;
}

.modal-content .formula {
  background: var(--surface2);
  border-radius: 6px;
  padding: 0.75rem;
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--accent-glow);
  text-align: center;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

/* === Fullscreen Chart === */
.chart-fullscreen-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  height: 90vh;
  position: relative;
  display: flex;
  flex-direction: column;
}

.chart-fullscreen-content h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  padding-right: 2rem;
}

.chart-fullscreen-content canvas {
  flex: 1;
  min-height: 0;
}

/* === Responsive === */
@media (min-width: 600px) {
  .card { margin: 0.75rem auto; max-width: 520px; width: 100%; }
  header { max-width: 552px; margin: 0 auto; width: 100%; }
}
