:root {
  /* Dark theme — Catppuccin Macchiato */
  --bg: #24273a; /* Base */
  --bg-secondary: #1e2030; /* Mantle */
  --bg-tertiary: #2b2f47; /* between Base and Surface 0 */
  --border: #494d64; /* Surface 1 */
  --text: #b8c0e0; /* Subtext 1 (softer than Text) */
  --text-muted: #8087a2; /* Overlay 1 (softer muted) */
  --accent: #8aadf4; /* Blue */
  --success: #a6da95; /* Green */
  --error: #ed8796; /* Red */
  --warning: #f5a97f; /* Peach */
  --info: #7dc4e4; /* Sky */
  --mauve: #c6a0f6; /* Mauve */
  --font-mono: "JetBrains Mono", "Fira Code", "Courier New", monospace;
  --font-sans: "Source Sans Pro", "Microsoft Yahei", sans-serif;
  --font-heading: "Lato", "Microsoft Yahei", sans-serif;
  --radius: 6px;
}

@media (prefers-color-scheme: light) {
  :root {
    /* Light theme — Catppuccin Latte */
    --bg: #eff1f5; /* Base */
    --bg-secondary: #e6e9ef; /* Mantle */
    --bg-tertiary: #e6e9ef; /* Mantle (closer to Base) */
    --border: #bcc0cc; /* Surface 1 */
    --text: #5c5f77; /* Subtext 1 (softer than Text) */
    --text-muted: #8c8fa1; /* Overlay 1 (softer muted) */
    --accent: #1e66f5; /* Blue */
    --success: #40a02b; /* Green */
    --error: #d20f39; /* Red */
    --warning: #fe640b; /* Peach */
    --info: #04a5e5; /* Sky */
    --mauve: #8839ef; /* Mauve */
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border: 2px solid var(--bg);
  border-radius: 6px;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.dragging {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
}

header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  font-family: var(--font-mono);
}

header h1 span {
  color: var(--accent);
}

.header-file {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Toolbar ───────────────────────────────────────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.result-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
}

/* ── Status bar ────────────────────────────────────────────────────────────── */

.status {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  max-height: 28vh;
  overflow-y: auto;
  flex-shrink: 0;
}

.status-head {
  font-family: var(--font-mono);
  font-size: 12px;
}
.status-ok .status-head {
  color: var(--success);
}
.status-bad .status-head {
  color: var(--error);
}

.err {
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--error);
  overflow-wrap: anywhere;
}
.err:hover {
  text-decoration: underline;
}
.err:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.err-more {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Layout ────────────────────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel {
  min-width: 0;
  overflow: auto;
}
.panel-left {
  border-right: 1px solid var(--border);
  display: flex;
  overflow: hidden;
}
.panel-right {
  padding: 10px 14px;
}

#editor {
  flex: 1;
  border: none;
  border-radius: 0;
  resize: none;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  padding: 10px 14px;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}
#editor:focus {
  border-color: transparent;
}

/* ── Tree ──────────────────────────────────────────────────────────────────── */

.tree {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.7;
}

.tree-empty {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text-muted);
}

.node > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  gap: 8px;
  align-items: baseline;
  border-radius: 3px;
  padding: 0 4px;
}
.node > summary::-webkit-details-marker {
  display: none;
}
.node > summary::before {
  content: "\25b8";
  color: var(--text-muted);
  font-size: 10px;
  width: 10px;
  flex-shrink: 0;
}
.node[open] > summary::before {
  content: "\25be";
}
.node > summary:hover {
  background: var(--bg-tertiary);
}
.node > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.kids {
  margin-left: 12px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}

.kids-more {
  color: var(--text-muted);
  font-size: 11px;
  padding-left: 18px;
}

.leaf {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 0 4px 0 18px;
  border-radius: 3px;
}
.leaf:hover {
  background: var(--bg-tertiary);
}

.node-key {
  color: var(--accent);
  flex-shrink: 0;
}

.node-count {
  color: var(--text-muted);
  font-size: 11px;
}

.node-val {
  overflow-wrap: anywhere;
}
.val-string {
  color: var(--success);
}
.val-number {
  color: var(--warning);
}
.val-boolean {
  color: var(--mauve);
}
.val-null {
  color: var(--text-muted);
}
.val-object,
.val-array {
  color: var(--text-muted);
  font-size: 11px;
}

/* ── Form controls ─────────────────────────────────────────────────────────── */

select,
textarea {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.15s;
}

select:focus,
textarea:focus {
  border-color: var(--accent);
}

select {
  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 12 12'%3E%3Cpath fill='%23656d76' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
  font-size: 13px;
  padding-top: 4px;
  padding-bottom: 4px;
}

.btn {
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 14px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.btn-secondary {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.hidden {
  display: none !important;
}

footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}

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

footer code {
  font-family: var(--font-mono);
  font-size: 12px;
}

@media (max-width: 900px) {
  body {
    height: auto;
    overflow: visible;
  }
  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .panel-left {
    border-right: none;
    border-bottom: 1px solid var(--border);
    min-height: 40vh;
  }
}

@media (max-width: 700px) {
  footer {
    flex-direction: column;
    align-items: flex-start;
    font-size: 13px;
  }
}
