/* Text diff tool — one page, one table.
 *
 * The colour choices are the load-bearing part of this file. Added, removed and
 * changed rows are distinguished by hue AND by a leading +/-/blank marker in the
 * line itself, so the output still reads correctly in monochrome, on a
 * projector, and for the ~8% of men with red-green colour vision deficiency.
 * Colour alone would make the tool's entire answer inaccessible to them.
 */

:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1c1d1f;
  --muted: #6b6f76;
  --line: #dfe1e5;
  --accent: #2b5eb8;

  --add-bg: #e6f5ea;
  --add-edge: #34894f;
  --del-bg: #fdeaea;
  --del-edge: #b4322f;
  --chg-bg: #fdf4e0;
  --chg-edge: #a97012;
  --seg-bg: #ffe08a;

  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --panel: #1e2126;
    --ink: #e7e9ec;
    --muted: #969ba3;
    --line: #333840;
    --accent: #7aa5ef;

    --add-bg: #16311f;
    --add-edge: #4cae68;
    --del-bg: #3a1d1d;
    --del-edge: #e0706c;
    --chg-bg: #37301a;
    --chg-edge: #d6a545;
    --seg-bg: #6b551d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 1.75rem 1.25rem 3rem;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

main { max-width: 1180px; margin: 0 auto; }

.page-head { margin-bottom: 1.25rem; }
h1 { margin: 0 0 .2rem; font-size: 1.4rem; letter-spacing: -.01em; }
.tagline { margin: 0; color: var(--muted); }
h2 { margin: 0 0 .6rem; font-size: 1.1rem; }

.muted { color: var(--muted); font-weight: 400; }

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

/* -- the form ----------------------------------------------------------- */

.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .9rem;
}

@media (max-width: 720px) {
  .panes { grid-template-columns: 1fr; }
}

.pane { display: flex; flex-direction: column; }

.pane label {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: .3rem;
}

textarea {
  width: 100%;
  min-height: 14rem;
  resize: vertical;
  padding: .7rem .8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: inherit;
  font: 13px/1.55 var(--mono);
  tab-size: 4;
}

textarea:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: .9rem;
}

.spacer { flex: 1; }

button {
  font: inherit;
  border-radius: 7px;
  padding: .45rem .95rem;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel);
  color: inherit;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button:hover { filter: brightness(1.06); }

.opt {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  color: var(--muted);
  cursor: pointer;
}

.hint { margin: .55rem 0 0; font-size: .82rem; color: var(--muted); }

kbd {
  font: 11px/1 var(--mono);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: .18rem .3rem;
  background: var(--panel);
}

.error {
  margin: 0 0 1rem;
  padding: .7rem .9rem;
  border-radius: 8px;
  border-left: 4px solid var(--del-edge);
  background: var(--del-bg);
}

/* -- the result --------------------------------------------------------- */

.result { margin-top: 2rem; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  list-style: none;
  margin: 0 0 .9rem;
  padding: 0;
  font-size: .85rem;
}

.stat {
  padding: .2rem .6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
}

.stat b { color: var(--ink); font-variant-numeric: tabular-nums; }

.stat-added   { background: var(--add-bg); border-color: var(--add-edge); }
.stat-removed { background: var(--del-bg); border-color: var(--del-edge); }
.stat-changed { background: var(--chg-bg); border-color: var(--chg-edge); }

.identical {
  margin: 0 0 1rem;
  padding: .7rem .9rem;
  border-radius: 8px;
  border-left: 4px solid var(--add-edge);
  background: var(--add-bg);
}

.diff-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table.diff {
  width: 100%;
  border-collapse: collapse;
  font: 13px/1.55 var(--mono);
}

table.diff thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: .4rem .6rem;
  font: 600 11px/1.4 system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

table.diff td {
  padding: .1rem .5rem;
  vertical-align: top;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 45%, transparent);
}

td.num {
  width: 1%;
  min-width: 3ch;
  text-align: right;
  color: var(--muted);
  user-select: none;
  font-variant-numeric: tabular-nums;
  border-right: 1px solid var(--line);
}

td.line {
  /* pre-wrap, not pre: a long line has to wrap rather than push the changed
     column off the right-hand edge, which is where the answer lives. */
  white-space: pre-wrap;
  word-break: break-word;
  width: 50%;
}

/* The +/-/space prefix. Carries the same information as the row colour, for
   anyone who cannot use the colour. */
.marker {
  display: inline-block;
  width: 1ch;
  margin-right: .4rem;
  color: var(--muted);
  user-select: none;
}

.row-insert  { background: var(--add-bg); }
.row-delete  { background: var(--del-bg); }
.row-replace { background: var(--chg-bg); }

.row-insert  td.line:last-child { box-shadow: inset 3px 0 0 var(--add-edge); }
.row-delete  td.line:nth-child(2) { box-shadow: inset 3px 0 0 var(--del-edge); }
.row-replace td.line { box-shadow: inset 3px 0 0 var(--chg-edge); }

/* The words that actually moved, inside a changed line. Underlined as well as
   filled, so the emphasis survives without colour. */
.seg-changed {
  background: var(--seg-bg);
  border-radius: 2px;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

/* An empty changed segment (a pure insertion mid-line) would otherwise be
   invisible; give it a sliver of width so the position is still shown. */
.seg-changed:empty { padding-left: 2px; }

/* -- unified export ----------------------------------------------------- */

.unified { margin-top: 1.1rem; }

.unified summary {
  cursor: pointer;
  font-weight: 600;
  padding: .3rem 0;
}

.unified pre {
  margin: .5rem 0 0;
  padding: .7rem .8rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font: 12px/1.5 var(--mono);
}

.unified button { margin-top: .5rem; }

footer {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: .84rem;
  color: var(--muted);
}

footer p { margin: .25rem 0; }
footer code { font: 12px/1 var(--mono); }
footer a { color: var(--accent); }
