:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #d9dce1;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #3b6fd4;
  --topbar: #24292f;
  --topbar-text: #f6f8fa;
  --gutter-bg: #f6f8fa;
  --added: rgba(46, 160, 67, 0.22);
  --added-strong: #2da44e;
  --removed: rgba(207, 34, 46, 0.2);
  --removed-strong: #cf222e;
  --changed: rgba(212, 167, 44, 0.3);
  --changed-strong: #bf8700;
  --error: rgba(207, 34, 46, 0.45);
  --tok-key: #0550ae;
  --tok-str: #0a3069;
  --tok-num: #953800;
  --tok-lit: #8250df;
  --tok-punc: #656d76;
  --line: 20px;
  --pad: 8px;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  --gutter-w: 44px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --border: #30363d;
    --text: #e6edf3;
    --muted: #8d96a0;
    --accent: #6ea8fe;
    --topbar: #010409;
    --topbar-text: #e6edf3;
    --gutter-bg: #0d1117;
    --added: rgba(63, 185, 80, 0.25);
    --added-strong: #3fb950;
    --removed: rgba(248, 81, 73, 0.25);
    --removed-strong: #f85149;
    --changed: rgba(210, 153, 34, 0.3);
    --changed-strong: #d29922;
    --error: rgba(248, 81, 73, 0.5);
    --tok-key: #79c0ff;
    --tok-str: #a5d6ff;
    --tok-num: #ffa657;
    --tok-lit: #d2a8ff;
    --tok-punc: #8d96a0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 10px 16px;
  background: var(--topbar);
  color: var(--topbar-text);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 600; }
