:root {
  color-scheme: light;
  --cork: #b07d51;
  --cork-speck: rgba(58, 34, 14, 0.26);
  --cork-light: rgba(255, 228, 190, 0.32);
  --desk: #201c18;
  --desk-2: #2c2722;
  --desk-ink: #ece2d0;
  --desk-dim: #a3958a;
  --brass: #d9b35f;
  --card: #fcf8f0;
  --card-yellow: #fbf0c4;
  --card-blue: #dfeaf6;
  --card-pink: #f9dcdf;
  --card-green: #dfeeda;
  --card-shadow: rgba(38, 22, 6, 0.4);
  --ink: #23201c;
  --ink-soft: #55504a;
  --ink-faint: #8b837a;
  --hair: rgba(35, 32, 28, 0.13);
  --pin: #c1372c;
  --pin-hi: #ee8b81;
  --accent: #b5342a;
  --focus: #3d7bdc;
  --backdrop: rgba(24, 15, 7, 0.6);
  --chip: rgba(35, 32, 28, 0.07);
  --tab-inactive: rgba(255, 255, 255, 0.1);
  --tab-ink: var(--desk-ink);
  --ok: #5f9c58;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --stamp: "Special Elite", "Courier New", monospace;
  --pad: clamp(14px, 3.5vw, 24px);
  --kb: 0px;
  --bar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --cork: #5a3f28;
    --cork-speck: rgba(0, 0, 0, 0.34);
    --cork-light: rgba(255, 206, 154, 0.13);
    --desk: #131110;
    --desk-2: #1d1a17;
    --card: #f2ece0;
    --card-yellow: #eee2b4;
    --card-blue: #d4e0ec;
    --card-pink: #eecdd1;
    --card-green: #d4e3ce;
    --card-shadow: rgba(0, 0, 0, 0.62);
    --backdrop: rgba(0, 0, 0, 0.72);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --cork: #5a3f28;
  --cork-speck: rgba(0, 0, 0, 0.34);
  --cork-light: rgba(255, 206, 154, 0.13);
  --desk: #131110;
  --desk-2: #1d1a17;
  --card: #f2ece0;
  --card-yellow: #eee2b4;
  --card-blue: #d4e0ec;
  --card-pink: #eecdd1;
  --card-green: #d4e3ce;
  --card-shadow: rgba(0, 0, 0, 0.62);
  --backdrop: rgba(0, 0, 0, 0.72);
}

/* The canvas background can be defeated by how a host frames us; an actual element cannot be.
   Fixed to the frame's viewport, behind every in-flow child, so no host ground can show. */
.ground {
  position: fixed; inset: -2px; z-index: -1; background: var(--cork); pointer-events: none;
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  background: var(--cork);          /* the canvas paints cork, never the host's ground */
  overflow-x: clip;                 /* clip, not hidden: hidden would force overflow-y:auto and
                                       make <body> its own scroll container, which breaks the
                                       embedding frame's height measurement */
}
html, body { margin: 0; padding: 0; }
body {
  background: var(--cork);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
  display: flex; flex-direction: column;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }

