:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: rgba(11, 11, 11, 0.10);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #e0531c;
  --accent-ink: #ffffff;
  --accent-soft: rgba(224, 83, 28, 0.10);
  --good: #006300;
  --good-mark: #0ca30c;
  --bad: #c42e2e;
  --warn: #9a6a00;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --seq-0: #f0efec; --seq-1: #b7d3f6; --seq-2: #86b6ef; --seq-3: #3987e5; --seq-4: #1c5cab;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --border: rgba(255,255,255,0.10);
    --text: #ffffff; --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --accent: #ff6a2b; --accent-ink: #140800; --accent-soft: rgba(255, 106, 43, 0.14);
    --good: #0ca30c; --bad: #e66767; --warn: #fab219;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-0: #242422; --seq-1: #184f95; --seq-2: #256abf; --seq-3: #3987e5; --seq-4: #86b6ef;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --border: rgba(255,255,255,0.10);
  --text: #ffffff; --text-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --accent: #ff6a2b; --accent-ink: #140800; --accent-soft: rgba(255, 106, 43, 0.14);
  --good: #0ca30c; --bad: #e66767; --warn: #fab219;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --seq-0: #242422; --seq-1: #184f95; --seq-2: #256abf; --seq-3: #3987e5; --seq-4: #86b6ef;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1100px 420px at -10% -20%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
    radial-gradient(800px 360px at 110% -10%, color-mix(in srgb, var(--s1) 14%, transparent), transparent 55%),
    var(--bg);
  color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); }
