/* Layout: one reading column of note "slips", a sticky top bar and a composer pinned to the bottom. */
:root {
  --bg: #f2f3f6;
  --surface: #ffffff;
  --code-bg: #fafbfc;
  --ink: #151821;
  --muted: #5d6476;
  --line: #dcdfe7;
  --accent: #2b3fd9;          /* carbon-copy blue: you */
  --accent-ink: #ffffff;
  --accent-soft: #e5e8fd;
  --other: #0d7d6c;           /* the other side */
  --other-soft: #dff3ef;
  --danger: #c22a2a;
  --danger-soft: #fbe7e7;
  --gutter: #a5abb9;
  --shadow: 0 1px 2px rgb(20 24 40 / .06), 0 4px 16px rgb(20 24 40 / .05);

  --hl-keyword: #2b3fd9;
  --hl-string: #0d7d6c;
  --hl-number: #a3480f;
  --hl-comment: #8a90a0;
  --hl-title: #7a2fbf;
  --hl-attr: #9a5b00;

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-code: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1015; --surface: #161920; --code-bg: #12141a; --ink: #e7e9ef; --muted: #8e95a8;
    --line: #272b36; --accent: #8d99ff; --accent-ink: #0e1015; --accent-soft: #1e2350;
    --other: #4cc4b1; --other-soft: #12302b; --danger: #ff7b7b; --danger-soft: #3a1717;
    --gutter: #4b5161; --shadow: 0 1px 2px rgb(0 0 0 / .3);
    --hl-keyword: #8d99ff; --hl-string: #6fd3c2; --hl-number: #f0a36b; --hl-comment: #6b7285;
    --hl-title: #c9a2ff; --hl-attr: #e7c06b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1015; --surface: #161920; --code-bg: #12141a; --ink: #e7e9ef; --muted: #8e95a8;
  --line: #272b36; --accent: #8d99ff; --accent-ink: #0e1015; --accent-soft: #1e2350;
  --other: #4cc4b1; --other-soft: #12302b; --danger: #ff7b7b; --danger-soft: #3a1717;
  --gutter: #4b5161; --shadow: 0 1px 2px rgb(0 0 0 / .3);
  --hl-keyword: #8d99ff; --hl-string: #6fd3c2; --hl-number: #f0a36b; --hl-comment: #6b7285;
  --hl-title: #c9a2ff; --hl-attr: #e7c06b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 10; background: var(--surface);
}
[hidden] { display: none !important; }
a { color: var(--accent); }
code { font-family: var(--font-code); font-size: .9em; }

.wrap {
  width: 100%;
  max-width: 920px;
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.wrap.narrow { max-width: 560px; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.cards h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.cards .hint { margin-bottom: 6px; }
.foot { margin-top: 20px; max-width: 46em; }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.center { text-align: center; }

/* ---------- controls ---------- */
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.primary, .ghost, .danger, .btnlink {
  border-radius: 8px; padding: 8px 14px; font-weight: 600; font-size: 14px;
  border: 1px solid transparent; line-height: 1.2; white-space: nowrap;
}
.primary, .btnlink { background: var(--accent); color: var(--accent-ink); text-decoration: none; display: inline-block; }
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .5; cursor: default; }
.ghost { background: transparent; border-color: var(--line); }
.ghost:hover { background: var(--accent-soft); border-color: var(--accent-soft); }
.danger { background: var(--danger); color: var(--surface); }
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; font-weight: 600; }
.danger-text { background: none; border: 0; padding: 8px 10px; color: var(--danger); text-align: left; width: 100%; border-radius: 6px; font-weight: 500; }
.danger-text:hover { background: var(--danger-soft); }

input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
#join-id, #join-pass { font-family: var(--font-code); }

.pill {
  font-size: 13px; font-weight: 600; border-radius: 999px; padding: 4px 11px;
  border: 1px solid var(--line); background: var(--surface); white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pill.live { color: var(--other); border-color: transparent; background: var(--other-soft); }
.pill.live::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; margin-right: 6px; vertical-align: 1px;
}
.pill.expiry:hover { border-color: var(--accent); }
.pill.expiry.soon { color: var(--danger); border-color: var(--danger); }

