:root {
  /* dark mode — warm Claude-style greys, light text */
  --bg: #1f1e1d;            /* main viewer background */
  --sidebar-bg: #1a1917;    /* sidebar, a touch darker */
  --panel: #2a2927;         /* cards + buttons, a touch lighter than bg */
  --panel-alt: #242321;     /* card back side */
  --ink: #ececea;           /* primary text (near white) */
  --muted: #a3a299;
  --faint: #75736d;
  --leaf-ink: #cbcac3;      /* deck (leaf) labels */
  --line: rgba(255,255,255,.08);
  --line-strong: rgba(255,255,255,.16);
  --hover: rgba(255,255,255,.06);
  --active: rgba(255,255,255,.10);
  --active-ink: #ffffff;
  --shit: #e5484d;
  --shit-hover: #d23b40;
  --shit-on: #7f1d1d;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 30px rgba(0,0,0,.45);
  font-synthesis: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 400px 1fr;
  height: 100vh;
}

/* ---------- sidebar ---------- */
#sidebar {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--sidebar-bg);
}

.side-head {
  padding: 18px 20px 13px;
  display: flex;
  align-items: baseline;
  gap: 9px;
  border-bottom: 1px solid var(--line);
}
.logo { font-weight: 700; letter-spacing: .14em; font-size: 15px; }
.sub { color: var(--faint); font-size: 14px; }

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 9px 7px 14px;
  font-size: 16px;
}

.row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.row:hover { background: var(--hover); }
.row .caret {
  width: 16px;
  color: var(--faint);
  flex: 0 0 auto;
  transition: transform .12s ease;
  font-size: 12px;
  text-align: center;
}
.row.collapsed .caret { transform: rotate(-90deg); }
.row .ic { flex: 0 0 auto; opacity: .9; }
.row .label {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
}
.row .count {
  color: var(--faint);
  font-size: 14px;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
.row.folder .label { color: var(--ink); font-weight: 550; }
.row.leaf .label { color: var(--leaf-ink); }
.row.leaf.active { background: var(--active); }
.row.leaf.active .label { color: var(--active-ink); font-weight: 600; }
.row.leaf.active .count { color: var(--ink); }

.children { margin-left: 13px; border-left: 1px solid var(--line); }
.children.hidden { display: none; }

.bad-summary {
  border-top: 1px solid var(--line);
  padding: 13px 20px;
  font-size: 14px;
  color: var(--muted);
}
.bad-summary b { color: var(--shit); }

/* ---------- viewer ---------- */
#viewer {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  min-width: 0;
}

.empty { text-align: center; color: var(--faint); }
.empty-title { font-size: 18px; color: var(--muted); margin-bottom: 6px; }
.empty-sub { font-size: 13px; }

.deck {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.hidden { display: none !important; }

.deck-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}
.deck-title { font-size: 16px; font-weight: 650; }
.deck-pos { color: var(--faint); font-size: 16px; font-variant-numeric: tabular-nums; }

