:root {
  --bg: #f5f6f8; --surface: #fff; --sunken: #eef0f4; --ink: #161a22; --muted: #5b6372; --line: #e2e5eb;
  --on-ink: #fff; --focus: #2f5bff; --danger: #c2332f; --ok: #167a4f; --warn: #a15c00;
  --shadow: 0 1px 2px rgba(20,26,40,.05), 0 6px 20px -8px rgba(20,26,40,.10);
  --g0: #3b6cf0; --g1: #0e9f7e; --g2: #e0663a; --g3: #9b5de5; --g4: #d6366b; --g5: #c28a00; --g6: #0f8fa8; --g7: #6b7a8f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1218; --surface: #171b23; --sunken: #1f242e; --ink: #eceff4; --muted: #9aa3b2; --line: #272d38;
  --on-ink: #0f1218; --focus: #7b9bff; --danger: #ff7a74; --ok: #4cc58f; --warn: #e3a54a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -10px rgba(0,0,0,.5);
  --g0: #6e93ff; --g1: #34c79f; --g2: #ff8a5c; --g3: #b98af0; --g4: #f06a97; --g5: #e0b040; --g6: #3cc0db; --g7: #9aa8bc;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --surface: #171b23; --sunken: #1f242e; --ink: #eceff4; --muted: #9aa3b2; --line: #272d38;
    --on-ink: #0f1218; --focus: #7b9bff; --danger: #ff7a74; --ok: #4cc58f; --warn: #e3a54a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -10px rgba(0,0,0,.5);
    --g0: #6e93ff; --g1: #34c79f; --g2: #ff8a5c; --g3: #b98af0; --g4: #f06a97; --g5: #e0b040; --g6: #3cc0db; --g7: #9aa8bc;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.icon { display: inline-flex; vertical-align: middle; flex: none; }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 22px 14px; display: flex; flex-direction: column; gap: 22px; border-right: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px; font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.mark { width: 22px; height: 22px; border-radius: 7px; background: var(--ink); position: relative; }
.mark::after { content: ""; position: absolute; left: 6px; top: 5px; width: 9px; height: 5px; border: 2px solid var(--on-ink); border-width: 0 0 2px 2px; transform: rotate(-45deg); }
#nav { display: flex; flex-direction: column; gap: 4px; }
#nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 520; }
#nav a:hover { background: var(--sunken); color: var(--ink); }
#nav a[aria-current="page"] { background: var(--sunken); color: var(--ink); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.ghost { display: flex; align-items: center; gap: 11px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 9px; color: var(--muted); text-align: left; }
.ghost:hover { background: var(--sunken); color: var(--ink); }
main { padding: 36px clamp(18px, 4vw, 56px) 80px; max-width: 1180px; width: 100%; min-width: 0; outline: none; }

/* page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.page-head h1 { font-size: 28px; line-height: 1.15; letter-spacing: -.02em; font-weight: 680; }
.page-head p { color: var(--muted); margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; margin-bottom: 14px; font-size: 14px; }
.back:hover { color: var(--ink); }
.page-head h1.month-title { font: 400 clamp(40px, 7vw, 68px)/1 var(--serif); letter-spacing: -.02em; }
.page-head h1.month-title small { display: block; font: 500 14px var(--sans); color: var(--muted); letter-spacing: 0; margin-bottom: 8px; }

/* buttons & fields */
a.btn { text-decoration: none; color: inherit; }
a.btn.primary { color: var(--on-ink); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 550; line-height: 1.3; }
.btn:hover { background: var(--sunken); }
.btn.primary { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: none; color: var(--muted); }
.icon-btn:hover:not(:disabled) { background: var(--sunken); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.danger:hover { color: var(--danger); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field > .lab { font-weight: 560; font-size: 13.5px; }
.field .hint { font-size: 12.5px; color: var(--muted); }
input[type=text], input[type=number], input[type=date], select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--ink) 25%, var(--line)); }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--sunken); border-radius: 10px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 8px; color: var(--muted); font-weight: 540; font-size: 13.5px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 140px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.card.pad { padding: 20px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.section-title { font-size: 16px; font-weight: 650; margin: 34px 0 12px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 560; background: var(--sunken); color: var(--muted); white-space: nowrap; }
.chip.high { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.chip.medium { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.chip.completed { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.chip.ongoing { color: var(--focus); background: color-mix(in srgb, var(--focus) 13%, transparent); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gc, var(--g0)); flex: none; }
.gc { --gc: var(--g0); } .gc1 { --gc: var(--g1); } .gc2 { --gc: var(--g2); } .gc3 { --gc: var(--g3); }
.gc4 { --gc: var(--g4); } .gc5 { --gc: var(--g5); } .gc6 { --gc: var(--g6); } .gc7 { --gc: var(--g7); }
.bar { height: 7px; border-radius: 99px; background: var(--sunken); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--gc, var(--ink)); transition: width .4s ease; }
.bar.ink > i { background: var(--ink); }
.bar.over > i { background: var(--ok); }

/* stat strip */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 8px; }
.stat { padding: 16px 18px; }
.stat .k { color: var(--muted); font-size: 13.5px; }
.stat .v { font-size: 26px; font-weight: 660; letter-spacing: -.02em; margin: 2px 0 8px; }
.stat .v small { font-size: 14px; font-weight: 520; color: var(--muted); letter-spacing: 0; }
.stat .s { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* goal cards */
.goal { display: flex; flex-direction: column; gap: 12px; padding: 18px; text-align: left; width: 100%; cursor: pointer; transition: transform .15s ease, border-color .15s ease; position: relative; overflow: hidden; }
.goal::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--gc); }
.goal:hover { border-color: color-mix(in srgb, var(--gc) 55%, var(--line)); transform: translateY(-1px); }
.goal h3 { font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.goal .desc { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.goal .levels { display: flex; align-items: center; gap: 8px; font-size: 14px; flex-wrap: wrap; }
.goal .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 13px; color: var(--muted); }
.goal .pr { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 6px; }
.goal.paused, .goal.completed { opacity: .72; }
.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); font-size: 17px; margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }

