/* ==========================================================================
   Text Diff Checker
   ========================================================================== */

.td {
  --add-bg: rgba(52, 211, 153, 0.1);
  --add-ln: rgba(52, 211, 153, 0.16);
  --add-hl: rgba(52, 211, 153, 0.34);
  --add-mk: #34d399;
  --del-bg: rgba(251, 113, 133, 0.1);
  --del-ln: rgba(251, 113, 133, 0.16);
  --del-hl: rgba(251, 113, 133, 0.36);
  --del-mk: #fb7185;
  --td-head-bg: #0d1022;
  grid-template-columns: minmax(0, 1fr);
}
:root[data-theme="light"] .td {
  --add-bg: #eaf8ef;
  --add-ln: #d5f2df;
  --add-hl: #a6e6bf;
  --add-mk: #047857;
  --del-bg: #fdeef1;
  --del-ln: #fadbe1;
  --del-hl: #f5b5c2;
  --del-mk: #be123c;
  --td-head-bg: #f3f4f9;
}
.td .ws-output { border-left: 0; border-top: 1px solid var(--border); }

/* Inputs ------------------------------------------------------------------- */
.td-editors { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem 1.25rem; }
@media (max-width: 760px) { .td-editors { grid-template-columns: minmax(0, 1fr); } }
.td-editor { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.td-editor-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.25rem 0.5rem; min-height: 36px; }
.td-editor-head .field-label { display: inline-flex; align-items: center; gap: 0.45rem; }
.td-side-mk {
  display: inline-grid; place-items: center;
  width: 20px; height: 20px;
  border-radius: 6px;
  font: 700 0.85rem/1 var(--font-mono);
}
.td-side-mk.is-del { background: var(--del-ln); color: var(--del-mk); }
.td-side-mk.is-add { background: var(--add-ln); color: var(--add-mk); }
.td-editor-actions { display: flex; flex-wrap: wrap; gap: 0.15rem; }
.td-input { height: 280px; min-height: 160px; font: 0.86rem/1.6 var(--font-mono); tab-size: 4; }
@media (max-width: 760px) { .td-input { height: 190px; } }
.td-meta { margin: 0; min-height: 1.2em; }

.td-options { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1.1rem 2.25rem; }
.td-checks { min-width: 0; margin: 0; padding: 0; border: 0; }
.td-checks legend { margin-bottom: 0.55rem; padding: 0; color: var(--text); font-size: 0.88rem; font-weight: 600; }
.td-check-list { display: flex; flex-wrap: wrap; gap: 0.55rem 1.25rem; }
.td-check-list .check { font-size: 0.88rem; }

.td-run { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.5rem; padding-top: 1.1rem; border-top: 1px solid var(--border); }
.td-run .btn { margin-left: auto; }
.td-run .check { font-size: 0.88rem; }
.td-kbd { color: var(--muted); font-size: 0.78rem; }
@media (max-width: 520px) {
  .td-run .btn { width: 100%; margin-left: 0; }
  .td-kbd { display: none; }
}

/* Output ------------------------------------------------------------------- */
.td-summary { margin: 0; color: var(--text); font-weight: 500; }
.td-summary:empty { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); }

.td-stat-add strong { color: var(--success); }
.td-stat-del strong { color: var(--danger); }
.td-stat-chg strong { color: var(--lilac); }

.td-notice {
  display: flex; flex-direction: column; gap: 0.3rem;
  margin: 0;
  padding: 0.65rem 0.9rem;
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 12px;
  background: rgba(245, 158, 11, 0.08);
  color: var(--warn-text);
  font-size: 0.86rem;
  line-height: 1.5;
}
.td-notice[hidden] { display: none; }

