:root {
  color-scheme: light;
  --bg: #f7f3ee;
  --surface: #fffdfa;
  --surface-2: #f3ede6;
  --border: #e7ded3;
  --text: #2b2521;
  --text-2: #6b615a;
  --muted: #968b82;
  --accent: #c0607a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3e8;
  --good: #2f8a55;
  --good-soft: #e1f2e7;
  --warn: #b26a00;
  --series-in: #eb6834;
  --series-out: #2a78d6;
  --series-weight: #2a78d6;
  --grid: #ece5dc;
  --shadow: 0 1px 2px rgba(60, 40, 30, .05), 0 6px 24px rgba(60, 40, 30, .06);
  --radius: 18px;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #151312;
    --surface: #1f1c1a;
    --surface-2: #2a2623;
    --border: #36302c;
    --text: #f4eee8;
    --text-2: #c3b8ae;
    --muted: #8f857c;
    --accent: #e48aa2;
    --accent-ink: #1f1c1a;
    --accent-soft: #3a2429;
    --good: #5cc185;
    --good-soft: #1f3327;
    --warn: #e0a040;
    --series-in: #d95926;
    --series-out: #3987e5;
    --series-weight: #3987e5;
    --grid: #2e2a27;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 30px; }
h2 { font-size: 20px; }
.sub-head { font-size: 15px; margin: 20px 0 8px; font-family: var(--sans); font-weight: 600; color: var(--text-2); }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between;
  max-width: 1180px; margin: 0 auto; padding: 28px 20px 8px;
}
.tagline { margin: 0; color: var(--muted); font-size: 13px; }
.datenav { display: flex; align-items: center; gap: 6px; }

.date-pill {
  position: relative; display: inline-flex; align-items: center;
  padding: 8px 16px; min-width: 150px; justify-content: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  font-weight: 600; cursor: pointer;
}
.date-pill input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

button, .btn, .ghost-btn, .icon-btn { font: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 16px; border-radius: 12px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.05); }
.ghost-btn {
  padding: 8px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.ghost-btn:hover, .icon-btn:hover { background: var(--surface-2); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 18px; line-height: 1;
}
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.banner {
  max-width: 1140px; margin: 8px auto 0; padding: 10px 16px; border-radius: 12px;
  background: var(--accent-soft); color: var(--text);
}
.banner.good { background: var(--good-soft); }

main { max-width: 1180px; margin: 0 auto; padding: 12px 20px 60px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 0;
}
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.stat-value { font-family: var(--serif); font-size: 32px; font-weight: 600; line-height: 1.2; margin-top: 4px; }
.stat-sub { font-size: 13px; color: var(--text-2); }

/* ---------- cards ---------- */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); min-width: 0;
}
.card.wide { grid-column: 1 / -1; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.chip {
  font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2);
}
.chip.good { background: var(--good-soft); color: var(--good); }

input, select {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid transparent; border-radius: 12px; padding: 9px 12px; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.inline-form { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.inline-form input { width: 150px; }
.unit { color: var(--muted); font-weight: 600; }

.add-form { display: grid; grid-template-columns: 1fr 80px 110px auto; gap: 8px; margin: 14px 0 10px; }
#workoutForm { grid-template-columns: 1fr 70px 80px auto; }

.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-bar { height: 100%; width: 0; border-radius: 999px; transition: width .3s ease; }
.progress-bar.in { background: var(--series-in); }
.progress-bar.out { background: var(--series-out); }
.progress-bar.over { background: var(--warn); }

.entry-list { display: flex; flex-direction: column; }
.meal-group + .meal-group { margin-top: 8px; }
.meal-title {
  display: flex; justify-content: space-between; font-size: 12px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); font-weight: 600; padding: 6px 2px;
}
.entry {
  display: flex; align-items: center; gap: 10px; padding: 8px 2px;
  border-top: 1px solid var(--border);
}
.entry-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta { color: var(--muted); font-size: 13px; }
.entry-cals { font-weight: 600; font-variant-numeric: tabular-nums; }
.entry .del {
  border: 0; background: none; color: var(--muted); width: 28px; height: 28px; border-radius: 8px; font-size: 16px;
}
.entry .del:hover { background: var(--surface-2); color: var(--text); }
.empty { color: var(--muted); font-size: 14px; padding: 8px 2px; }

/* ---------- skincare ---------- */
.skin-toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.skin-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.skin-box {
  display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: 16px;
  background: var(--surface-2); border: 2px solid transparent; cursor: pointer; transition: all .15s ease;
}
.skin-toggle input:focus-visible + .skin-box { outline: 2px solid var(--accent); outline-offset: 2px; }
.skin-toggle input:checked + .skin-box { background: var(--accent-soft); border-color: var(--accent); }
.skin-icon { font-size: 24px; width: 28px; text-align: center; }
.skin-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.skin-text small { color: var(--muted); font-size: 12px; }
.check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0;
  display: grid; place-items: center; background: var(--surface);
}
.skin-toggle input:checked + .skin-box .check { background: var(--accent); border-color: var(--accent); }
.skin-toggle input:checked + .skin-box .check::after { content: '✓'; color: var(--accent-ink); font-weight: 700; font-size: 14px; }

