/* Layout: a dark ink rail on the left holds the tabs; the rest is a viewport
   onto one fixed-size board per tab, which pans and zooms. Ideas are paper
   notes pinned to the board wherever someone put them.

   Themes are per viewer (theme.js / the rail's picker). Each one defines the
   whole token set. No data-theme means "match my device": Cork in light,
   Night in dark. */
:root {
  --board: #c59d70;
  --board-texture:
    radial-gradient(rgb(92 58 26 / 0.22) 1px, transparent 1.6px),
    radial-gradient(rgb(255 243 220 / 0.28) 1px, transparent 1.6px),
    radial-gradient(rgb(92 58 26 / 0.22) 0.7px, transparent 1.2px);
  --board-texture-size: 7px 7px, 11px 11px, 13px 13px;
  --board-texture-pos: 0 0, 3px 5px, 6px 2px;
  --frame: #7a5634;
  --outside: #ddd5c9;

  --rail: #1c2531;
  --rail-ink: #edf1f6;
  --rail-muted: #93a1b3;
  --rail-hover: rgb(255 255 255 / 0.06);
  --rail-active: rgb(255 255 255 / 0.13);

  --surface: #ffffff;
  --ink: #1d232b;
  --muted: #5b6573;
  --line: #dde2e8;
  --field: #f4f6f8;
  --accent: #2462a6;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --danger-ink: #ffffff;
  --pin: #cf3f35;

  --note-ink: #29241d;
  --note-meta: rgb(41 36 29 / 0.68);
  --note-yellow: #fff0a3;
  --note-pink: #ffd2dc;
  --note-mint: #caeedb;
  --note-sky: #cde4fa;
  --note-lilac: #e2d8fb;

  --shadow-note: 0 1px 1px rgb(45 28 10 / 0.18), 0 8px 16px -6px rgb(45 28 10 / 0.45);
  --shadow-lift: 0 2px 2px rgb(45 28 10 / 0.16), 0 18px 30px -8px rgb(45 28 10 / 0.5);
  --shadow-pop: 0 24px 60px -12px rgb(15 20 30 / 0.45);

  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;

  --rail-width: 252px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --board: #3a2f25;
    --board-texture:
      radial-gradient(rgb(0 0 0 / 0.3) 1px, transparent 1.6px),
      radial-gradient(rgb(255 230 190 / 0.06) 1px, transparent 1.6px),
      radial-gradient(rgb(0 0 0 / 0.3) 0.7px, transparent 1.2px);
    --frame: #1f1812;
    --outside: #0d1014;
    --rail: #10151b;
    --rail-ink: #e9eef4;
    --rail-muted: #8794a5;
    --surface: #1b2028;
    --ink: #e7ebf0;
    --muted: #9aa4b2;
    --line: #2e3540;
    --field: #232a33;
    --accent: #6ea8ea;
    --accent-ink: #0b1420;
    --danger: #ff8f86;
    --danger-ink: #2a0b08;
    --pin: #e0574c;
    --note-yellow: #ece08e;
    --note-pink: #e9bcc8;
    --note-mint: #b3dbc6;
    --note-sky: #b4cfe9;
    --note-lilac: #cbc1ea;
    --shadow-note: 0 1px 1px rgb(0 0 0 / 0.4), 0 10px 18px -6px rgb(0 0 0 / 0.65);
    --shadow-lift: 0 2px 2px rgb(0 0 0 / 0.4), 0 18px 30px -8px rgb(0 0 0 / 0.7);
    color-scheme: dark;
  }
}

