/* Design tokens — inspired by open-source minimal systems (Inkwell / Purissimo) */

:root,
[data-theme="light"] {
  color-scheme: light;
  --font-sans: "DM Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --border: #e8e6e1;
  --border-strong: #d4d1ca;
  --text: #1a1917;
  --text-muted: #6b6860;
  --text-faint: #9c9890;
  --accent: #2d6a4f;
  --accent-hover: #1b4332;
  --accent-soft: #d8f3dc;
  --del-bg: #fde8e8;
  --del-text: #9b1c1c;
  --del-border: #f5c6c6;
  --add-bg: #e6f4ea;
  --add-text: #1e6b3c;
  --add-border: #b7dfc5;
  --highlight-ring: #f59e0b;
  --shadow: 0 1px 2px rgba(26, 25, 23, 0.04), 0 8px 32px rgba(26, 25, 23, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 180ms ease;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1917;
  --surface-2: #222120;
  --border: #2e2d2a;
  --border-strong: #3d3b37;
  --text: #f0eeeb;
  --text-muted: #a8a49c;
  --text-faint: #6b6860;
  --accent: #52b788;
  --accent-hover: #74c69d;
  --accent-soft: #1b3326;
  --del-bg: #3b1515;
  --del-text: #fca5a5;
  --del-border: #7f1d1d;
  --add-bg: #14291c;
  --add-text: #86efac;
  --add-border: #166534;
  --highlight-ring: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 32px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

/* Header */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.header__brand {
  display: flex;
  align-items: center;
}

.header__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* Card */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.card--dragover {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft);
}

.card__lead {
  margin: 0 0 1.25rem;
  font-size: 0.9375rem;
  color: var(--text-muted);
}

/* Editors */

.editors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.editor__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.375rem;
}

.editor__label {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.editor__stats {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-faint);
}

.editor__input {
  width: 100%;
  min-height: 200px;
  padding: 0.875rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  transition: border-color var(--transition), background var(--transition);
}

.editor__input::placeholder {
  color: var(--text-faint);
}

.editor__input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}

/* Toolbar */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.toolbar__options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
}

.toolbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.check input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.select-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.select-wrap__label {
  font-size: 0.8125rem;
  color: var(--text-faint);
}

.select {
  padding: 0.375rem 1.75rem 0.375rem 0.625rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6860' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
}

.select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

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

.btn--sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

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

.btn-icon--sm {
  width: 1.75rem;
  height: 1.75rem;
}

.btn-icon--theme {
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(26, 25, 23, 0.1);
}

[data-theme="light"] .btn-icon--theme {
  background: #ffffff;
  border-color: #b8b4ac;
  color: #1a1917;
  box-shadow: 0 1px 4px rgba(26, 25, 23, 0.14), 0 0 0 1px rgba(26, 25, 23, 0.04);
}

[data-theme="light"] .btn-icon--theme:hover {
  background: #f6f5f3;
  border-color: #9c9890;
  color: #1a1917;
}

#themeToggle svg {
  display: none;
  pointer-events: none;
}

[data-theme="light"] #themeToggle .icon-sun,
:root:not([data-theme]) #themeToggle .icon-sun {
  display: block;
}

[data-theme="dark"] #themeToggle .icon-moon {
  display: block;
}

/* Metrics */

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.metric {
  padding: 0.875rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}

.metric__value {
  display: block;
  font-size: 1.375rem;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.metric__value--add { color: var(--add-text); }
.metric__value--del { color: var(--del-text); }

.metric__label {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Result */

.result__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.result__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}

.result__controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-diff {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-right: 0.25rem;
}

.nav-diff__counter {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-width: 3.5rem;
  text-align: center;
}

.result__body {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.7;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: auto;
  max-height: 480px;
}

.diff-side {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: min-content;
}

.diff-col {
  padding: 1rem;
  border-right: 1px solid var(--border);
}

.diff-col:last-child {
  border-right: none;
}

.diff-col__label {
  display: block;
  margin-bottom: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
}

.diff-unified,
.diff-changes {
  padding: 1rem;
}

.diff-line {
  display: block;
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-line--equal {
  color: var(--text-muted);
}

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

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

.diff-chunk {
  border-radius: 3px;
  white-space: pre-wrap;
  word-break: break-word;
}

.diff-chunk--equal {
  color: var(--text);
}

.diff-chunk--del {
  background: var(--del-bg);
  color: var(--del-text);
  text-decoration: line-through;
  text-decoration-color: var(--del-border);
}

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

.diff-chunk--active {
  outline: 2px solid var(--highlight-ring);
  outline-offset: 1px;
}

.diff-line--active {
  outline: 2px solid var(--highlight-ring);
  outline-offset: -1px;
}

/* Empty state */

.empty {
  padding: 2.5rem 1rem;
  text-align: center;
}

.empty p {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-faint);
}

.empty[hidden],
.result[hidden],
.metrics[hidden] {
  display: none !important;
}

/* Toast */

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  background: var(--text);
  color: var(--bg);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 100;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Responsive */

@media (max-width: 720px) {
  .page {
    padding: 1.25rem 1rem 2rem;
  }

  .card {
    padding: 1rem;
  }

  .editors,
  .diff-side {
    grid-template-columns: 1fr;
  }

  .diff-col {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .diff-col:last-child {
    border-bottom: none;
  }

  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar__actions {
    justify-content: flex-end;
  }
}

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