:root {
  --bg: #f7f7f5;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #111827;
  --accent-text: #f9fafb;
  --danger: #b91c1c;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --card: #171c23;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #2a313b;
    --accent: #e5e7eb;
    --accent-text: #111827;
    --danger: #f87171;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}
h1.page-title {
  font-size: 1.25rem;
  margin: 20px 0 12px;
}
h2.list-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 20px 0 8px;
}
a { color: inherit; }

/* top bar */
header.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
header.top .search { flex: 1; display: flex; }
header.top .search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
.quiet {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
}
.quiet:hover { text-decoration: underline; }

/* capture form */
form.capture {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
form.capture input[type="text"],
form.capture textarea,
form.capture select,
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
form.capture textarea { resize: vertical; }
.capture-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.capture-row select { width: auto; flex: 1; }
button, .button {
  display: inline-block;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  text-align: center;
}
button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

/* filter chips */
nav.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 14px 0 2px;
  -webkit-overflow-scrolling: touch;
}
.chip {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
}
.chip.off {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
}

/* note list */
.note-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    "badge title meta"
    "badge snippet snippet";
  column-gap: 10px;
  align-items: baseline;
  padding: 12px;
  margin-bottom: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
}
.note-row:active { opacity: 0.8; }
.badge {
  grid-area: badge;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.badge-inbox { color: #92400e; border-color: #fcd34d; background: #fffbeb; }
.badge-idea { color: #6d28d9; border-color: #ddd6fe; background: #f5f3ff; }
.badge-decision { color: #065f46; border-color: #a7f3d0; background: #ecfdf5; }
.badge-project { color: #1e40af; border-color: #bfdbfe; background: #eff6ff; }
@media (prefers-color-scheme: dark) {
  .badge-inbox { color: #fbbf24; border-color: #57534e; background: transparent; }
  .badge-idea { color: #c4b5fd; border-color: #4c1d95; background: transparent; }
  .badge-decision { color: #6ee7b7; border-color: #065f46; background: transparent; }
  .badge-project { color: #93c5fd; border-color: #1e3a8a; background: transparent; }
}
.note-title {
  grid-area: title;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.note-meta {
  grid-area: meta;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
}
.note-snippet {
  grid-area: snippet;
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 4px;
  overflow-wrap: anywhere;
}

/* single note */
article.note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.note-body h2 { font-size: 1.1rem; margin: 18px 0 6px; }
.note-body h3, .note-body h4 { font-size: 1rem; margin: 14px 0 4px; }
.note-body p { margin: 10px 0; }
.note-body ul { margin: 10px 0; padding-left: 22px; }
.note-body li { margin: 4px 0; }
.note-body a { text-decoration: underline; }
.actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.actions form { margin: 0; }

/* login */
.login-card {
  max-width: 340px;
  margin: 15vh auto 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}
.login-card h1 { font-size: 1.3rem; margin: 0 0 4px; }
.login-card form { margin-top: 18px; display: flex; flex-direction: column; gap: 12px; }
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  font-size: 0.9rem;
  color: var(--muted);
}
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.error { color: var(--danger); font-size: 0.9rem; }

/* chat */
.chat-wrap { display: flex; flex-direction: column; min-height: calc(100dvh - 140px); }
.chat-top { display: flex; gap: 8px; margin: 12px 0 4px; }
.chat-top select {
  flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--card); color: var(--text); font: inherit;
  font-size: 0.9rem;
}
button.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: 6px 12px; font-weight: 500; font-size: 0.85rem;
}
button.ghost.danger-text { color: var(--danger); border-color: var(--line); }
.chat-log { flex: 1; overflow-y: auto; padding: 8px 0 12px; }
.chat-hint { padding: 24px 8px; text-align: center; font-size: 0.92rem; max-width: 40ch; margin: 0 auto; white-space: pre-line; }
.msg { margin: 10px 0; display: flex; flex-direction: column; }
.msg-body {
  max-width: 88%; padding: 10px 14px; border-radius: 14px;
  overflow-wrap: anywhere; font-size: 0.97rem;
}
.msg-body p { margin: 6px 0; }
.msg-body ul { margin: 6px 0; padding-left: 20px; }
.msg-user { align-items: flex-end; }
.msg-user .msg-body { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 4px; }
.msg-assistant { align-items: flex-start; }
.msg-assistant .msg-body { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-tools { max-width: 88%; margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rel-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.rel-chip {
  font-size: 0.78rem; padding: 3px 10px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  text-decoration: none; white-space: nowrap; max-width: 200px;
  overflow: hidden; text-overflow: ellipsis;
}
.rel-chip:hover { color: var(--text); }
button.save-note.saved { color: var(--muted); }
.chat-form {
  display: flex; gap: 8px; align-items: flex-end;
  position: sticky; bottom: 0; padding: 10px 0 6px; background: var(--bg);
}
.chat-form textarea {
  flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); font: inherit; resize: none;
  max-height: 30dvh;
}
.chat-form button { padding: 10px 18px; border-radius: 12px; }
.dots span {
  display: inline-block; width: 6px; height: 6px; margin-right: 4px;
  border-radius: 50%; background: var(--muted);
  animation: dotpulse 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotpulse { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* note linking */
a.wikilink { text-decoration: underline; text-underline-offset: 2px; }
.link-block { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 10px; }
.link-label {
  display: block; font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--muted); margin-bottom: 6px;
}
.chat-caveat { font-size: 0.78rem; margin: 6px 2px 2px; }