/* ---------- desk ---------- */
.desk {
  background: linear-gradient(180deg, var(--desk-2), var(--desk));
  color: var(--desk-ink);
  padding: 10px var(--pad) 0;
  padding-top: max(10px, env(safe-area-inset-top));
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.34);
  position: sticky; top: 0; z-index: 20;
}
.desk-row { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 9px; margin-right: auto; min-width: 0; flex: 0 1 auto; }
.brand h1 {
  font-family: var(--stamp); font-weight: 400; font-size: 19px; letter-spacing: 0.05em;
  margin: 0; color: var(--brass); white-space: nowrap;
  min-width: 0; overflow: hidden; text-overflow: ellipsis;  /* the wordmark yields space before the row wraps */
}
.brand small {
  color: var(--desk-dim); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  font-family: var(--display); font-weight: 600;
}
.search-wrap {
  display: flex; align-items: center; gap: 6px; flex: 1 1 190px; max-width: 340px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px; padding: 0 8px 0 10px; min-width: 0;
}
.search-wrap:focus-within { border-color: rgba(255, 255, 255, 0.34); }
.search-i { display: grid; place-items: center; color: var(--desk-dim); flex: none; }
.search-i svg { width: 16px; height: 16px; }
.search {
  background: transparent; border: 0; padding: 9px 0; color: var(--desk-ink);
  font-size: 16px; min-width: 0; flex: 1;
}
.search:focus { outline: none; }
.search::placeholder { color: var(--desk-dim); }
.search::-webkit-search-cancel-button { display: none; }
.deskicon {
  background: transparent; border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 8px;
  width: 40px; height: 40px; display: grid; place-items: center; color: var(--desk-ink); flex: none; padding: 0;
}
.deskicon:hover { border-color: var(--brass); color: var(--brass); }
.deskicon svg { width: 18px; height: 18px; }
.deskicon.in-search { border: 0; width: 30px; height: 30px; color: var(--desk-dim); }
.deskicon.in-search:hover { color: var(--desk-ink); }
.only-narrow { display: none; }
.btn.add .i { display: none; }
.btn.add { display: inline-flex; align-items: center; gap: 7px; }
.btn {
  background: transparent; border: 1px solid rgba(255, 255, 255, 0.24);
  color: var(--desk-ink); border-radius: 6px; padding: 8px 13px; min-height: 40px;
  font-family: var(--display); font-weight: 600; font-size: 13px; white-space: nowrap;
}
.btn:hover { border-color: var(--brass); color: var(--brass); }
.btn.primary { background: var(--brass); border-color: var(--brass); color: #221d18; }
.btn.primary:hover { filter: brightness(1.07); color: #221d18; }
.btn[hidden] { display: none; }
.status {
  font-family: var(--display); font-size: 11px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--desk-dim);
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 10px; min-height: 40px;
}
.status:hover { border-color: rgba(255, 255, 255, 0.2); color: var(--desk-ink); }
.s-clock {
  font-family: var(--sans); font-size: 11.5px; font-weight: 500; letter-spacing: 0;
  text-transform: none; color: var(--desk-dim); font-variant-numeric: tabular-nums;
}
.s-clock:empty { display: none; }
.status.stale .s-clock { color: var(--pin-hi); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--desk-dim); flex: none; }
.status.dirty::before { background: var(--brass); }
.status.saving::before { background: var(--brass); animation: blink 0.9s infinite; }
.status.saved::before { background: var(--ok); }
.status.error::before, .status.readonly::before { background: var(--pin); }
@keyframes blink { 50% { opacity: 0.25; } }

.desk-meta {
  display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 8px 14px;
  font-size: 14.5px; color: var(--ink); line-height: 1.45;
}
.desk-meta .k {
  font-family: var(--display); font-size: 10.5px; font-weight: 700; letter-spacing: 0.11em;
  text-transform: uppercase; color: var(--ink-faint);
}
.desk-meta .v { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; min-width: 0; }
.desk-meta b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.desk-meta .note { grid-column: 1 / -1; color: var(--ink-soft); font-size: 14px; }
.desk-meta .linkish {
  background: transparent; border: 0; padding: 6px 2px; color: var(--accent);
  font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; min-height: 40px;
}
.desk-meta .stale b { color: var(--accent); }
.board-sheet { width: min(520px, 100%); }
.board-sheet h2 { font-family: var(--display); font-weight: 700; font-size: 18px; margin: 0; flex: 1; }
.board-acts { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--hair); }
.board-acts .sbtn[hidden] { display: none; }

.tabs {
  display: flex; gap: 4px; margin-top: 8px; align-items: flex-end;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: var(--tab-inactive); color: var(--tab-ink); border: 0;
  border-radius: 8px 8px 0 0; padding: 10px 15px 9px; min-height: 42px;
  font-family: var(--display); font-weight: 600; font-size: 13.5px; letter-spacing: 0.01em;
  display: inline-flex; gap: 7px; align-items: center; white-space: nowrap; opacity: 0.72;
  transition: opacity 0.15s, background 0.15s;
}
.tab .n { font-size: 11px; font-weight: 700; opacity: 0.7; font-variant-numeric: tabular-nums; }
.tab:hover { opacity: 1; }
.tab[aria-selected="true"] { background: var(--card); color: var(--ink); opacity: 1; }
.view-toggle { margin-left: auto; display: flex; gap: 4px; padding: 0 0 6px 10px; }
.view-toggle button {
  background: transparent; border: 1px solid rgba(255, 255, 255, 0.2); color: var(--desk-dim);
  font-family: var(--display); font-weight: 600; font-size: 12px; padding: 6px 10px; border-radius: 5px;
  min-height: 34px; white-space: nowrap;
}
.view-toggle button[aria-pressed="true"] { color: var(--brass); border-color: var(--brass); }
.view-toggle .fs {
  display: grid; place-items: center; width: 34px; padding: 0; margin-left: 4px;
}
.view-toggle .fs svg { width: 15px; height: 15px; }
body.focus .desk { display: none; }
.fs-exit {
  position: fixed; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 28;
  display: none; place-items: center; width: 44px; height: 44px; padding: 0;
  border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(28, 22, 16, 0.82); color: var(--desk-ink);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); backdrop-filter: blur(6px);
}
.fs-exit svg { width: 19px; height: 19px; }
.fs-exit:hover { background: var(--desk); color: var(--brass); }
body.focus .fs-exit { display: grid; }
@media (max-width: 720px) { .view-toggle .fs { width: 40px; min-height: 40px; } }