:root[data-theme="night"] {
  --board: #3a2f25;
  --board-texture:
    radial-gradient(rgb(0 0 0 / 0.3) 1px, transparent 1.6px),
    radial-gradient(rgb(255 230 190 / 0.06) 1px, transparent 1.6px),
    radial-gradient(rgb(0 0 0 / 0.3) 0.7px, transparent 1.2px);
  --frame: #1f1812;
  --outside: #0d1014;
  --rail: #10151b;
  --rail-ink: #e9eef4;
  --rail-muted: #8794a5;
  --surface: #1b2028;
  --ink: #e7ebf0;
  --muted: #9aa4b2;
  --line: #2e3540;
  --field: #232a33;
  --accent: #6ea8ea;
  --accent-ink: #0b1420;
  --danger: #ff8f86;
  --danger-ink: #2a0b08;
  --pin: #e0574c;
  --note-yellow: #ece08e;
  --note-pink: #e9bcc8;
  --note-mint: #b3dbc6;
  --note-sky: #b4cfe9;
  --note-lilac: #cbc1ea;
  --shadow-note: 0 1px 1px rgb(0 0 0 / 0.4), 0 10px 18px -6px rgb(0 0 0 / 0.65);
  --shadow-lift: 0 2px 2px rgb(0 0 0 / 0.4), 0 18px 30px -8px rgb(0 0 0 / 0.7);
  color-scheme: dark;
}

:root[data-theme="whiteboard"] {
  --board: #fafbfc;
  --board-texture: radial-gradient(rgb(60 80 110 / 0.16) 1.2px, transparent 1.7px);
  --board-texture-size: 28px 28px;
  --board-texture-pos: 0 0;
  --frame: #a9b3bf;
  --outside: #d3d9e0;
  --rail: #222b37;
  --pin: #2b6cb0;
  --shadow-note: 0 1px 1px rgb(20 30 45 / 0.12), 0 8px 16px -6px rgb(20 30 45 / 0.3);
  --shadow-lift: 0 2px 2px rgb(20 30 45 / 0.12), 0 18px 30px -8px rgb(20 30 45 / 0.35);
}

:root[data-theme="chalk"] {
  --board: #2e4a3b;
  --board-texture:
    radial-gradient(rgb(255 255 255 / 0.06) 1px, transparent 1.6px),
    radial-gradient(rgb(0 0 0 / 0.2) 1px, transparent 1.6px);
  --board-texture-size: 9px 9px, 13px 13px;
  --board-texture-pos: 0 0, 4px 6px;
  --frame: #6b4c31;
  --outside: #141b17;
  --rail: #101713;
  --rail-ink: #e6efe9;
  --rail-muted: #8fa398;
  --surface: #1a221e;
  --ink: #e6ece8;
  --muted: #9fb0a6;
  --line: #2c3832;
  --field: #212b26;
  --accent: #8fd0a8;
  --accent-ink: #0c1a12;
  --danger: #ff8f86;
  --danger-ink: #2a0b08;
  --pin: #e8e3d3;
  --note-yellow: #ece08e;
  --note-pink: #e9bcc8;
  --note-mint: #b3dbc6;
  --note-sky: #b4cfe9;
  --note-lilac: #cbc1ea;
  --shadow-note: 0 1px 1px rgb(0 0 0 / 0.4), 0 10px 18px -6px rgb(0 0 0 / 0.65);
  --shadow-lift: 0 2px 2px rgb(0 0 0 / 0.4), 0 18px 30px -8px rgb(0 0 0 / 0.7);
  color-scheme: dark;
}

/* Pens, the string between pins, and group outlines. Light themes first;
   the dark ones (device dark, Night, Chalkboard) swap in brighter inks so
   drawing and writing stay readable on a dark board. */
:root {
  --font-hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --live-on: #2f9e57;
  --live-wait: #d9a21b;
  --live-off: #d0632b;
  --pen-ink: #23201c;
  --pen-red: #c0392b;
  --pen-blue: #1f5fae;
  --pen-green: #2e7d32;
  --string: #b3312a;
  --group-blue: #2f6fb0;
  --group-green: #2f8a57;
  --group-orange: #b8601a;
  --group-purple: #7a4fc0;
  --group-teal: #16808a;
  --group-ink: #ffffff;
}
:root[data-theme="whiteboard"] { --string: #2b5fa8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --pen-ink: #ece6d8;
    --pen-red: #ff8a7a;
    --pen-blue: #8cc4ff;
    --pen-green: #9fe0a0;
    --string: #e2675a;
    --group-blue: #7fb2ec;
    --group-green: #79c99a;
    --group-orange: #f0a462;
    --group-purple: #b79af0;
    --group-teal: #6fc8cf;
    --group-ink: #0d1117;
  }
}
:root[data-theme="night"], :root[data-theme="chalk"] {
  --pen-ink: #ece6d8;
  --pen-red: #ff8a7a;
  --pen-blue: #8cc4ff;
  --pen-green: #9fe0a0;
  --string: #e2675a;
  --group-blue: #7fb2ec;
  --group-green: #79c99a;
  --group-orange: #f0a462;
  --group-purple: #b79af0;
  --group-teal: #6fc8cf;
  --group-ink: #0d1117;
}
:root[data-theme="chalk"] {
  --pen-ink: #f3f1e8;
  --string: #f2d27a;
}

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

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--board);
}

