/* ─── Reset ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg:       #0a0a0a;
  --surface:  #111111;
  --border:   #1e1e1e;
  --border-h: #2a2a2a;
  --text:     #ededed;
  --text-2:   #888888;
  --text-3:   #555555;
  --accent:   #ffffff;
  --blue:     #3b82f6;
  --red:      #ef4444;
  --orange:   #f59e0b;
  --green:    #22c55e;
  --radius:   8px;
  --font:     'Inter', -apple-system, sans-serif;
  --mono:     'JetBrains Mono', monospace;
}

html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ─── */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 1.25rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main { flex: 1; padding-bottom: 3rem; }

/* ─── Header ─── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo {
  font-size: 1.1rem;
  color: var(--text-2);
}

.wordmark {
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  color: var(--text);
}

.header-desc {
  font-size: 0.8rem;
  color: var(--text-3);
}

/* ─── Sections ─── */
.section {
  margin-bottom: 1.75rem;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 0.75rem;
}

.section-desc {
  font-size: 0.82rem;
  color: var(--text-3);
  margin-top: -0.4rem;
  margin-bottom: 0.65rem;
}

.section-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.section-head-row .section-title { margin-bottom: 0; }

/* ─── Textarea ─── */
textarea {
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.65;
  resize: vertical;
  transition: border-color 0.15s;
}

textarea:focus {
  outline: none;
  border-color: var(--border-h);
}

textarea::placeholder { color: var(--text-3); }

/* ─── Buttons ─── */
.btn-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.btn-secondary {
  background: transparent;
  color: var(--text-2);
}

.btn-secondary:hover {
  background: var(--surface);
  border-color: var(--border-h);
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.4; cursor: default; }

.spinner { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Error ─── */
.error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.85rem;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius);
  color: var(--red);
  font-size: 0.82rem;
  margin-bottom: 1.5rem;
}

.error-x {
  background: none;
  border: none;
  color: var(--red);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}

/* ─── Stats ─── */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.stat {
  background: var(--surface);
  padding: 1rem 0.75rem;
  text-align: center;
}

.stat-val {
  display: block;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

.stat-val.warn { color: var(--orange); }

.stat-key {
  display: block;
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  margin-top: 0.25rem;
}

/* ─── Hierarchies ─── */
.hier-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 0.65rem;
}

.hier-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.85rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.hier-root {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.tag {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tag-tree  { background: rgba(34,197,94,0.1);  color: var(--green); }
.tag-cycle { background: rgba(239,68,68,0.1);  color: var(--red);   }
.tag-depth { background: rgba(59,130,246,0.08); color: var(--blue);  }

.hier-body {
  padding: 0.65rem 0.85rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.75;
  color: var(--text-2);
}

.hier-body .node { color: var(--text); font-weight: 500; }
.hier-body .branch { color: var(--text-3); }
.hier-body .leaf { color: var(--green); }
.hier-body .indent { padding-left: 1.3rem; }

.cycle-msg {
  color: var(--text-3);
  font-size: 0.8rem;
  font-style: italic;
}

/* ─── Diagnostics ─── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.count {
  font-size: 0.7rem;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
}

.pill {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
  margin: 0.15rem 0.2rem 0.15rem 0;
}

.pill-red    { background: rgba(239,68,68,0.08);  color: var(--red);    border: 1px solid rgba(239,68,68,0.15);  }
.pill-orange { background: rgba(245,158,11,0.08); color: var(--orange); border: 1px solid rgba(245,158,11,0.15); }

.empty-msg {
  font-size: 0.78rem;
  color: var(--text-3);
}

/* ─── JSON Toggle ─── */
.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.section-toggle .section-title { margin-bottom: 0; }

.arrow {
  font-size: 1rem;
  color: var(--text-3);
  transition: transform 0.2s;
}

.arrow.open { transform: rotate(90deg); }

.json {
  margin-top: 0.6rem;
  padding: 0.75rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.73rem;
  color: var(--text-2);
  line-height: 1.6;
  overflow: auto;
  max-height: 360px;
}

/* ─── Footer ─── */
.footer {
  text-align: center;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}

/* ─── Utility ─── */
.hidden { display: none !important; }

/* ─── Responsive ─── */
@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .btn-row { flex-wrap: wrap; }
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-h); border-radius: 2px; }
