:root {
  --bg: #ebe8dd;
  --paper: #f5f2ea;
  --ink: #1f1e1d;
  --muted: #6b6960;
  --line: #d8d3c5;
  --field: #f5f2ea;
  --del-bg: #fdd;
  --del-ink: #b30000;
  --ins-bg: #d4edda;
  --ins-ink: #155724;
  --focus: #c96442;
  --accent: #c96442;
  --tip: #f3f0e7;
  --tip-alpha: 72%;
  --serif: Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1e1d; --paper: #262624; --ink: #ece9e1; --muted: #a3a097; --line: #3a3935; --field: #2a2927;
    --del-bg: #3d1515; --del-ink: #ff8a8a; --ins-bg: #15302a; --ins-ink: #7ddb9a; --focus: #d97757; --accent: #d97757; --tip: #34332f; --tip-alpha: 72%;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1f1e1d; --paper: #262624; --ink: #ece9e1; --muted: #a3a097; --line: #3a3935; --field: #2a2927;
  --del-bg: #3d1515; --del-ink: #ff8a8a; --ins-bg: #15302a; --ins-ink: #7ddb9a; --focus: #d97757; --accent: #d97757; --tip: #34332f; --tip-alpha: 72%;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { color-scheme: light; }
@media (prefers-color-scheme: dark) { html { color-scheme: dark; } }
:root[data-theme="light"] { color-scheme: light; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  padding-block: 16px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.wrap { display: grid; gap: 16px; }
header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 32px; }
header h1 { font-family: var(--serif); font-weight: 600; font-size: 1.4rem; line-height: 1.2; margin: 0; }
header p { margin: 0; color: var(--muted); font-size: 0.85rem; }

.workspace { display: grid; gap: 20px; }
.inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-content: start; }
@media (max-width: 760px) { .inputs { grid-template-columns: 1fr; } }
.splitter { display: none; }
/* Wide screens: the app fills the window and each panel scrolls on its own. */
@media (min-width: 1100px) and (min-height: 560px) {
  body { height: 100vh; height: 100dvh; padding-block: 14px; overflow: hidden; }
  .wrap { height: 100%; grid-template-rows: auto minmax(0, 1fr); }
  .workspace { grid-template-columns: var(--split, 42%) 18px minmax(0, 1fr); gap: 0; min-height: 0; }
  .inputs { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; align-content: stretch; min-height: 0; }
  .inputs .field { grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
  .inputs textarea { height: 100%; min-height: 0; resize: none; }
  .result { grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
  .paper { overflow-y: auto; align-content: start; }
  .splitter { display: block; cursor: col-resize; position: relative; touch-action: none; }
  .splitter::after { content: ""; position: absolute; inset: 0 8px; border-radius: 1px; background: var(--line); transition: background 0.15s; }
  .splitter:hover::after, .splitter:focus-visible::after, .splitter.drag::after { background: var(--accent); }
  .splitter:focus-visible { outline: none; }
  body.resizing { cursor: col-resize; user-select: none; }
}
/* Keep the header on one row: the subtitle wraps before the controls drop down. */
@media (min-width: 1100px) {
  header { flex-wrap: nowrap; gap: 10px 16px; }
  .brand { min-width: 0; }
  .controls, .header-end { flex-shrink: 0; }
}
@media (min-width: 1100px) and (max-width: 1279px) { header p { display: none; } }
@media (min-width: 1100px) and (max-height: 559px) {
  .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); align-items: start; }
  .inputs { grid-template-columns: 1fr; }
}
.field { display: grid; gap: 6px; min-width: 0; }
.field-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 30px; }
.field label { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.field label .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.field.old .sw { background: var(--del-ink); }
.field.new .sw { background: var(--ins-ink); }
.field.new .field-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.field.new .count { justify-self: end; }
button.icon { padding: 3px 10px; line-height: 0; color: var(--muted); }
.header-end { display: flex; align-items: center; gap: 2px; }
#b-theme { padding: 0; width: 32px; height: 32px; display: inline-grid; place-items: center; border: none; background: none; }
#gh { display: inline-flex; align-items: center; gap: 5px; height: 32px; padding: 0 8px; border-radius: 6px; color: var(--muted); text-decoration: none; }
#b-theme:hover, #gh:hover { color: var(--ink); background: color-mix(in srgb, var(--line) 60%, transparent); }
#gh:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
#b-theme svg, #gh svg { width: 17px; height: 17px; }
button.icon:hover { color: var(--ink); }
@media (min-width: 761px) and (max-width: 1099px) { #b-swap svg { transform: rotate(90deg); } }
.count { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
textarea {
  width: 100%; min-height: 220px; resize: vertical;
  font-family: var(--serif); font-size: 15px; line-height: 1.55;
  color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px;
}
textarea:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; margin-inline: auto; padding: 4px 4px 4px 14px; border: 1px solid color-mix(in srgb, var(--line) 70%, transparent); border-radius: 8px; background: color-mix(in srgb, var(--paper) 55%, transparent); }
.ctl { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; }
.ctl input[type="range"] { width: 100px; accent-color: var(--accent); }
.ctl output { font-family: var(--mono); font-size: 0.8rem; min-width: 3.5ch; font-variant-numeric: tabular-nums; }
.ctl input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; }
button {
  font: inherit; font-size: 0.85rem; font-weight: 500;
  padding: 7px 12px; border-radius: 5px; cursor: pointer;
  border: 1px solid var(--line); background: var(--field); color: var(--ink);
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.result { display: grid; gap: 6px; }
.result-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 12px; }
.result-info { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; min-height: 30px; }
.result-head .toast:empty { display: none; }
#b-copy { padding: 4px 10px; font-size: 0.8rem; }
.result-actions { display: flex; align-items: center; gap: 6px; }
.lh-wrap { position: relative; }
#b-lh { border: none; background: none; padding: 6px; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; min-width: 130px;
  display: grid; padding: 4px; border: 1px solid var(--line); border-radius: 7px;
  background: color-mix(in srgb, var(--tip) var(--tip-alpha), transparent);
  -webkit-backdrop-filter: blur(12px) saturate(1.3); backdrop-filter: blur(12px) saturate(1.3);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
}
.menu[hidden] { display: none; }
.menu button { border: none; background: none; text-align: left; font-size: 0.82rem; padding: 5px 10px 5px 26px; border-radius: 4px; position: relative; }
.menu button:hover { background: color-mix(in srgb, var(--line) 60%, transparent); }
.menu button[aria-checked="true"]::before { content: "✓"; position: absolute; left: 9px; color: var(--accent); }
.result-head h2 { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; margin: 0; }
.stats { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 14px; font-variant-numeric: tabular-nums; }
.stats .d { color: var(--del-ink); }
.stats .i { color: var(--ins-ink); }
.toast { font-size: 0.8rem; color: var(--muted); min-height: 1.2em; }