.cork {
  background-color: var(--board);
  background-image: var(--board-texture);
  background-size: var(--board-texture-size);
  background-position: var(--board-texture-pos);
}

h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; line-height: 1.15; }
p { margin: 0; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons and fields ---------- */

.btn {
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:not(:disabled):hover { background: color-mix(in srgb, var(--accent) 86%, var(--ink)); }
.btn-danger { background: var(--danger); color: var(--danger-ink); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-quiet:not(:disabled):hover { background: var(--field); }
.btn-quiet-danger { color: var(--danger); }
.btn-wide { width: 100%; padding-block: 11px; }
.btn-on-note { color: var(--note-ink); border-color: rgb(41 36 29 / 0.25); padding: 6px 12px; }
.btn-on-note:not(:disabled):hover { background: rgb(41 36 29 / 0.08); }

.link-btn {
  font: inherit; font-size: 0.82rem; font-weight: 700; color: var(--muted);
  background: none; border: 0; padding: 2px 4px; cursor: pointer; border-radius: 4px;
}
.link-btn:hover { color: var(--danger); }

.stack { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; border: 0; margin: 0; padding: 0; }
.field > label, .field > legend {
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.03em; color: var(--muted); padding: 0;
}
.optional { font-weight: 400; letter-spacing: 0; }
.field-row { display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: flex-start; }
.field-row > .field:last-child { flex: 1 1 180px; }

input[type="text"], input[type="password"], textarea, select {
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--accent); }

.form-error { color: var(--danger); font-size: 0.9rem; font-weight: 700; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.8rem; }

/* ---------- Sign in ---------- */

.signin { min-height: 100%; display: grid; place-items: center; padding: 40px 16px; }
.signin-card {
  position: relative;
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: 4px;
  padding: 36px 28px 28px;
  box-shadow: var(--shadow-lift);
  display: flex; flex-direction: column; gap: 18px;
}
.signin-title { font-size: 2.1rem; font-weight: 750; letter-spacing: -0.02em; }
.signin-lede { color: var(--muted); }
.signin-note { color: var(--muted); }

/* ---------- Pins ---------- */

.pin, .brand-pin {
  display: block;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 32%, rgb(255 255 255 / 0.6), transparent 42%),
    var(--pin);
  box-shadow: 0 2px 3px rgb(0 0 0 / 0.35);
}
.pin { position: absolute; top: -7px; left: 50%; width: 16px; height: 16px; margin-left: -8px; }
.brand-pin { width: 12px; height: 12px; flex: none; }

/* ---------- App frame ---------- */

.app {
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  height: 100%;
  overflow: hidden;
  transition: grid-template-columns 0.22s ease;
}
.app.rail-collapsed { grid-template-columns: 0 minmax(0, 1fr); }

.rail {
  background: var(--rail);
  color: var(--rail-ink);
  display: flex; flex-direction: column; gap: 22px;
  padding: 20px 14px;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
}
.app.rail-collapsed .rail { visibility: hidden; padding-inline: 0; }

.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 750; font-size: 1.2rem; letter-spacing: -0.01em;
  padding: 2px 8px; white-space: nowrap;
}
.rail-tabs { display: flex; flex-direction: column; gap: 6px; flex: 1; min-height: 0; }
.rail-label {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--rail-muted); padding: 0 10px;
}
.tab-list { display: flex; flex-direction: column; gap: 2px; }
.tab {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px;
  font: inherit; color: var(--rail-ink); text-align: left;
  background: transparent; border: 0; border-radius: 8px; cursor: pointer;
}
.tab:hover { background: var(--rail-hover); }
.tab[aria-current="page"] { background: var(--rail-active); font-weight: 700; }
.tab-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-count { font-size: 0.78rem; color: var(--rail-muted); font-variant-numeric: tabular-nums; }
.tab .lock { flex: none; color: var(--rail-muted); }
.tab[aria-current="page"] .lock { color: var(--rail-ink); }