/* ---------- start / join / gone ---------- */
.screen { padding-block: clamp(32px, 9vh, 96px) 48px; }
.brand { font-weight: 800; letter-spacing: -.01em; margin: 0 0 8px; font-size: 22px; }
.brand span { color: var(--muted); font-weight: 500; }
.brand.small { margin: 0; font-size: 16px; }
h1 { font-size: clamp(30px, 6vw, 44px); line-height: 1.05; letter-spacing: -.03em; margin: 0 0 14px; font-weight: 800; text-wrap: balance; }
.lede { color: var(--muted); font-size: 16px; margin: 0 0 24px; max-width: 34em; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.form { display: flex; flex-direction: column; gap: 6px; padding: 22px; }
.form label { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 8px; }
.form label:first-child { margin-top: 0; }
.form .primary { margin-top: 18px; padding: 12px; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 4px; }
.grid2 > div { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; margin: 10px 0 0; font-size: 14px; }
.facts { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 10px; color: var(--muted); font-size: 14px; }
.facts li { padding-left: 20px; position: relative; }
.facts li::before { content: ""; position: absolute; left: 2px; top: .62em; width: 8px; height: 2px; background: var(--accent); }

/* ---------- room ---------- */
.room { min-height: 100%; display: flex; flex-direction: column; }
.top {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 10px; padding-block: 10px; flex-wrap: wrap; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); width: 260px; z-index: 6;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 10px;
}
.menu-label { margin: 2px 4px 8px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.menu-opts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.menu-opts button { border: 1px solid var(--line); background: var(--bg); border-radius: 6px; padding: 6px 0; font-size: 13px; font-weight: 600; }
.menu-opts button:hover { border-color: var(--accent); }
.menu.invite { width: min(360px, calc(100vw - 32px)); }
.kv { display: grid; grid-template-columns: 82px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 13px; }
.kv span { color: var(--muted); font-weight: 600; }
.kv code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.kv button { border: 1px solid var(--accent-soft); background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 4px 9px; font-size: 12px; font-weight: 600; }
.menu.invite .hint { margin: 10px 4px 2px; font-size: 12px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0 6px; }

.feed { flex: 1; display: flex; flex-direction: column; gap: 14px; padding-block: 18px 24px; }
.empty { flex: 1; color: var(--muted); padding-block: 40px; text-align: center; }

.note {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  min-width: 0; overflow: hidden;
}
.note.fresh { animation: fresh 1.6s ease-out; }
@keyframes fresh { from { box-shadow: 0 0 0 3px var(--other); } to { box-shadow: 0 0 0 3px transparent; } }
.note-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.who { font-weight: 700; display: inline-flex; align-items: center; gap: 7px; }
.who::before { content: ""; width: 9px; height: 9px; border-radius: 3px; background: var(--other); }
.note.mine .who::before { background: var(--accent); }
.meta { color: var(--muted); font-variant-numeric: tabular-nums; }
.meta b { font-weight: 600; color: var(--ink); font-family: var(--font-code); font-size: 12px; }
.note-actions { display: flex; gap: 4px; margin-left: auto; }
.note-actions button { border: 1px solid transparent; background: none; border-radius: 6px; padding: 5px 9px; font-size: 13px; font-weight: 600; color: var(--muted); }
.note-actions button:hover { color: var(--ink); background: var(--bg); }
.note-actions .copy { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-soft); }
.note-actions .copy.done { color: var(--other); background: var(--other-soft); border-color: var(--other-soft); }
.note-actions .del:hover { color: var(--danger); background: var(--danger-soft); }

.code {
  display: flex; background: var(--code-bg); overflow: auto; max-height: 60vh;
  font: 13px/1.6 var(--font-code); tab-size: 4;
}
.note.expanded .code { max-height: none; }
.gutter {
  user-select: none; -webkit-user-select: none; text-align: right; color: var(--gutter);
  padding: 12px 10px 12px 14px; border-right: 1px solid var(--line); white-space: pre;
  position: sticky; left: 0; background: var(--code-bg); font-variant-numeric: tabular-nums;
}
.code pre { margin: 0; padding: 12px 16px; white-space: pre; flex: 1; min-width: 0; }
.code pre code { font: inherit; }
.note.wrap-lines .code pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.note.wrap-lines .gutter { display: none; }
.more {
  display: block; width: 100%; border: 0; border-top: 1px solid var(--line); background: var(--surface);
  padding: 7px; font-size: 13px; font-weight: 600; color: var(--muted);
}
.more:hover { color: var(--accent); }

.hljs-keyword, .hljs-built_in, .hljs-selector-tag, .hljs-literal, .hljs-type { color: var(--hl-keyword); font-weight: 600; }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-symbol { color: var(--hl-string); }
.hljs-number, .hljs-variable, .hljs-template-variable { color: var(--hl-number); }
.hljs-comment, .hljs-quote, .hljs-meta, .hljs-deletion { color: var(--hl-comment); font-style: italic; }
.hljs-title, .hljs-section, .hljs-name, .hljs-function { color: var(--hl-title); }
.hljs-attr, .hljs-attribute, .hljs-property, .hljs-params, .hljs-selector-class { color: var(--hl-attr); }

/* ---------- composer ---------- */
.composer {
  position: sticky; bottom: 0; z-index: 4; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.composer form { display: flex; flex-direction: column; gap: 8px; padding-block: 12px; }
#compose-text {
  font: 13px/1.55 var(--font-code); resize: none; max-height: 40vh; tab-size: 4; white-space: pre; overflow: auto;
}
.compose-row { display: flex; align-items: center; gap: 10px; }
.compose-row select { width: auto; padding: 7px 10px; font-size: 13px; }
.compose-row .as { font-size: 13px; color: var(--muted); }
.compose-row .name-in { width: 150px; padding: 7px 10px; font-size: 13px; }

/* ---------- overlays ---------- */
.confirm {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgb(10 12 20 / .45);
}
.confirm-box { padding: 20px; max-width: 380px; width: 100%; }
.confirm-box p { margin: 0 0 18px; font-weight: 500; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(120px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
}

.demo-bar { background: var(--accent-soft); color: var(--ink); font-size: 13px; }
.demo-bar .wrap { padding-block: 8px; }

@media (max-width: 720px) { .cards { grid-template-columns: 1fr; } }
@media (max-width: 560px) {
  .grid2 { grid-template-columns: 1fr; }
  #invite-btn { padding: 6px 10px; }
  .compose-row { flex-wrap: wrap; }
  .compose-row .name-in { width: 110px; }
  #compose-size { display: none; }
  .note-head { padding-left: 12px; }
  .meta .lines { display: none; }
}
@media (prefers-reduced-motion: reduce) { .note.fresh { animation: none; } }
