/* ===== CSS Variables & Theme ===== */
:root {
  --bg: #f8f9fc;
  --bg-panel: #ffffff;
  --bg-toolbar: #ffffff;
  --bg-header: #ffffff;
  --bg-footer: #f1f3f8;
  --bg-code: #f6f8fa;
  --bg-hover: #f0f2f7;
  --bg-input: #ffffff;
  --border: #e2e5ee;
  --border-focus: #4f7df9;
  --text: #1a1d27;
  --text-muted: #6b7280;
  --text-code: #24292e;
  --accent: #4f7df9;
  --accent-hover: #3b6ae8;
  --accent-soft: #e8eeff;
  --success: #22c55e;
  --success-bg: #ecfdf5;
  --error: #ef4444;
  --error-bg: #fef2f2;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --radius: 8px;
  --radius-sm: 6px;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  /* syntax */
  --syn-key: #0550ae;
  --syn-string: #0a3069;
  --syn-number: #0550ae;
  --syn-bool: #cf222e;
  --syn-null: #8250df;
  --syn-bracket: #6b7280;
  --line-num-bg: #f1f3f8;
  --line-num-text: #9ca3af;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-panel: #161b22;
  --bg-toolbar: #161b22;
  --bg-header: #161b22;
  --bg-footer: #0d1117;
  --bg-code: #1c2128;
  --bg-hover: #1f2937;
  --bg-input: #1c2128;
  --border: #30363d;
  --border-focus: #58a6ff;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-code: #e6edf3;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-soft: #1a2742;
  --success: #3fb950;
  --success-bg: #0d2117;
  --error: #f85149;
  --error-bg: #2d1117;
  --warning: #d29922;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,.3);
  --syn-key: #79c0ff;
  --syn-string: #a5d6ff;
  --syn-number: #79c0ff;
  --syn-bool: #ff7b72;
  --syn-null: #d2a8ff;
  --syn-bracket: #8b949e;
  --line-num-bg: #161b22;
  --line-num-text: #484f58;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  transition: background .2s, color .2s;
}

/* ===== Header ===== */
.header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 10;
}
.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
}
.logo h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.02em;
}
.ampersand { color: var(--accent); }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* Buy Me a Coffee button */
.bmc-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  background: #ffdd00;
  color: #000;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: transform .15s, box-shadow .15s;
}
.bmc-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,.12); }

/* Theme toggle */
.icon-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { border-color: var(--accent); }

[data-theme="light"] .moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: none; }

/* ===== Toolbar ===== */
.toolbar {
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  flex-shrink: 0;
}
.toolbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 100%;
  flex-wrap: wrap;
}
.toolbar-group { display: flex; align-items: center; gap: 6px; }
.toolbar-info { margin-left: auto; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn svg { flex-shrink: 0; }

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

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn-secondary.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }

/* Status badge */
.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  transition: all .2s;
}
.status-badge.valid { background: var(--success-bg); color: var(--success); }
.status-badge.invalid { background: var(--error-bg); color: var(--error); }
.status-badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.status-badge:empty { display: none; }
.status-badge:empty::before { display: none; }

/* ===== Main Panels ===== */
.main { flex: 1; padding: 16px 24px; min-height: 0; }
.panels {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  gap: 0;
  height: 100%;
}
.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-code);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.panel-hint { font-size: 12px; color: var(--text-muted); }
.panel-body { flex: 1; position: relative; overflow: hidden; display: flex; }

/* Line numbers */
.line-numbers {
  width: 44px;
  flex-shrink: 0;
  background: var(--line-num-bg);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--line-num-text);
  text-align: right;
  overflow: hidden;
  user-select: none;
}
.line-numbers span {
  display: block;
  padding: 0 8px 0 0;
}

/* Textarea */
.code-textarea {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  background: var(--bg-input);
  color: var(--text-code);
  tab-size: 2;
}
.code-textarea::placeholder { color: var(--text-muted); opacity: .6; }

