:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --side: #f6f6f4;
  --fg: #1c1917;
  --muted: #78716c;
  --line: #e7e5e4;
  --hover: #ecebe8;
  --accent: #2563eb;
  --danger: #dc2626;
  --toast: #1c1917;
  --toast-fg: #fafaf9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --side: #151517;
    --fg: #ececec;
    --muted: #9a9a9f;
    --line: #2c2c30;
    --hover: #26262a;
    --accent: #60a5fa;
    --danger: #f87171;
    --toast: #ececec;
    --toast-fg: #151517;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }
.ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 14px;
}
.spacer { flex: 1; }
.pill {
  font-size: 12px;
  color: var(--muted);
  background: var(--hover);
  border-radius: 99px;
  padding: 1px 8px;
}
.pill:empty { display: none; }

/* ---------- header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--side);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}
.row { display: flex; align-items: center; gap: 8px; }
.row b { font-size: 18px; }
.row form { margin: 0; }
#q {
  display: block;
  width: 100%;
  margin: 10px 0 8px;
  padding: 9px 12px;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
#q:focus { border-color: var(--accent); }
.tabs { display: flex; gap: 4px; }
.tabs button {
  border: 0;
  background: none;
  padding: 8px 10px 9px;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- list ---------- */
main { max-width: 760px; margin: 0 auto; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
#list { list-style: none; margin: 0; padding: 0; }
.day {
  padding: 18px 16px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.item { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.item a {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 12px;
  padding: 12px 0 12px 16px;
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.item a:active { background: var(--hover); }
.fav {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 2px;
  border-radius: 5px;
  object-fit: contain;
}
.fav.letter {
  display: grid;
  place-items: center;
  background: var(--hover);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.body { min-width: 0; flex: 1; }
.t { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.item.unread .t::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin: 0 7px 1px 0;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}
.item.read .t { font-weight: 500; color: var(--muted); }
.s { font-size: 13px; color: var(--muted); margin-top: 2px; }
.e {
  font-size: 14px;
  color: var(--muted);
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
mark { background: #fde68a; color: #1c1917; border-radius: 2px; }
.dots {
  flex: none;
  width: 48px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 20px;
  letter-spacing: 1px;
}
.empty, .more { padding: 40px 24px; text-align: center; color: var(--muted); }
.more { padding: 20px; }

/* ---------- action sheet ---------- */
dialog#sheet {
  width: min(100% - 16px, 480px);
  margin: auto auto calc(8px + env(safe-area-inset-bottom));
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--fg);
}
dialog#sheet::backdrop { background: rgb(0 0 0 / .4); }
#sheet form { display: flex; flex-direction: column; gap: 8px; }
#sheet button, .sheet-title {
  display: block;
  width: 100%;
  margin: 0;
  padding: 15px;
  border: 0;
  background: var(--side);
  font-size: 17px;
  text-align: center;
}
.sheet-title {
  font-size: 13px;
  color: var(--muted);
  border-radius: 14px 14px 0 0;
  margin-bottom: -8px !important;
  border-bottom: 1px solid var(--line) !important;
  overflow-wrap: anywhere;
}
#sheet button:not(.cancel) { border-bottom: 1px solid var(--line); margin-bottom: -8px; }
#sheet button.danger { color: var(--danger); border-radius: 0 0 14px 14px; border-bottom: 0; margin-bottom: 0; }
#sheet button.cancel { border-radius: 14px; font-weight: 600; }
#sheet button:active { background: var(--hover); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--toast);
  color: var(--toast-fg);
  font-size: 14px;
  box-shadow: 0 6px 24px rgb(0 0 0 / .25);
  z-index: 5;
}
.toast[hidden] { display: none; }
.toast .ghost { border-color: currentColor; color: inherit; }

/* ---------- login ---------- */
body.login { min-height: 100vh; display: grid; place-items: center; background: var(--side); padding: 16px; }
.login form {
  width: min(100%, 360px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 24px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.login h1 { margin: 0; font-size: 22px; }
.login label { width: 100%; font-size: 14px; color: var(--muted); }
.login input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.login button {
  width: 100%;
  padding: 11px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.login .err { margin: 0; color: var(--danger); font-size: 14px; }
