:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f8;
  --text: #1b1f2e;
  --muted: #5d6479;
  --border: #e2e5ee;
  --border-strong: #b9bfd0;
  --accent: #4f6df5;
  --c0: #4f6df5;
  --c1: #0ea5a0;
  --c2: #e8890c;
  --good: #16a34a;
  --warn: #c2410c;
  --warn-bg: #fff1e6;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(20, 28, 60, .06), 0 6px 20px rgba(20, 28, 60, .06);
  --radius: 14px;
}
:root[data-theme="dark"] {
  --bg: #0f1220;
  --surface: #181c2e;
  --surface-2: #20253a;
  --text: #e8ebf6;
  --muted: #9aa3bd;
  --border: #2a3050;
  --border-strong: #4a5278;
  --accent: #7b93ff;
  --c0: #7b93ff;
  --c1: #2dd4bf;
  --c2: #fbae3c;
  --good: #4ade80;
  --warn: #fdba74;
  --warn-bg: #3a2616;
  --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
p { margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.pad { padding: 2rem 1rem; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff; padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: 8px; top: 8px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: .6rem 1rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 6px; top: 4px; width: 9px; height: 5px; border-left: 3px solid #fff; border-bottom: 3px solid #fff; transform: rotate(-45deg); }
.tabs { display: flex; gap: .25rem; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: .45rem; padding: .45rem .8rem; border-radius: 999px; color: var(--muted); text-decoration: none; white-space: nowrap; font-weight: 500; }
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 650; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--cat, var(--accent)); display: inline-block; }
.topbar-tools { display: flex; align-items: center; gap: .6rem; margin-left: auto; }
.save-status { font-size: .8rem; color: var(--muted); min-width: 7.5rem; text-align: right; }
.save-status[data-state="saving"] { color: var(--accent); }
.save-status[data-state="error"] { color: var(--danger); font-weight: 600; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 10px; width: 38px; height: 38px; cursor: pointer; font-size: 1.1rem; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); }

