/* Twain: a two-pane text comparison tool.

   Direction C: a small Mac comparison utility. Two sheets of paper with rounded corners
   and title-bar headers sit on a warm grey window; the 48px channel between them is only
   the gap. Each change is ONE soft shape: a rounded block in the left text, a filled
   curve across the channel, a rounded block in the right text. Blue for replaced lines,
   green for lines on one side only (Meld's pairing: deletions are green too, the status
   bar tells added from removed). The one other colour is a caramel accent on toggles
   that are switched on.

   How the shape is built: the blocks are DOM (pane.js: band rows behind the text and
   the line-number rows), the bridges are one canvas in the channel (linkmap.js,
   drawRibbons). They meet at the sheet's inner edge, so the block fills run flush to
   that edge and the bridge starts there. Both are painted from the same opaque hex
   tokens below, both snap to device pixels, and the lines that cross the join (the
   current change's outline, a one-sided change's landing line) take their weights from
   the same whole-pixel tokens, so the join has no seam and nothing is painted twice.

   Every colour, size and timing lives in a token below. Canvas code reads the change
   tokens, so those stay plain hex (converted from the approved mockup's OKLCH). */

:root {
  color-scheme: light;

  /* Window and sheets */
  --win: #edeae6;
  --sheet: #fffefc;
  --sheet-ring: rgb(50 45 41 / 0.11);
  --sheet-shadow: 0 1px 1px rgb(50 45 41 / 0.04), 0 2px 6px rgb(50 45 41 / 0.05), 0 12px 32px -12px rgb(50 45 41 / 0.1);
  --hair: rgb(50 45 41 / 0.08);
  --ink: #25211d;
  --ink-2: #665f5a;
  --ink-3: #918b86;
  --focus: #25211d;             /* focus rings stay neutral */
  --selection: rgb(244 190 64 / 0.36);
  --thumb: rgb(50 45 41 / 0.28); /* textarea scrollbars: thumb only, the track is clear */

  /* Controls */
  --track: rgb(50 45 41 / 0.065);
  --track-sep: rgb(50 45 41 / 0.12);
  --track-hover: rgb(50 45 41 / 0.06);
  --track-press: rgb(50 45 41 / 0.12);
  --on: #ffffff;
  --on-shadow: 0 0 0 0.5px rgb(50 45 41 / 0.16), 0 1px 2px rgb(50 45 41 / 0.12);
  --accent: #b96025;            /* caramel: only on toggles that are on, and the logo's bridge */
  --btn: #ffffff;
  --btn-hover: #f8f6f3;
  --btn-press: #efece8;
  --btn-shadow: 0 0 0 0.5px rgb(50 45 41 / 0.2), 0 1px 1.5px rgb(50 45 41 / 0.1);

  /* Replaced lines */
  --rep-fill: #daecff;
  --rep-fill-cur: #bee0ff;
  --rep-word: #acd5ff;
  --rep-word-cur: #8fc6ff;
  --rep-edge: #3674c5;
  --rep-ink: #21539c;
  /* Lines on one side only (inserted or deleted) */
  --one-fill: #d8f3d5;
  --one-fill-cur: #bfeaba;
  --one-edge: #4e9a52;
  --one-ink: #26652b;
  --land-alpha: 0.6;            /* the landing line on the empty side, when not current */

  /* Weights shared with the canvas (linkmap.js reads them). Whole CSS pixels on purpose:
     browsers snap fractional borders and boxes in different ways (Chrome draws a 1.5px
     border as 1px), and the canvas half of a line must match the DOM half exactly.
     --ow: the current change's outline. --land-w: the landing line on a one-sided change's
     empty side (= the bridge's thin end), centred on the line boundary (--land-a above it). */
  --ow: 1px;
  --land-w: 2px;
  --land-a: 1px;

  /* Tooltip, message bar */
  --tip-bg: #fefdfc;
  --tip-shadow: 0 0 0 0.5px rgb(50 45 41 / 0.18), 0 4px 14px rgb(50 45 41 / 0.16);
  --info-bg: #fff0cc;
  --info-edge: #edc889;
  --info-icon: #b77610;

  /* Type. System faces only: no downloads. */
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", "Helvetica Neue", Cantarell, Ubuntu, Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, "Cascadia Mono", Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --ui-size: 13px;
  --small-size: 12px;
  --mono-size: 13px;
  --lh: 24px;                   /* editor line height: an integer, used by JS for every line position */
  --gutter-size: 11.5px;
  --weight-medium: 500;
  --weight-semibold: 600;

  /* Space and shape */
  --frame: 10px;                /* window margin around the sheets */
  --channel: 48px;              /* the gap between the sheets, where the bridges run */
  --tb-h: 52px;
  --head-h: 44px;
  --status-h: 30px;
  --map-w: 18px;                /* change map along each sheet's outer edge */
  --sheet-r: 10px;
  --block-r: 7px;               /* outer corners of a change block */
  --seg-h: 28px;
  --seg-btn-h: 24px;
  --merge-size: 22px;           /* = BTN in linkmap.js */
  --ed-pad-y: 10px;
  --ed-pad-l: 6px;              /* gutter padding-right + this = the 12px between numbers and text */
  --ed-pad-r: 14px;

  /* Stacking */
  --z-seal: 1;
  --z-buttons: 2;
  --z-drop: 3;
  --z-tip: 10;

  /* Motion hooks (kept minimal on purpose) */
  --dur-fast: 120ms;
  --dur-med: 200ms;
  --dur-slow: 320ms;
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-in: cubic-bezier(0.5, 0, 0.75, 0);
  /* Motion pass. Opacity fades carry meaning, not movement, so they keep running under
     reduced motion and get their own durations that the reduce block below leaves alone.
     The merge timings are mirrored in app.js (FLASH_MS, DISSOLVE_MS) and linkmap.js. */
  --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
  --ease-in-out-sine: cubic-bezier(0.37, 0, 0.63, 1);
  --fade-in: 120ms;
  --fade-out: 90ms;
  --merge-land: 220ms;       /* merged lines sweep in from the channel side */
  --merge-settle: 900ms;     /* ...then hold and fade: FLASH_MS */
  --merge-dissolve: 360ms;   /* source block, bridge ghost and its arrows fade together: DISSOLVE_MS */
  /* Hover and press. Colour feedback uses --fade-in, which reduced motion keeps; the press
     scale uses --dur-fast, which reduced motion zeroes (and the scale itself is removed). */
  --ease-hover: ease;
  --press-scale: 0.96;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --win: #171614;
    --sheet: #22201e;
    --sheet-ring: rgb(255 255 255 / 0.07);
    --sheet-shadow: 0 0 0 0 transparent;
    --hair: rgb(255 255 255 / 0.07);
    --ink: #eae7e3;
    --ink-2: #aba7a2;
    --ink-3: #77746f;
    --focus: #eae7e3;
    --selection: rgb(244 190 64 / 0.26);
    --thumb: rgb(255 255 255 / 0.24);

    --track: rgb(255 255 255 / 0.07);
    --track-sep: rgb(255 255 255 / 0.1);
    --track-hover: rgb(255 255 255 / 0.05);
    --track-press: rgb(255 255 255 / 0.1);
    --on: #4f4d4a;
    --on-shadow: 0 0 0 0.5px rgb(255 255 255 / 0.08) inset, 0 1px 2px rgb(0 0 0 / 0.3);
    --accent: #efa464;
    --btn: #3a3735;
    --btn-hover: #423f3c;
    --btn-press: #4a4744;
    --btn-shadow: 0 0 0 0.5px rgb(255 255 255 / 0.08) inset, 0 1px 1.5px rgb(0 0 0 / 0.3);

    --rep-fill: #23364f;
    --rep-fill-cur: #25466f;
    --rep-word: #285388;
    --rep-word-cur: #2e64a6;
    --rep-edge: #6fa7ee;
    --rep-ink: #a8ceff;
    --one-fill: #243c25;
    --one-fill-cur: #265029;
    --one-edge: #67b36a;
    --one-ink: #a5e0a5;
    --land-alpha: 0.6;

    --tip-bg: #353230;
    --tip-shadow: 0 0 0 0.5px rgb(255 255 255 / 0.1) inset, 0 6px 18px rgb(0 0 0 / 0.45);
    --info-bg: #362913;
    --info-edge: #6a5124;
    --info-icon: #e6b55d;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur-med: 0ms; --dur-slow: 0ms; }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--win);
  color: var(--ink);
  font: var(--ui-size)/1.3 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: default; }