.private-badge {
  display: inline-block; margin-right: 8px; padding: 1px 8px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--surface); background: var(--muted); border-radius: 999px;
  vertical-align: 1px;
}

.visibility { gap: 8px; }
/* More specific than .field > label, which styles a field's own caption. */
.visibility > label.choice {
  font-size: inherit; font-weight: 400; letter-spacing: 0; color: inherit;
  padding: 10px 12px;
}
.choice {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice span { display: flex; flex-direction: column; gap: 2px; font-size: 0.88rem; color: var(--muted); }
.choice strong { color: var(--ink); font-size: 0.95rem; }
.visibility:disabled .choice { opacity: 0.6; cursor: default; }
.rail-empty { color: var(--rail-muted); padding: 4px 10px; font-size: 0.9rem; }
.rail-add {
  font: inherit; font-weight: 700; font-size: 0.9rem; text-align: left;
  color: var(--rail-ink); background: transparent;
  border: 1px dashed var(--rail-muted); border-radius: 8px;
  padding: 8px 10px; margin-top: 6px; cursor: pointer;
}
.rail-add:hover { background: var(--rail-hover); }

.rail-foot { display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--rail-active); padding-top: 14px; }
.who { display: flex; align-items: center; gap: 10px; padding: 0 6px; min-width: 0; }
.who-initial {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--note-yellow); color: var(--note-ink);
  font-family: var(--font-display); font-weight: 750;
}
.who-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.who-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-role { font-size: 0.8rem; color: var(--rail-muted); }
.theme-pick { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 6px; font-size: 0.85rem; color: var(--rail-muted); font-weight: 700; }
.theme-pick select {
  width: auto; min-width: 0; padding: 5px 8px; font-size: 0.85rem;
  color: var(--rail-ink); background: var(--rail-hover); border-color: var(--rail-active);
}
.theme-pick option { color: var(--ink); background: var(--surface); }
.rail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.rail-btn {
  font: inherit; font-size: 0.85rem; font-weight: 700;
  color: var(--rail-ink); background: var(--rail-hover);
  border: 1px solid var(--rail-active); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
.rail-btn:hover { background: var(--rail-active); }
.rail-btn[aria-pressed="true"] { background: var(--note-yellow); color: var(--note-ink); border-color: transparent; }

/* ---------- Board ---------- */

.board { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--outside); }
.board-head {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  position: relative; z-index: 2;
}
.rail-toggle { padding: 7px 9px; display: grid; place-items: center; color: var(--muted); }
.rail-toggle[aria-expanded="false"] { color: var(--accent); border-color: var(--accent); }
.head-title { flex: 1 1 180px; min-width: 0; }
.head-title h1 { font-size: 1.45rem; font-weight: 750; letter-spacing: -0.015em; overflow-wrap: anywhere; }
.tab-count-line { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.head-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.admin-tools { display: flex; flex-wrap: wrap; gap: 6px; padding-right: 10px; border-right: 1px solid var(--line); }
.admin-tools .btn { padding: 7px 11px; font-size: 0.84rem; }
.zoom { display: flex; align-items: center; gap: 4px; }
.zoom .btn { padding: 7px 10px; font-size: 0.84rem; }
.zoom-step { min-width: 36px; font-size: 1rem !important; line-height: 1; }
.zoom-level { min-width: 62px; font-variant-numeric: tabular-nums; }

.banner {
  margin: 12px 20px 0;
  background: var(--surface); color: var(--danger);
  border-radius: 8px; padding: 10px 14px; font-weight: 700;
  box-shadow: var(--shadow-note);
}

.viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--outside);
  touch-action: none;
  cursor: grab;
  user-select: none;
}
.viewport.panning { cursor: grabbing; }