.sub { color: var(--text-2); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(16px); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; padding: 4px 10px 18px; letter-spacing: -0.02em; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text-2); font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 19px; height: 19px; flex: none; }
.side-foot { margin-top: auto; padding: 10px; font-size: 13px; }
.main { padding: 28px 32px 60px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; }
.bottom-nav, .topbar { display: none; }
.topbar a.active { color: var(--accent); }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.mt { margin-top: 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head .sub { margin-top: 2px; }

/* ---------- stat tiles ---------- */
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { color: var(--text-2); font-size: 13px; font-weight: 550; display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; white-space: nowrap; }
.tile .value small { font-size: 14px; font-weight: 550; color: var(--text-2); margin-left: 3px; }
.tile .delta { font-size: 13px; margin-top: 2px; color: var(--text-2); }
.delta .up::before { content: "▲ "; font-size: 10px; }
.delta .down::before { content: "▼ "; font-size: 10px; }

/* ---------- forms ---------- */
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 550; color: var(--text-2); min-width: 0; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 70px; }
.btn {
  font: inherit; font-weight: 650; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 10px 16px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { font: inherit; font-size: 13px; font-weight: 600; background: none; border: 0; color: var(--text-2); padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { font: inherit; font-size: 13px; font-weight: 600; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; text-transform: capitalize; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip.plan { border-color: var(--accent); }
.split-day { margin-bottom: 14px; }
.split-day .chips { margin-top: 6px; }

.stepper { display: flex; align-items: stretch; }
.stepper input { text-align: center; font-size: 20px; font-weight: 700; border-radius: 0; padding: 10px 4px; }
.stepper button { font: inherit; font-size: 20px; width: 46px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; }
.stepper button:first-child { border-radius: 10px 0 0 10px; border-right: 0; }
.stepper button:last-child { border-radius: 0 10px 10px 0; border-left: 0; }

/* ---------- tables & lists ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }

.ex-group { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.ex-group + .ex-group { margin-top: 10px; }
.set-row { display: grid; grid-template-columns: 36px 1fr auto auto; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px dashed var(--border); font-variant-numeric: tabular-nums; }
.set-row:first-of-type { border-top: 0; }
.set-no { width: 28px; height: 28px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--text-2); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; }
.badge.pr { background: var(--accent-soft); color: var(--accent); }
.badge.ok { color: var(--good); }
.badge.off { color: var(--bad); }

.ex-list { max-height: 330px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.ex-item { text-align: left; font: inherit; border: 1px solid transparent; background: none; color: var(--text); padding: 9px 11px; border-radius: 10px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ex-item:hover { background: var(--surface-2); }
.ex-item.on { border-color: var(--accent); background: var(--accent-soft); }
.ex-item .sub { font-size: 12px; }

.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.day-cell { border: 1px solid var(--border); border-radius: 12px; padding: 10px 6px; text-align: center; background: var(--surface); min-width: 0; }
.day-cell .d { font-size: 12px; color: var(--muted); font-weight: 600; }
.day-cell .m { font-size: 13px; font-weight: 650; text-transform: capitalize; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-cell .s { margin-top: 6px; height: 20px; display: grid; place-items: center; }
.day-cell.today { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--grid); display: inline-block; }
.dot.done { background: var(--good-mark); }
.dot.miss { background: var(--bad); opacity: .6; }

.insight { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.insight:first-child { border-top: 0; padding-top: 0; }
.insight .ic { width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center; background: var(--surface-2); font-size: 15px; }
.insight b { font-weight: 650; }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.chart-box.short { height: 190px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 13px); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap div { width: 13px; height: 13px; border-radius: 3px; background: var(--seq-0); }
.heat-legend { display: flex; gap: 3px; align-items: center; font-size: 11px; color: var(--muted); margin-top: 8px; }
.heat-legend div { width: 11px; height: 11px; border-radius: 3px; }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; font-size: 14px; }

.hero-today { background: linear-gradient(145deg, #ff7a3d 0%, var(--accent) 42%, #9a2d08 100%); color: #fff; border: 0; position: relative; overflow: hidden; }
.hero-today::after { content: ""; position: absolute; width: 220px; height: 220px; border-radius: 50%; right: -60px; top: -80px; background: rgba(255,255,255,.12); pointer-events: none; }
.hero-today .sub { color: rgba(255,255,255,.85); }
.hero-today h1 { font-size: 30px; text-transform: capitalize; }
.hero-today .btn { background: #fff; color: #7a2400; border: 0; }
.hero-today .btn.ghost-light { background: rgba(255,255,255,.16); color: #fff; }
.hero-row { display: flex; justify-content: space-between; gap: 16px; align-items: center; position: relative; z-index: 1; }

.score-ring { width: 96px; flex: none; display: grid; justify-items: center; color: #fff; text-decoration: none; }
.score-ring svg, .score-num { grid-area: 1 / 1; width: 96px; height: 96px; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring circle { fill: none; stroke-width: 7; }
.score-ring .track { stroke: rgba(255,255,255,.28); }
.score-ring .val { stroke: #fff; stroke-linecap: round; }
.score-ring.ink { color: var(--text); }
.score-ring.ink .track { stroke: var(--surface-2); }
.score-ring.ink .val { stroke: var(--accent); }
.score-num { display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 26px; letter-spacing: -0.03em; line-height: 1; }
.score-caption { margin-top: 4px; font-size: 11px; font-weight: 700; text-align: center; line-height: 1.2; }

.mbar { margin: 10px 0; font-size: 13px; text-transform: capitalize; }
.mbar-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.mbar .track, .ach .track { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 5px; }
.mbar .track > div, .ach .track > div { height: 100%; border-radius: 99px; background: var(--accent); }
.mbar .num { color: var(--text-2); font-size: 12px; white-space: nowrap; }

.macros { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.macro { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.macro b { display: block; font-size: 18px; letter-spacing: -0.02em; }
.macro .sub { font-size: 12px; }
.food-hit { text-align: left; font: inherit; width: 100%; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 12px; padding: 10px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.food-hit + .food-hit { margin-top: 8px; }
.food-hit:hover { border-color: var(--accent); }

.water-dots { display: flex; gap: 8px; flex-wrap: wrap; }
.water-dots button { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; padding: 0; }
.water-dots button.on { background: var(--s1); border-color: transparent; }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.ach { border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: var(--surface-2); opacity: .72; }
.ach.on { opacity: 1; background: var(--accent-soft); border-color: transparent; }
.ach-title { font-weight: 700; margin-bottom: 2px; }
.ach .track { margin-top: 10px; background: color-mix(in srgb, var(--text) 8%, transparent); }

.banner { border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.banner.warn { background: color-mix(in srgb, var(--warn) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); }
.tile { transition: transform .15s ease; }
.tile:hover { transform: translateY(-1px); }

/* rest timer */
.timer { position: fixed; right: 20px; bottom: 20px; background: var(--text); color: var(--bg); border-radius: 16px; padding: 12px 16px; display: flex; align-items: center; gap: 14px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.timer .t { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 70px; }
.timer button { background: none; border: 1px solid currentColor; color: inherit; border-radius: 8px; padding: 4px 9px; font: inherit; font-size: 12px; cursor: pointer; opacity: .8; }

/* toast & modal */
.toast { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; font-weight: 600; z-index: 100; font-size: 14px; max-width: calc(100vw - 32px); }
.toast.err { background: var(--bad); color: #fff; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 80; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; padding: 22px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; border: 1px solid var(--border); }
.modal h2 { margin-bottom: 14px; }

/* auth */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art { background: radial-gradient(circle at 20% 20%, #ff7a3d, #b83a0c 55%, #3a1203); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-art h1 { font-size: 42px; letter-spacing: -0.03em; max-width: 480px; }
.auth-art p { font-size: 17px; opacity: .9; max-width: 440px; }
.auth-feats { display: grid; gap: 10px; font-size: 15px; }
.auth-feats div { display: flex; gap: 10px; align-items: center; }
.auth-form { display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 24px; margin-bottom: 4px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }
.err-text { color: var(--bad); font-size: 13px; min-height: 18px; }

@media (max-width: 1080px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 18px 16px 96px; }
  .topbar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 40; background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 12px 10px 16px; }
  .topbar .icon-btn svg { width: 21px; height: 21px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .bottom-nav { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); z-index: 40; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .macros { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; font-weight: 600; }
  .bottom-nav a.active { color: var(--accent); }
  .bottom-nav svg { width: 22px; height: 22px; }
  .timer { bottom: 84px; right: 12px; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 28px 20px; gap: 18px; }
  .auth-art h1 { font-size: 28px; }
  .auth-feats { display: none; }
  .tile .value { font-size: 23px; }
  .hero-row { align-items: flex-start; }
  .score-ring, .score-ring svg, .score-num { width: 84px; }
  .score-ring svg, .score-num { height: 84px; }
  .week-strip { gap: 4px; }
  .day-cell { padding: 8px 2px; }
  .day-cell .m { font-size: 11px; }
  h1 { font-size: 21px; }
}
@media (max-width: 420px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px 13px; }
}