p { margin: 0; }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Every icon is a stroke drawing; the sprite's paths inherit these. */
.icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

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

::selection { background: var(--selection); }

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

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  isolation: isolate;
}

/* ---------- Toolbar ----------
   Three columns with equal outer tracks, so the Copy capsule sits exactly over the
   channel between the sheets. Each side hugs the centre: navigation on the left, view
   and comparison toggles on the right, the two whole-document actions pushed to the far
   end. When the split moves, that middle band (navigation, Copy, toggles) travels with
   the channel as one piece, as far as the wordmark and Swap/Clear let it (app.js). */

.titlebar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  min-height: var(--tb-h);
  padding: 0 14px 0 18px;
}

.tb-start, .tb-end {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.tb-start { padding-right: 14px; }
.tb-end { padding-left: 14px; }
.tb-spacer { flex: 1; }
.tb-nav, .tb-opts { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  font-size: 13.5px;
  font-weight: var(--weight-semibold);
  letter-spacing: -0.005em;
  user-select: none;
}
.brand-mark { width: 20px; height: 20px; flex-shrink: 0; }
.mark-sheet { fill: var(--sheet); stroke: var(--ink-2); stroke-width: 1.3; }
.mark-bridge { fill: var(--accent); }

/* Segmented capsule: a recessed track holding flat segments split by short hairlines. */
.seg {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  height: var(--seg-h);
  padding: 2px;
  gap: 1px;
  border-radius: 8px;
  background: var(--track);
}

.seg-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--seg-btn-h);
  margin: 0;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  white-space: nowrap;
  user-select: none;
  transition:
    background-color var(--fade-in) var(--ease-hover),
    box-shadow var(--fade-in) var(--ease-hover),
    scale var(--dur-fast) var(--ease-out);
}
.seg-btn.icon-only { width: 30px; padding: 0; }
.seg-btn.lead { padding-left: 8px; }
.seg-btn.trail { padding-right: 8px; }
.seg-btn .icon { color: var(--ink-2); transition: color var(--fade-in) var(--ease-hover); }

.seg-btn + .seg-btn::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--track-sep);
  pointer-events: none;
}