/* milestones / lists */
.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); align-items: flex-start; }
.item:first-child { border-top: 0; }
.item .body { flex: 1; min-width: 0; }
.item .t { font-weight: 580; }
.item.done .t { text-decoration: line-through; color: var(--muted); }
.item .sub { font-size: 13px; color: var(--muted); }
.item .acts { display: flex; gap: 0; flex: none; }
.check { width: 22px; height: 22px; flex: none; border-radius: 7px; border: 1.8px solid color-mix(in srgb, var(--ink) 35%, var(--line)); background: var(--surface); display: inline-grid; place-items: center; margin-top: 1px; padding: 0; color: var(--on-ink); }
.check:hover { border-color: var(--ink); }
.check[aria-checked="true"] { background: var(--gc, var(--ink)); border-color: var(--gc, var(--ink)); }
.check[aria-checked="true"] .icon { display: inline-flex; }
.check .icon { display: none; }
.plan-text { white-space: pre-wrap; font-size: 14px; color: var(--muted); margin-top: 8px; line-height: 1.55; max-width: 72ch; }
details > summary { cursor: pointer; list-style: none; color: var(--muted); font-size: 13.5px; display: inline-flex; align-items: center; gap: 4px; padding: 2px 0; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: ""; width: 6px; height: 6px; border: solid currentColor; border-width: 0 1.6px 1.6px 0; transform: rotate(-45deg); transition: transform .15s; margin-right: 4px; }
details[open] > summary::before { transform: rotate(45deg); }
details > summary:hover { color: var(--ink); }

/* monthly */
.month-nav { display: flex; gap: 6px; align-items: center; }
.target { padding: 20px; margin-bottom: 14px; border-left: 4px solid var(--gc); }
.target .head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.target .head h3 { font-size: 15px; font-weight: 620; }
.target .goal-of { color: var(--muted); font-size: 13.5px; }
.target .tt { font-size: 20px; font-weight: 620; letter-spacing: -.01em; margin: 12px 0 2px; display: flex; gap: 12px; align-items: flex-start; }
.target .tt span { flex: 1; }
.target .prog { display: flex; align-items: center; gap: 12px; margin-top: 14px; font-size: 13px; color: var(--muted); }
.target .prog .bar { flex: 1; }
.missing { padding: 14px 18px; display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; border-style: dashed; box-shadow: none; background: transparent; margin-bottom: 10px; }

