:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --line: #d9dee8;
  --text: #18202f;
  --muted: #637083;
  --accent: #ffe082;
  --accent-strong: #f3b82f;
  --danger: #b42318;
  --danger-bg: #fff0ed;
  --focus: #2563eb;
  --gutter-width: 52px;
  --editor-pad-y: 18px;
  --editor-pad-x: 20px;
  --btn-bg: #ffffff;
  --btn-text: var(--text);
  --btn-border: var(--line);
  --btn-hover: #f1f3f7;
  --shadow: rgba(24, 32, 47, 0.05);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --line: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #453b1b;
  --accent-strong: #fbbf24;
  --danger: #f87171;
  --danger-bg: #450a0a;
  --focus: #3b82f6;
  --btn-bg: #334155;
  --btn-text: #f1f5f9;
  --btn-border: #475569;
  --btn-hover: #475569;
  --shadow: rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  transition: background-color 0.2s, color 0.2s;
}

.app {
  width: min(1440px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 20px 24px 24px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.topbar {
  min-height: 46px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

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

.heading {
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border: 1px solid var(--btn-border);
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--btn-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

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

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

.btn-small {
  padding: 4px 8px;
  font-size: 12px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
}

.status {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.status.is-error {
  color: var(--danger);
  background: var(--danger-bg);
}

.compare-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.pane {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 30px var(--shadow);
}

.pane-header {
  min-height: 44px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pane-header h2 {
  font-size: 14px;
  font-weight: 650;
}

.pane-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.count {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
}

.editor-shell {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--surface);
}

.line-numbers {
  position: absolute;
  top: 0; bottom: 0; left: 0;
  z-index: 2;
  width: var(--gutter-width);
  padding: var(--editor-pad-y) 10px 20px 8px;
  border-right: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  font: 15px/1.65 monospace;
  text-align: right;
  white-space: pre;
  overflow: hidden;
  user-select: none;
}

.highlight-layer,
textarea {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  left: var(--gutter-width);
  width: calc(100% - var(--gutter-width));
  height: 100%;
  margin: 0;
  border: 0;
  padding: var(--editor-pad-y) var(--editor-pad-x) 20px;
  font: 15px/1.65 monospace;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

.highlight-layer {
  z-index: 0;
  color: var(--text);
  pointer-events: none;
  background: var(--surface);
  overflow: hidden; /* Scroll is handled by textarea */
}

textarea {
  z-index: 1;
  background: transparent;
  color: var(--text);
  -webkit-text-fill-color: currentColor;
  caret-color: var(--text);
  resize: none;
  outline: none;
}

html.is-enhanced textarea {
  color: transparent;
  -webkit-text-fill-color: transparent;
}

textarea::placeholder {
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
}

.highlight-layer mark {
  background: var(--accent);
  color: inherit;
  border-radius: 2px;
}

.diff-format-line {
  display: inline-block;
  width: 0.75em;
  height: 1.15em;
  margin: 0 1px;
  border-radius: 2px;
  background: var(--accent-strong);
  opacity: 0.45;
  vertical-align: -0.15em;
}

.pane.is-locked {
  background: var(--bg);
  opacity: 0.8;
}

.pane.is-locked .editor-shell,
.pane.is-locked .highlight-layer {
  background: var(--bg);
}

@media (max-width: 820px) {
  .compare-grid {
    grid-template-columns: 1fr;
  }
}
