:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e6;
  --text: #1f2328;
  --muted: #6b7380;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --del-bg: #ffecec;
  --del-mark: #ffb8b8;
  --ins-bg: #e6f9ec;
  --ins-mark: #a6e9bc;
  --gap-bg: #eef2f8;
  --gap-text: #4a5568;
  --ln: #8b939e;
  --current: #f5b301;
  --rem-text: #d1242f;
  --add-text: #1a7f37;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e232b;
    --border: #2c333d;
    --text: #e3e6ea;
    --muted: #8d96a3;
    --accent: #4c8dff;
    --del-bg: #3a1d21;
    --del-mark: #7a2b33;
    --ins-bg: #16301f;
    --ins-mark: #24613a;
    --gap-bg: #1b2230;
    --gap-text: #a7b1c2;
    --ln: #5f6874;
    --rem-text: #ff7b7b;
    --add-text: #56d47f;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e232b;
  --border: #2c333d;
  --text: #e3e6ea;
  --muted: #8d96a3;
  --accent: #4c8dff;
  --del-bg: #3a1d21;
  --del-mark: #7a2b33;
  --ins-bg: #16301f;
  --ins-mark: #24613a;
  --gap-bg: #1b2230;
  --gap-text: #a7b1c2;
  --ln: #5f6874;
  --rem-text: #ff7b7b;
  --add-text: #56d47f;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; padding: 0 16px 24px; }

button, select, input, textarea { font: inherit; color: inherit; }

.spacer { flex: 1; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.tagline { margin: 0; color: var(--muted); font-size: 13px; flex: 1; min-width: 200px; }
.top-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Buttons ---------- */
.btn, .icon-btn, .seg button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 7px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover, .icon-btn:hover, .seg button:hover { border-color: var(--muted); }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn.ghost { background: transparent; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  padding: 7px 20px;
}
.btn.primary:hover { filter: brightness(1.08); }
.icon-btn { padding: 4px 9px; min-width: 32px; justify-content: center; }
.icon-btn:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; padding: 4px 10px; font-size: 13px; }
.seg button:first-child { border-radius: 7px 0 0 7px; margin-left: 0; }
.seg button:last-child { border-radius: 0 7px 7px 0; }
.seg button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); position: relative; }

/* ---------- Inputs ---------- */
.inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.pane.dragover { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.pane-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.pane-title { font-weight: 600; }
.pane-count { color: var(--muted); font-size: 12.5px; }
.pane textarea {
  border: 0;
  outline: none;
  resize: vertical;
  min-height: 160px;
  height: 34vh;
  padding: 10px 12px;
  background: var(--surface);
  font: 13px/1.5 var(--mono);
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

/* ---------- Options ---------- */
.options, .result-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 12px 2px;
}
.options .actions { display: flex; gap: 10px; margin-left: auto; }
.opt { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; }
.opt select {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 7px;
  padding: 4px 6px;
}
.opt.check { cursor: pointer; user-select: none; }
.opt.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }

/* ---------- Result ---------- */
.result { margin-top: 4px; }
.result-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 2px;
}
.stats { display: flex; gap: 12px; font-size: 13.5px; font-weight: 600; flex-wrap: wrap; }
.stats .rem { color: var(--rem-text); }
.stats .add { color: var(--add-text); }
.stats .blk { color: var(--muted); font-weight: 500; }
.stats .same { color: var(--muted); }
.stats .fmt-note { color: var(--muted); font-weight: 400; font-size: 12.5px; }
.diff-wrap .msg.error { color: var(--rem-text); }
.stale-note { color: var(--current); font-size: 13px; }
.nav { display: inline-flex; align-items: center; gap: 6px; }
.nav-pos { font-size: 13px; color: var(--muted); min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
#contextWrap.disabled, #turkishWrap.disabled { opacity: .45; }

.diff-wrap {
  margin-top: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: auto;
}
.diff-wrap .msg { padding: 28px; text-align: center; color: var(--muted); }

table.diff {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font: 12.5px/1.55 var(--mono);
  tab-size: 4;
}
table.diff col.ln { width: 52px; }
table.diff col.sign { width: 22px; }
table.diff td { padding: 0 8px; vertical-align: top; }
table.diff td.ln {
  color: var(--ln);
  text-align: right;
  user-select: none;
  font-size: 11.5px;
  padding-top: 1px;
  border-right: 1px solid var(--border);
}
table.diff td.code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
table.diff.split td.code.a { border-right: 1px solid var(--border); }
table.diff td.sign { user-select: none; color: var(--muted); text-align: center; padding: 0; }

td.del, tr.u-del td { background: var(--del-bg); }
td.ins, tr.u-ins td { background: var(--ins-bg); }
td.empty { background: repeating-linear-gradient(-45deg, transparent 0 6px, var(--surface-2) 6px 8px); }
td.muted, tr.u-skip td.code { color: var(--muted); }
mark { color: inherit; border-radius: 2px; }
td.del mark, tr.u-del mark { background: var(--del-mark); }
td.ins mark, tr.u-ins mark { background: var(--ins-mark); }

tr.gap td {
  background: var(--gap-bg);
  padding: 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
tr.gap button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--gap-text);
  font: 12px var(--sans);
  padding: 5px 12px;
  cursor: pointer;
  text-align: left;
}
tr.gap button:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

tr.current td.ln { box-shadow: inset 3px 0 0 var(--current); }

/* In the split view, select text from one column only */
table.diff.sel-a td.code.b, table.diff.sel-b td.code.a { user-select: none; }

.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 14px 16px 18px; }

/* ---------- Narrow screens ---------- */
@media (max-width: 820px) {
  .inputs { grid-template-columns: 1fr; }
  .pane textarea { height: 24vh; }
  .tagline { order: 3; flex-basis: 100%; }
  table.diff col.ln { width: 38px; }
  table.diff td { padding: 0 4px; }
}