/* ---------- board ---------- */
.board-wrap { flex: 1; position: relative; }
.board-wrap::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image:
    radial-gradient(circle at 20% 30%, var(--cork-speck) 0 1px, transparent 1.6px),
    radial-gradient(circle at 70% 60%, var(--cork-speck) 0 1.2px, transparent 2px),
    radial-gradient(circle at 45% 85%, var(--cork-light) 0 1px, transparent 1.8px),
    radial-gradient(circle at 85% 15%, var(--cork-speck) 0 0.8px, transparent 1.4px),
    radial-gradient(circle at 10% 75%, var(--cork-light) 0 1.2px, transparent 2px);
  background-size: 23px 19px, 37px 31px, 29px 41px, 17px 23px, 43px 27px;
}
.board-wrap::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 0%, transparent 45%, rgba(40, 20, 5, 0.22) 100%);
}
.board {
  position: relative; z-index: 1;
  padding: 26px var(--pad) calc(60px + env(safe-area-inset-bottom));
  display: grid; gap: 24px 18px;
  grid-template-columns: repeat(auto-fill, minmax(262px, 1fr));
  align-items: start;
}
.board.spread { display: block; column-width: 320px; column-gap: 18px; }
.board.spread .card { break-inside: avoid; margin-bottom: 22px; }
.board.spread .card-body { max-height: none; }
.board.spread .card-body::after { display: none; }
.intro {
  grid-column: 1 / -1; font-family: var(--display); font-weight: 600;
  color: var(--desk-ink); font-size: 13px; letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45); margin: -6px 0 0 2px;
}
.board.spread .intro { margin-bottom: 16px; }
.empty {
  grid-column: 1 / -1; color: var(--desk-ink); font-size: 14px;
  opacity: 0.9; padding: 30px 4px; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* ---------- index card ---------- */
.card {
  position: relative;
  background: var(--card);
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.22), 0 12px 20px -10px var(--card-shadow);
  padding: 26px 16px 15px;
  transform: rotate(var(--tilt, 0deg));
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  min-height: 150px;
  display: flex; flex-direction: column; gap: 7px;
  color: var(--ink);
  text-align: left; width: 100%; border: 0; font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.card[data-color="yellow"] { background: var(--card-yellow); }
.card[data-color="blue"] { background: var(--card-blue); }
.card[data-color="pink"] { background: var(--card-pink); }
.card[data-color="green"] { background: var(--card-green); }
.card:hover { transform: rotate(0deg) translateY(-3px); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.24), 0 20px 28px -12px var(--card-shadow); z-index: 2; }
.card:active { transform: rotate(0deg) scale(0.995); }
.card:focus-visible { transform: rotate(0deg); }
.card.dragging { opacity: 0.35; }
.card.drop-before::after, .card.drop-after::after {
  content: ""; position: absolute; top: 8px; bottom: 8px; width: 4px; background: var(--brass); border-radius: 2px;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25);
}
.card.drop-before::after { left: -11px; }
.card.drop-after::after { right: -11px; }
.pin {
  position: absolute; top: -8px; left: 50%; width: 15px; height: 15px; margin-left: -7.5px;
  border-radius: 50%; background: radial-gradient(circle at 35% 30%, var(--pin-hi), var(--pin) 58%, #75190f);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.42), 0 6px 6px -4px rgba(0, 0, 0, 0.5);
  z-index: 3;
}
.eyebrow {
  display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
  font-family: var(--display); font-weight: 700; font-size: 10px; letter-spacing: 0.13em;
  text-transform: uppercase; color: var(--accent);
}
.eyebrow .col-tag { color: var(--ink-faint); font-weight: 600; letter-spacing: 0.08em; }
.card h3 {
  font-family: var(--display); font-weight: 600; font-size: 16px; line-height: 1.25;
  margin: 0; text-wrap: balance; letter-spacing: -0.005em;
}
.card h3.untitled { color: var(--ink-faint); font-weight: 500; font-style: italic; }
.card-body {
  font-size: 14px; line-height: 1.5; color: var(--ink-soft);
  position: relative; max-height: 126px; overflow: hidden;
  display: flex; flex-direction: column; gap: 7px;
}
.card-body p { margin: 0; }
.card-body ul { margin: 0; padding-left: 17px; display: flex; flex-direction: column; gap: 5px; }
.card-body strong { color: var(--ink); font-weight: 600; }
.card-body.clipped::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 44px;
  background: linear-gradient(transparent, var(--card-bg, var(--card)));
  pointer-events: none;
}
.card[data-color="yellow"] { --card-bg: var(--card-yellow); }
.card[data-color="blue"] { --card-bg: var(--card-blue); }
.card[data-color="pink"] { --card-bg: var(--card-pink); }
.card[data-color="green"] { --card-bg: var(--card-green); }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: auto; padding-top: 3px; }
.chip {
  font-family: var(--display); font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; background: var(--chip); color: var(--ink-soft);
  padding: 3px 8px; border-radius: 10px;
}

