:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #1f2329;
  --muted: #646a73;
  --border: #e5e6eb;
  --shadow: 0 10px 30px rgba(31, 35, 41, 0.18);
  --link: #1677ff;
  --key: #c23b22;
  --string: #2a7a2e;
  --number: #b35c00;
  --bool: #6f42c1;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand-title {
  font-size: 16px;
  font-weight: 600;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chip {
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fafafa;
  color: var(--muted);
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}

.btn.small {
  padding: 6px 8px;
  font-size: 12px;
}

.btn.primary {
  border-color: rgba(22, 119, 255, 0.3);
  background: rgba(22, 119, 255, 0.08);
  color: #0b57d0;
}

.btn:active {
  transform: translateY(1px);
}

.toast {
  position: fixed;
  left: 50%;
  top: 68px;
  transform: translateX(-50%);
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(31, 35, 41, 0.92);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 140ms ease, visibility 0s linear 140ms;
  z-index: 20000;
}

.toast.show {
  opacity: 1;
  visibility: visible;
  transition: opacity 140ms ease;
}

.layout {
  flex: 1;
  padding: 16px;
  display: flex;
  gap: 12px;
  min-height: 0;
}

.layout > .panel {
  min-width: 0;
}

.layout > .panel:not(.input-panel) {
  flex: 1 1 auto;
}

.input-panel {
  flex: 0 0 380px;
  max-width: 380px;
  overflow: hidden;
}

.layout.input-hidden {
  gap: 12px;
}

.layout.input-hidden .input-panel {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.panel-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
}

.panel-hint {
  font-size: 12px;
  color: var(--muted);
}

.input-area {
  padding: 12px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

textarea {
  width: 100%;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  resize: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  font-size: 12px;
  line-height: 1.5;
  background: #fbfbfd;
  color: var(--text);
}

.viewer {
  padding: 12px;
  flex: 1;
  overflow: auto;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.6;
  min-height: 0;
}

.editor {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.editor-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fbfbfd;
  overflow: hidden;
}

.editor-highlight,
.editor-input {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
    monospace;
  font-size: 12px;
  line-height: 1.5;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  overflow: auto;
}

.editor-highlight {
  pointer-events: none;
  color: var(--text);
}

.editor-input {
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
}

.editor-input::selection {
  background: rgba(22, 119, 255, 0.22);
}

.hl-k {
  color: var(--key);
}

.hl-s {
  color: var(--string);
}

.hl-n {
  color: var(--number);
}

.hl-b {
  color: var(--bool);
}

.hl-null {
  color: rgba(31, 35, 41, 0.55);
}

.hl-p {
  color: rgba(31, 35, 41, 0.5);
}

.node {
  position: relative;
  padding-left: 18px;
  margin-left: 10px;
}

.node::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 0;
  bottom: 0;
  border-left: 1px dashed rgba(31, 35, 41, 0.22);
  pointer-events: none;
}

.expander {
  display: inline-block;
  width: 14px;
  position: absolute;
  left: 0;
  top: 0;
  height: 1.6em;
  line-height: 1.6em;
  text-align: center;
  z-index: 1;
  color: rgba(31, 35, 41, 0.55);
  cursor: pointer;
  user-select: none;
}

.k[data-collapsible="1"] {
  cursor: pointer;
  user-select: none;
}

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

.punct {
  color: rgba(31, 35, 41, 0.5);
}

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

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

.v-bool {
  color: var(--bool);
}

.v-null {
  color: rgba(31, 35, 41, 0.55);
}

.clickable {
  color: var(--link);
  text-decoration: underline;
  cursor: pointer;
}

.clickable:hover {
  text-decoration-thickness: 2px;
}

.tooltip {
  position: relative;
}

.tooltip:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: 6px;
  white-space: nowrap;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(31, 35, 41, 0.92);
  color: #fff;
  font-size: 12px;
  z-index: 2;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#diffOverlay {
  z-index: 11000;
}

.overlay.open {
  display: flex;
}

.modal-stack {
  position: relative;
  width: 80vw;
  height: 80vh;
}

.modal {
  position: absolute;
  inset: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-title {
  font-size: 13px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.modal-title-path {
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
  color: var(--key);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.modal-title-path:hover {
  text-decoration: underline;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 16px;
  line-height: 1;
}

.modal-body {
  padding: 12px;
  flex: 1;
  overflow: auto;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.6;
  min-height: 0;
}

.diff-summary {
  color: var(--muted);
  margin-bottom: 8px;
}

.diff-view {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  background: #fbfbfd;
}

.diff-line {
  white-space: pre;
  padding: 2px 10px;
}

.diff-add {
  background: rgba(42, 122, 46, 0.12);
}

.diff-del {
  background: rgba(194, 59, 34, 0.12);
}

.diff-context {
  background: transparent;
}

.diff-skip {
  color: var(--muted);
  text-align: center;
  padding: 8px 10px;
  background: rgba(31, 35, 41, 0.04);
}

.context-menu {
  position: fixed;
  z-index: 10000;
  min-width: 160px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.context-menu-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.context-menu-item:hover {
  background: rgba(22, 119, 255, 0.08);
}

@media (max-width: 980px) {
  .layout {
    flex-direction: column;
  }
}
