/* ============================================================
   Notes — calm, editorial PWA. Light + dark via prefers-color-scheme.
   ============================================================ */

:root {
  /* Light: warm paper neutrals + one restrained terracotta accent */
  --bg:        #faf8f4;
  --bg-raise:  #ffffff;
  --bg-sunk:   #f3efe8;
  --ink:       #26231d;
  --ink-soft:  #5c574d;
  --ink-faint: #908a7d;
  --line:      #e7e1d6;
  --line-soft: #efe9df;
  --accent:    #b4552d;   /* terracotta / sienna */
  --accent-soft:#f0dfd5;
  --accent-ink:#9a4524;
  --ok:        #5b8a4a;
  --shadow:    0 1px 2px rgba(40,32,20,.05), 0 8px 24px rgba(40,32,20,.05);
  --radius:    14px;
  --radius-sm: 10px;
  --measure:   66ch;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --serif: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #16140f;
    --bg-raise:  #1f1c16;
    --bg-sunk:   #100e0a;
    --ink:       #ece7dd;
    --ink-soft:  #b3ac9e;
    --ink-faint: #7c7567;
    --line:      #2c2820;
    --line-soft: #242019;
    --accent:    #d98b5e;
    --accent-soft:#39281d;
    --accent-ink:#e7a880;
    --ok:        #8fb87c;
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 10px 30px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: 16px; }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
}
.login-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.brand-mark { color: var(--accent); display: inline-flex; margin-bottom: 6px; }
.login-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 30px;
  letter-spacing: -0.01em;
  margin: 4px 0 2px;
}
.login-sub { color: var(--ink-faint); margin: 0 0 26px; font-size: 15px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-pass {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-raise);
  color: var(--ink);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
#login-pass:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn-primary {
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  transition: transform .08s ease, filter .15s ease;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { transform: scale(.985); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.login-error { color: var(--accent); min-height: 18px; font-size: 14px; margin: 4px 0 0; }

/* ---------- App shell ---------- */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
  padding-top: var(--safe-top);
}
.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  height: 52px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar-title {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
.sync {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--ink-faint);
  transition: opacity .3s ease;
}
.sync-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok);
  transition: background .2s ease;
}
.sync[data-state="saving"] .sync-dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.sync[data-state="error"]  .sync-dot { background: #c0492f; }
.sync[data-state="offline"] .sync-dot { background: var(--ink-faint); }
@keyframes pulse { 50% { opacity: .3; } }

.main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px 120px;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  justify-content: center;
  gap: 4px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line-soft);
  padding: 6px 8px calc(6px + var(--safe-bottom));
}
.tab {
  flex: 1;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px;
  border-radius: var(--radius-sm);
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .01em;
  text-decoration: none;
  min-height: var(--tap);
  justify-content: center;
  transition: color .15s ease, background .15s ease;
}
.tab:hover { text-decoration: none; }
.tab-ico { width: 23px; height: 23px; }
.tab[aria-current="page"] { color: var(--accent); }
.tab[aria-current="page"] .tab-ico { transform: scale(1.02); }

/* ---------- Shared blocks ---------- */
.view { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-pad { padding-top: 22px; }
.eyebrow {
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
  margin: 0 0 10px;
}
.hero-date {
  font-family: var(--serif);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 2px 0 2px;
}
.hero-sub { color: var(--ink-faint); font-size: 14px; margin: 0 0 18px; }

/* Capture composer */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 8px 8px 14px;
  box-shadow: var(--shadow);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  color: var(--ink);
  line-height: 1.5;
  padding: 6px 0;
  max-height: 40dvh;
  min-height: 24px;
}
.composer textarea::placeholder { color: var(--ink-faint); }
.composer-send {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border: none;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  transition: transform .08s ease, filter .15s ease, opacity .15s ease;
}
.composer-send:hover { filter: brightness(1.05); }
.composer-send:active { transform: scale(.92); }
.composer-send svg { width: 19px; height: 19px; }