/* weekly */
.plan { margin-bottom: 18px; border-top: 4px solid var(--gc); }
.plan-head { padding: 18px 20px 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.plan-head h3 { font-size: 18px; font-weight: 650; }
.plan-hours { display: flex; align-items: center; gap: 14px; padding: 12px 20px 0; flex-wrap: wrap; }
.plan-hours .bar { flex: 1 1 200px; }
.hrs-input { width: 66px !important; padding: 4px 8px !important; text-align: right; }
.objectives { padding: 12px 20px 0; font-size: 14.5px; }
.act { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; padding: 12px 20px; border-top: 1px solid var(--line); align-items: center; }
.act:first-child { border-top: 0; }
.act .t { font-weight: 560; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.act .t.is-done { color: var(--muted); }
.act .ctl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.act .logs { grid-column: 1 / -1; font-size: 13.5px; color: var(--muted); }
.logs li { display: flex; align-items: center; gap: 4px; padding: 2px 0; }
.logs ul { list-style: none; margin: 4px 0 0; padding: 0; }
.plan-foot { padding: 6px 20px 18px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; border-top: 1px solid var(--line); padding-top: 14px; }
.review { margin: 0 20px 18px; padding: 14px 16px; background: var(--sunken); border-radius: 12px; }
.review-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-top: 12px; }
.review-sum { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.prev { margin: 10px 20px 0; font-size: 13.5px; }
.prev .box { margin-top: 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); display: grid; gap: 4px; }
.prev b { color: var(--ink); font-weight: 580; }
.hist-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.hist-row:first-child { border-top: 0; }
.hist-row:hover { background: var(--sunken); }
.hist-row .bar { width: 90px; flex: none; }

/* charts */
.charts { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.chart { padding: 18px 20px; }
.chart h3 { font-size: 14.5px; font-weight: 620; }
.chart .cap { font-size: 13px; color: var(--muted); margin: 2px 0 12px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 10.5px; font-family: var(--sans); }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.hb { display: grid; grid-template-columns: minmax(70px, 30%) 1fr auto; gap: 8px 12px; align-items: center; font-size: 13.5px; }
.hb .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: var(--sunken); }
.stack i { display: block; height: 100%; }
.cols { display: flex; align-items: flex-end; gap: 10px; height: 130px; margin-top: 4px; }
.cols .c { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; font-size: 11.5px; color: var(--muted); }
.cols .c i { display: block; width: 100%; max-width: 34px; background: var(--ink); border-radius: 6px 6px 2px 2px; min-height: 3px; }
.cols .c i.zero { background: var(--sunken); }
.chart svg.heat text { font-size: 7.5px; }
.chart.wide { grid-column: span 2; }
@media (max-width: 1000px) { .chart.wide { grid-column: auto; } }
.legend svg { width: 12px; height: 12px; display: inline-block; }
.l0 { fill: var(--sunken); } .l1 { fill: color-mix(in srgb, var(--ok) 30%, var(--sunken)); }
.l2 { fill: color-mix(in srgb, var(--ok) 55%, var(--sunken)); } .l3 { fill: color-mix(in srgb, var(--ok) 80%, var(--sunken)); } .l4 { fill: var(--ok); }

/* dialog, toast */
dialog { border: 1px solid var(--line); border-radius: 18px; padding: 0; background: var(--surface); color: var(--ink); width: min(560px, calc(100vw - 24px)); box-shadow: 0 24px 60px -12px rgba(0,0,0,.35); max-height: calc(100vh - 24px); }
dialog::backdrop { background: rgba(10,14,22,.45); }
dialog[open] { animation: pop .16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 4px; }
.dlg-head h2 { font-size: 18px; font-weight: 650; }
.dlg-body { padding: 14px 22px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; max-height: calc(100vh - 190px); }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 20px; }
.dlg-err { color: var(--danger); font-size: 13.5px; min-height: 0; }
.preview { font-size: 13.5px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.preview li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.preview ul { margin: 0; padding: 0; list-style: none; }
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; align-items: center; pointer-events: none; padding: 0 12px; }
.toast { background: var(--ink); color: var(--on-ink); padding: 10px 16px; border-radius: 11px; font-size: 14px; box-shadow: var(--shadow); animation: pop .16s ease-out; max-width: 90vw; }
.toast.err { background: var(--danger); color: #fff; }
.bk { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.bk .grow { flex: 1; min-width: 0; }
.loading { color: var(--muted); padding: 40px 0; }

/* responsive */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 20; inset: auto 0 0 0; height: auto; flex-direction: row; align-items: center; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 6px; border-right: 0; border-top: 1px solid var(--line); }
  .brand, .side-foot .label { display: none; }
  #nav { flex-direction: row; flex: 1; justify-content: space-around; }
  #nav a { flex-direction: column; gap: 2px; font-size: 11.5px; padding: 6px 10px; }
  .side-foot { margin: 0; flex-direction: row; }
  .ghost { padding: 10px; width: auto; }
  main { padding: 22px 16px 110px; }
  .act { grid-template-columns: 1fr; }
  .act .ctl { justify-content: flex-start; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media print { .side, #toasts { display: none; } .shell { display: block; } }

/* touch screens (phones, tablets) */
@media (pointer: coarse) {
  .icon-btn { width: 42px; height: 42px; }
  .btn.sm { padding: 9px 13px; }
  .btn { min-height: 42px; }
  .seg button { padding: 9px 13px; }
  .check { width: 26px; height: 26px; }
  input[type=text], input[type=number], input[type=date], select, textarea { font-size: 16px; }
  summary { padding: 6px 0; }
}
@media (max-width: 820px) {
  dialog { width: calc(100vw - 16px); }
  .dlg-body { max-height: calc(100dvh - 190px); }
  .page-head h1 { font-size: 24px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .plan-head, .plan-hours, .objectives { padding-left: 16px; padding-right: 16px; }
  .act, .plan-foot { padding-left: 16px; padding-right: 16px; }
  .review, .prev { margin-left: 12px; margin-right: 12px; }
  .hist-row { flex-wrap: wrap; }
  .hist-row .bar { width: 100%; order: 5; }
}

@media (max-width: 820px) {
  .stat { padding: 14px; }
  .stat .v { line-height: 1.15; font-size: 24px; }
  .stat .v small { display: block; margin-top: 2px; font-size: 13px; }
  #nav a { flex: 1; text-align: center; line-height: 1.15; justify-content: flex-start; min-height: 56px; }
  .ghost { padding: 13px; }
}

.plan-chips { display: inline-flex; gap: 8px; flex-wrap: wrap; align-items: center; }
@media (max-width: 820px) {
  .plan-head { row-gap: 6px; }
  .plan-head h3 { flex: 1; min-width: 0; }
  .plan-head .plan-chips { order: 5; flex-basis: 100%; }
}

/* ---- backup reminder and backup dialog */
#banner:empty, #backup-note:empty, #update-note:empty { display: none; }
.banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 14px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.banner.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); background: color-mix(in srgb, var(--warn) 9%, var(--surface)); }
.banner .grow, .status .grow { flex: 1; min-width: 180px; }
.banner > svg { color: var(--warn); flex: none; }
.status { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--sunken); }
.status.warn svg { color: var(--warn); } .status.ok svg { color: var(--ok); }
.bk-actions { display: flex; flex-direction: column; gap: 8px; }
.bk-actions .btn { justify-content: center; min-height: 46px; }
.ghost .sub { display: block; font-size: 11.5px; opacity: .8; }
#backup-btn.needs-backup svg { color: var(--warn); }
.dlg-body details summary { cursor: pointer; padding: 6px 0; }
