:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --body: #212529;
  --surface: #2b3035;
  --surface-2: #343a40;
  --surface-3: #1b1f22;
  --text: #dee2e6;
  --muted: #9ba3aa;
  --faint: #707880;
  --border: #495057;
  --border-soft: rgba(255, 255, 255, 0.11);
  --primary: #6ea8fe;
  --primary-strong: #0d6efd;
  --primary-soft: rgba(13, 110, 253, 0.14);
  --success: #75b798;
  --success-soft: #0a3622;
  --danger: #ea868f;
  --danger-soft: #58151c;
  --shadow: rgba(0, 0, 0, 0.22);
}

:root[data-theme="light"] {
  color-scheme: light;
  --body: #f4f5f6;
  --surface: #ffffff;
  --surface-2: #e9ecef;
  --surface-3: #f8f9fa;
  --text: #212529;
  --muted: #606970;
  --faint: #7a8289;
  --border: #ced4da;
  --border-soft: rgba(0, 0, 0, 0.1);
  --primary: #0d6efd;
  --primary-strong: #0b5ed7;
  --primary-soft: rgba(13, 110, 253, 0.1);
  --success: #146c43;
  --success-soft: #d1e7dd;
  --danger: #b02a37;
  --danger-soft: #f8d7da;
  --shadow: rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }
html { min-height: 100%; }

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  color: var(--text);
  background: var(--body);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  transition: color 180ms ease, background-color 180ms ease;
}

button, input, select, textarea { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, .drop-zone:focus-within {
  outline: 3px solid rgba(13, 110, 253, 0.3);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.site-header { padding: 8px 8px 0; }
.site-header nav {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 16px;
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: 0 2px 6px var(--shadow);
}

.brand { color: var(--text); font-size: 1.18rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.nav-actions { display: flex; align-items: center; gap: 8px; }
.nav-button, .button {
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, opacity 150ms ease;
}
.nav-button { padding: 7px 10px; color: var(--primary); background: transparent; }
.nav-button:hover { color: var(--text); background: var(--surface-2); }

.privacy-pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; color: var(--muted); font-size: 0.82rem; }
.privacy-pill > span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 16%, transparent);
}

main { width: min(1320px, 100%); flex: 1; margin: 0 auto; padding: 24px; }
.upload-only main { display: flex; flex-direction: column; justify-content: center; padding-bottom: 70px; }
.upload-card { width: min(760px, 100%); margin: 0 auto; }
.section-heading { margin-bottom: 20px; text-align: center; }
.section-heading h1, .section-heading h2 { margin: 0 0 5px; font-size: 1.55rem; font-weight: 500; }
.section-heading p { margin: 0; color: var(--muted); }
.section-heading.compact { margin: 0; text-align: left; }
.section-heading.compact h2 { font-size: 1.2rem; }

.drop-zone {
  min-height: 330px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px;
  border: 1px dashed var(--border);
  border-radius: 7px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 48%, transparent);
  text-align: center;
  cursor: pointer;
  transition: border-color 150ms ease, color 150ms ease, background-color 150ms ease, transform 150ms ease;
}
.drop-zone:hover, .drop-zone.dragging, .drop-zone.has-file { border-color: var(--primary); color: var(--text); background: var(--primary-soft); }
.drop-zone.dragging { transform: scale(1.006); }
.drop-zone strong { color: var(--text); font-size: 1.05rem; font-weight: 500; }
.drop-zone small { margin-top: 8px; color: var(--faint); }
.drop-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--primary);
  font-size: 1.65rem;
  font-weight: 300;
}

