:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --line: 20px;
  --topbar-h: 56px;

  --bg: #f8f7fa;
  --card: #fff;
  --text: #6f6b7d;
  --heading: #5d596c;
  --muted: #a5a3ae;
  --border: #dbdade;
  --hover: rgba(75, 70, 92, 0.06);
  --primary: #7367f0;
  --primary-soft: rgba(115, 103, 240, 0.12);
  --success: #28c76f;
  --danger: #ea5455;
  --danger-soft: rgba(234, 84, 85, 0.1);
  --info: #00bad1;
  --tooltip: #2f2b3d;
  --shadow: 0 0.25rem 1.125rem rgba(75, 70, 92, 0.1);

  --json-key: #92278f;
  --json-string: #3ab54a;
  --json-number: #25aae2;
  --json-boolean: #f98280;
  --json-null: #f1592a;
  --json-link: #1fb5bd;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #141414;
  --card: #1d1d1d;
  --text: #c9c9c9;
  --heading: #ececec;
  --muted: #8a8a8a;
  --border: #303030;
  --hover: rgba(255, 255, 255, 0.06);
  --primary: #1f58d6;
  --primary-soft: rgba(31, 88, 214, 0.22);
  --success: #52c41a;
  --danger: #e04f4f;
  --danger-soft: rgba(224, 79, 79, 0.14);
  --info: #3a8ee6;
  --tooltip: #303030;
  --shadow: none;

  --json-key: #d38ce6;
  --json-string: #5fd47a;
  --json-number: #4cc3f0;
  --json-boolean: #ff9e9c;
  --json-null: #ff7a50;
  --json-link: #61d2d6;

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  font: 15px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
}

button {
  font: inherit;
}

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--card);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--heading);
  font-weight: 600;
  font-size: 1.1rem;
  text-decoration: none;
}