/* ---------- merge notice ---------- */
.notice {
  position: relative; z-index: 3; margin: 18px var(--pad) -8px; padding: 13px 15px;
  background: var(--card-yellow); color: var(--ink); border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.22), 0 12px 20px -12px var(--card-shadow);
  border-left: 4px solid var(--brass);
  display: flex; flex-direction: column; gap: 10px;
}
.notice[hidden] { display: none; }
.notice.conflict { border-left-color: var(--pin); background: var(--card-pink); }
.notice-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.notice-head h2 { font-family: var(--display); font-weight: 700; font-size: 14.5px; margin: 0; }
.notice-head p { margin: 0; font-size: 13px; color: var(--ink-soft); flex: 1; min-width: 180px; }
.notice-x {
  background: transparent; border: 0; color: var(--ink-faint); font-size: 15px; line-height: 1;
  padding: 8px; min-height: 36px; min-width: 36px;
}
.notice-x:hover { color: var(--ink); }
.notice ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.notice li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; padding-top: 8px; border-top: 1px solid var(--hair); }
.notice li:first-child { border-top: 0; padding-top: 0; }
.notice .who { font-family: var(--display); font-weight: 600; font-size: 13.5px; margin-right: auto; }
.notice .mini {
  border: 1px solid rgba(35, 32, 28, 0.28); background: rgba(255, 255, 255, 0.55); border-radius: 6px;
  padding: 7px 12px; min-height: 38px; font-family: var(--display); font-size: 12.5px; font-weight: 600;
}
.notice .mini:hover { border-color: var(--ink); }
.notice .mini.keep { background: var(--ink); color: var(--card); border-color: var(--ink); }
.notice .diff { flex-basis: 100%; display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.notice .diff[hidden] { display: none; }
.notice .diff section { background: rgba(255, 255, 255, 0.5); border-radius: 4px; padding: 9px 11px; min-width: 0; }
.notice .diff h3 {
  margin: 0 0 5px; font-family: var(--display); font-size: 10px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint);
}
.notice .diff pre {
  margin: 0; font-family: var(--sans); font-size: 13px; line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 190px; overflow: auto;
}

/* ---------- sheet (card detail + history) ---------- */
.backdrop {
  position: fixed; inset: 0; background: var(--backdrop); z-index: 30;
  display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.backdrop.open { display: flex; }
.sheet {
  width: min(720px, 100%); background: var(--card); color: var(--ink); border-radius: 8px;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.7); position: relative;
  padding: 22px 26px 16px; display: flex; flex-direction: column; gap: 12px;
}
.sheet[data-color="yellow"] { background: var(--card-yellow); }
.sheet[data-color="blue"] { background: var(--card-blue); }
.sheet[data-color="pink"] { background: var(--card-pink); }
.sheet[data-color="green"] { background: var(--card-green); }
.sheet .pin { top: -7px; }

