.tool-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-direction: column;
  align-items: flex-start;
}

.tool-link {
  margin-top: 0.75rem;
  align-self: flex-start;
}

.trust-line {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.compare-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 1.25rem;
  margin-top: 1.25rem;
  align-items: stretch;
}

.compare-left {
  display: grid;
  gap: 1.25rem;
  min-height: 620px;
  height: 100%;
}

.compare-right {
  display: grid;
  gap: 1rem;
  height: 100%;
  min-height: 620px;
}

.editor-stage[hidden],
.results-card[hidden] {
  display: none;
}

.editor-stage,
.results-card {
  height: 100%;
}

.editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: stretch;
  height: 100%;
}

.editor-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 620px;
  padding: 1rem;
  height: 100%;
}

.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.editor-body {
  display: grid;
  grid-template-columns: var(--line-gutter-width, 52px) 1fr;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  overflow: hidden;
  min-height: 260px;
  flex: 1;
}

.editor-pane {
  position: relative;
  display: grid;
}

.editor-text {
  border: none;
  resize: vertical;
  padding: 0.75rem 1rem;
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.55;
  background: transparent;
  color: var(--text);
  outline: none;
  min-height: 260px;
  height: 100%;
  white-space: pre;
  background-image: linear-gradient(to right, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 2.5ch 100%;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--primary) 45%, var(--border)) transparent;
}

.editor-preview {
  padding: 0.75rem 1rem;
  overflow: auto;
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text);
  display: block;
  min-height: 260px;
  height: 100%;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--primary) 45%, var(--border)) transparent;
}

.editor-preview[hidden] {
  display: none;
}

.editor-preview .json-line {
  white-space: pre;
}

.editor-preview .code-lines {
  padding: 0;
  gap: 0;
}

.tree-preview {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-muted);
  padding: 0.6rem 0.75rem;
  display: grid;
  gap: 0.5rem;
  max-height: 220px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--primary) 45%, var(--border)) transparent;
}

.tree-preview::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.tree-preview::-webkit-scrollbar-track {
  background: transparent;
}

.tree-preview::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--primary) 40%, var(--border));
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}

.tree-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.tree-body {
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.85rem;
  color: var(--text);
  display: grid;
  gap: 0.25rem;
}

.tree-node {
  padding-left: 0.5rem;
}

.tree-node details {
  padding-left: 0.5rem;
}

.tree-node summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.tree-node summary::-webkit-details-marker {
  display: none;
}

.tree-toggle {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-grid;
  place-items: center;
  font-size: 0.65rem;
}

.tree-node details[open] > summary .tree-toggle {
  transform: rotate(90deg);
}

.tree-leaf {
  padding-left: 1.6rem;
  color: var(--muted);
}

.editor-text:focus {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary) 40%, transparent);
}

.line-numbers {
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--muted);
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  line-height: 1.55;
  text-align: right;
  user-select: none;
  overflow: hidden;
  border-right: 1px solid color-mix(in srgb, var(--border) 75%, transparent);
}

.editor-body .line-numbers {
  font-size: 0.9rem;
  padding: 0.75rem 0.5rem;
}

.json-view .line-numbers {
  font-size: 0.88rem;
  padding: 0.5rem 0.5rem;
}

.line-numbers .line-number-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  box-sizing: border-box;
  padding-right: 0.35rem;
  margin: 0;
  line-height: inherit;
  min-height: 1.55em;
}

.line-numbers .line-number-row:nth-child(odd) {
  background: color-mix(in srgb, var(--surface) 82%, transparent);
}

.line-numbers .line-number-row.collapsible {
  position: relative;
  cursor: pointer;
  padding-right: 1.2rem;
}

.line-numbers .line-number-row.collapsible::before {
  content: ">";
  position: absolute;
  right: 0.2rem;
  top: 0;
  color: var(--muted);
  font-size: 0.7rem;
  transform: translateY(2px);
}

.line-numbers .line-number-row.collapsible[aria-expanded="true"]::before {
  content: "v";
  color: var(--primary);
}

.line-numbers .line-number-row.error {
  color: var(--danger, #e25555);
  font-weight: 700;
}

.editor-status {
  min-height: 1.2rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: -0.15rem;
  margin-bottom: 0.1rem;
}

.editor-status.is-error {
  color: var(--danger, #e25555);
}

.controls-row {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1.25rem;
  align-items: center;
}

.controls-left,
.controls-right {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.controls-hint {
  margin: 0.5rem 0 0;
  padding: 0.55rem 0.75rem;
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 88%, var(--accent-soft));
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.controls-hint strong,
.controls-hint em {
  color: var(--text);
}

.toggle {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.9rem;
  color: var(--muted);
}

.toggle input {
  accent-color: var(--primary);
}

.summary-card {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-height: 620px;
  padding: 1rem;
  height: 100%;
}

.summary-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.summary-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.nav-loader {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--surface) 68%, transparent);
  backdrop-filter: blur(2px);
}

.nav-loader[hidden] {
  display: none !important;
}

.nav-loader-card {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  color: var(--text);
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 90%, var(--accent-soft));
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border));
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
}