/* The board itself: fixed size (BOARD in app.js), framed so its edge reads as
   the limit. Positioned by a transform, so panning never re-lays out notes. */
.world {
  position: absolute; left: 0; top: 0;
  width: 3200px; height: 2000px;
  transform-origin: 0 0;
  border-radius: 6px;
  box-shadow: 0 0 0 16px var(--frame), 0 0 0 17px rgb(0 0 0 / 0.25), 0 30px 60px 10px rgb(0 0 0 / 0.3);
}
/* Board layers, bottom to top: group outlines, drawings, strings, text,
   notes. The layers themselves let presses through to the board (so empty
   space pans); only the things on them catch the pointer, and each tool
   decides which of those it wants. */
.layer { position: absolute; inset: 0; pointer-events: none; }
svg.layer { overflow: visible; }
.note, .text-item, .group-tag { pointer-events: auto; }
.string-hit { pointer-events: stroke; }
.viewport.mode-draw .note,
.viewport.mode-draw .text-item,
.viewport.mode-draw .group-tag,
.viewport.mode-draw .string-hit,
.viewport.mode-group .text-item,
.viewport.mode-group .group-tag,
.viewport.mode-group .string-hit,
.viewport.mode-line .text-item,
.viewport.mode-line .group-tag { pointer-events: none; }
.viewport.mode-line .note { cursor: crosshair; }
.viewport.mode-group .note { cursor: pointer; }
.viewport.mode-draw, .viewport.mode-draw.panning { cursor: crosshair; }

.pen--ink { --pen: var(--pen-ink); }
.pen--red { --pen: var(--pen-red); }
.pen--blue { --pen: var(--pen-blue); }
.pen--green { --pen: var(--pen-green); }

.ink-stroke { fill: none; stroke: var(--pen); stroke-linecap: round; stroke-linejoin: round; }

.string, .string--default { --sc: var(--string); }
.string--red { --sc: var(--pen-red); }
.string--blue { --sc: var(--pen-blue); }
.string--green { --sc: var(--pen-green); }
.string--orange { --sc: var(--group-orange); }
.string--purple { --sc: var(--group-purple); }
.sc-fill { background: var(--sc); }
.string-line {
  fill: none; stroke: var(--sc); stroke-width: 2.5; stroke-linecap: round;
  filter: drop-shadow(0 1.5px 1px rgb(0 0 0 / 0.3));
}
.string-hit { fill: none; stroke: transparent; stroke-width: 18; cursor: pointer; }
.string:hover .string-line { stroke-width: 4; }
.string-band { fill: none; stroke: var(--string); stroke-width: 2.5; stroke-dasharray: 8 7; stroke-linecap: round; }

