:root {
  --bg: #0d1117;
  --bg-pane: #0f141b;
  --bg-header: #161b22;
  --border: #2d333b;
  --text: #c9d1d9;
  --text-dim: #8b949e;
  --gutter-bg: #11161d;
  --gutter-text: #6e7681;
  --accent: #58a6ff;

  --add-bg: rgba(46, 160, 67, 0.22);
  --add-inline: rgba(46, 160, 67, 0.45);
  --del-bg: rgba(248, 81, 73, 0.20);
  --del-inline: rgba(248, 81, 73, 0.45);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

/* Header / toolbar */
.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 0.6rem 1rem;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
}

.app-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.app-title::before {
  content: "\270E";
  margin-right: 0.4rem;
  color: var(--accent);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-left: auto;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
  color: var(--text-dim);
}

.toggle input { cursor: pointer; accent-color: var(--accent); }

.diff-summary {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 9ch;
}

.btn {
  background: #21262d;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn:hover { background: #30363d; }
.btn:active { background: #282e36; }

/* Panes */
.panes {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  background: var(--bg-pane);
  min-width: 0;
  min-height: 0;
}

.pane-header {
  flex: 0 0 auto;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-header);
}

.pane-label {
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.6px;
}

/* Editor: textarea (input) overlaid by diff-view (rendered output) */
.editor {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.input,
.diff-view {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0.5rem 0.75rem 0.5rem 0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 20px;
  tab-size: 4;
  border: 0;
  overflow: auto;
}

/* The textarea sits on top, transparent text, so the user edits directly.
   The diff-view underneath shows numbered lines + highlights. */
.input {
  z-index: 2;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  resize: none;
  white-space: pre;
  padding-left: 3.5rem;
}

.input::selection { background: rgba(88, 166, 255, 0.30); }
.input:focus { outline: none; }

.diff-view {
  z-index: 1;
  white-space: pre;
  color: var(--text);
  pointer-events: none;
}

/* Word wrap mode */
.wrap .input,
.wrap .diff-view {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Rendered lines */
.line {
  display: flex;
  min-height: 20px;
}

.gutter {
  flex: 0 0 3.5rem;
  position: sticky;
  left: 0;
  padding: 0 0.5rem 0 0;
  text-align: right;
  color: var(--gutter-text);
  background: var(--gutter-bg);
  user-select: none;
  font-variant-numeric: tabular-nums;
}

.content {
  flex: 1 1 auto;
  padding-left: 0.25rem;
  min-width: 0;
}

.wrap .content { white-space: pre-wrap; }

/* Diff states */
.line.added .content { background: var(--add-bg); }
.line.removed .content { background: var(--del-bg); }
.line.empty .content { background: rgba(110, 118, 129, 0.08); }

.line.added .gutter { background: var(--add-bg); }
.line.removed .gutter { background: var(--del-bg); }

/* Inline (word-level) highlighting */
.tok-add { background: var(--add-inline); border-radius: 2px; }
.tok-del { background: var(--del-inline); border-radius: 2px; }

/* Footer */
.app-footer {
  flex: 0 0 auto;
  padding: 0.4rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-header);
  color: var(--text-dim);
  font-size: 0.78rem;
}

@media (max-width: 720px) {
  .panes { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .toolbar { gap: 0.6rem; }
}