.nav-spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
  margin: 0;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.stat {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.stat-label {
  color: var(--muted);
}

.summary-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  display: inline-block;
}

.swatch-missing {
  background: color-mix(in srgb, #f36 65%, transparent);
}

.swatch-changed {
  background: color-mix(in srgb, #f7b731 70%, transparent);
}

.swatch-type {
  background: color-mix(in srgb, #9b59b6 70%, transparent);
}

.swatch-collection {
  background: color-mix(in srgb, #4aa3ff 70%, transparent);
}

.summary-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.summary-list {
  max-height: none;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem;
  background: var(--surface-muted);
  display: grid;
  gap: 0.5rem;
  align-content: start;
  grid-auto-rows: max-content;
  flex: 1;
  min-height: 240px;
  color: var(--text);
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--primary) 45%, var(--border)) transparent;
}

.summary-scroll-hint {
  font-size: 0.85rem;
  text-align: right;
  color: var(--muted);
  margin-top: auto;
  padding-top: 0.35rem;
}

.how-it-works {
  margin-top: 2rem;
  background: var(--surface-muted);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
}

.how-it-works summary {
  cursor: pointer;
  font-weight: 600;
}

.how-it-works ul {
  margin: 0.8rem 0 0 1.2rem;
  color: var(--muted);
}

.diff-item {
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  display: grid;
  gap: 0.25rem;
}

.diff-item.diff-missing {
  border-left: 4px solid #f36;
  background: color-mix(in srgb, #f36 6%, var(--surface));
}

.diff-item.diff-value {
  border-left: 4px solid #f7b731;
  background: color-mix(in srgb, #f7b731 8%, var(--surface));
}

.diff-item.diff-type {
  border-left: 4px solid #9b59b6;
  background: color-mix(in srgb, #9b59b6 8%, var(--surface));
}

.diff-item.diff-collection {
  border-left: 4px solid #4aa3ff;
  background: color-mix(in srgb, #4aa3ff 8%, var(--surface));
}

.diff-item:hover,
.diff-item:focus {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  outline: none;
}

.diff-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--primary) 40%, transparent);
}

.diff-path {
  font-weight: 600;
  color: var(--text);
}

.diff-meta {
  font-size: 0.85rem;
  color: color-mix(in srgb, var(--text) 80%, var(--muted));
  white-space: normal;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.diff-line {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.diff-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
}

.results-card {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 620px;
  padding: 1rem;
}

.results-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.compare-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
  flex: 1;
  min-height: 0;
}

.json-panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
  display: grid;
  grid-template-rows: auto auto;
  align-content: start;
  min-height: 360px;
  height: 100%;
}

.json-panel-head {
  padding: 0.75rem 1rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
}

.json-view {
  display: grid;
  grid-template-columns: var(--line-gutter-width, 52px) 1fr;
  font-family: "JetBrains Mono", "Fira Code", "SFMono-Regular", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.88rem;
  line-height: 1.55;
  overflow: auto;
  max-height: none;
  height: auto;
  align-self: start;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--primary) 45%, var(--border)) transparent;
}

.code-lines {
  padding: 0.5rem 0.75rem;
  display: grid;
  gap: 0;
  align-content: start;
  grid-auto-rows: max-content;
}

.code-lines .json-line:nth-child(odd) {
  background: color-mix(in srgb, var(--surface) 90%, transparent);
}

.json-line {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  white-space: pre;
  min-height: 1.55em;
  line-height: inherit;
}

.json-line[hidden] {
  display: none !important;
}

.line-number-row[hidden] {
  display: none !important;
}