@media (hover: hover) {
  .seg-btn:hover:not(:disabled) { background: var(--track-hover); }
  .seg-btn:hover:not(:disabled) .icon { color: var(--ink); }
}
.seg-btn:active:not(:disabled) { background: var(--track-press); scale: var(--press-scale); }
.seg-btn:disabled { color: var(--ink-3); }
.seg-btn:disabled .icon { color: var(--ink-3); opacity: 0.7; }

/* A switched-on toggle: a raised segment, and the one caramel accent on its icon. */
.seg-input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.seg-btn:has(.seg-input:checked) { background: var(--on); box-shadow: var(--on-shadow); }
.seg-btn:has(.seg-input:checked) .icon { color: var(--accent); }
.seg-btn:has(.seg-input:checked)::before,
.seg-btn:has(.seg-input:checked) + .seg-btn::before { opacity: 0; }
.seg-btn:has(.seg-input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }

@media (forced-colors: active) {
  .seg-input { position: static; opacity: 1; width: auto; height: auto; pointer-events: auto; }
}

.counter {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  user-select: none;
}
.counter b { color: var(--ink); font-weight: var(--weight-semibold); }

.caption { margin-right: -4px; color: var(--ink-2); font-size: var(--small-size); white-space: nowrap; user-select: none; }

/* ---------- Sheets ----------
   The split is two flex factors that app.js writes on .compare (--split-l, --split-r):
   whole pixels of the shared width, so every sheet edge, and so every block-to-bridge
   join, lands on a whole pixel. Registered as non-inheriting so a drag restyles
   .compare alone. The stacked phone layout below sets its own columns. */

@property --split-l { syntax: "*"; inherits: false; }
@property --split-r { syntax: "*"; inherits: false; }

.compare {
  display: grid;
  grid-template-columns: minmax(0, var(--split-l, 1fr)) var(--channel) minmax(0, var(--split-r, 1fr));
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
  padding: 0 var(--frame);
}

.pane {
  position: relative;
  display: grid;
  grid-row: 1 / span 3;
  grid-template-rows: subgrid;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--sheet-r);
  background: var(--sheet);
  box-shadow: 0 0 0 1px var(--sheet-ring), var(--sheet-shadow);
}

/* Title-bar style header: side, then the document centred on the sheet, then Open… */
.pane-head {
  grid-row: 1;
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) minmax(0, max-content) minmax(max-content, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: var(--head-h);
  padding: 0 10px 0 16px;
  border-bottom: 1px solid var(--hair);
  container: pane-head / inline-size;
}

.pane-side { color: var(--ink-3); font-size: var(--small-size); white-space: nowrap; user-select: none; transition: color var(--fade-in) var(--ease-hover); }
/* The sheet you are typing in names itself in ink. */
.pane:has(.editor textarea:focus) .pane-side { color: var(--ink); }

.pane-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  white-space: nowrap;
}

.pane-icon { width: 15px; height: 15px; color: var(--ink-3); stroke-width: 1.6; }

.pane-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--weight-semibold);
  color: var(--ink);
}

.pane[data-named="false"] .pane-name { color: var(--ink-2); font-weight: var(--weight-medium); }

/* Edited since it was opened: a small ink dot before the file name */
.pane-name .dirty {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 6px 0 0;
  vertical-align: 0.12em;
  border-radius: 50%;
  background: var(--ink-2);
}

.pane-meta {
  flex-shrink: 0;
  margin-left: 2px;
  color: var(--ink-3);
  font-size: var(--small-size);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Open… : a small raised push button */
.button {
  position: relative;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  height: 24px;
  padding: 0 10px 0 8px;
  border: 0;
  border-radius: 6px;
  background: var(--btn);
  box-shadow: var(--btn-shadow);
  color: var(--ink);
  font-size: 12.5px;
  white-space: nowrap;
  transition:
    background-color var(--fade-in) var(--ease-hover),
    scale var(--dur-fast) var(--ease-out);
}
.button .icon { width: 14px; height: 14px; color: var(--ink-2); }

@media (hover: hover) {
  .button:hover { background: var(--btn-hover); }
}
.button:active { background: var(--btn-press); scale: var(--press-scale); }

.icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-2);
  transition:
    background-color var(--fade-in) var(--ease-hover),
    color var(--fade-in) var(--ease-hover),
    scale var(--dur-fast) var(--ease-out);
}

@media (hover: hover) {
  .icon-button:hover { background: var(--track-hover); color: var(--ink); }
}
.icon-button:active { background: var(--track-press); scale: var(--press-scale); }

/* Message bar: a note pinned under the sheet's header */
.infobar {
  grid-row: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 8px 0;
  padding: 3px 3px 3px 10px;
  min-height: 34px;
  background: var(--info-bg);
  box-shadow: inset 0 0 0 1px var(--info-edge);
  border-radius: 7px;
  font-size: var(--small-size);
}

/* Restarts each time the bar is shown (display: none -> flex). Dismissing is instant. */
.infobar { animation: infobar-in var(--dur-med) var(--ease-out) both; }
@keyframes infobar-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes fade-in { from { opacity: 0; } }

.infobar[hidden] { display: none; }
.infobar > .icon { width: 15px; height: 15px; color: var(--info-icon); }
.infobar p { flex: 1; min-width: 0; padding-block: 4px; text-wrap: pretty; }

/* Sheet body: change map, line numbers, editor. The text stops one corner radius above
   the sheet's bottom edge, so a block never meets the rounded corner the bridge cannot follow. */
.pane-body {
  grid-row: 3;
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
  padding-bottom: var(--sheet-r);
}

