:root {
  --bg: #e8e9ec;
  --surface: #f6f7f9;
  --surface-2: #fdfdfe;
  --ink: #26282e;
  --ink-2: #5f636c;
  --muted: #969ba4;
  --line: #dcdee3;
  --line-strong: #c7cad1;
  --accent: #3f5b73;
  --accent-bg: #e6ecf2;
  --done: #4f6f6a;
  --warm: #ef9f27;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30,33,40,.04), 0 6px 20px rgba(30,33,40,.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181b; --surface: #1f2125; --surface-2: #26282d;
    --ink: #e7e8ea; --ink-2: #a6aab1; --muted: #71757d;
    --line: #313339; --line-strong: #40434a;
    --accent: #8fb0cc; --accent-bg: #223140; --done: #7fa9a2;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 0.5px solid var(--line); border-radius: 20px; padding: 30px 24px; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.brand-mark { width: 26px; height: 26px; }
.auth-sub { color: var(--ink-2); margin: 8px 0 24px; font-size: 14px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 6px; letter-spacing: .02em; }
.field input, .field textarea {
  width: 100%; padding: 12px; border: 0.5px solid var(--line-strong); border-radius: 10px;
  background: var(--surface-2); color: var(--ink); font-size: 15px; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.auth-error, .sheet-error { color: #b5654b; font-size: 13px; min-height: 18px; margin: 2px 0 8px; }
.auth-ok { color: var(--done); font-size: 13px; min-height: 18px; margin: 2px 0 8px; }
.btn-primary { width: 100%; padding: 13px; border: none; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: 15px; font-weight: 500; }
.btn-primary:active { transform: scale(.99); }
.btn-link { width: 100%; margin-top: 12px; background: none; border: none; color: var(--ink-2); font-size: 14px; }
.auth-row { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; }
.auth-row .btn-link { width: auto; margin: 0; }

/* ---------- App shell ---------- */
.app { min-height: 100dvh; max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: calc(20px + var(--safe-t)) 20px 12px; background: var(--bg); }
.topbar-eyebrow { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.topbar-title { margin: 2px 0 0; font-size: 27px; font-weight: 600; letter-spacing: -.02em; }
.icon-btn { background: none; border: none; color: var(--ink-2); padding: 8px; border-radius: 10px; }
.icon-btn:active { background: var(--surface); }
.views { flex: 1; padding: 0 16px calc(96px + var(--safe-b)); }
.view { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- Week strip ---------- */
.week { display: flex; gap: 6px; overflow-x: auto; padding: 4px 4px 14px; scrollbar-width: none; }
.week::-webkit-scrollbar { display: none; }
.wday { flex: 0 0 auto; width: 44px; text-align: center; padding: 8px 0; border-radius: 12px; }
.wday .d { font-size: 11px; color: var(--muted); }
.wday .n { font-size: 15px; color: var(--ink-2); margin-top: 2px; }
.wday .dot { width: 4px; height: 4px; border-radius: 50%; margin: 4px auto 0; }
.wday.today { background: var(--ink); }
.wday.today .d, .wday.today .n { color: var(--bg); font-weight: 500; }

.sec-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 16px 6px 8px; }

/* ---------- Item card ---------- */
.item { display: flex; align-items: flex-start; gap: 12px; padding: 13px; margin-bottom: 8px; background: var(--surface); border: 0.5px solid var(--line); border-radius: var(--radius); }
.item.event { border-color: var(--accent); }
.check { flex: 0 0 auto; width: 22px; height: 22px; border-radius: 7px; border: 1.6px solid var(--line-strong); background: transparent; margin-top: 1px; display: grid; place-items: center; padding: 0; }
.check svg { width: 14px; height: 14px; opacity: 0; color: var(--bg); }
.item.done .check { background: var(--done); border-color: var(--done); }
.item.done .check svg { opacity: 1; }
.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 15px; color: var(--ink); word-break: break-word; }
.item.done .item-title { text-decoration: line-through; color: var(--ink-2); }
.item-notes { font-size: 13px; color: var(--ink-2); margin-top: 3px; }
.item-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge svg { width: 13px; height: 13px; }
.badge.c1 { background: #faeeda; color: #854f0b; }
.badge.c2 { background: #fac775; color: #633806; }
.badge.c3 { background: #ef9f27; color: #412402; }
.badge.event { background: var(--accent-bg); color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: .5; }
.empty p { margin: 0; font-size: 14px; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 4px 12px; }
.cal-head h2 { font-size: 18px; font-weight: 600; margin: 0; }
.cal-nav { display: flex; gap: 6px; }
.cal-nav button { width: 34px; height: 34px; border-radius: 10px; border: 0.5px solid var(--line); background: var(--surface); color: var(--ink); font-size: 18px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.cal-cell { aspect-ratio: 1; border-radius: 10px; background: var(--surface); border: 0.5px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 13px; color: var(--ink); }
.cal-cell.blank { background: transparent; border: none; }
.cal-cell.today { border-color: var(--ink); border-width: 1.5px; font-weight: 600; }
.cal-cell.has { cursor: pointer; }
.cal-dots { display: flex; gap: 3px; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; display: inline-block; }
.dot-task { background: var(--muted); }
.dot-carry { background: var(--warm); }
.dot-event { background: var(--accent); }
.cal-legend { display: flex; gap: 14px; justify-content: center; margin-top: 16px; font-size: 11px; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cal-legend i { width: 6px; height: 6px; border-radius: 50%; }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.stat { background: var(--surface); border: 0.5px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stat .v { font-size: 30px; font-weight: 600; letter-spacing: -.02em; }
.stat .l { font-size: 13px; color: var(--ink-2); margin-top: 4px; }

/* ---------- Tabbar ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; max-width: 480px; margin: 0 auto; display: flex; align-items: center; justify-content: space-around; padding: 8px 8px calc(8px + var(--safe-b)); background: var(--surface-2); border-top: 0.5px solid var(--line); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: none; color: var(--muted); font-size: 10px; padding: 4px 10px; }
.tab.active { color: var(--ink); }
.fab { width: 50px; height: 50px; border-radius: 50%; border: none; background: var(--ink); color: var(--bg); display: grid; place-items: center; margin-top: -26px; box-shadow: 0 3px 12px rgba(0,0,0,.2); }
.fab:active { transform: scale(.96); }

/* ---------- Sheet + modal ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(20,22,26,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 480px; background: var(--bg); border-radius: 22px 22px 0 0; padding: 10px 20px calc(24px + var(--safe-b)); animation: slideup .24s ease; }
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 6px auto 14px; }
.sheet h2 { font-size: 18px; margin: 0 0 14px; }
.seg { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.seg button { flex: 1; padding: 9px; border: none; border-radius: 9px; background: transparent; color: var(--ink-2); font-size: 14px; }
.seg button.active { background: var(--surface-2); color: var(--ink); font-weight: 500; box-shadow: var(--shadow); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions .btn-primary { flex: 1; }
.btn-ghost { padding: 12px 16px; border: 0.5px solid var(--line-strong); border-radius: 10px; background: transparent; color: var(--ink); font-size: 15px; }
#sheet-delete { color: #b5654b; border-color: #e2c3ba; }

/* day popup (centered modal) */
.modal-backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(20,22,26,.45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { width: 100%; max-width: 360px; background: var(--bg); border-radius: 18px; padding: 20px; box-shadow: var(--shadow); animation: pop .2s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.modal h3 { margin: 0 0 4px; font-size: 18px; }
.modal .modal-sub { color: var(--ink-2); font-size: 13px; margin: 0 0 14px; }
.modal-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 0.5px solid var(--line); }
.modal-item:first-of-type { border-top: none; }
.modal-icon { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; }
.modal-close { width: 100%; margin-top: 16px; padding: 11px; border: 0.5px solid var(--line-strong); border-radius: 10px; background: transparent; color: var(--ink); font-size: 15px; }