.brand-logo {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font: 600 14px var(--mono);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.home-link {
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}

.home-link:hover {
  background: var(--hover);
  color: var(--heading);
}

.theme-icon {
  display: none;
}

[data-theme-pref="system"] .theme-icon--system,
[data-theme-pref="light"] .theme-icon--light,
[data-theme-pref="dark"] .theme-icon--dark {
  display: block;
}

/* ---------- 按钮 & 提示 ---------- */

.icon-btn,
.tool-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.icon-btn:hover,
.tool-btn:hover:not(:disabled) {
  background: var(--hover);
  color: var(--heading);
}

.tool-btn.is-active,
.tool-btn.is-active:hover {
  color: var(--success);
}

.tool-btn[data-action="lines"].is-active {
  color: var(--primary);
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.icon-btn:focus-visible,
.tool-btn:focus-visible,
.link-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background: var(--tooltip);
  color: #fff;
  font: 12px/1.4 var(--font);
  white-space: nowrap;
  pointer-events: none;
  z-index: 30;
}

.tip-end[data-tip]:hover::after,
.tip-end[data-tip]:focus-visible::after {
  left: auto;
  right: 0;
  transform: none;
}

.link-btn {
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
}

.link-btn:hover {
  background: var(--primary-soft);
}

/* ---------- 页面 & 卡片 ---------- */

.page {
  padding: 1.25rem 1.5rem 2rem;
}

.card {
  background: var(--card);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: 1.25rem;
}

/* ---------- 主工具区 ---------- */

.tool {
  height: calc(100vh - var(--topbar-h) - 2.5rem);
  min-height: 500px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tool-body {
  --split: 41.6667%;
  flex: 1;
  min-height: 0;
  display: flex;
}

.pane-input {
  flex: 0 0 var(--split);
  min-width: 0;
  display: flex;
  overflow: hidden;
}

.pane-output {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.is-dragging,
.is-dragging * {
  cursor: col-resize !important;
  user-select: none;
}

.splitter {
  flex: 0 0 1px;
  position: relative;
  z-index: 5;
  background: var(--border);
  cursor: col-resize;
  touch-action: none;
  transition: background-color 0.15s;
}

.splitter::before {
  content: '';
  position: absolute;
  inset: 0 -4px;
}

.splitter:hover,
.splitter:focus-visible,
.is-dragging .splitter {
  background: var(--primary);
  outline: none;
}

/* 行号 */

.gutter-wrap {
  display: none;
  flex: 0 0 2.75rem;
  overflow: hidden;
  border-right: 1px dashed var(--border);
}

.show-lines .gutter-wrap {
  display: block;
}

.gutter {
  margin: 0;
  padding: 1rem 0.5rem 0 0;
  text-align: right;
  font: 13px/var(--line) var(--mono);
  color: var(--muted);
  user-select: none;
  will-change: transform;
}

.output-area .gutter {
  padding-top: 0.75rem;
}

.has-error .output-area .gutter,
.is-empty .output-area .gutter {
  visibility: hidden;
}

/* 输入框 */

.editor {
  flex: 1;
  min-width: 0;
  height: 100%;
  margin: 0;
  padding: 1rem 1rem 3rem;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--heading);
  font: 14px/var(--line) var(--mono);
  tab-size: 4;
}

.editor::placeholder {
  color: var(--muted);
}

.show-lines .editor {
  padding-left: 0.75rem;
  white-space: pre;
  overflow-wrap: normal;
}

/* 工具栏 */

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.125rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.toolbar-spacer {
  flex: 1;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: 0.5rem;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.fullscreen-btn .icon-minimize,
.is-fullscreen .fullscreen-btn .icon-maximize {
  display: none;
}

.is-fullscreen .fullscreen-btn .icon-minimize {
  display: block;
}

/* 输出区 */

.output-area {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}

.output-scroll {
  flex: 1;
  min-width: 0;
  overflow: auto;
  padding: 0.75rem 1rem 1.5rem 1.25rem;
}

.show-lines .output-scroll {
  padding-left: 0.75rem;
}

.json-target {
  min-height: var(--line);
  font: 14px/var(--line) var(--mono);
  color: var(--heading);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.show-lines .json-target {
  white-space: pre;
  overflow-wrap: normal;
}

.jt-plain {
  margin: 0;
  font: inherit;
  white-space: inherit;
}

.editable-tip {
  display: none;
  position: absolute;
  top: 0.5rem;
  right: 1.25rem;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

.can-edit .editable-tip {
  display: block;
}

.empty-hint {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}

.empty-hint .link-btn {
  pointer-events: auto;
}

.is-empty .empty-hint {
  display: flex;
}

/* JSON 高亮 */

.json_key { color: var(--json-key); font-weight: 600; }
.json_string { color: var(--json-string); font-weight: 600; }
.json_number { color: var(--json-number); font-weight: 600; }
.json_boolean { color: var(--json-boolean); font-weight: 600; }
.json_null { color: var(--json-null); font-weight: 600; }

.json_link {
  color: var(--json-link);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

[data-ref] {
  border-radius: 3px;
  outline: none;
}

[data-ref]:hover {
  background: var(--hover);
}

[data-ref]:focus {
  background: var(--primary-soft);
  box-shadow: 0 0 0 1px var(--primary);
}

[data-ref].is-invalid {
  text-decoration: wavy underline var(--danger);
  text-underline-offset: 4px;
}

/* 折叠 */

.jt-toggle,
.inline-toggle {
  display: inline-block;
  position: relative;
  width: 13px;
  height: 13px;
  margin-right: 4px;
  vertical-align: -2px;
  border: 1.5px solid currentColor;
  border-radius: 4px;
  color: var(--danger);
  cursor: pointer;
  user-select: none;
}

.jt-toggle::before,
.jt-toggle::after,
.inline-toggle::before {
  content: '';
  position: absolute;
  left: 2px;
  right: 2px;
  top: 50%;
  height: 1.5px;
  margin-top: -0.75px;
  background: currentColor;
}

.jt-toggle::after {
  display: none;
  transform: rotate(90deg);
}

.jt-node.is-collapsed > .jt-toggle {
  color: var(--info);
}

.jt-node.is-collapsed > .jt-toggle::after {
  display: block;
}

.jt-summary {
  display: none;
  cursor: pointer;
}

.jt-node.is-collapsed > .jt-summary {
  display: inline;
}

.jt-node.is-collapsed > .jt-content {
  display: none;
}

/* 错误提示 */

.jt-error {
  padding: 0.875rem 1rem;
  border-radius: 6px;
  background: var(--danger-soft);
  color: var(--danger);
  font-family: var(--font);
  white-space: normal;
}

.jt-error-title {
  font-weight: 600;
}

.jt-error-snippet {
  margin: 0.5rem 0 0.75rem;
  padding: 0.5rem 0.75rem;
  overflow-x: auto;
  border-radius: 4px;
  background: var(--card);
  color: var(--heading);
  font: 13px/1.5 var(--mono);
  white-space: pre;
}

.jt-error-locate {
  padding: 0.25rem 0.75rem;
  border: 1px solid currentColor;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-size: 13px;
  cursor: pointer;
}

.jt-error-locate:hover {
  background: var(--danger-soft);
}

/* 全屏 */

.is-fullscreen,
.is-fullscreen body {
  overflow: hidden;
}

.is-fullscreen .tool {
  position: fixed;
  inset: 0;
  z-index: 100;
  height: auto;
  border-radius: 0;
}

/* ---------- 介绍 ---------- */

.intro {
  padding: 1.25rem 1.5rem;
}

.intro h2 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  color: var(--heading);
}

.intro h3 {
  margin: 1.25rem 0 0.5rem;
  font-size: 1rem;
  color: var(--heading);
}

.intro p {
  margin: 0.5rem 0;
}

.intro ul {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.intro li + li {
  margin-top: 0.25rem;
}

.intro code {
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: var(--hover);
  color: var(--danger);
  font: 13px var(--mono);
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  z-index: 200;
  max-width: calc(100vw - 2rem);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  background: var(--tooltip);
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, -150%);
  transition: transform 0.2s, opacity 0.2s;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast[data-type="success"] { background: var(--success); }
.toast[data-type="error"] { background: var(--danger); }

/* ---------- 暗色：控制台风格，细边框 + 小圆角 ---------- */

[data-theme="dark"] .topbar {
  border-bottom: 1px solid var(--border);
}

[data-theme="dark"] .card {
  border: 1px solid var(--border);
}

[data-theme="dark"] .toolbar {
  background: #191919;
}

[data-theme="dark"] :is(.card, .tool-btn, .brand-logo, .toast, .jt-error, .jt-error-locate) {
  border-radius: 2px;
}

/* ---------- 移动端 ---------- */

@media (max-width: 768px) {
  .topbar {
    padding: 0 1rem;
  }

  .page {
    padding: 0.75rem;
  }

  .tool {
    height: auto;
    min-height: 0;
  }

  .tool-body {
    flex-direction: column;
  }

  .pane-input {
    flex: none;
    height: 32vh;
    border-bottom: 1px solid var(--border);
  }

  .splitter {
    display: none;
  }

  .output-area {
    flex: none;
    height: 60vh;
  }

  .is-fullscreen .tool {
    overflow: auto;
  }
}
