:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c1e21;
  --muted: #687080;
  --border: #dde1e7;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #c4372f;
  --warn-bg: #fff4d6;
  --warn-text: #6b4b00;
  --code-bg: #f1f3f6;
  --pinned: #f2b705;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --card: #1e2127;
    --text: #e6e8eb;
    --muted: #9198a5;
    --border: #30353d;
    --accent: #5b8ff0;
    --danger: #f0675e;
    --warn-bg: #3a2f10;
    --warn-text: #f5d58a;
    --code-bg: #171a1f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }

h1, h2 { margin: 0; }
h1 { font-size: 1.25rem; display: flex; align-items: center; gap: 0.6rem; }
h2 { font-size: 1rem; overflow-wrap: anywhere; }

.muted { color: var(--muted); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

button, .button {
  font: inherit;
  font-size: 0.875rem;
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  line-height: 1.4;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.5rem 0.65rem;
  width: 100%;
}
input:focus, textarea:focus, button:focus-visible, .button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.error { color: var(--danger); }
.error a { color: inherit; }

/* ---------- auth ---------- */
.auth { max-width: 380px; margin: 12vh auto 0; padding: 0 1.25rem; }
.auth h1 { margin-bottom: 0.4rem; }
.auth-form { display: grid; gap: 0.6rem; margin-top: 1.25rem; }
.auth-form label { font-weight: 600; font-size: 0.875rem; }
.auth-form button { padding: 0.55rem; }
.tag {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  background: var(--accent);
  color: var(--accent-text);
}

/* ---------- layout ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem max(1rem, calc((100% - 960px) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.actions form { margin: 0; }

.viewer, .editor { max-width: 960px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.hint { margin: 0; color: var(--muted); font-size: 0.875rem; }
.empty { color: var(--muted); text-align: center; padding: 3rem 0; margin: 0; }
.filter { max-width: 360px; }
#notes { display: grid; gap: 1rem; }

/* ---------- notes ---------- */
.note {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: grid;
  gap: 0.6rem;
  min-width: 0;
}
.note.pinned { border-left: 4px solid var(--pinned); }
.note.orphan { border: 1px dashed var(--danger); }
.note.selected { outline: 2px solid var(--accent); outline-offset: -1px; }
.note .pick { display: none; flex: none; width: 1.1rem; height: 1.1rem; margin: 0; accent-color: var(--accent); cursor: pointer; }
.selecting .note .pick { display: block; }

/* Pinned to the bottom of the screen so it's in reach anywhere in a long list. */
.select-bar {
  position: fixed;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  width: min(960px - 2rem, calc(100% - 2rem));
  z-index: 6;
  box-shadow: 0 4px 18px rgb(0 0 0 / 0.2);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}
.select-bar .spacer { flex: 1; }
#select-count { font-weight: 600; font-size: 0.875rem; }
button:disabled { opacity: 0.5; cursor: default; }
#select[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.selecting .editor { padding-bottom: 6rem; }
.selecting .toast { bottom: 5.5rem; }
.note-head { display: flex; gap: 0.75rem; align-items: center; justify-content: space-between; }
.note-head .title { font-weight: 600; border-color: transparent; padding-left: 0.3rem; }
.note-head .title:hover { border-color: var(--border); }

.note pre, .note textarea.body {
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.5;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.65rem 0.75rem;
  margin: 0;
  tab-size: 4;
}
.note pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 60vh;
  overflow: auto;
  user-select: text;
}
.note textarea.body { resize: vertical; min-height: 5.5rem; max-height: 70vh; white-space: pre-wrap; }

.note-foot { display: flex; gap: 0.5rem; align-items: center; }
.note-foot .spacer { flex: 1; }
.state { font-size: 0.8rem; color: var(--muted); }
.state.error { color: var(--danger); }
.meta { font-size: 0.8rem; color: var(--muted); }
.warn {
  margin: 0;
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: var(--warn-bg);
  color: var(--warn-text);
}

/* ---------- status + toast ---------- */
.status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.status[data-state="live"] { color: #1f9d55; }
.status[data-state="connecting"] { color: #c98a00; }
.status[data-state="offline"] { color: var(--danger); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  box-shadow: 0 4px 18px rgb(0 0 0 / 0.2);
}
