:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --green-line: #86efac;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --amber-line: #fcd34d;
  --empty: #eef0f3;
  --danger: #dc2626;
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}
/* Dark theme: data-theme is set before first paint from the saved choice (System / Light / Dark). */
:root[data-theme=dark] {
    color-scheme: dark;
    --bg: #111317;
    --card: #1b1e24;
    --text: #f1f2f4;
    --muted: #9aa1ad;
    --line: #2b2f37;
    --accent: #60a5fa;
    --green: #4ade80;
    --green-bg: #13321f;
    --green-line: #1f6b3a;
    --amber: #fbbf24;
    --amber-bg: #3a2c0b;
    --amber-line: #7a5a12;
    --empty: #252932;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.error { color: var(--danger); margin: 0; font-size: 14px; }

/* ---------- layout ---------- */
#app { max-width: 520px; margin: 0 auto; min-height: 100%; }
main { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  min-height: 64px;
}
.topbar-center { flex: 1; text-align: center; position: relative; min-width: 0; }
.title { font-size: 19px; font-weight: 700; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 0;
  background: var(--card); font-size: 28px; line-height: 1; padding-bottom: 4px;
  box-shadow: 0 1px 2px rgb(0 0 0 / .06);
}
.icon-btn:disabled { opacity: .3; }
.picker input[type=date] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; border: 0; cursor: pointer;
}
.picker input[type=date]::-webkit-calendar-picker-indicator {
  position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer;
}
.content { padding: 4px 12px 12px; display: flex; flex-direction: column; gap: 12px; }
.list { display: flex; flex-direction: column; gap: 10px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 130px; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; border: 1.5px solid transparent;
  box-shadow: 0 1px 2px rgb(0 0 0 / .05);
  transition: background-color .2s, border-color .2s;
}
.card.col { display: flex; flex-direction: column; gap: 10px; }
.card.met { background: var(--green-bg); border-color: var(--green-line); }
.card.partial { background: var(--amber-bg); border-color: var(--amber-line); }

.track { display: flex; align-items: center; gap: 12px; }
.track-main { flex: 1; min-width: 0; }
.track-name { font-weight: 650; font-size: 17px; overflow-wrap: anywhere; }
.track-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.card.met .track-sub { color: var(--green); font-weight: 600; }
.card.partial .track-sub { color: var(--amber); font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--empty); margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--amber); transition: width .2s; }
.card.met .bar i { background: var(--green); }

.stepper { display: flex; align-items: center; gap: 6px; }
.step {
  width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: var(--bg); font-size: 24px; font-weight: 600; line-height: 1;
}
.step:active { transform: scale(.94); }
.stepper input {
  width: 56px; height: 44px; text-align: center; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--card); font-size: 18px; font-weight: 650;
}
.stepper input:focus { outline: none; border-color: var(--accent); }

.tick {
  width: 52px; height: 52px; border-radius: 50%; flex: none;
  border: 2.5px solid var(--line); background: var(--card);
  display: grid; place-items: center;
}
.tick svg { width: 28px; height: 28px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.tick.on { background: var(--green); border-color: var(--green); }
.tick.on svg { opacity: 1; }
button.card { width: 100%; text-align: left; }
button.card:active { transform: scale(.99); }

/* ---------- summary ---------- */
.summary { display: flex; align-items: center; gap: 14px; padding: 6px 4px; }
.ring { --p: 0; width: 56px; height: 56px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--green) calc(var(--p) * 1%), var(--empty) 0);
  display: grid; place-items: center; }
.ring::after { content: attr(data-label); width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.summary .big { font-size: 17px; font-weight: 650; }

/* ---------- week ---------- */
.week-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 10px; }
.wd {
  border: 0; border-radius: 10px; padding: 6px 0; background: var(--empty);
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px;
}
.wd .dow { font-size: 11px; color: var(--muted); font-weight: 600; }
.wd .v { font-size: 15px; font-weight: 700; }
.wd.met { background: var(--green); }
.wd.met .dow, .wd.met .v { color: #fff; }
.wd.partial { background: var(--amber-bg); box-shadow: inset 0 0 0 1.5px var(--amber-line); }
.wd.partial .v { color: var(--amber); }
.wd.future { opacity: .4; }
.wd.today { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- items ---------- */
.item-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; }
.item-row .chev { color: var(--muted); font-size: 22px; }
.item-row.archived { opacity: .55; }
.section-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 8px 4px 0; }
.empty { text-align: center; padding: 28px 16px; }
.empty p { margin: 0 0 14px; }

/* ---------- buttons & forms ---------- */
.btn {
  height: 50px; padding: 0 18px; border-radius: 14px; border: 0;
  font-weight: 650; font-size: 16px; background: var(--card);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.danger { background: transparent; border: 1.5px solid var(--danger); color: var(--danger); }
.btn.block { width: 100%; }
.btn:active { transform: scale(.98); }
.small-btn { align-self: center; height: 42px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
input:not([type=date]):not(.stepper input), select {
  height: 50px; padding: 0 14px; border-radius: 12px; font-size: 16px;
  border: 1.5px solid var(--line); background: var(--card); color: var(--text); font-weight: 500;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented.three { grid-template-columns: 1fr 1fr 1fr; }
.segmented button {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 10px; font-weight: 650; display: flex; flex-direction: column; align-items: center;
}
.segmented small { font-weight: 500; color: var(--muted); font-size: 12px; }
.segmented button.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--card)); color: var(--accent); }

/* ---------- sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / .4);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease-out;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
  animation: up .2s ease-out;
}
.sheet h2 { margin: 0; font-size: 20px; }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); align-self: center; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login-box h1 { margin: 0; font-size: 28px; }
.login-box p { margin: 0; }
.login-box label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.login-logo { width: 64px; height: 64px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; box-shadow: 0 4px 16px rgb(0 0 0 / .2);
  max-width: calc(100% - 32px);
}
.toast.bad { background: var(--danger); color: #fff; }
.row2 > *, .field > input, .field > select { min-width: 0; width: 100%; }
.list > .section-label { margin-top: 10px; }

/* ---------- drag to reorder ---------- */
.drag {
  flex: none; align-self: stretch; display: flex; align-items: center; justify-content: center;
  width: 28px; margin: -14px 0 -14px -10px; font-size: 20px; color: var(--muted); opacity: .6;
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
}
.card-head { display: flex; align-items: center; gap: 4px; }
.card-head .drag { margin: -8px 0 -8px -10px; align-self: center; height: 40px; }
.dragging { position: relative; z-index: 6; transition: none !important; box-shadow: 0 10px 28px rgb(0 0 0 / .22); cursor: grabbing; }
body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
.hint { text-align: center; margin: 4px 0 0; }

/* ---------- auth ---------- */
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form h2 { margin: 8px 0 0; font-size: 20px; }
.auth-links { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.link { background: none; border: 0; padding: 8px 0; color: var(--accent); font-weight: 600; font-size: 15px; }
.notice { margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--green-bg); color: var(--text); font-size: 14px; }