.sheet-top { display: flex; align-items: center; gap: 10px; }
.sheet-top .eyebrow { flex: 1; min-width: 0; }
.icon-btn {
  background: transparent; border: 1px solid transparent; border-radius: 50%;
  width: 38px; height: 38px; display: grid; place-items: center; color: var(--ink-faint); flex: none;
}
.icon-btn:hover { color: var(--ink); border-color: var(--hair); background: rgba(255, 255, 255, 0.45); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn[aria-pressed="true"] { color: var(--ink); background: rgba(35, 32, 28, 0.1); border-color: var(--hair); }
.icon-btn.big { width: 46px; height: 46px; color: var(--ink-soft); }
.icon-btn.big svg { width: 21px; height: 21px; }
.icon-btn.big:hover { color: var(--ink); background: rgba(255, 255, 255, 0.55); border-color: var(--hair); }
.icon-btn.big.primary { background: var(--ink); border-color: var(--ink); color: var(--card); }
.icon-btn.big.primary:hover { background: var(--ink); color: var(--card); filter: brightness(1.25); }

.pane-read, .pane-edit { display: flex; flex-direction: column; gap: 12px; }
.sheet[data-mode="read"] .pane-edit, .sheet[data-mode="edit"] .pane-read { display: none; }
.pane-read { cursor: text; }
.read-title { font-family: var(--display); font-weight: 700; font-size: 22px; line-height: 1.2; margin: 0; text-wrap: balance; }
.read-title.untitled { color: var(--ink-faint); font-weight: 500; font-style: italic; }
.read-body { font-size: 16px; line-height: 1.62; color: var(--ink); display: flex; flex-direction: column; gap: 12px; max-width: 62ch; }
.read-body p { margin: 0; }
.read-body ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.read-body strong { font-weight: 600; }
.read-body .none { color: var(--ink-faint); font-style: italic; }
.read-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.read-tags:empty { display: none; }

.title-in {
  width: 100%; border: 0; border-bottom: 1px dashed var(--hair); background: transparent;
  padding: 0 0 6px; margin: 0; font-family: var(--display); font-weight: 700; font-size: 22px; line-height: 1.2;
}
.title-in:focus { outline: none; border-bottom-color: var(--ink-faint); }
.body-in {
  width: 100%; border: 0; background: transparent; resize: none; padding: 0; margin: 0;
  font-family: var(--sans); font-size: 16px; line-height: 1.62; color: var(--ink);
  min-height: 40dvh;
}
.body-in:focus { outline: none; }

.opts {
  display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: center;
  padding: 14px 0 2px; border-top: 1px solid var(--hair);
}
.opts[hidden] { display: none; }
.opts label {
  font-family: var(--display); font-size: 10.5px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-faint); display: flex; align-items: center; gap: 9px;
}
.opts select, .opts input[type="text"] {
  background: rgba(255, 255, 255, 0.6); border: 1px solid rgba(35, 32, 28, 0.22); border-radius: 6px;
  padding: 9px 10px; min-height: 42px; font-family: var(--sans); font-weight: 400; letter-spacing: 0;
  text-transform: none; font-size: 16px; color: var(--ink);
}
.opts input[type="text"] { min-width: 190px; flex: 1; }
.opts .row-wide { flex-basis: 100%; display: flex; gap: 10px; align-items: center; }
.posrow { display: flex; align-items: center; gap: 6px; }
.nudge {
  border: 1px solid rgba(35, 32, 28, 0.22); background: rgba(255, 255, 255, 0.6); border-radius: 6px;
  width: 42px; height: 42px; display: grid; place-items: center; color: var(--ink); padding: 0;
}
.nudge svg { width: 17px; height: 17px; }
.nudge:hover:not(:disabled) { border-color: var(--ink); }
.nudge:disabled { opacity: 0.35; cursor: default; }
.swatches { display: flex; gap: 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(35, 32, 28, 0.22); padding: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
}
.swatch[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--card), 0 0 0 3px var(--ink); }
.swatch[data-c="cream"] { background: #fcf8f0; }
.swatch[data-c="yellow"] { background: #fbf0c4; }
.swatch[data-c="blue"] { background: #dfeaf6; }
.swatch[data-c="pink"] { background: #f9dcdf; }
.swatch[data-c="green"] { background: #dfeeda; }

.sheet-actions, .sheet-bar { display: flex; gap: 8px; align-items: center; padding-top: 12px; border-top: 1px solid var(--hair); }
.sheet-actions .spacer, .sheet-bar .spacer { flex: 1; }
.sbtn {
  border: 1px solid rgba(35, 32, 28, 0.26); background: rgba(255, 255, 255, 0.5); border-radius: 6px;
  padding: 9px 14px; min-height: 42px; font-family: var(--display); font-weight: 600; font-size: 13.5px; color: var(--ink);
}
.sbtn:hover { border-color: var(--ink); }
.sbtn.danger { color: var(--accent); border-color: rgba(181, 52, 42, 0.45); }
.sbtn.danger:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.sbtn.done { background: var(--ink); color: var(--card); border-color: var(--ink); }
.hint { font-size: 12.5px; color: var(--ink-faint); }

/* ---------- history ---------- */
.hist { width: min(620px, 100%); }
.hist h2 { font-family: var(--display); font-weight: 700; font-size: 19px; margin: 0; }
.hist > p { margin: -4px 0 6px; font-size: 13.5px; color: var(--ink-soft); }
.hist ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.hist li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 11px 0; border-top: 1px solid var(--hair); }
.hist li:first-child { border-top: 0; }
.hist .when { font-size: 14px; font-variant-numeric: tabular-nums; margin-right: auto; }
.hist .now { font-family: var(--display); font-size: 10.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.hist .empty-h { font-size: 13.5px; color: var(--ink-soft); padding: 10px 0; }
.hist .peek { flex-basis: 100%; margin: 4px 0 2px; background: rgba(255, 255, 255, 0.55); border-radius: 6px; padding: 11px 13px; }
.hist .peek[hidden] { display: none; }
.hist .peek pre {
  margin: 0; font-family: var(--sans); font-size: 13px; line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 240px; overflow: auto;
}

/* ---------- read-through ---------- */
.board.read { display: block; padding: 0; }
.readprog {
  position: sticky; top: var(--hdr, 104px); z-index: 6; height: 2px;
  background: rgba(255, 255, 255, 0.12);
}
.readprog i { display: block; height: 100%; width: 0; background: var(--brass); transition: width 0.1s linear; }
.read-wrap {
  display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 0 26px;
  max-width: 1080px; margin: 0 auto; padding: 22px var(--pad) 90px;
  align-items: start;
}
.rail {
  position: sticky; top: calc(var(--hdr, 104px) + 20px); align-self: start;
  max-height: calc(100dvh - var(--hdr, 104px) - 48px); overflow-y: auto;
  scrollbar-width: thin; display: flex; flex-direction: column; gap: 1px;
  background: rgba(22, 15, 9, 0.46); border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px; padding: 8px 5px;
}
.rail-h { display: none; }
.rail button {
  display: grid; gap: 4px; justify-items: center; width: 100%;
  background: transparent; border: 0; border-radius: 7px;
  padding: 7px 4px; color: var(--desk-ink); opacity: 0.72; transition: opacity 0.15s, background 0.15s;
}
.rail button:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }
.rail button[aria-current="true"] { opacity: 1; background: rgba(255, 255, 255, 0.14); }
.rail button[aria-current="true"] .num { color: var(--brass); }
.rail .num {
  font-family: var(--display); font-weight: 700; font-size: 13px; color: var(--desk-ink);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.rail .bar { width: 100%; height: 2px; border-radius: 1px; background: rgba(255, 255, 255, 0.1); }
.rail .bar i { display: block; height: 100%; border-radius: 1px; background: var(--brass); opacity: 0.4; }
.rail button[aria-current="true"] .bar i { opacity: 0.95; }

.railtip {
  position: fixed; z-index: 25; pointer-events: none;
  background: var(--desk); color: var(--desk-ink); border-left: 3px solid var(--brass);
  padding: 8px 11px; border-radius: 6px; font-size: 13px; line-height: 1.35;
  max-width: min(280px, 70vw); box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5);
}
.railtip[hidden] { display: none; }
.railtip .tn {
  font-family: var(--display); font-size: 10px; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--brass); display: block; margin-bottom: 2px;
}

.stream {
  background: var(--card); color: var(--ink); border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2), 0 22px 40px -22px var(--card-shadow);
  padding: 0 clamp(20px, 4vw, 44px) 40px;
}
.stream-head {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 26px 0 18px; border-bottom: 2px solid var(--ink);
}
.stream-head h2 { font-family: var(--display); font-weight: 700; font-size: 20px; margin: 0; }
.stream-head .meta {
  font-family: var(--display); font-size: 10.5px; font-weight: 700; letter-spacing: 0.11em;
  text-transform: uppercase; color: var(--ink-faint); margin-left: auto;
}
.stream-intro { padding: 14px 0 0; color: var(--ink-soft); font-size: 14.5px; }
.scene { scroll-margin-top: calc(var(--hdr, 104px) + 12px); }
.scene-h {
  position: sticky; top: var(--hdr, 104px); z-index: 2; background: var(--card);
  display: flex; align-items: baseline; gap: 12px;
  padding: 18px 0 10px; margin-bottom: 6px; border-bottom: 1px solid var(--hair);
}
.scene-h::after {
  content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 14px; pointer-events: none;
  background: linear-gradient(var(--card), transparent);
}
.scene-h .n {
  font-family: var(--display); font-weight: 700; font-size: 10.5px; letter-spacing: 0.13em;
  text-transform: uppercase; color: var(--accent); flex: none; padding-top: 3px;
}
.scene-h h3 {
  font-family: var(--display); font-weight: 700; font-size: 19px; line-height: 1.25; margin: 0;
  flex: 1; min-width: 0; text-wrap: balance;
}
.scene-h h3.untitled { color: var(--ink-faint); font-weight: 500; font-style: italic; }
.scene-h .edit {
  background: transparent; border: 1px solid transparent; border-radius: 50%;
  width: 36px; height: 36px; display: grid; place-items: center; color: var(--ink-faint); flex: none;
  opacity: 0; transition: opacity 0.15s;
}
.scene-h .edit svg { width: 16px; height: 16px; }
.scene:hover .edit, .scene-h .edit:focus-visible { opacity: 1; }
.scene-h .edit:hover { color: var(--ink); background: rgba(35, 32, 28, 0.07); border-color: var(--hair); }
.scene-body {
  font-size: 16.5px; line-height: 1.68; max-width: 64ch;
  display: flex; flex-direction: column; gap: 14px; padding: 6px 0 30px;
}
.scene-body p { margin: 0; }
.scene-body ul { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 9px; }
.scene-body strong { font-weight: 600; }
.scene-body .none { color: var(--ink-faint); font-style: italic; }
.scene-tags { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 26px; margin-top: -18px; }
.scene + .scene .scene-h { border-top: 0; }
.scene:not(:last-child)::after {
  content: ""; display: block; height: 1px; background: var(--hair); margin: 0 0 2px;
}
@media (hover: none) { .scene-h .edit { opacity: 0.55; } }

@media (max-width: 900px) {
  .read-wrap { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 0 0 70px; max-width: none; }
  .rail {
    position: sticky; top: var(--hdr, 102px); z-index: 5; flex-direction: row; gap: 5px;
    background: var(--desk); border: 0; border-radius: 0;
    max-height: none; overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
    padding: 8px var(--pad); background: var(--desk); box-shadow: 0 6px 14px -8px rgba(0, 0, 0, 0.6);
  }
  .rail::-webkit-scrollbar { display: none; }
  .rail-h { display: none; }
  .view-toggle {
    position: sticky; right: 0; margin-left: auto; background: var(--desk);
    padding-left: 10px; box-shadow: -10px 0 12px -6px var(--desk);
  }
  .rail button {
    width: auto; flex: none; gap: 0; min-width: 40px; min-height: 40px;
    justify-items: center; align-content: center; border: 1px solid rgba(255, 255, 255, 0.16);
  }
  .rail .bar { display: none; }
  .rail .num { font-size: 13px; }
  .readprog { top: calc(var(--hdr, 102px) + 56px); }
  .stream { border-radius: 0; padding: 0 var(--pad) 30px; box-shadow: none; }
  .scene-h { top: calc(var(--hdr, 102px) + 56px); padding: 16px 0 9px; }
  .scene { scroll-margin-top: calc(var(--hdr, 102px) + 70px); }
  .scene-h h3 { font-size: 17.5px; }
  .scene-body { font-size: 16px; line-height: 1.62; padding-bottom: 24px; }
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  background: var(--desk); color: var(--desk-ink); padding: 11px 15px; border-radius: 7px;
  font-size: 13.5px; max-width: min(440px, calc(100vw - 32px));
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); z-index: 40; opacity: 0;
  transition: opacity 0.2s; pointer-events: none; border-left: 3px solid var(--brass);
}
.toast.show { opacity: 1; }

/* ---------- phone ---------- */
@media (max-width: 900px) {
  /* with wrap on, flexbox breaks the line instead of shrinking — so let the wordmark yield instead */
  .desk-row { flex-wrap: nowrap; }
  .desk.searching .desk-row { flex-wrap: wrap; }
  .search-wrap { display: none; }
  .desk.searching .search-wrap { display: flex; flex-basis: 100%; max-width: none; order: 9; margin-top: 2px; }
  .desk.searching .brand { display: none; }
  .only-narrow { display: grid; }
}
@media (max-width: 620px) {
  .btn.add .lbl { display: none; }
  .btn.add .i { display: grid; place-items: center; }
  .btn.add {
    display: grid; place-items: center; gap: 0;
    width: 40px; height: 40px; padding: 0; border-radius: 8px; line-height: 0;
  }
  .btn.add svg { width: 19px; height: 19px; display: block; }
  .status { padding: 8px 6px; gap: 6px; min-width: 0; }
  .status .s-word { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .status.saved .s-word { display: none; }   /* green dot + freshness clock is enough */
  .status:not(.saved) .s-clock { display: none; }
  .status .s-clock { font-size: 12px; }
}
@media (max-width: 380px) {
  .desk-row { gap: 6px; }
  .brand h1 { font-size: 15px; }
  .deskicon, .btn.add { width: 38px; height: 38px; }
  .deskicon svg { width: 17px; height: 17px; }
  .status { padding: 6px 3px; gap: 5px; }
}
@media (max-width: 720px) {
  .brand small { display: none; }
  .brand h1 { font-size: 17px; }
  .desk { padding-top: max(8px, env(safe-area-inset-top)); }
  .desk-row { gap: 8px; }
  .view-toggle button { min-height: 40px; }
  .tab { padding: 9px 13px; font-size: 13px; min-height: 40px; }
  .tools { gap: 6px; }
  .search { order: 3; flex-basis: 100%; min-width: 0; }
  .btn { padding: 8px 11px; font-size: 12.5px; }
  .desk-meta { font-size: 11px; margin-top: 6px; }
  .board { gap: 20px 0; grid-template-columns: 1fr; padding-top: 20px; }
  .card { padding: 24px 16px 14px; min-height: 0; transform: none; }
  .card:hover { transform: none; }
  .card-body { max-height: 108px; font-size: 14.5px; }
  .view-toggle { padding-left: 6px; }

  .backdrop { padding: 0; align-items: stretch; }
  #sheet {
    width: 100%; border-radius: 0; min-height: 100dvh; padding: 12px 18px 0;
    padding-top: max(12px, env(safe-area-inset-top));
    gap: 10px;
  }
  #board-backdrop, #hist-backdrop { align-items: flex-end; }
  #board-sheet, #hist {
    width: 100%; border-radius: 16px 16px 0 0; max-height: 88dvh; overflow-y: auto;
    padding: 16px 18px max(16px, env(safe-area-inset-bottom));
  }
  .sheet .pin { display: none; }
  .read-title, .title-in { font-size: 20px; }
  .body-in { min-height: 34dvh; }
  .sheet-actions, .sheet-bar {
    position: sticky; bottom: var(--kb, 0px); margin-top: auto; z-index: 6;
    padding: 11px 0 max(11px, env(safe-area-inset-bottom));
    background: inherit;
  }
  /* options come up as a drawer by the thumb, not buried under a long card */
  .opts {
    position: fixed; left: 0; right: 0; bottom: calc(var(--kb, 0px) + var(--bar-h)); z-index: 7;
    gap: 12px 14px; border-radius: 14px 14px 0 0; border-top: 1px solid var(--hair);
    padding: 14px 18px 16px; box-shadow: 0 -16px 34px -20px rgba(0, 0, 0, 0.6);
    max-height: 62dvh; overflow-y: auto;
  }
  .opts label { width: 100%; }
  .opts select, .opts input[type="text"] { flex: 1; }
  .opts .row-wide { justify-content: space-between; }
  .notice { margin: 14px var(--pad) -6px; }
  .notice .diff { grid-template-columns: 1fr; }
  .notice .mini { flex: 1; min-width: 96px; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .tab { transition: none; }
  .status.saving::before { animation: none; }
}
