:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --border: #d9e1ec;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #e8f0ff;
  --editor-bg: #fbfdff;
  --editor-text: #111827;
  --line-bg: #f3f6fb;
  --line-text: #94a3b8;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --error-bg: #fff4f4;
  --error-border: #f1b7b7;
  --error-text: #b42318;
  --key-color: #c2185b;
  --string-color: #15803d;
  --number-color: #2563eb;
  --bool-color: #7c3aed;
  --null-color: #ea580c;
}

body.dark {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #111827;
  --panel-soft: #172033;
  --border: #253049;
  --text: #e5edf7;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --accent-soft: #1d4f91;
  --editor-bg: #0b1220;
  --editor-text: #e2e8f0;
  --line-bg: #121b2d;
  --line-text: #64748b;
  --shadow: 0 14px 36px rgba(2, 6, 23, 0.35);
  --error-bg: #2b1417;
  --error-border: #7a2731;
  --error-text: #fda4af;
  --key-color: #f472b6;
  --string-color: #4ade80;
  --number-color: #60a5fa;
  --bool-color: #a78bfa;
  --null-color: #fb923c;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "Oxygen",
    "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  transition: background-color 0.2s ease, color 0.2s ease;
}

.app {
  height: 100vh;
  padding: 0;
}

.shell {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: none;
  border-radius: 0;
  overflow: hidden;
  box-shadow: none;
}

.theme-btn,
.tool-btn,
.collapse-toggle {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: all 0.18s ease;
}

.theme-btn {
  /* 保留：如果未来还要单独放主题切换 */
  min-width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 10px;
  font-size: 12px;
  display: grid;
  place-items: center;
}

.theme-btn:hover,
.tool-btn:hover,
.collapse-toggle:hover {
  background: var(--accent-soft);
}

.theme-btn.active,
.tool-btn.active {
  background: var(--accent);
  color: #ffffff;
}

.panels {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 4fr 6fr;
}

.panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel + .panel {
  border-left: 1px solid var(--border);
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 10px;
  border-radius: 10px;
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  font-size: 12px;
  user-select: none;
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(255, 255, 255, 0.40);
}

body.dark .tool-btn {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.10);
}

body.dark .tool-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.16);
}

.tool-btn:active,
.theme-btn:active,
.collapse-toggle:active {
  transform: translateY(1px) scale(0.99);
}

.tool-btn.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 10px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}

.tool-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* 主题按钮：默认只显示太阳，深色只显示月亮（提升优先级覆盖 .tool-btn svg） */
.tool-btn svg.icon-moon {
  display: none;
}

body.dark .tool-btn svg.icon-sun {
  display: none;
}

body.dark .tool-btn svg.icon-moon {
  display: block;
}

.floating-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  display: flex;
  flex-direction: row;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.38) 0%,
    rgba(255, 255, 255, 0.10) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.10);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  backdrop-filter: blur(18px) saturate(180%);
  background-clip: padding-box;
}

body.dark .floating-tools {
  background: linear-gradient(
    180deg,
    rgba(17, 24, 39, 0.42) 0%,
    rgba(17, 24, 39, 0.10) 100%
  );
  border-color: rgba(255, 255, 255, 0.10);
  box-shadow: 0 12px 30px rgba(2, 6, 23, 0.50);
}

/* 自定义 tooltip：比原生 title 更快出现 */
.floating-tools .tool-btn {
  position: relative;
}

.floating-tools .tool-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  padding: 6px 8px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1;
  color: var(--text);
  background: rgba(255, 255, 255, 0.70);
  border: 1px solid rgba(255, 255, 255, 0.55);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  backdrop-filter: blur(14px) saturate(180%);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
  opacity: 0;
  transform: translateY(-2px);
  pointer-events: none;
  transition: opacity 80ms ease, transform 80ms ease;
  white-space: nowrap;
  z-index: 10;
}

body.dark .floating-tools .tool-btn[data-tip]::after {
  color: #e5edf7;
  background: rgba(17, 24, 39, 0.55);
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: 0 12px 30px rgba(2, 6, 23, 0.55);
}

.floating-tools .tool-btn[data-tip]:hover::after,
.floating-tools .tool-btn[data-tip]:focus-visible::after {
  opacity: 1;
  transform: translateY(0);
}

.tool-btn svg {
  opacity: 0.92;
}

