:root {
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 14px; --r-sm: 9px;
  --side: 248px;
}
[data-theme="dark"] {
  --bg: #111113; --bg2: #0c0c0d; --surface: #18181b; --surface2: #202024; --hover: #26262b;
  --line: #2a2a30; --line2: #34343b;
  --text: #ececef; --muted: #9b9ba5; --faint: #6c6c76;
  --accent: #d6a85c; --accent-ink: #1a1408; --accent-soft: rgba(214,168,92,.14);
  --green: #74c08f; --green-soft: rgba(116,192,143,.14);
  --red: #e5786d; --red-soft: rgba(229,120,109,.14);
  --amber: #e2b45a; --amber-soft: rgba(226,180,90,.16);
  --blue: #7fa9e3; --blue-soft: rgba(127,169,227,.14);
  --shadow: 0 10px 40px rgba(0,0,0,.45);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f5f3ee; --bg2: #ece9e2; --surface: #ffffff; --surface2: #f7f5f1; --hover: #efece6;
  --line: #e4e0d8; --line2: #d6d1c7;
  --text: #1c1b1f; --muted: #6b6871; --faint: #9a97a0;
  --accent: #a47228; --accent-ink: #fff; --accent-soft: rgba(164,114,40,.12);
  --green: #2f8a55; --green-soft: rgba(47,138,85,.11);
  --red: #c4483c; --red-soft: rgba(196,72,60,.10);
  --amber: #a8730f; --amber-soft: rgba(168,115,15,.12);
  --blue: #2f66b3; --blue-soft: rgba(47,102,179,.10);
  --shadow: 0 10px 40px rgba(40,30,10,.14);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14.5px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--bg2); border-right: 1px solid var(--line); padding: 18px 12px 24px; display: flex; flex-direction: column; gap: 2px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; }