.path-helper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  background: var(--surface);
}
.path-helper > div { min-width: 0; }
.path-label { display: block; margin-bottom: 2px; color: var(--faint); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.path-helper code { display: block; overflow: hidden; color: var(--muted); font-family: Consolas, monospace; font-size: 0.82rem; text-overflow: ellipsis; white-space: nowrap; }

.button { padding: 8px 12px; font-weight: 500; }
.button-ghost { flex: 0 0 auto; border-color: var(--border); color: var(--text); background: transparent; }
.button-ghost:hover { background: var(--surface-2); }
.button-ghost.danger { color: var(--danger); }
.button-download { padding: 10px 15px; color: #fff; background: var(--primary-strong); }
.button-download:hover { filter: brightness(1.08); }
.button:disabled { cursor: wait; opacity: 0.62; }

.alert { width: min(900px, 100%); display: flex; gap: 10px; margin: 0 auto 18px; padding: 11px 14px; border: 1px solid; border-radius: 5px; }
.alert-success { border-color: var(--success); color: var(--success); background: var(--success-soft); }
.alert-error { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }

.has-save main { padding-top: 18px; }
.has-save .upload-card {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(210px, 0.65fr) minmax(320px, 1.35fr);
  gap: 12px;
  align-items: stretch;
  margin-bottom: 14px;
}
.has-save .upload-card .section-heading { display: none; }
.has-save .upload-card form { min-width: 0; }
.has-save .drop-zone { min-height: 94px; height: 100%; padding: 14px; }
.has-save .drop-icon { display: none; }
.has-save .path-helper { margin-top: 0; }

.editor-card, .how-it-works {
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 4px 18px var(--shadow);
}
.editor-card { overflow: hidden; }
.editor-topbar, .editor-toolbar, .download-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; }
.editor-topbar { border-bottom: 1px solid var(--border-soft); }
.editor-actions { display: flex; gap: 8px; }
.inline-form { margin: 0; }
.editor-toolbar { position: sticky; top: 0; z-index: 4; border-bottom: 1px solid var(--border-soft); background: var(--surface-3); }

.search-box { min-width: 240px; flex: 1; display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 5px; background: var(--body); }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; }
.search-box input::placeholder { color: var(--faint); }
.variable-count { flex: 0 0 auto; color: var(--muted); font-size: 0.82rem; }
.view-switch { display: flex; padding: 2px; border: 1px solid var(--border); border-radius: 5px; background: var(--body); }
.view-switch button { padding: 6px 10px; border: 0; border-radius: 3px; color: var(--muted); background: transparent; cursor: pointer; }
.view-switch button.active { color: #fff; background: var(--primary-strong); }

.editor-status { min-height: 0; padding: 0 16px; color: var(--muted); font-size: 0.82rem; }
.editor-status:not(:empty) { padding-top: 10px; }
.tree-view, .search-results { max-height: 62vh; overflow: auto; padding: 10px 16px 18px; }
.tree-branch { border-left: 1px solid var(--border); }
.tree-branch + .tree-branch { margin-top: 3px; }
.tree-branch > summary { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 3px; list-style: none; cursor: pointer; }
.tree-branch > summary::-webkit-details-marker { display: none; }
.tree-branch > summary::before { content: "+"; width: 16px; color: var(--primary); font-family: Consolas, monospace; }
.tree-branch[open] > summary::before { content: "−"; }
.tree-branch > summary:hover { background: var(--surface-2); }
.tree-branch > summary span { font-weight: 500; }
.tree-branch > summary small { margin-left: auto; color: var(--faint); }
.branch-children { padding: 2px 0 5px 17px; }

.variable-row { display: grid; grid-template-columns: minmax(180px, 0.8fr) minmax(220px, 1.2fr); gap: 14px; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--border-soft); }
.variable-row:hover { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.variable-identity { min-width: 0; display: flex; align-items: center; gap: 8px; }
.variable-identity strong { overflow: hidden; font-family: Consolas, monospace; font-size: 0.84rem; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.variable-identity small { display: block; overflow: hidden; color: var(--faint); font-size: 0.7rem; text-overflow: ellipsis; white-space: nowrap; }
.type-badge { flex: 0 0 auto; padding: 1px 5px; border: 1px solid var(--border); border-radius: 3px; color: var(--faint); font-size: 0.66rem; text-transform: uppercase; }
.value-input { width: 100%; min-height: 34px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; outline: none; color: var(--text); background: var(--body); }
.value-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
textarea.value-input { resize: vertical; }

.compact-row { grid-template-columns: minmax(250px, 1fr) minmax(240px, 1fr); margin-bottom: 4px; border: 1px solid var(--border-soft); border-radius: 4px; }
.compact-row .variable-identity { display: block; }
.empty-search { padding: 45px; color: var(--muted); text-align: center; }
.load-more { width: 100%; margin-top: 6px; padding: 8px; border: 1px solid var(--border); border-radius: 4px; color: var(--primary); background: transparent; cursor: pointer; }
.json-view { padding: 14px 16px; }
.json-warning { margin-bottom: 9px; color: var(--muted); font-size: 0.82rem; }
#raw-json { width: 100%; min-height: 58vh; padding: 12px; border: 1px solid var(--border); border-radius: 4px; outline: none; color: var(--text); background: var(--surface-3); font: 0.82rem/1.55 Consolas, monospace; resize: vertical; }
.download-bar { border-top: 1px solid var(--border-soft); background: var(--surface-3); }
.download-bar > div { display: flex; flex-direction: column; }
.download-bar span { color: var(--muted); font-size: 0.8rem; }

.how-it-works { margin-top: 14px; padding: 16px; }
.upload-only .how-it-works { display: none; }
.how-it-works ol { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 0; padding: 0; list-style: none; }
.how-it-works li { display: flex; gap: 10px; padding: 10px; border: 1px solid var(--border-soft); border-radius: 4px; }
.how-it-works li > span { color: var(--primary); font-weight: 600; }
.how-it-works p { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; }

footer { display: flex; justify-content: center; gap: 8px; padding: 10px 16px 14px; color: var(--faint); font-size: 0.76rem; text-align: center; }
footer span + span::before { content: "· "; }
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  max-width: min(390px, calc(100vw - 32px));
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 8px 25px var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast[data-kind="error"] { border-color: var(--danger); }

@media (max-width: 760px) {
  .privacy-pill { display: none; }
  main { padding: 16px 10px; }
  .upload-only main { padding-bottom: 50px; }
  .drop-zone { min-height: 280px; padding: 24px 14px; }
  .path-helper { align-items: stretch; flex-direction: column; }
  .path-helper .button { width: 100%; }
  .has-save .upload-card { grid-template-columns: 1fr; }
  .editor-topbar, .editor-toolbar, .download-bar { align-items: stretch; flex-direction: column; }
  .editor-actions, .editor-actions .button, .download-bar .button { width: 100%; }
  .editor-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .variable-count { align-self: flex-start; }
  .view-switch { width: 100%; }
  .view-switch button { flex: 1; }
  .variable-row, .compact-row { grid-template-columns: 1fr; gap: 6px; }
  .how-it-works ol { grid-template-columns: 1fr; }
  footer { flex-direction: column; gap: 0; }
  footer span + span::before { content: ""; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