#pane-left .pane-body { grid-template-columns: var(--map-w) auto minmax(0, 1fr); }
#pane-right .pane-body { grid-template-columns: auto minmax(0, 1fr) var(--map-w); }

.overview {
  display: block;
  width: var(--map-w);
  height: 100%;
  min-height: 0;
  cursor: pointer;
  touch-action: none;
}

.gutter {
  position: relative;
  overflow: hidden;
  min-width: 3ch;
  color: var(--ink-3);
  font: var(--gutter-size)/var(--lh) var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  user-select: none;
}

.gutter-inner { position: absolute; inset: 0 auto auto 0; width: 100%; will-change: transform; }

/* = the 26px in pane.js renderGutter */
.gutter-row {
  position: relative;
  height: var(--lh);
  padding: 0 6px 0 20px;
  white-space: nowrap;
}

.editor {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.editor textarea,
.backdrop,
.measurer {
  position: absolute;
  inset: 0;
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--mono-size);
  line-height: var(--lh);
  tab-size: 4;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
  letter-spacing: 0;
}

.editor textarea {
  width: 100%;
  height: 100%;
  padding: var(--ed-pad-y) var(--ed-pad-r) var(--ed-pad-y) var(--ed-pad-l);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  caret-color: var(--ink);
  resize: none;
  white-space: pre;
  overflow: auto;
  overflow-wrap: normal;
  outline: none;
  /* A thin thumb on a clear track: the blocks run under the scrollbar to the sheet's
     edge, where the bridge picks them up. (Overlay scrollbars take no room at all.) */
  scrollbar-width: thin;
  scrollbar-color: var(--thumb) transparent;
}

/* The placeholder stays for assistive tech; the empty hint below is what you see. */
.editor textarea::placeholder { color: transparent; }

/* Not a scroll container: its rows run the full width of the editor, under the
   textarea's scrollbar, while the text inside them keeps the textarea's width. */
.backdrop {
  overflow: visible;
  pointer-events: none;
  color: transparent;
}

/* ---------- Soft wrap ----------
   The textarea, the bands' text layer and the measurer (pane.js) must break every line
   at exactly the same characters, so they share every rule that decides it: the font
   block above, the horizontal padding (--ed-pad-l/-r), white-space, overflow-wrap and
   word-break, and the scrollbar gutter. The textarea and the measurer reserve the same
   thin gutter; the band rows are full width, so their text takes the measured width
   (--text-w, written by pane.js) instead. */
.measurer {
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
  contain: strict;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}
.measure-probe { height: 0; padding: 0 var(--ed-pad-r) 0 var(--ed-pad-l); white-space: pre; }
.measure-lines > div { padding: 0 var(--ed-pad-r) 0 var(--ed-pad-l); }

.measure-lines,
#app[data-wrap="on"] .editor textarea,
#app[data-wrap="on"] .row {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
}

#app[data-wrap="on"] .editor textarea { overflow-x: hidden; scrollbar-gutter: stable; }
#app[data-wrap="on"] .row-text { width: var(--text-w, auto); }

/* Empty sheet: a short note in the middle. Clicks pass through to the text. */
.empty-hint {
  position: absolute;
  inset: 0;
  display: none;
  place-content: center;
  gap: 4px;
  padding: 16px;
  text-align: center;
  pointer-events: none;
  user-select: none;
}

/* Fades in when a pane becomes empty (Clear, or deleting everything); typing hides it at once. */
.editor:has(textarea:placeholder-shown) .empty-hint { display: grid; animation: fade-in var(--dur-med) var(--ease-out) both; }

.empty-title {
  font-size: 15px;
  font-weight: var(--weight-semibold);
  color: var(--ink);
  text-wrap: balance;
}

.empty-body {
  max-width: 30ch;
  margin-inline: auto;
  color: var(--ink-2);
  text-wrap: pretty;
}

/* ---------- Change blocks ----------
   One row per visible changed line, positioned by JS with transform, plus the line
   number rows beside them. Together they make the block: rounded on the sheet's outer
   side, flush with its inner edge where the bridge on the canvas carries on. */
.row {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--lh);
  white-space: pre;
}

/* (A one-sided change's empty side is a landing line, not a block: .is-gap, below.) */
.row:not(.is-gap).is-replace, .gutter-row.is-replace { background: var(--rep-fill); }
.row:not(.is-gap).is-insert, .row:not(.is-gap).is-delete,
.gutter-row.is-insert, .gutter-row.is-delete { background: var(--one-fill); }
.row:not(.is-gap).is-current.is-replace, .gutter-row.is-current.is-replace { background: var(--rep-fill-cur); }
.row:not(.is-gap).is-current.is-insert, .row:not(.is-gap).is-current.is-delete,
.gutter-row.is-current.is-insert, .gutter-row.is-current.is-delete { background: var(--one-fill-cur); }

.gutter-row.is-replace { color: var(--rep-ink); }
.gutter-row.is-insert, .gutter-row.is-delete { color: var(--one-ink); }
.gutter-row.is-current { font-weight: var(--weight-semibold); }

/* Outer corners: the line numbers on the left sheet, the text's far end on the right sheet */
.pane[data-side="left"] .gutter-row.is-first { border-top-left-radius: var(--block-r); }
.pane[data-side="left"] .gutter-row.is-last { border-bottom-left-radius: var(--block-r); }
.pane[data-side="right"] .row.is-first { border-top-right-radius: var(--block-r); }
.pane[data-side="right"] .row.is-last { border-bottom-right-radius: var(--block-r); }