.td-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.td-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-left: auto; }
.td-counter { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.td .icon-btn:disabled { opacity: 0.45; cursor: not-allowed; color: var(--text-2); border-color: var(--border-2); background: var(--surface-2); }
.td .icon-btn:focus-visible, .td-fold:focus-visible { outline: 2px solid var(--lilac); outline-offset: 2px; }
@media (max-width: 520px) { .td-nav { margin-left: 0; } }

/* Diff view ---------------------------------------------------------------- */
.td-view {
  --lnw: 4.5ch;
  max-height: min(75vh, 880px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--field-bg);
  color: var(--text);
  font: 0.82rem/1.6 var(--font-mono);
}
.td-view:focus-visible { outline: 2px solid var(--lilac); outline-offset: 2px; }

.td-row { display: grid; }
.td-split .td-row { grid-template-columns: var(--lnw) minmax(0, 1fr) var(--lnw) minmax(0, 1fr); }
.td-unified .td-row { grid-template-columns: var(--lnw) var(--lnw) minmax(0, 1fr); }
.td-row:focus { outline: none; }

.td-headrow {
  position: sticky; top: 0; z-index: 2;
  border-bottom: 1px solid var(--border-2);
  background: var(--td-head-bg);
  color: var(--text-2);
  font: 600 0.78rem/1.4 var(--font-body);
}
.td-h { min-width: 0; padding: 0.55rem 0.75rem; overflow-wrap: anywhere; }
.td-split .td-h { grid-column: span 2; }
.td-split .td-h + .td-h { border-left: 1px solid var(--border); }
.td-unified .td-h { grid-column: 1 / -1; }
.td-h-note { color: var(--muted); font-weight: 500; }

.td-n {
  padding: 0 0.4rem 0 0.3rem;
  border-right: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.74rem;
  line-height: calc(0.82rem * 1.6);
  text-align: right;
  font-variant-numeric: tabular-nums;
  user-select: none;
  -webkit-user-select: none;
}
.td-c {
  position: relative;
  min-width: 0;
  min-height: calc(0.82rem * 1.6);
  padding: 0 0.6rem 0 1.45rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 4;
}
.td-split .td-c + .td-n { border-left: 1px solid var(--border-2); }
.td-m {
  position: absolute; left: 0.4rem; top: 0;
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
}
.td-del { background: var(--del-bg); }
.td-add { background: var(--add-bg); }
.td-n.td-del { background: var(--del-ln); color: var(--del-mk); }
.td-n.td-add { background: var(--add-ln); color: var(--add-mk); }
.td-del .td-m { color: var(--del-mk); }
.td-add .td-m { color: var(--add-mk); }
.td-skip { color: var(--muted); }
.td-none { background: repeating-linear-gradient(135deg, transparent 0 6px, rgba(var(--ink), 0.035) 6px 12px); }
.td-n.td-none { background-color: var(--surface); }

.td-x { border-radius: 3px; color: inherit; }
del.td-x {
  background: var(--del-hl);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--del-mk) 75%, transparent);
  text-decoration-thickness: 1px;
}
ins.td-x {
  background: var(--add-hl);
  text-decoration: underline;
  text-decoration-color: var(--add-mk);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.td-eol {
  margin-left: 0.5rem;
  padding: 0 0.35rem;
  border: 1px solid var(--border-2);
  border-radius: 5px;
  color: var(--muted);
  font: 500 0.7rem/1.5 var(--font-body);
  white-space: nowrap;
}

.td-row.is-chg + .td-row:not(.is-chg) .td-c,
.td-row:not(.is-chg):not(.td-headrow) + .td-row.is-chg .td-c { box-shadow: inset 0 1px 0 var(--border); }
.td-row.is-current > .td-n:first-child { box-shadow: inset 3px 0 0 var(--lilac); }

.td-foldrow { grid-template-columns: minmax(0, 1fr) !important; }
.td-fold {
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  width: 100%;
  padding: 0.35rem 0.75rem;
  border: 0;
  border-block: 1px dashed var(--border-2);
  background: var(--surface-2);
  color: var(--link);
  font: 600 0.78rem/1.4 var(--font-body);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}
.td-fold:hover { background: var(--surface-3); color: var(--text); }
.td-fold .icon { width: 14px; height: 14px; }
.td-fold:focus-visible { outline-offset: -2px; }

.td-same { margin: 0; padding: 1rem; color: var(--muted); }

.td-chunk { content-visibility: auto; contain-intrinsic-size: auto 2100px; }