.json-line.diff-missing {
  background: color-mix(in srgb, #f36 18%, transparent);
  border-radius: 6px;
  padding: 0 0.25rem;
}

.json-line.diff-changed {
  background: color-mix(in srgb, #f7b731 22%, transparent);
  border-radius: 6px;
  padding: 0 0.25rem;
}

.json-line.diff-type {
  background: color-mix(in srgb, #9b59b6 18%, transparent);
  border-radius: 6px;
  padding: 0 0.25rem;
}

.json-line.diff-collection {
  background: color-mix(in srgb, #4aa3ff 18%, transparent);
  border-radius: 6px;
  padding: 0 0.25rem;
}

.json-line.is-active {
  outline: 3px solid color-mix(in srgb, var(--primary) 60%, transparent);
  border-radius: 6px;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 18%, transparent);
}

.json-line.is-active-missing {
  background: color-mix(in srgb, #f36 26%, transparent) !important;
}

.json-line.is-active-value {
  background: color-mix(in srgb, #f7b731 30%, transparent) !important;
}

.json-line.is-active-collection {
  background: color-mix(in srgb, #4aa3ff 28%, transparent) !important;
}

.json-line.is-active-type {
  background: color-mix(in srgb, #9b59b6 24%, transparent) !important;
}

.line-number-row.is-active {
  outline: 3px solid color-mix(in srgb, var(--primary) 60%, transparent);
  outline-offset: -2px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--primary) 14%, var(--surface));
  color: var(--text);
  font-weight: 700;
}

.json-token.diff-token {
  background: color-mix(in srgb, #f7b731 45%, transparent);
  border-radius: 4px;
  padding: 0 0.2rem;
}

.json-token.diff-token-missing {
  background: color-mix(in srgb, #f36 35%, transparent);
  border-radius: 4px;
  padding: 0 0.2rem;
}

.json-token.diff-token-collection {
  background: color-mix(in srgb, #4aa3ff 34%, transparent);
  border-radius: 4px;
  padding: 0 0.2rem;
}

.json-toggle {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  font-size: 0.7rem;
  line-height: 1;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
}

.json-toggle:hover {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  color: var(--primary);
}

.json-toggle[aria-expanded="false"] {
  transform: rotate(-90deg);
}

.json-toggle.placeholder {
  visibility: hidden;
}

.editor-text::-webkit-scrollbar,
.json-view::-webkit-scrollbar,
.summary-list::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.editor-text::-webkit-scrollbar-track,
.json-view::-webkit-scrollbar-track,
.summary-list::-webkit-scrollbar-track {
  background: transparent;
}

.editor-text::-webkit-scrollbar-thumb,
.json-view::-webkit-scrollbar-thumb,
.summary-list::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--primary) 40%, var(--border));
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}

.editor-preview::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.editor-preview::-webkit-scrollbar-track {
  background: transparent;
}

.editor-preview::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--primary) 40%, var(--border));
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
.loading-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--surface) 65%, transparent);
  display: grid;
  place-items: center;
  z-index: 40;
  backdrop-filter: blur(3px);
}

.loading-overlay[hidden] {
  display: none;
}

.loading-card {
  display: grid;
  gap: 0.6rem;
  padding: 1.5rem 2rem;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
}

.copy-toast {
  position: fixed;
  z-index: 1200;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--primary) 35%, var(--border));
  background: color-mix(in srgb, var(--surface) 90%, var(--accent-soft));
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

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

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn.small {
  padding: 6px 10px;
  font-size: 0.85rem;
}

.btn.is-ready {
  position: relative;
  animation: pulse 1.6s ease-in-out infinite;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary) 50%, transparent);
}

.btn.is-ready:disabled {
  animation: none;
  box-shadow: none;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary) 45%, transparent);
  }
  70% {
    box-shadow: 0 0 0 12px color-mix(in srgb, var(--primary) 0%, transparent);
  }
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary) 0%, transparent);
  }
}

@media (max-width: 1024px) {
  .compare-layout {
    grid-template-columns: 1fr;
  }

  .editor-grid,
  .compare-grid {
    grid-template-columns: 1fr;
  }

  .tool-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .compare-left,
  .compare-right {
    min-height: auto;
  }
}

@media (max-width: 768px) {
  .editor-card,
  .summary-card,
  .results-card {
    min-height: 520px;
  }

  .controls-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .controls-hint {
    margin-top: 0.4rem;
    font-size: 0.86rem;
    width: 100%;
  }

  .editor-body,
  .json-view {
    grid-template-columns: var(--line-gutter-width, 40px) 1fr;
  }

  .controls-left,
  .controls-right,
  .editor-actions,
  .summary-actions {
    width: 100%;
  }

  .controls-left .btn,
  .controls-right .btn,
  .editor-actions .btn,
  .summary-actions .btn {
    width: 100%;
  }

  .editor-actions,
  .summary-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .summary-stats {
    grid-template-columns: 1fr;
  }

  .summary-legend {
    grid-template-columns: 1fr 1fr;
  }

  .summary-filters {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 520px) {
  .editor-card,
  .summary-card,
  .results-card {
    min-height: 480px;
  }

  .compare-grid {
    gap: 0.9rem;
  }

  .editor-text,
  .editor-preview {
    padding: 0.6rem 0.75rem;
  }

  .line-numbers {
    padding: 0.6rem 0.35rem;
  }

  .summary-legend {
    grid-template-columns: 1fr;
  }
}

h1, h2 {
  word-break: break-word;
}
