:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #20201d;
  --muted: #6d6c66;
  --line: #e2e0d9;
  --accent: #2f6f55;
  --accent-ink: #ffffff;
  --danger: #a93a2c;
  --overdue: #a3561d;
  --shadow: 0 10px 40px rgb(0 0 0 / 0.14);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614;
    --surface: #21211e;
    --ink: #f0efe9;
    --muted: #a09f97;
    --line: #34332f;
    --accent: #6fbf9b;
    --accent-ink: #10201a;
    --danger: #ec8a7c;
    --overdue: #e0a06a;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: 0.5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Under 16px, iPhones zoom into the field and stay zoomed. */
input, select, textarea { font-size: 16px; }

.page {
  max-width: 620px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.topbar-actions { display: flex; flex: none; }
.topbar h1 { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -0.01em; }
.topbar .sub { color: var(--muted); font-size: 14px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--line); }
.icon-btn svg { width: 22px; height: 22px; }

.add { display: flex; gap: 8px; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 6px 6px 6px 14px; }
.add:focus-within { border-color: var(--accent); }
.add textarea { flex: 1; min-width: 0; border: 0; outline: 0; background: none; resize: none; padding: 8px 0; max-height: 160px; line-height: 1.35; }
.add button { flex: none; height: 38px; padding: 0 14px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px; }

.understood, .pending { margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; font-size: 15px; }
.pending { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.pending .text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spinner { width: 14px; height: 14px; flex: none; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.understood-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 14px; }
.understood ul { list-style: none; margin: 6px 0 0; padding: 0; }
.understood li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.understood li span:last-child { color: var(--muted); white-space: nowrap; font-size: 14px; }
.link-btn { color: var(--accent); font-weight: 600; font-size: 14px; min-height: 32px; }

.section-title { margin: 22px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.section-title.overdue { color: var(--overdue); }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: stretch; border-top: 1px solid var(--line); transition: opacity 0.2s ease; }
.row:first-child { border-top: 0; }
.row.leaving { opacity: 0.35; }
.tick { flex: none; width: 52px; display: grid; place-items: center; min-height: 52px; }
.tick span { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--muted); display: grid; place-items: center; color: transparent; }
.tick svg { width: 14px; height: 14px; }
.tick:hover span { border-color: var(--accent); }
.tick.done span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.row-main { flex: 1; min-width: 0; text-align: left; padding: 13px 14px 13px 0; display: block; }
.row-title { display: block; overflow-wrap: anywhere; }
.row.closed .row-title { color: var(--muted); }
.row-meta { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 2px; font-size: 13px; color: var(--muted); }
.row-meta .late { color: var(--overdue); }

.empty { text-align: center; color: var(--muted); padding: 44px 16px; }
.empty strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 4px; font-weight: 600; }
.error-box { margin-top: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--danger); color: var(--danger); font-size: 15px; }
.search { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); outline: 0; }
.search:focus { border-color: var(--accent); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--bg); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs-inner { max-width: 620px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); }
.tab { height: 56px; font-size: 15px; font-weight: 600; color: var(--muted); }
.tab[aria-current="page"] { color: var(--ink); box-shadow: inset 0 2px 0 var(--accent); }
.tab .count { font-weight: 500; margin-left: 4px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 68px); z-index: 30; display: flex; align-items: center; gap: 14px; width: max-content; max-width: calc(100vw - 32px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 15px; }
.toast.error { background: var(--danger); color: #fff; }
.toast button { color: inherit; font-weight: 700; text-decoration: underline; min-height: 28px; flex: none; }

dialog { color: var(--ink); background: var(--surface); border: 0; padding: 0; box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.sheet { width: min(560px, 100vw); max-width: 100vw; max-height: 88dvh; margin: auto auto 0; border-radius: 18px 18px 0 0; overflow-y: auto; }
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 18px; } }
.sheet-body { padding: 14px 16px calc(env(safe-area-inset-bottom) + 18px); }
.sheet-head { display: flex; justify-content: flex-end; }
.sheet label, .field-title { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 16px 0 6px; }
.title-input { width: 100%; font-size: 19px; font-weight: 600; border: 0; border-bottom: 1px solid var(--line); background: none; outline: 0; padding: 6px 0; resize: none; }
.title-input:focus { border-color: var(--accent); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { position: relative; min-height: 40px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 15px; display: inline-flex; align-items: center; }
.pill:hover { border-color: var(--accent); }
.pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pill input[type="date"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.pill.day { min-width: 46px; justify-content: center; padding: 8px 6px; }
.field { width: 100%; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.repeat-grid { display: grid; grid-template-columns: 1fr 96px; gap: 8px; }
.note { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.spoken { font-size: 15px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.btn { min-height: 44px; padding: 8px 16px; border-radius: 10px; font-weight: 600; background: var(--bg); border: 1px solid var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.ask { width: min(420px, calc(100vw - 32px)); border-radius: 16px; }
.ask-body { padding: 20px; }
.ask h2 { margin: 0 0 6px; font-size: 18px; }
.ask p { margin: 0; color: var(--muted); font-size: 15px; }

.signin { max-width: 400px; margin: 0 auto; padding: 18vh 20px 40px; }
.signin h1 { font-size: 30px; margin: 0 0 6px; letter-spacing: -0.01em; }
.signin p { color: var(--muted); margin: 0 0 20px; }
.signin .field { padding: 12px 14px; margin-bottom: 10px; }
.signin .btn { width: 100%; }
.code-input { letter-spacing: 0.2em; font-size: 22px !important; text-align: center; }
.signin .link-btn { display: block; margin: 12px auto 0; }

@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } .row { transition: none; } }

.sheet-title { margin: 0 0 8px; font-size: 20px; }
.notes-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; margin: 16px 0 6px; }
.notes-head .field-title { margin: 0; }
.tools { display: flex; gap: 4px; }
.tool { width: 36px; height: 32px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); font-size: 15px; }
.tool svg { width: 16px; height: 16px; }
.notes { min-height: 72px; max-height: 40dvh; overflow-y: auto; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); outline: 0; font-size: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.notes:focus { border-color: var(--accent); }
.notes.is-empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.notes ul, .notes ol { margin: 4px 0; padding-left: 22px; }
.notes a, .links a, .files a, .note a { color: var(--accent); }
.links { list-style: none; margin: 0; padding: 0; font-size: 15px; overflow-wrap: anywhere; }
.links li { padding: 2px 0; }
.files { list-style: none; margin: 0 0 8px; padding: 0; }
.files li { display: flex; align-items: center; gap: 10px; padding: 4px 0; font-size: 15px; }
.files img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: none; }
.files a { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--muted); font-size: 13px; flex: none; }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small svg { width: 16px; height: 16px; }
.file-pill { cursor: pointer; overflow: hidden; }
.file-pill input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.actions.tight { margin-top: 10px; }
.offline-line { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--surface); border: 1px dashed var(--line); color: var(--muted); font-size: 14px; }
.install-hint { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.install-hint span { flex: 1 1 100%; }
.link-btn.quiet { color: var(--muted); font-weight: 500; }
.steps { margin: 0; padding-left: 20px; font-size: 15px; }
.steps li { padding: 2px 0; }
.token { font-family: ui-monospace, Menlo, monospace; font-size: 14px !important; }
.install-links a { text-decoration: none; color: inherit; }
.signin-foot { margin-top: 24px; text-align: center; }