/* Notes list */
.notes { list-style: none; margin: 18px 0 0; padding: 0; max-width: var(--measure); }
.note {
  position: relative;
  padding: 4px 0 4px 18px;
  color: var(--ink);
  line-height: 1.6;
  animation: noteIn .25s ease;
}
@keyframes noteIn { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.note::before {
  content: "";
  position: absolute;
  left: 2px; top: 0.72em;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: .8;
}
.note[data-depth="1"] { padding-left: 38px; }
.note[data-depth="2"] { padding-left: 58px; }
.note[data-depth="3"] { padding-left: 78px; }
.note[data-depth="1"]::before, .note[data-depth="2"]::before, .note[data-depth="3"]::before {
  background: var(--ink-faint); width: 4px; height: 4px;
}
.note[data-depth="1"]::before { left: 22px; }
.note[data-depth="2"]::before { left: 42px; }
.note[data-depth="3"]::before { left: 62px; }
.note.pending { opacity: .5; }
.note .note-text { outline: none; }
.note .note-text[contenteditable="true"] {
  background: var(--bg-sunk);
  border-radius: 6px;
  padding: 2px 6px;
  margin: -2px -6px;
}

/* Task groups */
.groups { margin-top: 26px; }
.group { margin-bottom: 22px; }
.group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.group-title {
  font-size: 12px;
  letter-spacing: .09em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--accent);
}
.group-count { font-size: 12px; color: var(--ink-faint); }
.tasks { list-style: none; margin: 0; padding: 0; }
.task {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 9px 4px 9px 0;
  min-height: var(--tap);
  border-bottom: 1px solid var(--line-soft);
  transition: opacity .2s ease;
}
.task:last-child { border-bottom: none; }
.task.pending { opacity: .5; }
.checkbox {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  margin-top: 1px;
  border: 1.8px solid var(--ink-faint);
  border-radius: 7px;
  background: transparent;
  display: grid;
  place-items: center;
  padding: 0;
  transition: border-color .18s ease, background .18s ease, transform .12s ease;
}
.checkbox:active { transform: scale(.9); }
.checkbox svg { width: 13px; height: 13px; opacity: 0; transform: scale(.5); transition: opacity .18s ease, transform .18s ease; color: #fff; }
.task.done .checkbox { background: var(--accent); border-color: var(--accent); }
.task.done .checkbox svg { opacity: 1; transform: scale(1); }
.task-text {
  flex: 1;
  line-height: 1.5;
  padding-top: 1px;
  color: var(--ink);
  outline: none;
  word-break: break-word;
}
.task.done .task-text { color: var(--ink-faint); text-decoration: line-through; text-decoration-color: var(--line); }
.task-text[contenteditable="true"] {
  background: var(--bg-sunk); border-radius: 6px; padding: 1px 6px; margin: -1px -6px; text-decoration: none;
}

/* Quick add task row */
.addtask {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}
.addtask input {
  flex: 1;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-raise);
  color: var(--ink);
  outline: none;
  min-height: var(--tap);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.addtask input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.seg {
  display: inline-flex;
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.seg button {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .03em;
  padding: 8px 11px;
  border-radius: 7px;
  min-height: 36px;
  transition: background .15s ease, color .15s ease;
}
.seg button[aria-pressed="true"] { background: var(--bg-raise); color: var(--accent); box-shadow: var(--shadow); }

/* Diary timeline */
.day {
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}
.day:last-child { border-bottom: none; }
.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.day-date {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.day-rel { font-size: 12.5px; color: var(--ink-faint); white-space: nowrap; }

/* Lists */
.list-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 18px;
}
.list-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-align: left;
  width: 100%;
  transition: transform .1s ease, border-color .15s ease, box-shadow .15s ease;
}
.list-card:hover { border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.list-card:active { transform: scale(.99); }
.list-card-title { font-weight: 600; font-size: 16px; }
.list-card-meta { font-size: 13px; color: var(--ink-faint); }
.list-card-arrow { color: var(--ink-faint); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  margin: 4px 0 2px;
  background: none;
  border: none;
  padding: 8px 0;
}
.back-link:hover { color: var(--accent); text-decoration: none; }
.back-link svg { width: 16px; height: 16px; }

.items { list-style: none; margin: 14px 0 0; padding: 0; max-width: var(--measure); }
.item {
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
  animation: noteIn .25s ease;
}
.item:last-child { border-bottom: none; }
.item[data-level="3"] { padding-left: 18px; }
.item-text { line-height: 1.5; }
.item-body { margin: 6px 0 0; padding: 0; list-style: none; }
.item-body li { color: var(--ink-soft); font-size: 14.5px; line-height: 1.5; padding: 2px 0 2px 14px; position: relative; }
.item-body li::before { content: "–"; position: absolute; left: 0; color: var(--ink-faint); }
.item.pending { opacity: .5; }

/* Empty / states */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--ink-faint);
}
.empty-title { font-family: var(--serif); font-size: 19px; color: var(--ink-soft); margin: 0 0 6px; }
.empty p { margin: 0 0 18px; font-size: 14.5px; }
.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  font-size: 14.5px;
  transition: background .15s ease, color .15s ease, transform .08s ease;
}
.btn-ghost:hover { background: var(--accent); color: #fff; }
.btn-ghost:active { transform: scale(.98); }

.loadmore {
  display: block;
  margin: 18px auto 0;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-raise);
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 500;
}
.loadmore:hover { border-color: var(--accent); color: var(--accent); }