.brand .mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font: 700 13px/1 var(--sans); letter-spacing: .5px; }
.brand b { font: 600 17px/1 var(--serif); letter-spacing: .2px; }
.brand small { display: block; color: var(--faint); font-size: 11.5px; margin-top: 3px; }
.navgroup { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 1.1px; padding: 14px 10px 5px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: var(--r-sm); color: var(--muted); text-decoration: none; cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.nav:hover { background: var(--hover); color: var(--text); }
.nav.on { background: var(--accent-soft); color: var(--text); }
.nav.on svg { color: var(--accent); }
.nav .count { margin-left: auto; font-size: 11.5px; background: var(--red-soft); color: var(--red); border-radius: 20px; padding: 0 7px; }
.side .grow { flex: 1; }

.main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 12px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top .menu { display: none; }
.search { flex: 1; max-width: 520px; position: relative; }
.search input { width: 100%; padding: 9px 12px 9px 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); outline: none; }
.search input:focus { border-color: var(--accent); }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 16px; height: 16px; }
.results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 60vh; overflow: auto; padding: 6px; }
.results .rr { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.results .rr:hover { background: var(--hover); }
.results .rr small { color: var(--faint); margin-left: auto; }
.top .sp { flex: 1; }
.view { padding: 28px 28px 120px; max-width: 1240px; }

/* ---------- headings ---------- */
.ph { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.ph h1 { font: 500 30px/1.15 var(--serif); margin: 0; letter-spacing: -.2px; }
.ph p { margin: 4px 0 0; color: var(--muted); }
.ph .acts { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
h2.sec { font: 600 12px/1 var(--sans); text-transform: uppercase; letter-spacing: 1.1px; color: var(--faint); margin: 26px 0 10px; display: flex; align-items: center; gap: 8px; }
h2.sec .n { color: var(--muted); font-weight: 500; letter-spacing: 0; text-transform: none; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line2); background: var(--surface); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.pri:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.ib { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.ib:hover { background: var(--hover); color: var(--text); }
.ib svg { width: 16px; height: 16px; }

/* ---------- chips / pills ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { padding: 5px 11px; border-radius: 20px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; text-transform: capitalize; }
.chip:hover { color: var(--text); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 20px; font-size: 12px; background: var(--surface2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pill.red { background: var(--red-soft); color: var(--red); border-color: transparent; }
.pill.amber { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.pill.green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.pill.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }
.pill.gold { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- cards & lists ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; min-width: 0; }
.card.click { cursor: pointer; transition: border-color .15s, transform .15s; }
.card.click:hover { border-color: var(--line2); transform: translateY(-1px); }
.card h3 { margin: 0 0 12px; font: 600 13px/1 var(--sans); letter-spacing: .2px; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.card h3 svg { color: var(--accent); width: 16px; height: 16px; }
.card h3 a { margin-left: auto; font-weight: 500; color: var(--faint); text-decoration: none; font-size: 12.5px; cursor: pointer; }
.card h3 a:hover { color: var(--text); }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); cursor: pointer; min-width: 0; }
.row:first-child { border-top: 0; }
.row:hover { background: var(--hover); }
.row .main-t { min-width: 0; flex: 1; }
.row .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .m { color: var(--muted); font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; align-items: center; }
.row .m span + span::before { content: "·"; margin-right: 8px; color: var(--faint); }
.row .r { text-align: right; flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.row.done .t { color: var(--faint); text-decoration: line-through; }
.mini .row { padding: 8px 0; border-top-color: var(--line); background: none !important; }
.mini .row .t { font-weight: 450; }
.empty { color: var(--faint); padding: 22px 16px; text-align: center; font-size: 13.5px; }
.card .empty { padding: 10px 0; text-align: left; }

.check { width: 20px; height: 20px; border-radius: 6px; border: 1.6px solid var(--line2); background: transparent; display: grid; place-items: center; cursor: pointer; flex: none; padding: 0; }
.check:hover { border-color: var(--accent); }
.check.on { background: var(--green); border-color: var(--green); color: #fff; }
.check svg { width: 13px; height: 13px; stroke-width: 3; }

/* ---------- today ---------- */
.hello { display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
.hello h1 { font: 500 38px/1.05 var(--serif); margin: 0; letter-spacing: -.4px; }
.hello p { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
.capture { display: flex; gap: 8px; margin: 0 0 22px; }
.capture input { flex: 1; padding: 13px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); outline: none; font-size: 15px; }
.capture input:focus { border-color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat small { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: .8px; }
.stat b { display: block; font: 500 24px/1.2 var(--serif); margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat > span { color: var(--muted); font-size: 12.5px; }
.up { color: var(--green); } .down { color: var(--red); }

.bar { height: 6px; background: var(--surface2); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.bar.green i { background: var(--green); }
.catrow { display: grid; grid-template-columns: 120px 1fr 90px; gap: 10px; align-items: center; font-size: 13px; padding: 4px 0; text-transform: capitalize; }
.catrow .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

.habits-today { display: flex; flex-wrap: wrap; gap: 8px; }
.hchip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 20px; border: 1px solid var(--line2); background: transparent; cursor: pointer; }
.hchip.on { background: var(--green-soft); border-color: transparent; color: var(--green); }

/* habits grid */
.hgrid { display: grid; grid-template-columns: minmax(160px, 1.4fr) repeat(7, 38px) 80px; gap: 6px; align-items: center; }
.hgrid .hd { font-size: 11.5px; color: var(--faint); text-align: center; text-transform: uppercase; }
.hgrid .hn { font-weight: 500; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hgrid .cell { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface2); cursor: pointer; display: grid; place-items: center; }
.hgrid .cell.on { background: var(--green); border-color: var(--green); color: #fff; }
.hgrid .cell svg { width: 15px; height: 15px; stroke-width: 3; }
.hgrid .st { font-size: 12.5px; color: var(--muted); text-align: right; }

/* month nav */
.monthnav { display: inline-flex; align-items: center; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.monthnav b { min-width: 120px; text-align: center; font-weight: 600; }

/* secret values */
.secret { font-family: var(--mono); font-size: 13px; letter-spacing: .5px; display: inline-flex; align-items: center; gap: 2px; }
.secret .ib { width: 26px; height: 26px; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumb { width: 92px; height: 92px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface2) center/cover no-repeat; position: relative; display: grid; place-items: center; color: var(--muted); font-size: 11px; text-align: center; padding: 6px; overflow: hidden; text-decoration: none; }
.thumb .x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; border: 0; cursor: pointer; display: grid; place-items: center; }
.thumb.gone { opacity: .35; }

.kb-body { color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-top: 6px; white-space: pre-line; }
.prog { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.prog .bar { flex: 1; }
.prog small { color: var(--muted); font-variant-numeric: tabular-nums; width: 36px; text-align: right; }

/* ---------- drawer / forms ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: flex-end; background: rgba(0,0,0,.45); animation: fade .15s; }
.panel { width: min(560px, 100%); height: 100%; background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; animation: slide .2s ease-out; }
.panel header { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel header h2 { margin: 0; font: 500 20px/1.2 var(--serif); flex: 1; }
.panel .body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.panel footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.panel footer .sp { flex: 1; }
@keyframes fade { from { opacity: 0 } }
@keyframes slide { from { transform: translateX(30px); opacity: .5 } }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 14px; }
.f { display: flex; flex-direction: column; gap: 6px; grid-column: span 2; min-width: 0; }
.f.half { grid-column: span 1; }
.f label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.f label em { color: var(--red); font-style: normal; }
.f input:not([type=checkbox]):not([type=range]), .f select, .f textarea { width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line2); background: var(--bg); outline: none; }
.f input:focus, .f select:focus, .f textarea:focus { border-color: var(--accent); }
.f textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
.f textarea.tall { min-height: 260px; }
.f .tog { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 0; }
.f .tog input { width: 18px; height: 18px; accent-color: var(--accent); }
.f input[type=range] { accent-color: var(--accent); }
.f .hint { font-size: 12px; color: var(--faint); }
.f input[type=file] { padding: 8px; border: 1px dashed var(--line2); border-radius: 9px; background: var(--bg); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 70% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login form { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 30px 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.login .brand { padding: 0 0 6px; }
.login h1 { font: 500 26px/1.2 var(--serif); margin: 0; }
.login p { margin: 0; color: var(--muted); font-size: 13.5px; }
.login .err { color: var(--red); font-size: 13px; min-height: 18px; }
.login .btn { justify-content: center; padding: 11px; }

.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); font-size: 14px; }
.toast.bad { background: var(--red); color: #fff; }

.fab { display: none; }
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--surface2); color: var(--text); box-shadow: 0 0 0 1px var(--line2); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.note { background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; color: var(--muted); font-size: 13.5px; }
.note b { color: var(--text); }
.scrim { display: none; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; width: 280px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .top { padding: 10px 14px; }
  .top .menu { display: inline-grid; }
  .view { padding: 20px 14px 110px; }
  .hello h1 { font-size: 30px; }
  .ph h1 { font-size: 25px; }
  .grid, .grid.two { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .f.half { grid-column: span 2; }
  .fab { display: grid; place-items: center; position: fixed; right: 18px; bottom: calc(20px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); border: 0; box-shadow: var(--shadow); z-index: 20; }
  .fab svg { width: 24px; height: 24px; stroke-width: 2.2; }
  .hgrid { grid-template-columns: minmax(70px, 1fr) repeat(7, 27px); gap: 4px; }
  .hgrid .cell { width: 27px; height: 27px; border-radius: 7px; }
  .hgrid .hn { font-size: 13px; }
  .top .addtop { display: none; }
  .hgrid .st, .hgrid .sth { display: none; }
  .catrow { grid-template-columns: 90px 1fr 76px; }
  .kv { grid-template-columns: 1fr; }
  .ph .acts { margin-left: 0; }
}