.group {
  position: absolute;
  border: 2px dashed var(--gc);
  border-radius: 16px;
  background: color-mix(in srgb, var(--gc) 10%, transparent);
}
.group--blue { --gc: var(--group-blue); }
.group--green { --gc: var(--group-green); }
.group--orange { --gc: var(--group-orange); }
.group--purple { --gc: var(--group-purple); }
.group--teal { --gc: var(--group-teal); }
.group-tag {
  position: absolute; top: 12px; left: 14px;
  max-width: calc(100% - 28px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 700 1rem/1.2 var(--font-display);
  color: var(--group-ink); background: var(--gc);
  border: 0; border-radius: 999px; padding: 6px 14px;
  box-shadow: var(--shadow-note);
  cursor: grab;
}
.group-tag:active { cursor: grabbing; }

.text-item {
  position: absolute;
  width: max-content; max-width: 1000px;
  padding: 2px 8px;
  font-family: var(--font-hand); font-weight: 600; line-height: 1.1;
  color: var(--pen);
  white-space: pre-wrap; overflow-wrap: anywhere;
  border-radius: 6px;
  cursor: grab;
}
.text-item:hover { outline: 1px dashed color-mix(in srgb, var(--pen) 45%, transparent); }
.text-item.dragging { cursor: grabbing; }
.text--s { font-size: 30px; }
.text--m { font-size: 44px; }
.text--l { font-size: 68px; }
.handwriting-input { font-family: var(--font-hand); font-size: 1.8rem; font-weight: 600; line-height: 1.2; color: var(--pen); }
.pen-fill { background: var(--pen); }

.note.selected { outline: 3px solid var(--accent); outline-offset: 5px; }
.note.line-start { outline: 3px dashed var(--string); outline-offset: 5px; }

.note {
  position: absolute;
  display: flex; flex-direction: column; gap: 8px;
  width: 220px; min-height: 150px;
  padding: 22px 16px 14px;
  font: inherit; text-align: left;
  color: var(--note-ink);
  background: var(--note-yellow);
  border: 0; border-radius: 3px;
  box-shadow: var(--shadow-note);
  transform: rotate(var(--tilt, 0deg));
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  cursor: grab;
  touch-action: none;
}
.note:hover, .note:focus-visible { transform: rotate(0deg) translateY(-3px); box-shadow: var(--shadow-lift); }
.note:focus-visible { outline-offset: 4px; }
.note.dragging {
  z-index: 1000; cursor: grabbing;
  transform: rotate(0deg) scale(1.04);
  box-shadow: var(--shadow-lift);
  transition: none;
}
.note--yellow { background: var(--note-yellow); }
.note--pink { background: var(--note-pink); }
.note--mint { background: var(--note-mint); }
.note--sky { background: var(--note-sky); }
.note--lilac { background: var(--note-lilac); }

.note-title {
  font-family: var(--font-display); font-weight: 650; font-size: 1.08rem; line-height: 1.25;
  overflow-wrap: anywhere;
}
.note-text {
  font-size: 0.94rem; line-height: 1.45;
  white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 7; -webkit-box-orient: vertical; overflow: hidden;
}
.note-meta {
  margin-top: auto; padding-top: 6px;
  display: flex; flex-wrap: wrap; gap: 2px 10px;
  font-size: 0.8rem; color: var(--note-meta);
}
.note-author { font-weight: 700; color: var(--note-ink); }
.note-comments { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

.empty {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  padding: 28px 28px 24px;
  width: min(460px, calc(100% - 32px));
  background: var(--surface); border-radius: 4px; box-shadow: var(--shadow-lift);
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  cursor: default;
}
.empty::before {
  content: ""; position: absolute; top: -7px; left: 50%; width: 16px; height: 16px; margin-left: -8px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 32%, rgb(255 255 255 / 0.6), transparent 42%), var(--pin);
  box-shadow: 0 2px 3px rgb(0 0 0 / 0.35);
}
.empty-title { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; }
.empty p:not(.empty-title) { color: var(--muted); }
.empty .btn { margin-top: 6px; }

.presence { display: flex; align-items: center; gap: 10px; min-width: 0; }
.live-status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.live-status--off { display: none; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live-wait); }
.live-status--live .live-dot { background: var(--live-on); box-shadow: 0 0 0 3px color-mix(in srgb, var(--live-on) 25%, transparent); }
.live-status--offline .live-dot { background: var(--live-off); }
.peers { display: flex; padding-left: 6px; }
.peer {
  width: 28px; height: 28px; margin-left: -6px;
  display: grid; place-items: center;
  font: 700 0.8rem/1 var(--font-display);
  color: #ffffff; background: var(--peer);
  border: 2px solid var(--surface); border-radius: 50%;
}
.peer--elsewhere { opacity: 0.5; }

.modes { display: flex; gap: 2px; padding: 2px; background: var(--field); border: 1px solid var(--line); border-radius: 9px; }
.mode {
  font: inherit; font-size: 0.84rem; font-weight: 700;
  color: var(--muted); background: transparent;
  border: 0; border-radius: 7px; padding: 6px 11px; cursor: pointer;
}
.mode:hover:not(:disabled) { color: var(--ink); }
.mode[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.18); }
.mode:disabled { opacity: 0.45; cursor: default; }

