:root {
  --bg: #0b0c0e;
  --surface: #14161a;
  --surface-2: #1c1f24;
  --border: #2a2d33;
  --text: #e6e7e9;
  --muted: #8a8f99;
  --accent: #3b82f6;
  --danger: #ef4444;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f8;
    --surface: #ffffff;
    --surface-2: #f0f1f3;
    --border: #d9dce0;
    --text: #14161a;
    --muted: #5a606b;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }
button { font: inherit; cursor: pointer; }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: 4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: .25rem;
  padding: .5rem 1rem env(safe-area-inset-top, .5rem);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: .5rem .9rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: .95rem;
  color: var(--muted);
}
.tab.on { background: var(--surface-2); color: var(--text); }
.logout { margin-left: auto; }
.logout button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 2.2rem; height: 2.2rem; border-radius: 50%;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
}
.card h2 { margin: 0 0 .5rem; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.empty-msg { color: var(--muted); font-size: .95rem; margin: .25rem 0; }
.hint { color: var(--muted); font-size: .8rem; margin-top: .5rem; }

.date-head {
  padding: .25rem 0 .25rem;
}
.date-head .weekday { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.date-head .iso { color: var(--muted); font-size: .9rem; }
.date-head .meta { display: flex; gap: .5rem; margin-top: .35rem; font-size: .8rem; }
.date-head .phase, .date-head .countdown {
  background: var(--surface-2);
  padding: .15rem .5rem;
  border-radius: 6px;
  color: var(--muted);
  text-transform: lowercase;
}

.readiness .readiness-head {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.readiness .score {
  background: color-mix(in srgb, var(--accent) 15%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  padding: .6rem .8rem;
  border-radius: 10px;
  min-width: 5rem;
  text-align: center;
}
.readiness .score-num { font-size: 2.2rem; font-weight: 700; line-height: 1; color: var(--accent); }
.readiness .score-label { font-size: .7rem; color: var(--muted); margin-top: .15rem; text-transform: uppercase; letter-spacing: .06em; }
.readiness .stats {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .25rem .75rem;
}
.readiness .stats > div { display: flex; justify-content: space-between; font-size: .85rem; }
.readiness .stats .k { color: var(--muted); }
.readiness .stats .v { font-variant-numeric: tabular-nums; }

.session-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.session-head h2 { margin: 0; }
.session-head .muted { color: var(--muted); font-size: .8rem; }
.badge {
  font-size: .8rem;
  font-weight: 600;
  padding: .2rem .55rem;
  border-radius: 6px;
  color: #fff;
}
.badge.dim { opacity: .6; }

.metrics {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .35rem .75rem;
}
.metrics li { display: flex; justify-content: space-between; font-size: .9rem; }
.metrics .k { color: var(--muted); }
.metrics .v { font-variant-numeric: tabular-nums; }

.session.changed { display: flex; flex-direction: column; gap: .5rem; }
.session.changed .row {
  border-left: 3px solid var(--accent);
  padding: .5rem .75rem;
  background: var(--surface-2);
  border-radius: 8px;
}
.session.changed .row.planned { opacity: .65; }
.session.changed .row-head { display: flex; justify-content: space-between; align-items: center; }
.session.changed .row-head .k { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.session.changed .row-meta { font-size: .9rem; margin-top: .25rem; }
.rationale { font-size: .9rem; color: var(--muted); margin: .5rem 0 0; font-style: italic; }

.activity .title { font-weight: 600; margin: .25rem 0 .5rem; }

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .35rem;
  margin-top: .5rem;
}
.week-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .5rem .25rem;
  text-align: center;
  font-size: .7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
}
.week-cell.current { border-color: var(--accent); background: var(--surface-2); }
.week-cell .dow { color: var(--muted); font-weight: 600; }
.week-cell .dot { width: .6rem; height: .6rem; border-radius: 50%; margin: .15rem 0; }
.week-cell .dur { font-weight: 600; }
.week-cell .lbl { color: var(--muted); }

.month-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.month-head h1 { font-size: 1.3rem; margin: 0; font-weight: 700; }
.nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 2.2rem; height: 2.2rem;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
}

.phase-strip { display: flex; gap: .35rem; flex-wrap: wrap; }
.phase-chip {
  font-size: .7rem;
  color: #fff;
  padding: .15rem .55rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}

.month-grid { display: flex; flex-direction: column; gap: .25rem; }
.dow-row, .day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: .25rem;
}
.dow-row { font-size: .7rem; color: var(--muted); padding: 0 .15rem; }
.dow-cell { text-align: center; }
.day-cell {
  position: relative;
  min-height: 64px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .3rem;
  font-size: .7rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
  overflow: hidden;
}
.day-cell.out { opacity: .35; }
.day-cell.today { border-color: var(--accent); }
.day-cell.race::after {
  content: '';
  position: absolute; inset: 0;
  border: 2px solid #f59e0b;
  border-radius: 8px;
  pointer-events: none;
}
.day-cell .day-num { font-weight: 700; color: var(--text); }
.day-cell .day-intent { font-weight: 600; color: var(--accent, var(--muted)); text-transform: capitalize; }
.day-cell[style*='--accent'] .day-intent { color: var(--accent); }
.day-cell .day-dur { color: var(--muted); font-variant-numeric: tabular-nums; }
.day-cell .day-done {
  position: absolute; bottom: 4px; right: 4px;
  width: 6px; height: 6px; border-radius: 50%;
  background: #22c55e;
}
.race-star { color: #f59e0b; }

.legend { margin-top: .5rem; color: var(--muted); font-size: .85rem; }
.legend-list { list-style: none; padding: 0; margin: .25rem 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: .15rem .75rem; }
.legend-list li { display: flex; align-items: center; gap: .4rem; }
.legend-dot { width: .7rem; height: .7rem; border-radius: 50%; }

.login {
  max-width: 320px;
  margin: 20vh auto 0;
  display: flex; flex-direction: column; gap: .75rem;
  text-align: center;
}
.login h1 { margin: 0 0 .5rem; font-size: 2rem; }
.login input {
  font: inherit;
  padding: .8rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: center;
  font-size: 1.4rem;
  letter-spacing: .25em;
}
.login button {
  padding: .8rem 1rem;
  border-radius: 10px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
}
.login .err { color: var(--danger); font-size: .9rem; }