/* 防止按钮 active/hover 造成“看起来不齐” */
.tool-btn,
.tool-btn * {
  box-sizing: border-box;
}

.tool-btn.active {
  outline: 2px solid rgba(37, 99, 235, 0.35);
  outline-offset: 0;
}

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

.left-editor {
  width: 100%;
  height: 100%;
  margin: 0;
  border: none;
  resize: none;
  background: transparent;
  color: var(--editor-text);
  padding: 16px;
  font: 15px/1.65 "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "Oxygen",
    "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  font-weight: 600;
  /* 视觉软换行：不出现横向滚动，不强行把字符拆得太碎 */
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  overflow-x: hidden;
  overflow-y: auto;
  tab-size: 4;
}

.left-editor:focus,
.compressed-editor:focus {
  outline: none;
}

.line-numbers {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 44px;
  display: none;
  padding: 14px 8px 14px 0;
  background: var(--line-bg);
  border-right: 1px solid var(--border);
  color: var(--line-text);
  font: 13px/1.7 "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "Oxygen",
    "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  font-weight: 600;
  text-align: right;
  user-select: none;
  white-space: pre;
  overflow: hidden;
}

.editor-wrap.with-lines .line-numbers {
  display: block;
}

.editor-wrap.with-lines .json-surface,
.editor-wrap.with-lines .compressed-editor {
  padding-left: 44px;
}

.json-surface,
.compressed-editor {
  width: 100%;
  height: 100%;
  overflow: auto;
  background: transparent;
}

.json-surface {
  padding: 12px 0;
}

.compressed-editor {
  display: none;
  margin: 0;
  border: none;
  resize: none;
  color: var(--editor-text);
  padding: 16px;
  font: 15px/1.65 "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "Oxygen",
    "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  font-weight: 600;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  overflow-x: hidden;
  tab-size: 4;
}

.editor-wrap.compressed-mode .json-surface {
  display: none;
}

.editor-wrap.compressed-mode .compressed-editor {
  display: block;
}

.json-tree {
  min-height: 100%;
  padding: 2px 0 10px;
}

/* 关键：恢复纯文本流布局，保证同层缩进/括号对齐 */
.json-line {
  --depth: 0;
  min-height: 24px;
  padding-left: calc(16px + var(--depth) * 4ch);
  padding-right: 16px;
  /* 保持结构符号稳定，不要把引号/冒号/逗号挤成“孤儿行” */
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  font: 15px/1.7 "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", "Oxygen",
    "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
  font-weight: 600;
  color: var(--editor-text);
}

/* 仅字符串内容自然换行（引号跟随字符串，不会单独占一行） */
.token-string {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.token-string::before,
.token-string::after {
  color: var(--editor-text);
}

.token-string::before {
  content: "\"";
}

.token-string::after {
  content: "\"";
}

.collapse-toggle {
  width: 16px;
  height: 16px;
  margin: 0 6px 0 0;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: transparent;
  line-height: 1;
  padding: 0;
  font-weight: 700;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: text-bottom;
}

.collapse-toggle.is-collapsed {
  color: #0ea5e9;
}

.collapse-toggle.is-expanded {
  color: #ef4444;
}

.json-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin: 0 6px 0 0;
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  vertical-align: text-bottom;
}

.json-action:hover {
  background: var(--accent-soft);
}

.toggle-placeholder {
  display: inline-block;
  width: 22px; /* 等于 toggle/action + margin 的“占位槽”，避免同层错位 */
}

.json-editable {
  display: inline-block;
  min-width: 2px;
  padding: 0 2px;
  border-radius: 4px;
  outline: none;
}

.json-editable:focus {
  background: var(--accent-soft);
}

.token-bracket,
.token-punctuation {
  color: var(--editor-text);
}

.token-key {
  color: var(--key-color);
}

.token-string {
  color: var(--string-color);
}

.token-number {
  color: var(--number-color);
}

.token-boolean {
  color: var(--bool-color);
}

.token-null {
  color: var(--null-color);
}

.token-muted {
  color: var(--muted);
}

.error-bar {
  display: none;
  padding: 8px 12px;
  border-top: 1px solid var(--error-border);
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.error-bar.show {
  display: block;
}

.copy-toast {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(17, 24, 39, 0.92);
  color: #ffffff;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.copy-toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .app {
    padding: 8px;
  }

  .panels {
    grid-template-columns: 1fr;
  }

  .panel + .panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