/* The current change: a thin outline tracing the whole shape. Top and bottom on every
   first and last row, the outer side on the rounded end; the canvas draws the rest.
   Inset shadows rather than borders, so a block's height never depends on whether it is current. */
.row.is-current:not(.is-gap)::after,
.gutter-row.is-current::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  --e: var(--one-edge);
  --o-t: 0 0 transparent;
  --o-b: 0 0 transparent;
  --o-s: 0 0 transparent;
  box-shadow: var(--o-t), var(--o-b), var(--o-s);
}
.row.is-current.is-replace::after, .gutter-row.is-current.is-replace::after { --e: var(--rep-edge); }
.row.is-current.is-first::after, .gutter-row.is-current.is-first::after { --o-t: inset 0 var(--ow) 0 0 var(--e); }
.row.is-current.is-last::after, .gutter-row.is-current.is-last::after { --o-b: inset 0 calc(-1 * var(--ow)) 0 0 var(--e); }
.pane[data-side="left"] .gutter-row.is-current::after { --o-s: inset var(--ow) 0 0 0 var(--e); }
.pane[data-side="right"] .row.is-current::after { --o-s: inset calc(-1 * var(--ow)) 0 0 0 var(--e); }

/* The empty side of a one-sided change: a thin landing line where the lines would go,
   across the line numbers and the text, into the thin end of the bridge. */
.row.is-gap,
.gutter-gap {
  height: var(--land-w);
  margin-top: calc(-1 * var(--land-a));
  background: var(--one-edge);
  opacity: var(--land-alpha);
}
.row.is-gap.is-current,
.gutter-gap.is-current { opacity: 1; }
.gutter-gap { position: absolute; left: 0; right: 0; }
.pane[data-side="left"] .gutter-gap { border-radius: var(--land-a) 0 0 var(--land-a); }
.pane[data-side="right"] .row.is-gap { border-radius: 0 var(--land-a) var(--land-a) 0; }

/* Lines touched by a merge. Receiving side (data-merge="land"): the block sweeps in from
   the channel side, holds, then settles away. Sending side ("source"): the old block
   dissolves with its bridge. JS sets --merge-age (a negative delay) on rows rebuilt mid-way
   so they rejoin the animation on the same frame. The tint is a pseudo-element so the
   row's own transform (its position) is never touched. The line numbers carry the same
   tint (gutter rows below), so the shape still runs unbroken into the text. */
.row.is-just-merged,
.gutter-row.is-just-merged {
  background: transparent;
  --flash-fill: var(--one-fill);
  --flash-edge: var(--one-edge);
}
.is-just-merged[data-type="replace"] { --flash-fill: var(--rep-fill); --flash-edge: var(--rep-edge); }
.is-just-merged[data-current] { --flash-fill: var(--one-fill-cur); }
.is-just-merged[data-current][data-type="replace"] { --flash-fill: var(--rep-fill-cur); }

/* Gutter: the number sits above its own tint */
.gutter-row.is-just-merged { isolation: isolate; }
.gutter-row.is-just-merged::before { z-index: -1; }

.row.is-just-merged::before,
.gutter-row.is-just-merged::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--flash-fill);
  animation: merge-dissolve var(--merge-dissolve) var(--ease-in-out-sine) both;
  animation-delay: var(--merge-age, 0ms);
}

/* Lines removed by a merge close to a landing line */
.row.is-just-merged.is-closed { height: 0; }
.row.is-just-merged.is-closed::before {
  inset: auto 0;
  top: calc(-1 * var(--land-a));
  height: var(--land-w);
  border-radius: 0;
  background: var(--flash-edge);
}

.row.is-just-merged[data-merge="land"]::before {
  animation: merge-land var(--merge-land) var(--ease-out-expo) both, merge-settle var(--merge-settle) linear both;
  animation-delay: var(--merge-age, 0ms);
}
.pane[data-side="left"] .row.is-just-merged[data-merge="land"]::before { transform-origin: right center; }
.pane[data-side="right"] .row.is-just-merged[data-merge="land"]::before { transform-origin: left center; }

/* The narrow gutter does not sweep (on the left sheet it sits at the far end of the sweep);
   it fades up on the same curve, so on the right sheet it reads as the start of the sweep. */
.gutter-row.is-just-merged[data-merge="land"]::before {
  animation: fade-in var(--merge-land) var(--ease-out-expo) both, merge-settle var(--merge-settle) linear both;
  animation-delay: var(--merge-age, 0ms);
}

@keyframes merge-land { from { transform: scaleX(0); } }
@keyframes merge-settle {
  0%, 30% { opacity: 1; animation-timing-function: cubic-bezier(0.37, 0, 0.63, 1); }
  100% { opacity: 0; }
}
@keyframes merge-dissolve { from { opacity: 1; } to { opacity: 0; } }

.row-text {
  display: block;
  padding: 0 var(--ed-pad-r) 0 var(--ed-pad-l);
  will-change: transform;
}

/* The exact words that changed: the block's colour one step stronger */
.mark { border-radius: 3px; }
.row.is-replace .mark { background: var(--rep-word); box-shadow: 0 0 0 1.5px var(--rep-word); }
.row.is-replace.is-current .mark { background: var(--rep-word-cur); box-shadow: 0 0 0 1.5px var(--rep-word-cur); }

