:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --glow: rgba(37, 99, 235, 0.09);
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #1b2432;
  --muted: #66738a;
  --border: #e2e7ee;
  --border-strong: #cbd4e1;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(37, 99, 235, 0.07);
  --focus-ring: rgba(37, 99, 235, 0.28);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 10px 28px rgba(16, 24, 40, 0.06);
  --add-bg: #edfcf3;
  --add-text: #067647;
  --del-bg: #fef1f1;
  --del-text: #b42318;
  --word-ins: #a9f0c4;
  --word-del: #fbc6c6;
  --chip-bg: #f1f4f8;
  --empty: #f7f9fb;
  --radius: 14px;
  --radius-sm: 9px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117;
  --glow: rgba(79, 140, 255, 0.11);
  --panel: #151b24;
  --panel-2: #111720;
  --text: #e6eaf1;
  --muted: #98a2b3;
  --border: #252d39;
  --border-strong: #364152;
  --accent: #4f8cff;
  --accent-hover: #6ba0ff;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(79, 140, 255, 0.1);
  --focus-ring: rgba(79, 140, 255, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 16px 40px rgba(0, 0, 0, 0.28);
  --add-bg: rgba(18, 183, 106, 0.11);
  --add-text: #75e0a7;
  --del-bg: rgba(240, 68, 56, 0.11);
  --del-text: #fda29b;
  --word-ins: rgba(18, 183, 106, 0.32);
  --word-del: rgba(240, 68, 56, 0.32);
  --chip-bg: #1c2430;
  --empty: #10161e;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: radial-gradient(1100px 520px at 50% -220px, var(--glow), transparent 72%);
  background-repeat: no-repeat;
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p {
  margin: 0;
}

button,
textarea,
input {
  font-family: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  z-index: 100;
  padding: 9px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

.app {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: 22px clamp(12px, 2vw, 32px) 34px;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 2px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-logo {
  border-radius: 9px;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.28);
  flex: 0 0 auto;
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

.brand p {
  color: var(--muted);
  font-size: 12.5px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.privacy {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.privacy .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #12b76a;
  box-shadow: 0 0 0 3px rgba(18, 183, 106, 0.16);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--border-strong);
  background: var(--panel-2);
  color: var(--text);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

.icon-sun {
  display: none;
}

:root[data-theme="dark"] .icon-sun {
  display: block;
}

:root[data-theme="dark"] .icon-moon {
  display: none;
}

/* ---------- Cards ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.compare {
  margin-bottom: 16px;
}

/* ---------- Editors ---------- */

.panes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px minmax(0, 1fr);
  align-items: stretch;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.pane-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 10px 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}

.pane-head h2 {
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.pane-head .meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.clear-one {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0 0 2px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.clear-one:hover {
  opacity: 1;
  background: var(--del-bg);
  color: var(--del-text);
}

textarea {
  display: block;
  width: 100%;
  min-height: 218px;
  padding: 14px 16px;
  border: 0;
  border-radius: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  resize: vertical;
  tab-size: 4;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

textarea::placeholder {
  color: var(--muted);
  opacity: 0.65;
}

textarea:focus {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

textarea.dragover {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.pane-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--panel-2);
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
}

.options {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.toolbar-label {
  margin-right: 4px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.toggle:hover {
  background: var(--chip-bg);
  color: var(--text);
}

.toggle:has(input:checked) {
  border-color: var(--border);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

.toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    opacity 0.15s ease, transform 0.06s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--panel-2);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  cursor: default;
  opacity: 0.45;
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12);
}

.btn.primary:hover:not(:disabled) {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.btn.primary kbd {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.2);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.btn.ghost {
  background: transparent;
}

.btn.ghost:hover:not(:disabled) {
  background: var(--chip-bg);
}

.btn.small {
  padding: 6px 10px;
  font-size: 12.5px;
}

/* ---------- Differences ---------- */

.diff-section {
  scroll-margin-top: 16px;
}

.diff-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 14px 11px 16px;
  border-bottom: 1px solid var(--border);
}

.diff-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}

.diff-title h2 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat.add {
  background: var(--add-bg);
  color: var(--add-text);
}

.stat.del {
  background: var(--del-bg);
  color: var(--del-text);
}

.stat.ok {
  background: var(--add-bg);
  color: var(--add-text);
}

.view-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--chip-bg);
}

.view-toggle button {
  padding: 5px 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.view-toggle button:hover {
  color: var(--text);
}

.view-toggle button[aria-pressed="true"] {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.09);
}

.diff-body {
  max-height: min(62vh, 760px);
  min-height: 172px;
  overflow: auto;
  overscroll-behavior: contain;
  outline: none;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.diff-body:focus-visible {
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.diff-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 1.55em;
}

.cell {
  display: flex;
  min-width: 0;
  padding: 1px 0;
}

.cell.left {
  border-right: 1px solid var(--border);
}

.cell.equal {
  background: transparent;
}

.cell.del,
.cell.change.left {
  background: var(--del-bg);
}

.cell.ins,
.cell.change.right {
  background: var(--add-bg);
}

.cell.empty {
  background: var(--empty);
}

.cell .ln {
  flex: 0 0 3.7em;
  padding: 0 0.55em 0 0.35em;
  color: var(--muted);
  font-size: 11px;
  line-height: 2;
  text-align: right;
  opacity: 0.72;
  user-select: none;
}

.cell .code {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0 0.9em 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.w-del,
.w-ins {
  border-radius: 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.w-del {
  background: var(--word-del);
}

.w-ins {
  background: var(--word-ins);
}

.u-row {
  display: grid;
  grid-template-columns: 3.7em 3.7em 1.9em minmax(0, 1fr);
  min-height: 1.55em;
  padding: 1px 0;
}

.u-row.del {
  background: var(--del-bg);
}

.u-row.ins {
  background: var(--add-bg);
}

.u-row .ln {
  padding: 0 0.5em;
  color: var(--muted);
  font-size: 11px;
  line-height: 2;
  text-align: right;
  opacity: 0.72;
  user-select: none;
}

.u-row .sign {
  color: var(--muted);
  text-align: center;
  user-select: none;
}

.u-row.del .sign {
  color: var(--del-text);
}

.u-row.ins .sign {
  color: var(--add-text);
}

.u-row .code {
  min-width: 0;
  padding-right: 0.9em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.diff-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 240px;
  padding: 44px 24px;
  color: var(--muted);
  font-family: var(--sans);
  text-align: center;
}

.diff-empty svg {
  width: 44px;
  height: 44px;
  margin-bottom: 4px;
  opacity: 0.35;
}

.diff-empty p {
  font-size: 13.5px;
}

.diff-empty .hint {
  color: var(--muted);
  font-size: 12px;
  opacity: 0.82;
}

/* ---------- Footer & toast ---------- */

.foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 18px 8px 0;
  color: var(--muted);
  font-size: 11.5px;
}

.foot .sep {
  opacity: 0.55;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--panel);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.clipboard-helper {
  position: fixed;
  top: 0;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .app {
    padding-top: 16px;
  }

  .privacy {
    display: none;
  }

  .panes {
    grid-template-columns: minmax(0, 1fr);
  }

  .pane-divider {
    padding: 5px 0;
    border: 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  .pane-divider .icon-btn svg {
    transform: rotate(90deg);
  }

  textarea {
    min-height: 160px;
  }

  .diff-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .cell.empty,
  .cell.right.equal {
    display: none;
  }

  .cell.left {
    border-right: 0;
  }

  .cell.change.left,
  .cell.del {
    border-bottom: 1px dashed var(--border);
  }

  .diff-body {
    max-height: none;
  }

  .diff-empty {
    min-height: 190px;
  }
}

@media (max-width: 560px) {
  .brand p {
    display: none;
  }

  .toolbar,
  .diff-head {
    align-items: stretch;
  }

  .toolbar-actions {
    width: 100%;
  }

  .toolbar-actions .btn {
    flex: 1 1 auto;
  }

  .btn.primary kbd {
    display: none;
  }

  .diff-title {
    gap: 8px;
  }

  .view-toggle {
    order: 2;
  }

  .diff-head .btn.small {
    order: 3;
    margin-left: auto;
  }

  .options {
    gap: 2px;
  }

  .toolbar-label {
    display: none;
  }

  .cell .ln {
    flex-basis: 3.1em;
  }

  .u-row {
    grid-template-columns: 3.1em 3.1em 1.5em minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