/* Output */
.code-output {
  flex: 1;
  margin: 0;
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  background: var(--bg-input);
  color: var(--text-code);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Syntax highlighting */
.syn-key { color: var(--syn-key); }
.syn-string { color: var(--syn-string); }
.syn-number { color: var(--syn-number); }
.syn-bool { color: var(--syn-bool); }
.syn-null { color: var(--syn-null); }
.syn-bracket { color: var(--syn-bracket); }
.syn-error { color: var(--error); }

/* ===== Tree View ===== */
.tree-view {
  flex: 1;
  padding: 12px 16px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  background: var(--bg-input);
}
.tree-view.hidden { display: none; }

.tree-item { padding-left: 20px; }
.tree-toggle {
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tree-toggle:hover { color: var(--accent); }
.tree-toggle::before {
  content: '▶';
  display: inline-block;
  font-size: 9px;
  transition: transform .15s;
  width: 12px;
}
.tree-toggle.open::before { transform: rotate(90deg); }
.tree-key { color: var(--syn-key); font-weight: 500; }
.tree-string { color: var(--syn-string); }
.tree-number { color: var(--syn-number); }
.tree-bool { color: var(--syn-bool); }
.tree-null { color: var(--syn-null); font-style: italic; }
.tree-bracket { color: var(--syn-bracket); font-size: 11px; }
.tree-children { overflow: hidden; }
.tree-children.collapsed { display: none; }
.tree-leaf { padding-left: 32px; }

/* ===== Resize Handle ===== */
.resize-handle {
  width: 8px;
  cursor: col-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}
.resize-dots {
  width: 3px;
  height: 24px;
  background: radial-gradient(circle, var(--text-muted) 1px, transparent 1px);
  background-size: 3px 6px;
  opacity: .4;
  transition: opacity .15s;
}
.resize-handle:hover .resize-dots { opacity: .8; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 1000;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.hidden { display: block; }

/* ===== Footer ===== */
.footer {
  background: var(--bg-footer);
  border-top: 1px solid var(--border);
  padding: 0 24px;
  height: 44px;
  flex-shrink: 0;
}
.footer-inner {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  gap: 16px;
}
.privacy-note {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}
.shortcuts-hint { font-size: 12px; color: var(--text-muted); }
kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: inset 0 -1px 0 var(--border);
}
.bmc-link {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color .15s;
}
.bmc-link:hover { color: var(--accent); }

/* ===== Error display ===== */
.error-display {
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.error-line {
  color: var(--error);
  font-weight: 600;
  margin-bottom: 8px;
}
.error-context {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
}
.error-context .line-highlight {
  background: var(--error-bg);
  display: block;
  margin: 0 -12px;
  padding: 0 12px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header { padding: 0 16px; }
  .logo h1 { font-size: 14px; }
  .bmc-btn span { display: none; }
  .toolbar { padding: 0 16px; height: auto; padding-top: 8px; padding-bottom: 8px; }
  .toolbar-inner { gap: 4px; }
  .btn { padding: 6px 10px; font-size: 12px; }
  .btn svg { display: none; }
  .main { padding: 8px 16px; }
  .panels { flex-direction: column; }
  .panel { min-height: 200px; }
  .resize-handle {
    width: 100%;
    height: 8px;
    cursor: row-resize;
  }
  .resize-dots {
    width: 24px;
    height: 3px;
    background-size: 6px 3px;
  }
  .footer { padding: 0 16px; height: auto; padding-top: 8px; padding-bottom: 8px; }
  .footer-inner { flex-direction: column; gap: 4px; text-align: center; }
  .shortcuts-hint { display: none; }
}

@media (max-width: 480px) {
  .bmc-btn { font-size: 0; padding: 7px; }
  .bmc-btn svg { width: 20px; height: 20px; }
  .toolbar-group { flex-wrap: wrap; }
}
