/* ballwictb _-_*/

:root {
  --bg: #0f1117;
  --surface: #161922;
  --surface-2: #1c202b;
  --surface-3: #232838;
  --border: #262b38;
  --border-strong: #333a4d;
  --text: #e6e9f0;
  --text-muted: #8b93a7;
  --text-faint: #5c6478;
  --accent: #ffb454;
  --accent-soft: rgba(255, 180, 84, 0.14);
  --accent-strong: #ffc06a;
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.12);
  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.12);
  --info: #60a5fa;

  --c-key: #7ee0c9;
  --c-string: #ffb454;
  --c-number: #a5b4fc;
  --c-boolean: #f472b6;
  --c-null: #94a3b8;
  --c-punct: #6b7280;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

:root[data-theme='light'] {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --surface-3: #e6e9f0;
  --border: #e2e6ee;
  --border-strong: #cdd3e0;
  --text: #1a1f2b;
  --text-muted: #5c6478;
  --text-faint: #8b93a7;
  --accent: #d97706;
  --accent-soft: rgba(217, 119, 6, 0.1);
  --accent-strong: #b45309;
  --c-key: #0f766e;
  --c-string: #b45309;
  --c-number: #4f46e5;
  --c-boolean: #be185d;
  --c-null: #64748b;
  --c-punct: #94a3b8;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  background: var(--bg);
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  overflow: hidden;
  zoom: 0.97;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 18px;
  color: var(--bg);
  width: 3rem;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  letter-spacing: -1px;
}

.brand-text h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.brand-text p {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.2s, box-shadow 0.2s;
}

.status[data-state='valid'] .status-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px var(--success-soft);
}

.status[data-state='valid'] .status-label {
  color: var(--success);
}

.status[data-state='invalid'] .status-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px var(--danger-soft);
}

.status[data-state='invalid'] .status-label {
  color: var(--danger);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

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

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn i {
  width: 16px;
  height: 16px;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-primary {
  background: var(--accent);
  color: #0f1117;
  border-color: var(--accent);
  font-weight: 600;
}

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

.btn-mini {
  padding: 6px;
  background: transparent;
  border-color: transparent;
}

.btn-mini:hover {
  background: var(--surface-3);
}

.btn-mini i {
  width: 15px;
  height: 15px;
  color: var(--text-muted);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.indent-select {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  padding-left: 6px;
}

.indent-select select {
  font-family: var(--font-sans);
  font-size: 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
}

.split {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.panel-input {
  flex: 0 0 50%;
}

.panel-output {
  flex: 1;
  border-left: 1px solid var(--border);
}

.resizer {
  flex: 0 0 6px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  transition: background 0.15s;
}

.resizer:hover,
.resizer:focus-visible {
  background: var(--accent);
  outline: none;
}

.resizer::after {
  content: '';
  position: absolute;
  inset: 0 -4px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 46px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.panel-title i {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.panel-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.editor-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  position: relative;
}

.gutter {
  padding: 14px 8px 14px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-faint);
  text-align: right;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  user-select: none;
  white-space: pre;
  min-width: 44px;
}

.editor {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 14px 16px;
  overflow: auto;
  white-space: pre;
  tab-size: 2;
}

.editor::placeholder {
  color: var(--text-faint);
}

.editor-schema {
  min-height: 160px;
  max-height: 260px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  white-space: pre;
}

.error-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--danger-soft);
  color: var(--danger);
  border-top: 1px solid rgba(255, 107, 107, 0.25);
  font-family: var(--font-mono);
  font-size: 12px;
}

.error-bar i {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

.error-bar[hidden] {
  display: none;
}

.tabs {
  display: flex;
  gap: 2px;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab i {
  width: 15px;
  height: 15px;
}

.tab:hover {
  color: var(--text);
  background: var(--surface-2);
}

.tab.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.views {
  flex: 1;
  min-height: 0;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.view.active {
  display: flex;
}

.tree-toolbar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}

.search-box i {
  width: 15px;
  height: 15px;
  color: var(--text-muted);
}

.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
}

.search-box input::placeholder {
  color: var(--text-faint);
}

.tree {
  flex: 1;
  overflow: auto;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
}

.tree-node {
  display: block;
}

.tree-row {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  padding: 1px 4px;
  border-radius: 5px;
  cursor: default;
  position: relative;
}

.tree-row.clickable {
  cursor: pointer;
}

.tree-row.clickable:hover {
  background: var(--surface-2);
}

.tree-row.match {
  background: var(--accent-soft);
}

.twisty {
  width: 16px;
  height: 21px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex: 0 0 auto;
  cursor: pointer;
}

.twisty i {
  width: 13px;
  height: 13px;
  transition: transform 0.15s;
}

.tree-node.collapsed>.tree-row .twisty i {
  transform: rotate(-90deg);
}

.twisty.leaf {
  visibility: hidden;
}

.tk-key {
  color: var(--c-key);
}

.tk-string {
  color: var(--c-string);
}

.tk-number {
  color: var(--c-number);
}

.tk-boolean {
  color: var(--c-boolean);
}

.tk-null {
  color: var(--c-null);
  font-style: italic;
}

.tk-punct {
  color: var(--c-punct);
}

.tk-count {
  color: var(--text-faint);
  font-size: 11px;
  margin-left: 6px;
}

.tk-colon {
  color: var(--c-punct);
  margin: 0 4px 0 2px;
}

.tree-children {
  padding-left: 18px;
  position: relative;
}

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

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

.tree-node.collapsed>.tree-row .collapse-preview {
  display: inline;
}

.collapse-preview {
  display: none;
  color: var(--text-faint);
  margin-left: 6px;
  font-style: italic;
}

.copy-path {
  margin-left: auto;
  opacity: 0;
  padding: 1px 5px;
  color: var(--text-faint);
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  transition: opacity 0.15s;
}

.copy-path i {
  width: 13px;
  height: 13px;
}

.tree-row:hover .copy-path {
  opacity: 1;
}

.copy-path:hover {
  color: var(--accent);
  background: var(--surface-3);
}

.code-output {
  flex: 1;
  overflow: auto;
  margin: 0;
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
  color: var(--text);
}

.code-output .tk-key {
  color: var(--c-key);
}

.view-schema {
  overflow: auto;
}

.schema-panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.schema-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.schema-head label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.schema-result:empty {
  display: none;
}

.schema-result {
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-mono);
}

.schema-result.ok {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid rgba(74, 222, 128, 0.25);
}

.schema-result.fail {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.25);
}

.schema-result ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.schema-result li {
  margin: 3px 0;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-faint);
  text-align: center;
  padding: 24px;
  pointer-events: none;
}

.empty-state i {
  width: 40px;
  height: 40px;
  opacity: 0.5;
}

.empty-state p {
  max-width: 240px;
  font-size: 13px;
}

.tree:empty+.empty-state {
  display: flex;
}

.footer {
  display: flex;
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  align-items: center;
  justify-content: space-between;
  padding: 8px 18px;
  font-size: 11px;
  color: var(--text-faint);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 6px;
  border: 2px solid var(--bg);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

#toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 500;
  pointer-events: auto;
  min-width: 220px;
}

.toast i {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.toast.success i {
  color: var(--success);
}

.toast.error i {
  color: var(--danger);
}

.toast.info i {
  color: var(--info);
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
  }

  .split {
    flex-direction: column;
  }

  .panel-input,
  .panel-output {
    flex: none;
    width: 100%;
  }

  .panel-input {
    height: 42vh;
  }

  .panel-output {
    height: 58vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .resizer {
    display: none;
  }

  .btn span {
    display: none;
  }

  .indent-select label {
    display: none;
  }
}