/* ---------- layout ---------- */
main { max-width: 1120px; margin: 0 auto; padding: 1.25rem 1rem 4rem; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.page-head .sub { color: var(--muted); margin-top: .25rem; }
.head-tools { display: flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
input[type="text"], input[type="date"], input[type="number"], textarea {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; padding: .55rem .7rem; width: 100%; color: var(--text);
}
input[type="date"] { width: auto; }
textarea { resize: vertical; min-height: 4.5rem; }
.btn { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 10px; padding: .5rem .9rem; cursor: pointer; font-weight: 550; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--cat, var(--accent)); border-color: var(--cat, var(--accent)); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .3rem .65rem; font-size: .85rem; border-radius: 8px; }
.btn[disabled] { opacity: .6; cursor: default; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; }
.grid { display: grid; gap: 1rem; }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 1rem; }
.stat .label { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.7rem; font-weight: 700; margin-top: .15rem; }
.stat .hint { color: var(--muted); font-size: .8rem; }
.stat.warn .value { color: var(--warn); }
.charts { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); margin-bottom: 1rem; }
.chart-card h2 { margin-bottom: .1rem; }
.chart-card .sub { color: var(--muted); font-size: .85rem; margin-bottom: .5rem; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.bar.s0 { fill: var(--c0); } .bar.s1 { fill: var(--c1); } .bar.s2 { fill: var(--c2); } .bar.smuted { fill: var(--border-strong); opacity: .55; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: .4rem; }
.swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.swatch.s0 { background: var(--c0); } .swatch.s1 { background: var(--c1); } .swatch.s2 { background: var(--c2); } .swatch.smuted { background: var(--border-strong); }

.cat-0 { --cat: var(--c0); } .cat-1 { --cat: var(--c1); } .cat-2 { --cat: var(--c2); }
.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.progress > span { display: block; height: 100%; background: var(--cat, var(--accent)); border-radius: 999px; transition: width .3s ease; }

.overall { display: grid; grid-template-columns: auto 1fr; gap: 1.25rem; align-items: center; margin-bottom: 1rem; }
.ring text { fill: var(--text); font-weight: 700; }
.ring .track { stroke: var(--surface-2); }
.ring .meter { stroke: var(--accent); transition: stroke-dashoffset .4s ease; }
.overall h2 { font-size: 1.25rem; }

.cat-cards { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: 1rem; }
.cat-card { text-decoration: none; color: inherit; display: block; transition: transform .15s ease; }
.cat-card:hover { transform: translateY(-2px); }
.cat-card .row { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; margin-bottom: .5rem; }
.cat-card .name { display: flex; align-items: center; gap: .5rem; font-weight: 650; font-size: 1.05rem; }
.cat-card .pct { font-weight: 700; font-size: 1.3rem; color: var(--cat); }
.cat-card .meta { display: flex; gap: 1rem; flex-wrap: wrap; color: var(--muted); font-size: .85rem; margin-top: .6rem; }

.next-list { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .1rem; }
.next-list a { display: flex; gap: .7rem; align-items: baseline; padding: .5rem .4rem; border-radius: 8px; text-decoration: none; color: inherit; }
.next-list a:hover { background: var(--surface-2); }
.next-list .when { color: var(--muted); font-size: .85rem; min-width: 6.5rem; }

details.card > summary { cursor: pointer; font-weight: 650; list-style: none; display: flex; justify-content: space-between; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "▾"; color: var(--muted); }
details.card[open] > summary::after { content: "▴"; }
.routine { list-style: none; padding: 0; margin: .8rem 0; display: grid; gap: .5rem; }
.routine li { display: grid; grid-template-columns: 8.5rem 4rem 1fr; gap: .6rem; }
.routine .step { font-weight: 600; }
.routine .mins { color: var(--muted); }
.tips { margin: .5rem 0 0; padding-left: 1.2rem; display: grid; gap: .3rem; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.5rem; }

.filters { display: flex; gap: .4rem; flex-wrap: wrap; margin: 1.25rem 0 .75rem; }
.chip { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: .3rem .9rem; cursor: pointer; font-size: .9rem; }
.chip[aria-pressed="true"] { background: var(--cat); border-color: var(--cat); color: #fff; font-weight: 600; }

.week { margin-bottom: 1.25rem; }
.week-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0 .2rem .5rem; flex-wrap: wrap; }
.week-head .theme { color: var(--muted); font-weight: 500; }
.week-head .count { color: var(--muted); font-size: .85rem; }
.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.task { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .75rem .9rem; display: grid; grid-template-columns: auto 1fr auto; gap: .2rem .8rem; box-shadow: var(--shadow); }
.task.done { background: color-mix(in srgb, var(--surface) 70%, var(--bg)); }
.task.done .task-title .t { text-decoration: line-through; color: var(--muted); }
.task.overdue { border-left: 4px solid var(--warn); }
.check { display: grid; place-items: center; padding: .15rem; cursor: pointer; align-self: start; }
.check input {
  -webkit-appearance: none; appearance: none; margin: 0; width: 24px; height: 24px; flex: none;
  border: 2px solid var(--border-strong); border-radius: 6px; background: var(--surface); cursor: pointer;
  display: grid; place-content: center; transition: background .12s, border-color .12s;
}
.check input::after { content: ""; width: 11px; height: 6px; border-left: 3px solid #fff; border-bottom: 3px solid #fff; transform: rotate(-45deg) scale(0); margin-top: -2px; transition: transform .12s; }
.check input:checked { background: var(--cat, var(--accent)); border-color: var(--cat, var(--accent)); }
.check input:checked::after { transform: rotate(-45deg) scale(1); }
.task-title { font-weight: 600; display: flex; gap: .4rem .5rem; flex-wrap: wrap; align-items: center; }
.task-meta { color: var(--muted); font-size: .82rem; }
.task-focus { margin-top: .2rem; }
.task-practice { margin-top: .15rem; color: var(--muted); font-size: .92rem; }
.task-practice strong { color: var(--text); font-weight: 600; }
.badge { font-size: .72rem; font-weight: 650; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.today { background: var(--cat); color: #fff; border-color: var(--cat); }
.badge.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.task-actions { display: flex; gap: .35rem; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; }
.task-details { grid-column: 2 / -1; margin-top: .6rem; padding-top: .7rem; border-top: 1px dashed var(--border); display: grid; gap: .7rem; }
.task-details[hidden] { display: none; }
.conf { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.conf .scale { display: inline-flex; gap: .3rem; }
.conf button { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 600; }
.conf button[aria-pressed="true"] { background: var(--cat); border-color: var(--cat); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem; border: 1px dashed var(--border-strong); border-radius: 12px; }

/* ---------- dialog & toast ---------- */
dialog { border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 1.5rem)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(10, 14, 30, .55); }
.dialog-form { padding: 1.25rem; display: grid; gap: .9rem; }
.dialog-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.form-error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }
.toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translate(-50%, 140%); background: #1b1f2e; color: #fff; padding: .7rem 1.1rem; border-radius: 12px; max-width: min(92vw, 520px); box-shadow: var(--shadow); transition: transform .25s ease; z-index: 50; }
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: #b91c1c; }

.error-card { max-width: 560px; margin: 3rem auto; text-align: center; display: grid; gap: .8rem; justify-items: center; }

@media (max-width: 720px) {
  h1 { font-size: 1.35rem; }
  .topbar-inner { gap: .5rem; }
  .tabs { order: 3; flex-basis: 100%; }
  .save-status { min-width: 0; }
  .task { grid-template-columns: auto 1fr; }
  .task-actions { grid-column: 2; justify-content: flex-start; margin-top: .3rem; }
  .task-details { grid-column: 1 / -1; }
  .check { padding: .35rem; }
  .overall { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .routine li { grid-template-columns: 1fr; gap: 0; }
  .charts { grid-template-columns: 1fr; }
  .dialog-form .row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }


/* Authentication screen */
.auth-wrap {
  width: min(100% - 2rem, 460px);
  margin: 3rem auto;
}

.auth-card {
  display: grid;
  gap: 1rem;
}

.auth-card h1,
.auth-card p {
  margin: 0;
}

.auth-card input[type="email"],
.auth-card input[type="password"] {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: .7rem;
  width: 100%;
  color: var(--text);
}

.auth-card .btn.primary {
  width: 100%;
  min-height: 44px;
}

.auth-switch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .5rem !important;
}