.card {
  position: relative;
  min-height: 320px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 38px 34px 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  will-change: transform;
}
.card:hover { border-color: rgba(255,255,255,.24); box-shadow: 0 1px 2px rgba(0,0,0,.35), 0 16px 40px rgba(0,0,0,.55); }
.card:active { cursor: grabbing; }
.card:focus-visible { outline: 2px solid #6f8cff; outline-offset: 2px; }
.card.back { background: var(--panel-alt); }

.side-label {
  position: absolute;
  top: 14px;
  left: 18px;
  font-size: 10.5px;
  letter-spacing: .16em;
  color: var(--faint);
  font-weight: 700;
}

.card-body {
  font-size: 21px;
  line-height: 1.45;
  max-width: 38ch;
  white-space: pre-wrap;
  color: var(--ink);
}
.card.front .card-body { font-weight: 600; }
.card .note {
  display: block;
  margin-top: 16px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 400;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-height: 20px;
  font-size: 11.5px;
  color: var(--muted);
}
.tag {
  background: var(--hover);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
}
.src { color: var(--faint); }

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.nav {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s ease;
}
.nav:hover:not(:disabled) { background: var(--hover); }
.nav:disabled { opacity: .35; cursor: default; }

.shit {
  min-width: 150px;
  height: 52px;
  padding: 0 26px;
  border-radius: 999px;
  border: none;
  background: var(--shit);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  transition: background .12s ease, transform .05s ease;
}
.shit:hover { background: var(--shit-hover); }
.shit:active { transform: translateY(1px); }
.shit.on { background: var(--shit-on); }

/* ============================================================= *
 *  Renderer upgrade — auth, notes, notes view
 * ============================================================= */

/* ---------- login gate ---------- */
.login {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 320px;
  max-width: calc(100vw - 40px);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 30px 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-logo { font-weight: 700; letter-spacing: .14em; font-size: 17px; }
.login-sub { color: var(--faint); font-size: 13px; margin-top: -10px; }
.login-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-field select,
.login-field input {
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--panel-alt);
  color: var(--ink);
  font-size: 15px;
  font-family: inherit;
}
.login-field select:focus,
.login-field input:focus { outline: 2px solid #6f8cff; outline-offset: 1px; }
.login-go {
  height: 44px;
  margin-top: 4px;
  border: none;
  border-radius: 10px;
  background: #6f8cff;
  color: #fff;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  transition: filter .12s ease;
}
.login-go:hover { filter: brightness(1.08); }
.login-err { color: var(--shit); font-size: 13px; min-height: 16px; text-align: center; }
.login-card.shake { animation: shake .32s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* ---------- sidebar head: mode toggle + footer ---------- */
.side-head { flex-direction: column; align-items: stretch; gap: 12px; }
.side-head-top { display: flex; align-items: baseline; gap: 9px; }
.modes {
  display: flex;
  gap: 4px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}
.mode {
  flex: 1;
  height: 32px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.mode:hover { color: var(--ink); }
.mode.active { background: var(--active); color: var(--active-ink); }

.side-foot {
  border-top: 1px solid var(--line);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.whoami { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signout {
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.signout:hover { color: var(--ink); background: var(--hover); }

/* notes-mode scope rows in the tree */
.row.scope.active { background: var(--active); }
.row.scope.active .label { color: var(--active-ink); font-weight: 600; }
.row.note-all .label { color: var(--ink); font-weight: 600; }

/* ---------- composer (always open) ---------- */
.composer {
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--panel-alt);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.composer.shake { animation: shake .32s ease; }
.composer-target {
  display: inline-flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 3px;
  align-self: flex-start;
}
.seg {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.seg.active { background: var(--active); color: var(--active-ink); }
#composer-text {
  width: 100%;
  resize: none;          /* height is driven by content (auto-grow in app.js) */
  overflow-y: hidden;    /* no inner scrollbar — the field grows instead */
  min-height: 64px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
}
#composer-text:focus { outline: 2px solid #6f8cff; outline-offset: 1px; }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.composer-hint { font-size: 12px; color: var(--faint); }
.composer-hint.warn { color: var(--shit); font-weight: 600; }
.composer-send {
  border: none;
  border-radius: 9px;
  background: #6f8cff;
  color: #fff;
  font-size: 14px;
  font-weight: 650;
  padding: 9px 20px;
  cursor: pointer;
  transition: filter .12s ease, opacity .12s ease;
}
.composer-send:hover { filter: brightness(1.08); }
.composer-send:disabled { opacity: .45; cursor: default; }
.composer-notes { display: flex; flex-direction: column; gap: 8px; }
.composer-notes:empty { display: none; }

/* ---------- a single note row (composer + feed) ---------- */
.note-item {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel);
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.note-head { display: flex; align-items: center; gap: 9px; }
.note-author { font-weight: 650; font-size: 13px; color: var(--ink); }
.note-time { font-size: 12px; color: var(--faint); }
.note-del {
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--faint);
  font-size: 12px;
  cursor: pointer;
}
.note-del:hover { color: var(--shit); }
.note-body { font-size: 15px; line-height: 1.45; color: var(--ink); white-space: pre-wrap; }
.note-source {
  align-self: flex-start;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--hover);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
}
.note-source-ic { flex: none; display: inline-flex; align-items: center; font-size: 13px; }
.note-source-ic svg { display: block; }
.note-source-tx { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.note-source:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---------- notes view ---------- */
.notes-view {
  width: 100%;
  max-width: 720px;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 100%;
  min-height: 0;
}
.notes-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.notes-scope { font-size: 18px; font-weight: 650; }
.notes-count { color: var(--faint); font-size: 14px; font-variant-numeric: tabular-nums; }
.notes-feed {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 0;
  padding-right: 4px;
}
.notes-feed .note-item { background: var(--panel); }
.notes-empty { color: var(--faint); font-size: 14px; padding: 20px 0; text-align: center; }

#viewer.notes-mode { align-items: flex-start; }
