:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1d1f23;
  --muted: #6b6f76;
  --faint: #a3a6ab;
  --line: #e7e5df;
  --accent: #2563eb;
  --accent-soft: #e6eefd;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --danger: #c62828;
  --private: #9333ea;
  --private-soft: #f3e8fd;
  --today: #2563eb;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 1px 1px rgba(20, 20, 30, .03);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --card: #1f2125;
    --ink: #ececee;
    --muted: #9a9ea6;
    --faint: #6c7078;
    --line: #2d3036;
    --accent: #6b9bff;
    --accent-soft: #1e2a44;
    --warn: #f0b35a;
    --warn-soft: #33281a;
    --danger: #ff6b6b;
    --private: #c084fc;
    --private-soft: #2c2140;
    --today: #6b9bff;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html {
  background: var(--bg);
  overscroll-behavior-y: contain; /* our own pull-to-refresh instead of a page reload */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom delay */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
input, textarea, .secret, .kv code, .notedetails-full { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-touch-callout: none; }
button, .btn, .li, .note, .mcell { transition: transform .12s ease, background-color .15s ease, opacity .15s ease; }
.ic { display: inline-grid; place-items: center; }
.ic svg { width: 1em; height: 1em; }
html.locked, html.locked body { overflow: hidden; }
html.locked body { position: fixed; left: 0; right: 0; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell {
  max-width: 720px; margin: 0 auto; overflow-x: clip;
  padding: 0 max(14px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
#pages { touch-action: pan-y pinch-zoom; min-height: 70vh; }
.shell.wide { max-width: 1080px; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  padding: calc(10px + env(safe-area-inset-top)) 0 10px;
}
.toprow { display: flex; align-items: center; gap: 10px; }
.brand { font-weight: 700; font-size: 20px; letter-spacing: -.01em; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.navrow { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.range { flex: 1; font-weight: 600; font-size: 15px; color: var(--muted); text-align: center; }
.iconbtn {
  width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--card);
  box-shadow: var(--shadow); display: grid; place-items: center; color: var(--ink); flex: none;
}
.iconbtn svg { width: 20px; height: 20px; }
.pill {
  border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; font-weight: 600;
}
.seg { display: inline-flex; background: var(--line); border-radius: 999px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; border: 0; font-weight: 700; color: #fff;
  display: grid; place-items: center; flex: none; font-size: 15px;
}

/* ---------- day cards ---------- */
.day { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 10px; padding: 4px 0 2px; }
.day.past { opacity: .72; }
.dayhead { display: flex; align-items: baseline; gap: 8px; padding: 10px 16px 4px; }
.dayname { font-weight: 700; font-size: 15px; }
.daydate { color: var(--muted); font-size: 14px; }
.badge { font-size: 12px; font-weight: 700; color: #fff; background: var(--today); padding: 2px 8px; border-radius: 999px; }
.day.today { box-shadow: 0 0 0 2px var(--today), var(--shadow); }

.note { display: flex; align-items: flex-start; gap: 12px; padding: 8px 16px; }
.note + .note { border-top: 1px solid var(--line); }
.check {
  flex: none; width: 24px; height: 24px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--faint); background: transparent; padding: 0; display: grid; place-items: center;
}
.check svg { width: 14px; height: 14px; opacity: 0; color: #fff; }
.check.on { background: var(--accent); border-color: var(--accent); }
.check.on svg { opacity: 1; }
.notebody { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 0; }
.notetitle { font-weight: 500; word-wrap: break-word; }
.note.done .notetitle { text-decoration: line-through; color: var(--faint); }
.notedetails { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notemeta { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: 12px; color: var(--muted); }
.time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); margin-right: 6px; }
.who { display: inline-flex; align-items: center; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.lock { color: var(--private); display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.lock svg { width: 12px; height: 12px; }
.note.private { background: linear-gradient(90deg, var(--private-soft), transparent 60%); }

.add { display: flex; align-items: center; gap: 12px; padding: 6px 16px 10px; }
.add .plus { flex: none; width: 24px; height: 24px; display: grid; place-items: center; color: var(--faint); }
.add input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none; padding: 6px 0; font-size: 16px;
}
.add input::placeholder { color: var(--faint); }
.add .lockbtn { border: 0; background: none; color: var(--faint); padding: 4px; display: grid; place-items: center; }
.add .lockbtn.on { color: var(--private); }
.add .lockbtn svg { width: 18px; height: 18px; }

/* ---------- overdue ---------- */
.overdue { background: var(--warn-soft); border-radius: var(--radius); margin-top: 10px; padding: 4px 0 4px; }
.overdue .dayhead .dayname { color: var(--warn); }
.overdue .note + .note { border-top-color: color-mix(in srgb, var(--warn) 18%, transparent); }
.overdue .when { color: var(--warn); font-weight: 600; font-size: 12px; }

/* ---------- month ---------- */
.monthgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-top: 10px; }
.mhead { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 4px 0; }
.mcell {
  background: var(--card); border-radius: 10px; min-height: 92px; padding: 6px; border: 0; text-align: left;
  display: flex; flex-direction: column; gap: 3px; box-shadow: var(--shadow); overflow: hidden;
}
.mcell.other { opacity: .45; }
.mcell.today { box-shadow: 0 0 0 2px var(--today); }
.mnum { font-size: 13px; font-weight: 700; }
.mcell.today .mnum { color: var(--today); }
.chip {
  font-size: 11.5px; line-height: 1.25; padding: 2px 5px; border-radius: 5px; background: var(--accent-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip.done { text-decoration: line-through; opacity: .55; }
.chip.private { background: var(--private-soft); }
.more { font-size: 11px; color: var(--muted); }
@media (max-width: 560px) {
  .mcell { min-height: 64px; padding: 4px; border-radius: 8px; }
  .chip { font-size: 10px; padding: 1px 3px; }
}

/* ---------- sheet ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(10, 10, 15, calc(.38 * var(--dim, 1))); z-index: 50;
  touch-action: none;
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease;
}
.sheet {
  background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; max-height: 92dvh; overflow: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; will-change: transform;
  border-radius: 20px 20px 0 0; padding: 8px 18px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s cubic-bezier(.2, .8, .3, 1);
}
@media (min-width: 640px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 20px; padding-bottom: 20px; }
}
.sheet { touch-action: pan-y; }
.backdrop.closing { animation: fadeout .22s forwards; pointer-events: none; }
@keyframes fadeout { to { background: rgba(10, 10, 15, 0); } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--faint); opacity: .5; margin: 2px auto 8px; }
.grab::before { content: ""; display: block; height: 24px; margin: -10px -40px 0; } /* bigger drag target */
@media (min-width: 640px) { .grab { display: none; } }
.sheethead { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheethead h2 { flex: 1; font-size: 18px; margin: 0; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 5px 2px; }
.input {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 11px 12px; font-size: 16px; outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.toggle { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.toggle .label { flex: 1; }
.toggle .label small { display: block; color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--private); }
.switch input:checked + .track::after { transform: translateX(20px); }
.meta { color: var(--muted); font-size: 13px; margin: 4px 2px 14px; }
.actions { display: flex; gap: 10px; margin-top: 6px; }
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; font-size: 16px;
  background: var(--card); box-shadow: var(--shadow);
}
.btn.primary { background: var(--accent); color: #fff; flex: 1; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.linkbtn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 4px; }

/* ---------- settings ---------- */
.section { margin-bottom: 22px; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px 4px; }
.list { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); }
.li { display: flex; align-items: center; gap: 10px; padding: 11px 14px; }
.li + .li { border-top: 1px solid var(--line); }
.li .grow { flex: 1; min-width: 0; }
.li small { display: block; color: var(--muted); font-size: 13px; }
.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 17px; letter-spacing: .02em;
  background: var(--card); border: 1px dashed var(--accent); border-radius: 12px; padding: 12px; text-align: center;
  user-select: all; -webkit-user-select: all; word-break: break-all;
}
.kv { font-size: 14px; color: var(--muted); margin: 8px 2px; }
.kv code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); user-select: all; -webkit-user-select: all; word-break: break-all; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 4px; }
.hint ol { padding-left: 20px; margin: 6px 0; }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.logincard { width: 100%; max-width: 360px; }
.logincard .logo { width: 64px; height: 64px; display: block; margin: 0 auto 14px; }
.logincard h1 { text-align: center; font-size: 24px; margin: 0 0 22px; }
.error { color: var(--danger); font-size: 14px; margin: -4px 2px 12px; min-height: 1em; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  z-index: 100; animation: up .2s ease; box-shadow: 0 4px 20px rgba(0,0,0,.2); max-width: 90vw;
}
.empty { color: var(--faint); font-size: 14px; padding: 2px 16px 0 52px; }
.boot { min-height: 100vh; }

.brand .short { display: none; }
@media (max-width: 480px) {
  .brand .long { display: none; }
  .brand .short { display: inline; }
  .chip .ctime { display: none; }
  .row.wrap { flex-wrap: wrap; }
  .row.wrap > * { flex: 1 1 100% !important; }
}

/* ---------- native feel: press states ---------- */
.iconbtn:active, .pill:active, .avatar:active, .btn:active:not(:disabled), .seg button:active { transform: scale(.94); }
.check:active { transform: scale(.85); }
.notebody:active, .li:active:is(a, button) { opacity: .6; }
.note:has(.notebody:active) { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.mcell:active { transform: scale(.96); }
.linkbtn:active { opacity: .5; }
.check { transition: background-color .15s, border-color .15s, transform .12s; }
.check.on svg { animation: pop .25s cubic-bezier(.2,.8,.3,1.4); }
@keyframes pop { from { transform: scale(.4); } }
@media (hover: hover) {
  .iconbtn:hover, .pill:hover { background: color-mix(in srgb, var(--card) 85%, var(--ink)); }
  .notebody:hover .notetitle { color: var(--accent); }
  .mcell:hover { box-shadow: 0 0 0 1px var(--accent); }
}
.pill.current { color: var(--muted); }
.note.pending { opacity: .55; }
.note.pending .check { border-style: dashed; }
.add { cursor: text; }
.add input:disabled { opacity: .6; }
.iconbtn.small { width: 30px; height: 30px; box-shadow: none; background: transparent; color: var(--muted); }
.iconbtn.small svg { width: 16px; height: 16px; }
.linkbtn.tiny { font-size: 12px; padding: 0 0 0 6px; }
.select {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 7px 28px 7px 10px; font-size: 15px;
  max-width: 55%; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
}
.select:disabled { opacity: .45; }
.switch.accent input:checked + .track { background: #34c759; }
.toggle-li { cursor: pointer; }
.bell { width: 36px; height: 36px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; font-size: 20px; }
.inl { display: inline-block; width: 1.1em; height: 1.1em; vertical-align: -.2em; color: var(--accent); }
.inl svg { width: 100%; height: 100%; }

/* ---------- banners ---------- */
#banners:empty { display: none; }
.banner { display: flex; align-items: flex-start; gap: 12px; margin-top: 10px; font-size: 14px; animation: up .25s ease; }
.banner .grow { flex: 1; min-width: 0; }
.banner .sub { color: var(--muted); margin-top: 2px; }
.banner.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 10px 12px 14px; }
.banner.offline { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 9px 14px; align-items: center; font-weight: 600; }
.banner.offline .ic { font-size: 18px; }
.bicon { width: 40px; height: 40px; border-radius: 10px; flex: none; }

/* ---------- loading ---------- */
.topbar { position: sticky; }
.topbar .progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; overflow: hidden; opacity: 0; transition: opacity .2s; }
html.busy .topbar .progress { opacity: 1; }
.topbar .progress::after {
  content: ""; position: absolute; top: 0; bottom: 0; width: 30%; background: var(--accent); border-radius: 2px;
  animation: indet 1s ease-in-out infinite;
}
@keyframes indet { from { left: -30%; } to { left: 100%; } }
#pages.loading .day .daynotes:empty::before {
  content: ""; display: block; height: 14px; width: 45%; margin: 6px 16px 6px 52px; border-radius: 7px;
  background: linear-gradient(90deg, var(--line), color-mix(in srgb, var(--line) 40%, transparent), var(--line));
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.spinner {
  width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sheetload { display: grid; place-items: center; padding: 40px 0; }

/* pull to refresh */
.ptr {
  position: fixed; left: 50%; z-index: 9; width: 36px; height: 36px; border-radius: 50%; background: var(--card);
  box-shadow: 0 2px 10px rgba(0,0,0,.15); display: grid; place-items: center; color: var(--muted);
  opacity: 0; transform: translate3d(-50%, -40px, 0); pointer-events: none;
}
.ptr .ptrarrow svg { width: 18px; height: 18px; display: block; transition: transform .15s; }
.ptr.armed { color: var(--accent); }
.ptr .spinner { display: none; width: 18px; height: 18px; }
.ptr.spin .spinner { display: inline-block; }
.ptr.spin .ptrarrow { display: none; }

/* deep link highlight */
.day.flash { animation: flash 1.4s ease; }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px var(--accent), var(--shadow); } }

.toast { display: flex; align-items: center; gap: 12px; }
.toast.out { opacity: 0; transform: translate(-50%, 10px); transition: .2s; }
.toastbtn { border: 0; background: none; color: var(--accent-soft); font-weight: 700; padding: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
#offline:empty { display: none; }
#offline .banner { margin-top: 8px; padding: 6px 12px; font-size: 13px; }