.tool-bar {
  position: absolute; top: 12px; left: 50%; z-index: 3;
  transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 24px);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px;
  padding: 8px 10px 8px 16px;
  background: var(--surface); color: var(--ink);
  border-radius: 12px; box-shadow: var(--shadow-lift);
  cursor: default;
}
.tool-text { font-weight: 700; font-size: 0.9rem; }
.tool-bar .btn { padding: 7px 12px; font-size: 0.85rem; }
.group-form { display: flex; gap: 8px; }
.group-form input { width: 190px; padding: 7px 10px; }
.pen-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.pen-colors, .pen-sizes { display: flex; gap: 6px; }
.pen-swatch {
  width: 28px; height: 28px; padding: 0;
  border-radius: 50%; border: 2px solid var(--line);
  background: var(--pen); cursor: pointer;
}
.pen-swatch[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--surface); }
.pen-swatch.sc-fill { background: var(--sc); }
.pen-size {
  width: 32px; height: 32px; padding: 0;
  display: grid; place-items: center;
  background: transparent; border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.pen-size[aria-pressed="true"] { background: var(--field); border-color: var(--ink); }
.pen-dot { display: block; border-radius: 50%; background: var(--ink); }
.pen-dot--s { width: 4px; height: 4px; }
.pen-dot--m { width: 8px; height: 8px; }
.pen-dot--l { width: 14px; height: 14px; }
#pen-eraser[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.board-menu {
  position: absolute; z-index: 4;
  min-width: 190px;
  display: flex; flex-direction: column;
  padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-pop);
  cursor: default;
}
.menu-item {
  font: inherit; font-size: 0.92rem; font-weight: 700; text-align: left;
  color: var(--ink); background: transparent;
  border: 0; border-radius: 7px; padding: 9px 12px; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--field); outline: none; }
.menu-sub { display: block; margin-top: 1px; font-size: 0.8rem; font-weight: 400; color: var(--muted); }

.download { position: relative; }
.download-menu { top: calc(100% + 6px); right: 0; min-width: 270px; }
.download .btn[aria-busy="true"] { cursor: progress; }

.viewport-hint {
  position: absolute; left: 12px; bottom: 12px;
  max-width: calc(100% - 24px);
  background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 5px 12px;
  font-size: 0.78rem; font-weight: 700;
  box-shadow: var(--shadow-note);
  pointer-events: none;
}
.hint-touch { display: none; }
@media (hover: none) {
  .hint-mouse { display: none; }
  .hint-touch { display: inline; }
}

/* ---------- Dialogs ---------- */

