/* Mobile-first. System fonts only (nothing to download), light/dark, 44px touch targets, safe-area aware. */
:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1d1c1a;
  --muted: #6f6b64;
  --line: #e4e1da;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d9efec;
  --danger: #b42318;
  --danger-soft: #fdebe9;
  --ok: #166534;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04);
  --radius: 14px;
  --gap: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121314;
    --surface: #1b1c1e;
    --ink: #ecebe8;
    --muted: #9b978f;
    --line: #2d2e31;
    --accent: #3cb8ab;
    --accent-ink: #06201d;
    --accent-soft: #14312e;
    --danger: #f2877d;
    --danger-soft: #3a1a17;
    --ok: #6fd08f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
a { color: inherit; }
button { font: inherit; color: inherit; }
.plain { list-style: none; margin: 0; padding: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- header ---------- */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; min-width: 0; margin: 0 0 0 4px; font-size: 19px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-actions { display: flex; gap: 2px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px;
  background: none; border: 0; border-radius: 12px; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }

main { max-width: 680px; margin: 0 auto; padding: 14px max(14px, env(safe-area-inset-left)) 0 max(14px, env(safe-area-inset-right)); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: color-mix(in srgb, var(--ink) 30%, var(--line)); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.tight { gap: 6px; }

/* ---------- search ---------- */
.search {
  display: flex; align-items: center; gap: 8px; height: 46px; padding: 0 14px; margin-bottom: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; }

/* ---------- categories ---------- */
.summary-line { margin: 4px 2px 10px; color: var(--muted); font-size: 14px; }
.cats { display: grid; gap: 10px; }
.cat {
  display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  text-decoration: none; color: inherit;
}
.cat:active { transform: scale(0.995); }
.cat-main { flex: 1; min-width: 0; }
.cat-name { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.cat-desc { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cat-meta { margin-top: 4px; color: var(--muted); font-size: 13px; }
.badge { min-width: 26px; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 13px; font-weight: 700; text-align: center; }
.cat svg { color: var(--muted); flex: none; }

.card { padding: 14px 16px; margin-bottom: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card h2 { margin: 0 0 8px; font-size: 15px; }
.sugg { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.sugg:first-child { border-top: 0; }

/* ---------- category header & tabs ---------- */
.cat-head { margin-bottom: 12px; }
.cat-description { margin: 0 0 10px; color: var(--muted); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; margin-bottom: 14px; background: color-mix(in srgb, var(--ink) 6%, transparent); border-radius: 12px; }
.seg { min-height: 40px; border: 0; border-radius: 9px; background: transparent; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.seg-n { margin-left: 2px; font-weight: 500; opacity: 0.75; }

/* ---------- items ---------- */
.items { display: grid; gap: 10px; }
.item {
  position: relative; touch-action: pan-y; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.item[data-swipe="right"] { box-shadow: inset 6px 0 0 var(--accent); }
.item[data-swipe="left"] { box-shadow: inset -6px 0 0 var(--danger); }
.item.leaving { opacity: 0; transform: translateX(-24px); }
.item:not(.unread) .title { color: var(--muted); }
.item.archived { opacity: 0.8; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.meta .when { margin-left: auto; }
.chip { padding: 1px 8px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 7%, transparent); font-size: 12.5px; max-width: 14em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.link { background: var(--accent-soft); color: var(--accent); text-decoration: none; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }
.title {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  margin: 8px 0 4px; font-size: 17px; font-weight: 650; line-height: 1.3; letter-spacing: -0.01em; text-decoration: none; overflow-wrap: anywhere;
}
a.title:hover { text-decoration: underline; }
.summary { margin: 0 0 10px; color: var(--muted); font-size: 15px; }
.summary.pending { font-style: italic; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }

.more { margin: 14px 0 0; text-align: center; }
.empty { margin: 36px 8px; text-align: center; color: var(--muted); }

/* ---------- notices, skeleton, toast ---------- */
.notice { padding: 20px; margin-top: 24px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.notice h2 { margin: 0 0 6px; }
.notice.error { border-color: var(--danger); background: var(--danger-soft); }
.skeleton { display: grid; gap: 10px; }
.sk-row { height: 78px; border-radius: var(--radius); background: linear-gradient(90deg, var(--line), color-mix(in srgb, var(--line) 50%, var(--surface)), var(--line)); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.toast {
  position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  display: flex; align-items: center; gap: 14px; max-width: min(92vw, 520px); padding: 12px 16px;
  background: var(--ink); color: var(--bg); border-radius: 12px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.25); font-size: 15px;
}
.toast-action { background: none; border: 0; padding: 4px 6px; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }

/* ---------- sheet (native <dialog>, bottom-aligned on phones) ---------- */
.sheet {
  width: min(100%, 560px); max-height: 85vh; margin: auto auto 0; padding: 0; overflow: auto;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet[open] { animation: rise 0.2s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 18px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet > :not(.sheet-head) { margin-left: 18px; margin-right: 18px; }
.sheet > :last-child { margin-bottom: 18px; }
.form { display: grid; gap: 6px; }
.form label { margin-top: 8px; font-weight: 600; font-size: 14px; }
.form input, .form textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.form input:disabled { opacity: 0.6; }
.hint { margin: 2px 0; color: var(--muted); font-size: 13px; }
.form-msg { min-height: 1.2em; margin: 4px 0; font-size: 14px; }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--danger); }
.choices { display: grid; gap: 6px; margin-top: 8px; }
.choice { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 0 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; font-weight: 600; text-align: left; cursor: pointer; }
.choice:disabled { opacity: 0.5; cursor: default; }

/* ---------- activity ---------- */
.events { display: grid; gap: 4px; }
.event { display: flex; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.ev-icon { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }

.noscript { padding: 24px; text-align: center; }

/* ---------- login ---------- */
.login-card { max-width: 380px; margin: 14vh auto 0; padding: 24px 22px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.login-card h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -0.02em; }
.login { display: grid; gap: 10px; margin-top: 14px; }
.login input[type="password"] { width: 100%; min-height: 48px; padding: 10px 14px; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.login input[type="password"]:focus { border-color: var(--accent); outline: none; }
.btn.block { width: 100%; min-height: 48px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
@media (min-width: 640px) {
  .item { padding: 16px 20px; }
}