.skeleton {
  background: linear-gradient(90deg, var(--bg-sunk) 25%, var(--line-soft) 37%, var(--bg-sunk) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  border-radius: 6px;
  height: 14px;
  margin: 10px 0;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + var(--safe-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 50;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Desktop refinements */
@media (min-width: 768px) {
  .topbar-inner, .main { max-width: 680px; }
  .list-grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---- Week view ---- */
.week-tasks { margin-top: 4px; }
.week-done { margin-top: 22px; border-top: 1px solid var(--hair, rgba(128,128,128,.18)); padding-top: 10px; }
.week-done summary { cursor: pointer; font-size: .82rem; letter-spacing: .02em; text-transform: uppercase; opacity: .6; padding: 6px 0; list-style: none; }
.week-done summary::-webkit-details-marker { display: none; }
.week-done[open] summary { opacity: .8; }

/* ---- List checklist (real list view) ---- */
.litems { list-style: none; margin: 14px 0 0; padding: 0; max-width: var(--measure); }
.litem {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 13px 2px;
  border-bottom: 1px solid var(--line-soft);
  animation: noteIn .25s ease;
}
.litem:last-child { border-bottom: none; }
.litem-mark {
  flex: 0 0 auto;
  width: 21px; height: 21px;
  margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff;
  transition: background .15s ease, border-color .15s ease;
}
.litem-mark svg { width: 14px; height: 14px; }
.litem.done .litem-mark { background: var(--accent); border-color: var(--accent); }
.litem-main { flex: 1 1 auto; min-width: 0; }
.litem-title { line-height: 1.45; font-weight: 500; }
.litem.done .litem-title { color: var(--ink-soft); }
.litem-note {
  margin-top: 3px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-faint);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.litem-date {
  flex: 0 0 auto;
  align-self: flex-start;
  margin-top: 1px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.litem-divider {
  margin: 26px 0 2px;
  font-size: .78rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ---- List item note composer ---- */
.litem-add { margin-top: 8px; }
.litem-add .composer { margin: 0; }

/* ---- Search ---- */
.search-bar { position: sticky; top: 0; padding: 6px 0 12px; background: var(--bg); z-index: 2; }
.search-input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-raise);
  color: var(--ink);
  -webkit-appearance: none;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.search-hint { color: var(--ink-faint); font-size: 14px; padding: 8px 2px; }
.search-results mark { background: var(--accent-soft); color: var(--accent-ink); border-radius: 3px; padding: 0 1px; }
.sresult {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.sresult:active { background: var(--bg-sunk); }
.sresult-kind {
  flex: 0 0 auto;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--accent-ink); background: var(--accent-soft);
  padding: 3px 7px; border-radius: 6px; margin-top: 2px;
}
.sresult-main { flex: 1 1 auto; min-width: 0; }
.sresult-text { line-height: 1.45; }
.sresult-label { font-size: 12.5px; color: var(--ink-faint); margin-top: 3px; }

/* tighten tab bar for 5 tabs */
.tabbar .tab span { font-size: 11px; }
