:root {
  --bg: #0f1020;
  --bg-card: #1a1b33;
  --bg-card-2: #232444;
  --text: #e8e9f3;
  --muted: #a3a5c0;
  --accent: #7c5cff;
  --good: #34d399;
  --bad: #f87171;
  --gold: #f5c451;
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #2a2350 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; position: sticky; top: 0; z-index: 10;
  background: rgba(15, 16, 32, 0.85); backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.1rem; margin: 0; font-weight: 650; }
.brand .crown { color: var(--gold); font-size: 1.4rem; }
.controls { display: flex; align-items: center; gap: 10px; }
.year-pick { font-size: .8rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
select, .btn {
  background: var(--bg-card-2); color: var(--text); border: 1px solid #34365e;
  border-radius: 10px; padding: 7px 12px; font-size: .9rem; cursor: pointer;
}
.btn { text-decoration: none; display: inline-block; }
.btn:hover { border-color: var(--accent); }
.btn.ghost { background: transparent; }

main { max-width: 880px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }

.card {
  background: linear-gradient(180deg, var(--bg-card) 0%, #16172c 100%);
  border: 1px solid #2a2c4f; border-radius: var(--radius); padding: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { font-size: 1rem; margin: 0; }

.banner { border-radius: 12px; padding: 12px 14px; font-size: .9rem; }
.banner.ok { background: rgba(52, 211, 153, 0.12); border: 1px solid var(--good); }
.banner.warn { background: rgba(245, 196, 81, 0.12); border: 1px solid var(--gold); }
.banner.err { background: rgba(248, 113, 113, 0.12); border: 1px solid var(--bad); }

.pill { font-size: .72rem; padding: 4px 10px; border-radius: 999px; background: var(--bg-card-2); color: var(--muted); }
.pill.good { color: var(--good); }
.pill.bad { color: var(--bad); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--bg-card-2); border-radius: 12px; padding: 12px; text-align: center;
}
.stat .v { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: .7rem; color: var(--muted); margin-top: 4px; }
.stat.emphasis .v { font-size: 1.9rem; }
.stat .v.good { color: var(--good); }
.stat .v.bad { color: var(--bad); }

.crown-card .v { color: var(--gold); }

.chart-wrap { position: relative; height: 260px; }
.trends { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.trends .chart-wrap { height: 200px; }

.note { color: var(--muted); font-size: .82rem; margin: 10px 0 0; }
.oura-actions { display: flex; gap: 10px; margin-top: 8px; }

.table-wrap { overflow-x: auto; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-size: .78rem; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid #2a2c4f; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

details summary { cursor: pointer; font-weight: 600; }

.foot { text-align: center; color: var(--muted); font-size: .75rem; padding: 24px; }

@media (max-width: 640px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .trends { grid-template-columns: 1fr; }
}
