:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --card: #161616;
  --border: #333333;
  --text: #ececec;
  --muted: #9a9a9a;
  --accent: #b3261e;
  --accent-hover: #d32f2f;
  --error: #ff5c4d;
  --ok: #8fd19e;
  --gold: #d4af37;
  --friendly: #4caf7d;
  --championship: #4a90d9;
}

* { box-sizing: border-box; }

a { color: var(--accent-hover); }
a:hover { color: var(--accent); }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand img {
  height: 2.3rem;
  width: auto;
}

/* Centered pre-auth pages (login/signup) */
main.center {
  max-width: 420px;
  margin: 3rem auto;
  padding: 0 1rem;
}

/* Authenticated app shell */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
}

.sidebar .brand {
  padding: 0 0.35rem 1.25rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
}

.sidebar-nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.8; }
.sidebar-nav a:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.sidebar-nav a.active { background: var(--accent); color: #fff; }
.sidebar-nav a.active svg { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1rem;
  font-size: 0.85rem;
}

.sidebar-footer .user-email {
  display: block;
  color: var(--muted);
  margin-bottom: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer a { color: var(--muted); }
.sidebar-footer a:hover { color: var(--error); }

.content { flex: 1; padding: 2.5rem; min-width: 0; }

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.content-header h1 { margin: 0; }

@media (max-width: 800px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    align-items: center;
    padding: 0.75rem 1rem;
    overflow-x: auto;
  }
  .sidebar .brand { border-bottom: none; margin: 0 1rem 0 0; padding: 0; }
  .sidebar-nav { flex-direction: row; flex: none; }
  .sidebar-footer {
    border-top: none;
    margin: 0 0 0 auto;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    white-space: nowrap;
  }
  .sidebar-footer .user-email { display: none; }
  .content { padding: 1.25rem; }
}

/* Landing hero (logged-out) */
.hero {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  background: radial-gradient(ellipse at top, rgba(179, 38, 30, 0.16), transparent 60%), var(--bg);
}

.hero img { height: 15rem; width: auto; margin-bottom: 1.5rem; filter: drop-shadow(0 12px 28px rgba(0, 0, 0, 0.55)); }
.hero h1 { font-size: 2.3rem; margin: 0 0 0.6rem; letter-spacing: 0.02em; }
.hero p { color: var(--muted); font-size: 1.05rem; max-width: 460px; margin: 0 0 2rem; line-height: 1.5; }

.hero-actions { display: flex; gap: 1rem; }
.hero-actions a {
  padding: 0.75rem 1.85rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
}
.hero-actions .primary { background: var(--accent); color: #fff; }
.hero-actions .primary:hover { background: var(--accent-hover); color: #fff; }
.hero-actions .secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
.hero-actions .secondary:hover { border-color: var(--accent-hover); color: var(--accent-hover); }

/* Dashboard stat tiles */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.15rem 1.25rem;
}
.stat-tile .value { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat-tile .label { color: var(--muted); font-size: 0.82rem; margin-top: 0.3rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }

.progress-track {
  position: relative;
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.progress-fill-reference {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
}
.progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}
.bar-chart-svg { width: 100%; height: auto; overflow: visible; }
.bar-chart-svg .bar:hover { opacity: 0.8; }
.bar-chart-svg .axis-label { fill: var(--muted); font-size: 9px; }
.bar-chart-svg .gridline { stroke: var(--border); stroke-width: 1; }

.chart-legend { display: flex; gap: 1rem; font-size: 0.78rem; color: var(--muted); margin-top: 0.5rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.chart-legend .swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.rank-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: rgba(179, 38, 30, 0.15);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
}

tr.match-win { background: rgba(143, 209, 158, 0.08); }
tr.match-loss { background: rgba(255, 92, 77, 0.08); }
.result-win { color: var(--ok); font-weight: 600; }
.result-loss { color: var(--error); font-weight: 600; }

dialog.modal { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1.5rem; max-width: 480px; width: 90vw; max-height: 85vh; overflow-y: auto; color: var(--text); }
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog.modal .modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
dialog.modal .modal-header h1 { font-size: 1.05rem; margin: 0; }
dialog.modal .modal-close { width: auto; margin-top: 0; padding: 0.2rem 0.55rem; background: transparent; border: 1px solid var(--border); color: var(--text); }

h1 { font-size: 1.4rem; margin-top: 0; }

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 1rem 0 0.35rem;
}

input, select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0d0d0d;
  color: var(--text);
  font-size: 0.95rem;
}

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

button {
  margin-top: 1.5rem;
  width: 100%;
  padding: 0.65rem;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
}

button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.msg { margin-top: 1rem; font-size: 0.9rem; }
.msg.error { color: var(--error); }
.msg.ok { color: var(--ok); }

.hint { font-size: 0.85rem; color: var(--muted); margin-top: 1rem; }
.hint a { color: var(--accent); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 500; }