.skin-history { margin-top: 18px; }
.dots { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; margin-top: 8px; }
.dot { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.dot i {
  width: 100%; max-width: 26px; aspect-ratio: 1; border-radius: 50%;
  background: var(--surface-2); border: 2px solid var(--border); display: block;
}
.dot.half i { background: linear-gradient(90deg, var(--accent) 50%, var(--surface-2) 50%); border-color: var(--accent); }
.dot.full i { background: var(--accent); border-color: var(--accent); }
.dot.sel span { color: var(--text); font-weight: 700; }

/* ---------- oura ---------- */
.oura { margin-top: 16px; padding: 14px; border-radius: 14px; background: var(--surface-2); }
.oura-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.oura-ring {
  width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--text); display: inline-block;
}
.spacer { flex: 1; }
.oura-body { margin-top: 10px; }
.oura-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.oura-metric { background: var(--surface); border-radius: 12px; padding: 10px 12px; }
.oura-metric b { display: block; font-family: var(--serif); font-size: 22px; }
.oura-metric span { font-size: 12px; color: var(--muted); }
.oura-workouts { margin-top: 8px; }
.oura-workouts .entry { border-top-color: var(--border); }
.oura-settings { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 14px; }

/* ---------- charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; font-family: var(--sans); }
.chart .goal-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .goal-label { fill: var(--text-2); font-size: 11px; font-family: var(--sans); }
.chart .line { fill: none; stroke: var(--series-weight); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--series-weight); stroke: var(--surface); stroke-width: 2; }
.chart .bar-in { fill: var(--series-in); }
.chart .bar-out { fill: var(--series-out); }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .hover-band { fill: var(--surface-2); }
.chart .direct-label { fill: var(--text); font-size: 12px; font-weight: 600; font-family: var(--sans); }

.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch.in { background: var(--series-in); }
.swatch.out { background: var(--series-out); }

.table-view { margin-top: 12px; font-size: 13px; color: var(--text-2); }
.table-view summary { cursor: pointer; }
.table-view table { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.table-view th:first-child, .table-view td:first-child { text-align: left; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 8px 10px; border-radius: 10px;
  font-size: 13px; line-height: 1.4; box-shadow: var(--shadow); white-space: nowrap;
}
.tooltip .t-row { display: flex; align-items: center; gap: 6px; }
.tooltip .t-date { font-weight: 600; margin-bottom: 2px; }

/* ---------- settings ---------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  padding: 24px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(20, 15, 12, .4); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--text-2); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 8px 0 0; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .topbar { padding: 20px 16px 4px; }
  main { padding: 12px 16px 48px; }
  .datenav { width: 100%; }
  .date-pill { flex: 1; min-width: 0; }
  #todayBtn { display: none; }
  .stat-value { font-size: 26px; }
  .add-form, #workoutForm { grid-template-columns: 1fr 1fr; }
  .add-form input[type="text"] { grid-column: 1 / -1; }
  .skin-toggles { grid-template-columns: 1fr; }
  .dots { gap: 3px; }
  .oura-metrics { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- sign in / loading ---------- */
.loading { min-height: 100vh; display: grid; place-items: center; color: var(--muted); padding: 16px; text-align: center; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px 28px; box-shadow: var(--shadow); text-align: center;
}
.auth-card form { display: flex; flex-direction: column; gap: 10px; margin: 24px 0 8px; text-align: left; }
.auth-card label { font-size: 14px; color: var(--text-2); }

.oura-settings p { margin: 0 0 8px; }
.token-row { display: flex; gap: 8px; }
.token-row input { flex: 1; }
.account { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); flex-wrap: wrap; }