/* Drop target: a dashed tray inside the sheet */
.dropzone {
  position: absolute;
  inset: 0;
  z-index: var(--z-drop);
  display: grid;
  place-items: center;
  padding: 16px;
  pointer-events: none;
  background: var(--sheet);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--fade-out) var(--ease-out), visibility 0s linear var(--fade-out);
}

.dropzone::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1.5px dashed var(--ink-3);
  border-radius: 8px;
}

/* The note settles up to full size as the target appears, and eases back as it goes. */
.dropzone-card {
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
  transform: scale(0.97);
  transition: transform var(--fade-out) var(--ease-out);
}

.dropzone-card .icon { width: 20px; height: 20px; margin-bottom: 6px; color: var(--ink); }
.dropzone-title { font-size: 15px; font-weight: var(--weight-semibold); color: var(--ink); }
.dropzone-body { color: var(--ink-2); }

.pane[data-drop="active"] .dropzone {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--fade-in) var(--ease-out), visibility 0s;
}

.pane[data-drop="active"] .dropzone::before,
.pane[data-drop="done"] .dropzone::before { border-color: var(--ink); }

.pane[data-drop="active"] .dropzone-card {
  transform: none;
  transition: transform var(--dur-med) var(--ease-out-expo);
}

/* A drop that landed: the tray fades in place instead of shrinking back the way a
   cancelled drag does, so "accepted" and "withdrawn" read differently. */
.pane[data-drop="done"] .dropzone-card { transform: none; transition: none; }

/* Loading: dim only if reading the file takes long enough to notice, then fade back. */
.editor { transition: opacity var(--fade-in) var(--ease-out); }
.pane[data-loading="true"] .editor { opacity: 0.6; transition-delay: 150ms; }

/* ---------- Channel ----------
   The gap between the sheets. Above the sheets' rings and shadows, so a bridge covers
   them exactly where it meets a block. */

.linkmap {
  position: relative;
  z-index: 1;
  display: grid;
  grid-row: 1 / span 3;
  grid-template-rows: subgrid;
  min-height: 0;
  /* The channel is the split's drag handle: all of it but the merge arrows (app.js). */
  cursor: col-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.linkmap-head {
  grid-row: 1;
  display: grid;
  place-items: center;
}

/* The grip: a short rounded bar between the two sheet headers, as quiet as a hairline at
   rest. It is the separator for keyboard and assistive tech; the pointer can take the
   whole channel. Hovering the channel darkens it, dragging darkens it further. */
.split-grip {
  display: grid;
  place-items: center;
  width: 20px;
  height: 30px;
  border-radius: 6px;
  color: var(--track-sep);
  transition: color var(--fade-in) var(--ease-hover);
}
.split-grip::before {
  content: "";
  width: 4px;
  height: 18px;
  border-radius: 2px;
  background: currentColor;
}

@media (hover: hover) {
  .linkmap:hover:not(:has(.merge-btn:hover)) .split-grip { color: var(--ink-3); }
}
.split-grip:focus-visible { color: var(--ink-2); outline-offset: 0; }
#app[data-resizing] .split-grip { color: var(--ink-2); }

/* While dragging, the pointer may be anywhere: keep the cursor and never select text. */
#app[data-resizing],
#app[data-resizing] * { cursor: col-resize; user-select: none; -webkit-user-select: none; }

.linkmap-body {
  grid-row: 3;
  position: relative;
  min-height: 0;
  margin-bottom: var(--sheet-r); /* = .pane-body padding-bottom: the canvas spans the text exactly */
  overflow: hidden;
}

#linkmap-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.linkmap-buttons { position: absolute; inset: 0; z-index: var(--z-buttons); pointer-events: none; }

/* Identical: an equals sign where the bridges would be */
.linkmap-seal {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: var(--z-seal);
  display: none;
  place-items: center;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 8px;
  background: var(--sheet);
  box-shadow: 0 0 0 1px var(--sheet-ring);
  color: var(--ink-2);
}

/* Arrives once, when the texts become identical (often as the last bridge dissolves). */
#app[data-state="identical"] .linkmap-seal { display: grid; animation: seal-in var(--dur-slow) var(--ease-out-expo) both; }
@keyframes seal-in { from { opacity: 0; scale: 0.9; } }

/* Merge arrows: bare glyphs riding each bridge, in the change's ink. Hover or focus
   turns one into a small filled square. linkmap.js puts each on the bridge's centre line. */
.merge-btn {
  position: absolute;
  top: 0;
  display: grid;
  place-items: center;
  width: var(--merge-size);
  height: var(--merge-size);
  padding: 0;
  border: 0;
  border-radius: 6px;
  --btn-ink: var(--one-ink);
  background: transparent;
  color: var(--btn-ink);
  opacity: 0.8;
  pointer-events: auto;
  will-change: transform;
  /* Position is JS's transform; press uses the separate `scale` property. Colour only
     transitions on hover (below): becoming the current change is instant, the same
     frame as its block and bridge. */
  transition: scale var(--dur-fast) var(--ease-out);
}

.merge-btn[data-type="replace"] { --btn-ink: var(--rep-ink); }
.merge-btn[data-dir="right"] { left: 1px; }
.merge-btn[data-dir="left"] { right: 1px; }
/* On a one-sided change, the arrow at the narrowing end steps 2px toward the wide part
   (= BTN_INSET_THIN in linkmap.js), so it sits inside the bridge, not on its tip. */
.merge-btn[data-thin][data-dir="right"] { left: 3px; }
.merge-btn[data-thin][data-dir="left"] { right: 3px; }
.merge-btn .icon { width: 13px; height: 13px; stroke-width: 2.3; }
.merge-btn.is-current { opacity: 1; }

@media (hover: hover) {
  .merge-btn:hover {
    opacity: 1;
    background: var(--btn-ink);
    color: var(--sheet);
    box-shadow: 0 0 0 0.5px rgb(0 0 0 / 0.15), 0 1px 3px rgb(0 0 0 / 0.2);
    transition:
      background-color var(--fade-in) var(--ease-hover),
      color var(--fade-in) var(--ease-hover),
      opacity var(--fade-in) var(--ease-hover),
      scale var(--dur-fast) var(--ease-out);
  }
}
.merge-btn:focus-visible { opacity: 1; background: var(--btn-ink); color: var(--sheet); outline-offset: 1px; }
/* A 22px square needs a deeper press than a toolbar button to be felt (0.96 is under 1px). */
.merge-btn:active { scale: 0.9; }

/* Bigger hit area on touch screens without changing the drawing */
@media (pointer: coarse) {
  .merge-btn::before { content: ""; position: absolute; inset: -8px -1px; }
}

/* The arrows' tooltip: placed above the change it describes (never over it), centred
   on the channel. Fixed, so it can overhang the sheets. */
.merge-tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-tip);
  padding: 6px 10px 7px;
  border-radius: 7px;
  background: var(--tip-bg);
  box-shadow: var(--tip-shadow);
  color: var(--ink);
  font-size: var(--small-size);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  pointer-events: none;
  animation: fade-in var(--fade-in) var(--ease-out) both;
}
.merge-tip[hidden] { display: none; }
.merge-tip-title { display: block; }
.merge-tip-sub { display: block; margin-top: 1px; color: var(--ink-2); font-size: 11px; font-weight: 400; }