.tagline { font-size: 12px; opacity: 0.7; }
.indent { margin-left: auto; font-size: 13px; }
.indent select {
  margin-left: 6px;
  padding: 3px 4px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  background: transparent;
  color: var(--topbar-text);
  font: inherit;
}
.indent option { background: var(--surface); color: var(--text); }
.wrap-toggle { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; cursor: pointer; }
.share {
  padding: 4px 14px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  background: transparent;
  color: var(--topbar-text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.share:hover { background: rgba(255, 255, 255, 0.12); }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.pane.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }

.pane-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.pane-title { font-weight: 600; }
.pane-status { margin-left: auto; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-status.error { color: var(--removed-strong); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button, .tool {
  padding: 2px 10px;
  border: 0;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.tool { border: 1px solid var(--border); border-radius: 6px; }
.tool:hover, .seg button[aria-pressed="false"]:hover { color: var(--accent); }
.text-tools, .tree-tools { display: inline-flex; gap: 4px; }

.editor { flex: 1; min-height: 0; display: flex; }

.gutter {
  flex: none;
  min-width: 44px;
  overflow: hidden;
  background: var(--gutter-bg);
  border-right: 1px solid var(--border);
  color: var(--muted);
  text-align: right;
  user-select: none;
}
.gutter-inner, .backdrop-inner, textarea {
  font-family: var(--mono);
  font-size: 13px;
  line-height: var(--line);
  tab-size: 2;
}
.gutter-inner { padding: var(--pad) 8px var(--pad) 6px; }
.gutter-inner span { display: block; }
.gutter-inner .added { box-shadow: inset 3px 0 var(--added-strong); }
.gutter-inner .removed { box-shadow: inset 3px 0 var(--removed-strong); }
.gutter-inner .changed { box-shadow: inset 3px 0 var(--changed-strong); }

.code { position: relative; flex: 1; min-width: 0; }

.backdrop { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.backdrop-inner {
  padding: var(--pad);
  white-space: pre;
  color: var(--text);
  will-change: transform;
}
.backdrop-inner mark { color: inherit; border-radius: 2px; }
.backdrop-inner mark.added { background: var(--added); }
.backdrop-inner mark.removed { background: var(--removed); }
.backdrop-inner mark.changed { background: var(--changed); }
.backdrop-inner mark.error { background: var(--error); }
.backdrop-inner mark.current { outline: 2px solid var(--accent); outline-offset: 0; }

textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: var(--pad);
  border: 0;
  outline: none;
  resize: none;
  white-space: pre;
  overflow: auto;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
}

.middle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 24px;
  text-align: center;
  font-size: 13px;
}
/* Summary and path keep a fixed height so the controls below them do not move as the text changes. */
.summary { min-height: 4.2em; font-weight: 600; }
.summary.same { color: var(--added-strong); }
.nav { display: flex; align-items: center; gap: 8px; }
.nav button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}
.nav button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.nav button:disabled { opacity: 0.4; cursor: default; }
#position { min-width: 44px; font-variant-numeric: tabular-nums; }
.current-path {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  max-width: 100%;
  height: 2.8em;
  overflow: hidden;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; color: var(--muted); }
.options {
  display: grid;
  gap: 10px;
  width: 100%;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  text-align: left;
  font-size: 12px;
}
.options .check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.options .field { display: grid; gap: 4px; color: var(--muted); }
.options .field input {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
}
.options .tool { padding: 4px 8px; }
.options .tool:disabled { opacity: 0.5; cursor: default; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 2px; }
.swatch.added { background: var(--added-strong); }
.swatch.removed { background: var(--removed-strong); }
.swatch.changed { background: var(--changed-strong); }

textarea::selection { background: rgba(59, 111, 212, 0.3); }

/* Wrap mode: the gutter column is drawn inside the editor so line numbers can follow wrapped lines. */
.editor.wrap .gutter { display: none; }
.editor.wrap .backdrop {
  background: linear-gradient(to right,
    var(--gutter-bg) var(--gutter-w), var(--border) var(--gutter-w) calc(var(--gutter-w) + 1px), transparent 0);
}
.editor.wrap textarea, .editor.wrap .backdrop-inner {
  padding-left: calc(var(--gutter-w) + 1px + var(--pad));
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.editor.wrap textarea { overflow-x: hidden; }
.ln { position: relative; min-height: var(--line); }
.ln::before {
  content: attr(data-n);
  position: absolute;
  left: calc(-1px - var(--pad) - var(--gutter-w));
  width: var(--gutter-w);
  padding-right: 8px;
  text-align: right;
  color: var(--muted);
}
.ln.added::before { box-shadow: inset 3px 0 var(--added-strong); }
.ln.removed::before { box-shadow: inset 3px 0 var(--removed-strong); }
.ln.changed::before { box-shadow: inset 3px 0 var(--changed-strong); }

.t-key { color: var(--tok-key); }
.t-str { color: var(--tok-str); }
.t-num { color: var(--tok-num); }
.t-lit { color: var(--tok-lit); }
.t-punc, .t-index, .count { color: var(--tok-punc); }

.tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: var(--pad) 0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: var(--line);
  white-space: nowrap;
}
.tree .row { display: block; padding: 0 10px 0 22px; border-radius: 2px; }
.tree summary.row { position: relative; cursor: pointer; list-style: none; }
.tree summary.row::-webkit-details-marker { display: none; }
.tree summary.row::before {
  content: "\25B8";
  position: absolute;
  left: 8px;
  color: var(--muted);
}
.tree details[open] > summary.row::before { content: "\25BE"; }
.tree summary.row.dirty::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--changed-strong);
  vertical-align: middle;
}
.tree .children { margin-left: 13px; border-left: 1px solid var(--border); }
.tree .row.added { background: var(--added); }
.tree .row.removed { background: var(--removed); }
.tree .row.changed { background: var(--changed); }
.tree .row.current { outline: 2px solid var(--accent); outline-offset: -2px; }
.tree .row:not(.added, .removed, .changed):hover { background-color: rgba(127, 127, 127, 0.1); }
.tree-empty { margin: 0; padding: 0 12px; color: var(--muted); font-family: system-ui, sans-serif; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 16px;
  border-radius: 6px;
  background: var(--topbar);
  color: var(--topbar-text);
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

@media (max-width: 760px) {
  .tagline { display: none; }
  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(240px, 1fr) auto minmax(240px, 1fr);
  }
  .middle { flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 4px 0; }
  .summary { min-height: 0; }
  .current-path { flex-basis: 100%; }
  .legend { display: flex; gap: 12px; }
  .options { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); align-items: end; }
}
