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

/* Light theme (default) */
:root {
  --bg: #fafafa;
  --surface: #fff;
  --border: #ddd;
  --text: #1a1a1a;
  --text-secondary: #555;
  --accent: #0066cc;
  --accent-hover: #0052a3;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --radius: 6px;
  --del-bg: #ffeef0;
  --del-word-bg: #fdaeb7;
  --ins-bg: #e6ffec;
  --ins-word-bg: #acf2bd;
}

/* Dark theme values */
[data-theme="dark"] {
  --bg: #111;
  --surface: #1a1a1a;
  --border: #333;
  --text: #e5e5e5;
  --text-secondary: #999;
  --accent: #4da3ff;
  --accent-hover: #7dbdff;
  --error-bg: #2d1515;
  --error-text: #f87171;
  --del-bg: #3d1418;
  --del-word-bg: #6e2028;
  --ins-bg: #14301a;
  --ins-word-bg: #1f5e2a;
}

/* System preference when no explicit choice */
@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #111;
    --surface: #1a1a1a;
    --border: #333;
    --text: #e5e5e5;
    --text-secondary: #999;
    --accent: #4da3ff;
    --accent-hover: #7dbdff;
    --error-bg: #2d1515;
    --error-text: #f87171;
    --del-bg: #3d1418;
    --del-word-bg: #6e2028;
    --ins-bg: #14301a;
    --ins-word-bg: #1f5e2a;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 3rem 1rem;
}

/* Top bar */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

#theme-toggle:hover {
  color: var(--text);
  border-color: var(--text-secondary);
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

/* Explainer */
.explainer {
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.explainer p + p {
  margin-top: 0.5rem;
}

/* Options bar */
.options-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  cursor: pointer;
}

.option input[type="checkbox"] {
  cursor: pointer;
}

.view-toggle {
  display: flex;
  gap: 0;
  margin-left: auto;
}

.view-btn {
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}

.view-btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.view-btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
  border-left: none;
}

.view-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.view-btn:hover:not(.active) {
  color: var(--text);
  border-color: var(--text-secondary);
}

/* Input panes */
.input-panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.pane label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.pane textarea {
  width: 100%;
  height: 200px;
  padding: 0.6rem 0.8rem;
  font-size: 0.875rem;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", "Consolas", monospace;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  outline: none;
  line-height: 1.5;
}

.pane textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.2);
}

/* Action buttons */
.actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

#compare-btn {
  padding: 0.6rem 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}

#compare-btn:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--text-secondary);
}

/* Diff output */
#diff-output {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  background: var(--surface);
}

.diff-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", "Consolas", monospace;
  font-size: 0.8rem;
  line-height: 1.5;
}

.diff-table td {
  padding: 1px 8px;
  vertical-align: top;
  white-space: pre-wrap;
  word-break: break-all;
}

.line-num {
  width: 1px;
  min-width: 2.5em;
  text-align: right;
  color: var(--text-secondary);
  opacity: 0.6;
  user-select: none;
  padding-right: 8px !important;
  border-right: 1px solid var(--border);
}

.diff-prefix {
  width: 1px;
  min-width: 1.5em;
  text-align: center;
  user-select: none;
  font-weight: 700;
}

.diff-content {
  width: 100%;
}

/* Side-by-side specific */
.side-by-side .diff-content {
  width: 50%;
}

.side-by-side td:nth-child(2) {
  border-right: 2px solid var(--border);
}

/* Row colors */
.diff-delete {
  background: var(--del-bg);
}

.diff-insert {
  background: var(--ins-bg);
}

.diff-delete .diff-prefix {
  color: var(--error-text);
}

.diff-insert .diff-prefix {
  color: #22863a;
}

[data-theme="dark"] .diff-insert .diff-prefix {
  color: #56d364;
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] .diff-insert .diff-prefix {
    color: #56d364;
  }
}

/* Word-level highlights */
mark.word-delete {
  background: var(--del-word-bg);
  color: inherit;
  border-radius: 2px;
}

mark.word-insert {
  background: var(--ins-word-bg);
  color: inherit;
  border-radius: 2px;
}

/* Footer */
footer {
  max-width: 960px;
  margin: 2rem auto 0;
  padding: 1rem 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

footer a {
  color: var(--accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 600px) {
  .input-panes {
    grid-template-columns: 1fr;
  }

  .view-toggle {
    margin-left: 0;
  }

  .options-bar {
    gap: 0.75rem;
  }

  .side-by-side .diff-content {
    width: 100%;
  }
}