dialog {
  border: 0; padding: 0;
  border-radius: 12px;
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-pop);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
}
dialog::backdrop { background: rgb(12 16 22 / 0.55); }
.dialog-body { padding: 22px 24px 24px; display: flex; flex-direction: column; gap: 16px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h2, .dialog-body > h2 { font-size: 1.3rem; font-weight: 700; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

.swatches { flex: none; }
.swatch-row { display: flex; gap: 10px; }
.swatch-row input { position: absolute; opacity: 0; pointer-events: none; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--line);
  box-shadow: inset 0 0 0 3px var(--surface);
}
.swatch-row input:checked + .swatch { border-color: var(--ink); }
.swatch-row input:focus-visible + .swatch { outline: 3px solid var(--accent); outline-offset: 2px; }

.detail-dialog { width: min(640px, calc(100vw - 32px)); }
.detail-note {
  padding: 18px 24px 20px;
  color: var(--note-ink);
  display: flex; flex-direction: column; gap: 12px;
}
.detail-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chip {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  background: rgb(41 36 29 / 0.1); border-radius: 999px; padding: 3px 10px;
  max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.detail-note h2 { font-size: 1.5rem; font-weight: 700; overflow-wrap: anywhere; }
.detail-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.detail-meta {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 0.85rem; color: var(--note-meta);
}
.detail-actions { display: flex; gap: 6px; }
.detail-group { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; font-weight: 700; color: var(--note-meta); }
.detail-group select {
  width: auto; padding: 5px 8px;
  color: var(--note-ink); background: rgb(255 255 255 / 0.55); border-color: rgb(41 36 29 / 0.25);
}

.comments { padding: 18px 24px 22px; display: flex; flex-direction: column; gap: 14px; }
.comments h3 { font-size: 1.05rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.count-pill {
  font-family: var(--font-body); font-size: 0.78rem; font-variant-numeric: tabular-nums;
  background: var(--field); color: var(--muted); border-radius: 999px; padding: 1px 9px;
}
.count-pill:empty { display: none; }
.comment-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.comment { border-left: 3px solid var(--line); padding: 2px 0 2px 12px; }
.comment-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.comment-time { color: var(--muted); font-size: 0.8rem; }
.comment-head .link-btn { margin-left: auto; }
.comment-text { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.comment-empty { color: var(--muted); }
.comment-form { display: flex; flex-direction: column; gap: 8px; }
.comment-form-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- People (admin) ---------- */

.people-title { display: flex; align-items: center; gap: 8px; }
.people-list {
  list-style: none; margin: 0; padding: 0;
  border: 1px solid var(--line); border-radius: 8px;
  max-height: min(40dvh, 340px); overflow-y: auto;
}
.person { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 6px 12px; }
.person + .person { border-top: 1px solid var(--line); }
.person-name { font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.person--removed .person-name { color: var(--muted); font-weight: 400; text-decoration: line-through; }
.person--empty { color: var(--muted); }
.person-tag {
  flex: none; padding: 1px 8px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--field); color: var(--muted);
}
.person-tag--added { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--accent); }
.person-tag--removed { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); color: var(--danger); }
.person .link-btn { flex: none; margin-left: auto; }
.person .link-btn--undo:hover { color: var(--accent); }
.people-add { display: flex; gap: 8px; }
.people-add input { flex: 1; min-width: 0; }
.people-status { font-size: 0.9rem; font-weight: 700; color: var(--accent); }
.people-summary { margin-right: auto; align-self: center; font-size: 0.88rem; color: var(--muted); }
.people-password { border-top: 1px solid var(--line); padding-top: 14px; }
.people-password summary { cursor: pointer; font-weight: 700; font-size: 0.92rem; color: var(--muted); }
.people-password summary:hover { color: var(--ink); }
.people-password[open] summary { margin-bottom: 14px; color: var(--ink); }

/* ---------- Toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 10;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  background: var(--rail); color: var(--rail-ink);
  border-radius: 10px; padding: 11px 16px;
  box-shadow: var(--shadow-pop);
  font-weight: 700; font-size: 0.92rem;
}
.toast--error { background: var(--danger); color: var(--danger-ink); }

/* ---------- Narrow screens: the rail becomes a top bar ---------- */

@media (max-width: 760px) {
  .app, .app.rail-collapsed { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .app.rail-collapsed { grid-template-rows: minmax(0, 1fr); }
  .app.rail-collapsed .rail { display: none; }
  .rail {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 12px; padding: 12px 16px;
    overflow: visible;
  }
  .brand { grid-column: 1 / -1; padding: 0; }
  .rail-foot {
    grid-column: 1 / -1; grid-row: 3;
    flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
    padding-top: 10px;
  }
  .who { display: none; }
  .theme-pick { padding: 0; }
  .rail-tabs { grid-column: 1 / -1; grid-row: 2; flex-direction: row; align-items: center; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
  .rail-label { display: none; }
  .tab-list { flex-direction: row; gap: 4px; }
  .tab { width: auto; white-space: nowrap; padding: 7px 12px; }
  .tab-name { overflow: visible; }
  .rail-add { margin: 0; white-space: nowrap; padding: 6px 10px; }
  .board-head { padding: 10px 16px; }
  .admin-tools { border: 0; padding: 0; }
  .banner { margin-inline: 16px; }
  .dialog-body, .comments { padding-inline: 18px; }
  .detail-note { padding-inline: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .app, .note, .btn { transition: none; }
  .note, .note:hover, .note:focus-visible { transform: none; }
}
.peer--more { background: var(--muted); font-size: 0.7rem; }