/* ---------- Status bar ---------- */

.statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  min-height: var(--status-h);
  padding: 0 20px;
  padding-bottom: env(safe-area-inset-bottom);
  color: var(--ink-2);
  font-size: var(--small-size);
  font-variant-numeric: tabular-nums;
}

.statusbar p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.status-summary strong { font-weight: var(--weight-semibold); color: var(--ink); }

/* Each count wears its block's colours, so the status bar is also the legend */
.key { display: inline-flex; align-items: center; gap: 6px; }

.key::before {
  content: "";
  width: 9px;
  height: 9px;
  flex-shrink: 0;
  border-radius: 2.5px;
  background: var(--one-fill-cur);
  box-shadow: inset 0 0 0 1px var(--one-edge);
}

.key.is-replace::before { background: var(--rep-fill-cur); box-shadow: inset 0 0 0 1px var(--rep-edge); }

.status-summary .icon { width: 14px; height: 14px; margin-right: -10px; color: var(--one-edge); stroke-width: 2.25; }

/* The summary and the note that stands in for it (hidden characters stripped) share one
   cell and crossfade: opacity only, so nothing in the bar moves. */
.status-lead { display: grid; align-items: center; min-width: 0; }
.status-lead > * { grid-area: 1 / 1; min-width: 0; transition: opacity var(--dur-med) var(--ease-out); }
.status-note { opacity: 0; pointer-events: none; }
#app[data-note] .status-note { opacity: 1; }
#app[data-note] .status-summary { opacity: 0; }

/* Option off and hidden characters found: a quiet offer to strip them. */
.status-hidden {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  height: 22px;
  margin: 0 -6px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-2);
  font-size: var(--small-size);
  white-space: nowrap;
  user-select: none;
  transition:
    background-color var(--fade-in) var(--ease-hover),
    color var(--fade-in) var(--ease-hover),
    scale var(--dur-fast) var(--ease-out);
}
.status-hidden[hidden] { display: none; }
.status-hidden .icon { width: 14px; height: 14px; color: var(--ink-3); transition: color var(--fade-in) var(--ease-hover); }
@media (hover: hover) {
  .status-hidden:hover { background: var(--track-hover); color: var(--ink); }
  .status-hidden:hover .icon { color: var(--ink-2); }
}
.status-hidden:active { background: var(--track-press); scale: var(--press-scale); }
.status-hidden:focus-visible { outline-offset: 0; }

.status-options { flex-shrink: 0; margin-left: auto; }
.status-options:empty { display: none; }

.status-hint {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.status-options:empty + .status-hint { margin-left: auto; }
.status-options:not(:empty) + .status-hint::before { content: "·"; margin-right: 12px; color: var(--ink-3); }

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--btn);
  box-shadow: var(--btn-shadow);
  color: var(--ink-2);
  font: 11px/16px var(--font-ui);
  text-align: center;
}

kbd:last-of-type { margin-right: 2px; }

/* ---------- Narrower windows ----------
   The toolbar gives way in steps, so nothing ever runs under the Copy capsule: Strip
   hidden characters becomes its icon, then Wrap, then Whitespace and Case, then Copy Left and Right become their
   arrows; below 940px the capsule stops tracking the channel, and at 720px the toolbar
   takes two rows (the phone's arrangement) while the sheets are still side by side.
   Labels stay in the accessibility tree; titles name each icon on hover. */

/* Strip hidden characters goes first: its label is the longest, and below 1360px the
   toolbar has no room for it. Its icon then takes the room Whitespace and Case gave up at
   1060px before it was there, so they give way at 1100px. */