.paper { background: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px 14px 12px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 18px 10px; }
.blk { grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; }
.lbl { font-family: var(--mono); font-size: 0.8rem; white-space: nowrap; color: var(--muted); line-height: calc(15.5px * var(--lh, 1.9)); cursor: default; }
.k-mv .lbl, .k-note .lbl { color: var(--accent); }
.k-del .lbl { color: var(--del-ink); }
.k-ins .lbl { color: var(--ins-ink); }
.lbl b { font-size: 1.05rem; margin-right: 1px; }
.txt { margin: 0; font-family: var(--serif); font-size: 15.5px; line-height: var(--lh, 1.9); }
.k-note .txt { font-family: var(--sans); font-size: 0.85rem; color: var(--muted); font-style: italic; }
@media (max-width: 600px) {
  .paper { padding: 12px 12px 12px 8px; }
}
del, ins { border-radius: 2px; padding: 1px 2px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
del { background: var(--del-bg); color: var(--del-ink); text-decoration: line-through; }
ins { background: var(--ins-bg); color: var(--ins-ink); text-decoration: none; }
details.same { grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; row-gap: 0; }
details.same > .blk { margin-top: 18px; }
details.same > summary { grid-column: 2; cursor: pointer; font-size: 0.8rem; color: var(--muted); list-style-position: inside; }
.empty { grid-column: 1 / -1; color: var(--muted); font-family: var(--serif); font-style: italic; margin: 0; }
.legend { font-size: 0.8rem; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }

.tip {
  position: fixed; z-index: 10; max-width: 260px; pointer-events: none;
  background: color-mix(in srgb, var(--tip) var(--tip-alpha), transparent); color: var(--ink); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(12px) saturate(1.3); backdrop-filter: blur(12px) saturate(1.3);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14); font-size: 0.8rem; line-height: 1.45;
  padding: 8px 11px; border-radius: 7px;
  opacity: 0; transform: translateY(-2px); transition: opacity 0.12s, transform 0.12s;
}
.tip.on { opacity: 1; transform: none; }
.controls button { padding: 4px 10px; border-color: transparent; background: none; border-radius: 4px; }
.controls button:hover { border-color: transparent; background: color-mix(in srgb, var(--line) 60%, transparent); }
