.formatter-layout {
  display: flex;
  flex-direction: column;
  margin-bottom: 2rem;
}

.indent-control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.indent-control label {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-weight: 500;
}

.indent-control select {
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
  outline: none;
}

.indent-control select:focus {
  border-color: var(--accent);
}

/* editor */
.editor-area {
  position: relative;
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  min-height: 320px;
  max-height: 65vh;
  overflow: hidden;
}

.line-numbers {
  padding: 0.8rem 0;
  min-width: 3rem;
  text-align: right;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--text-dim);
  opacity: 0.5;
  user-select: none;
  overflow: hidden;
  white-space: pre;
  padding-right: 0.6rem;
  border-right: 1px solid var(--border);
}

#json-input {
  flex: 1;
  padding: 0.8rem;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--text);
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  tab-size: 2;
  overflow-y: auto;
  white-space: pre;
}

#json-input::placeholder {
  color: var(--text-dim);
  opacity: 0.4;
}

.kbd-hint {
  position: absolute;
  bottom: 0.5rem;
  right: 0.7rem;
  font-size: 0.6rem;
  color: var(--text-dim);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#json-input:focus ~ .kbd-hint {
  opacity: 0.6;
}

/* tree view */
.tree-area {
  margin-top: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tree-area.hidden {
  display: none;
}

.tree-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.tree-title {
  font-family: 'Sora', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-right: auto;
}

.tree-content {
  padding: 0.6rem 0.8rem;
  max-height: 400px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.75rem;
  line-height: 1.7;
}

/* tree nodes */
.tree-node {
  padding-left: 1.2rem;
  position: relative;
}

.tree-node::before {
  content: '';
  position: absolute;
  left: 0.35rem;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.tree-key {
  color: var(--accent);
  cursor: default;
}

.tree-toggle {
  cursor: pointer;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.tree-toggle:hover .tree-key {
  color: var(--accent-hover);
}

.tree-arrow {
  display: inline-block;
  width: 0.7rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.6rem;
  transition: transform 0.15s;
}

.tree-arrow.collapsed {
  transform: rotate(-90deg);
}

.tree-children {
  overflow: hidden;
}

.tree-children.collapsed {
  display: none;
}

.tree-value-string { color: var(--color-valid); }
.tree-value-number { color: var(--accent2); }
.tree-value-boolean { color: var(--color-boolean); }
.tree-value-null { color: var(--text-dim); font-style: italic; }

.tree-bracket {
  color: var(--text-dim);
}

.tree-item-count {
  color: var(--text-dim);
  font-size: 0.65rem;
  opacity: 0.7;
}

/* scrollbar styling */
#json-input::-webkit-scrollbar,
.tree-content::-webkit-scrollbar {
  width: 6px;
}

#json-input::-webkit-scrollbar-track,
.tree-content::-webkit-scrollbar-track {
  background: transparent;
}

#json-input::-webkit-scrollbar-thumb,
.tree-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

#json-input::-webkit-scrollbar-thumb:hover,
.tree-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* responsive */
@media (max-width: 560px) {
  .editor-area {
    min-height: 240px;
  }

  .line-numbers {
    min-width: 2.2rem;
    font-size: 0.72rem;
  }

  #json-input {
    font-size: 0.72rem;
  }
}

/* Prevent iOS auto-zoom on focus */
@supports (-webkit-touch-callout: none) {
  input, select, textarea { font-size: 16px !important; }
}