@media (max-width: 1360px) {
  .seg-strip .seg-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .seg-strip .seg-btn { width: 30px; padding: 0; }
}

@media (max-width: 1180px) {
  .seg-view .seg-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .seg-view .seg-btn { width: 30px; padding: 0; }
}

@media (max-width: 1100px) {
  .seg-ignore .seg-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .seg-ignore .seg-btn { width: 30px; padding: 0; }
}

@media (max-width: 940px) {
  .seg-copy .seg-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .seg-copy .seg-btn { width: 30px; padding: 0; }
}

@media (max-width: 900px) {
  .status-hint { display: none; }
}

/* A sheet dragged narrow gives up its line count, then its side label, then Open's word. */
@container pane-head (max-width: 360px) {
  .pane-meta { display: none; }
}
@container pane-head (max-width: 280px) {
  .pane-side { display: none; }
  .pane-head { grid-template-columns: 0 minmax(0, 1fr) max-content; gap: 6px; padding-left: 10px; }
  .pane-title { justify-content: flex-start; }
  .button-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .button { width: 28px; padding: 0; justify-content: center; }
}

@media (max-width: 720px) {
  .titlebar {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "start changes" "end end";
    row-gap: 6px;
    padding: 8px 10px 8px 14px;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .tb-start { grid-area: start; padding-right: 12px; }
  .toolbar-changes { grid-area: changes; justify-self: end; }
  .tb-end { grid-area: end; padding-left: 0; }
}

/* Phone width: stack the sheets, drop the channel, keep blocks, maps and navigation */
@media (max-width: 560px) {
  :root {
    --ui-size: 15px;
    --small-size: 13px;
    --mono-size: 16px;   /* 16px stops iOS zooming into the textarea */
    --lh: 24px;
    --gutter-size: 13px;
    --seg-h: 40px;
    --seg-btn-h: 36px;
    --head-h: 44px;
    --frame: 8px;
    --ed-pad-r: 18px;    /* a space hanging at a wrap stays inside the block's inset end */
  }
  .seg-btn.icon-only,
  .seg-view .seg-btn, .seg-ignore .seg-btn, .seg-strip .seg-btn, .seg-copy .seg-btn { width: 40px; }
  .titlebar { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "start start" "end changes"; padding-inline: 8px; }
  .tb-start { padding-right: 0; }
  .brand-mark { width: 22px; height: 22px; }
  .tb-end, .tb-opts { gap: 8px; }
  .toolbar-doc { order: -1; }
  .tb-end .tb-spacer { display: none; }
  .compare {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    row-gap: 8px;
  }
  .pane { grid-row: auto; grid-template-rows: auto auto minmax(0, 1fr); }
  .linkmap { display: none; }
  /* Both sheets read the same way: map, numbers, text; blocks are rounded at both ends. */
  #pane-right .pane-body { grid-template-columns: var(--map-w) auto minmax(0, 1fr); }
  #pane-right .overview { grid-column: 1; grid-row: 1; }
  #pane-right .gutter { grid-column: 2; grid-row: 1; }
  #pane-right .editor { grid-column: 3; grid-row: 1; }
  .row { right: 6px; }
  .pane .row.is-first { border-top-right-radius: var(--block-r); }
  .pane .row.is-last { border-bottom-right-radius: var(--block-r); }
  .pane .gutter-row.is-first { border-top-left-radius: var(--block-r); }
  .pane .gutter-row.is-last { border-bottom-left-radius: var(--block-r); }
  .pane .row.is-current::after { --o-s: inset calc(-1 * var(--ow)) 0 0 0 var(--e); }
  .pane .gutter-row.is-current::after { --o-s: inset var(--ow) 0 0 0 var(--e); }
  .row.is-gap { border-radius: 0 var(--land-a) var(--land-a) 0; }
  .pane .gutter-gap { border-radius: var(--land-a) 0 0 var(--land-a); }
  .button { height: 32px; }
  .icon-button { width: 36px; height: 36px; }
  .statusbar { padding-inline: 14px; }
  .status-summary { gap: 12px; }
  .status-hidden { height: 32px; }
}

/* ---------- Reduced motion: keep the fades, drop the movement ----------
   (The glide and the bridge ghost's change of shape are switched off in JS.) */

@media (prefers-reduced-motion: reduce) {
  .row.is-just-merged[data-merge="land"]::before {
    animation: merge-settle var(--merge-settle) linear both;
    animation-delay: var(--merge-age, 0ms);
  }
  .dropzone-card,
  .pane[data-drop="active"] .dropzone-card { transform: none; transition: none; }
  .infobar { animation: fade-in var(--fade-in) var(--ease-out) both; }
  .seg-btn:active:not(:disabled), .button:active, .icon-button:active, .merge-btn:active, .status-hidden:active { scale: none; }
  /* --dur-med/slow are zeroed here, so the opacity-only entrances get explicit durations */
  #app[data-state="identical"] .linkmap-seal { animation: fade-in 200ms var(--ease-out) both; }
  .editor:has(textarea:placeholder-shown) .empty-hint { animation: fade-in 200ms var(--ease-out) both; }
  .status-lead > * { transition: opacity 200ms var(--ease-out); }
}

/* A colour-scheme switch repaints everything at once; JS sets this for two frames so the
   few colour transitions do not trail behind the canvas and the blocks. */
.app.is-retheming *, .app.is-retheming *::before, .app.is-retheming *::after { transition: none !important; }
