:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #687383;
  --line: #d9e0ea;
  --soft-line: #e9edf3;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --accent-hover: #245dce;
  --teal: #0f766e;
  --amber: #b45309;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(26, 37, 55, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell > * {
  min-width: 0;
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
  padding: 28px;
}

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

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand > div {
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 850;
  box-shadow: inset 0 -8px 20px rgba(0, 0, 0, 0.12);
}

.home-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
  text-decoration: none;
}

.home-link:hover,
.home-link:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  word-break: keep-all;
  line-height: 1.15;
}

h2 {
  font-size: 19px;
  line-height: 1.2;
}

.brand p,
.toolbar p,
.status,
.metric-card span,
.preview-actions span,
.field,
.tree-empty {
  color: var(--muted);
}

.input-panel,
.control-group {
  display: grid;
  gap: 16px;
  padding-top: 6px;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 680;
}

.field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

select {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.14);
}

.compact-field {
  max-width: 132px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 680;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.primary-action,
.secondary-action {
  height: 42px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 780;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.primary-action {
  width: 100%;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
}

.primary-action:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.secondary-action {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.secondary-action:hover:not(:disabled),
.secondary-action:focus-visible {
  border-color: var(--accent);
  background: #eef5ff;
  color: var(--accent);
  outline: none;
}

.primary-action:disabled,
.secondary-action:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.status {
  min-height: 44px;
  font-size: 13px;
}

.status.is-error {
  color: var(--danger);
}

.copyright {
  margin-top: auto;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  align-content: start;
  gap: 24px;
  min-width: 0;
  padding: 28px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

.toolbar-action {
  width: max-content;
  padding: 0 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 12px;
}

.metric-card,
.preview-panel {
  background: var(--panel);
  border: 1px solid var(--soft-line);
  border-radius: var(--radius);
}

.metric-card {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 16px;
}

.metric-card strong {
  overflow: hidden;
  font-size: 24px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-panel {
  display: grid;
  min-height: 560px;
  overflow: hidden;
}

.output-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px;
  border-bottom: 1px solid var(--soft-line);
}

.tab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 760;
}

.tab-button:hover,
.tab-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}

.tab-button.is-active {
  border-color: var(--accent);
  background: #eef5ff;
  color: var(--accent);
}

textarea {
  width: 100%;
  min-width: 0;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfe;
  color: var(--ink);
  padding: 14px;
  outline: none;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  tab-size: 4;
}

.input-field textarea {
  min-height: 300px;
}

#outputText {
  min-height: 440px;
  border: 0;
  border-bottom: 1px solid var(--soft-line);
  border-radius: 0;
  padding: 18px;
}

.tree-view {
  min-height: 440px;
  max-height: 68vh;
  overflow: auto;
  border-bottom: 1px solid var(--soft-line);
  background: #fbfcfe;
  padding: 18px;
  font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.tree-children {
  display: grid;
  gap: 2px;
  margin-left: 18px;
  padding-left: 12px;
  border-left: 1px solid var(--soft-line);
}

.tree-view details {
  margin: 2px 0;
}

.tree-view summary {
  cursor: pointer;
  color: var(--ink);
}

.tree-leaf {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  padding: 1px 0;
}

.tree-key {
  color: #475569;
  font-weight: 760;
}

.tree-type {
  color: var(--muted);
}

.value-string {
  color: var(--teal);
}

.value-number {
  color: var(--amber);
}

.value-boolean {
  color: var(--accent);
}

.value-null {
  color: var(--muted);
  font-style: italic;
}

.error-panel {
  display: grid;
  gap: 12px;
  min-height: 440px;
  border-bottom: 1px solid var(--soft-line);
  background: #fff8f7;
  padding: 18px;
  color: var(--danger);
}

.error-panel[hidden],
.tree-view[hidden],
#outputText[hidden] {
  display: none;
}

.error-panel pre {
  overflow: auto;
  margin: 0;
  border: 1px solid #f0c7c2;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 14px;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.preview-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
}

.preview-actions span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.preview-actions .secondary-action {
  min-width: 76px;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .controls,
  .workspace {
    padding: 20px;
  }

  .input-field textarea {
    min-height: 220px;
  }
}

@media (max-width: 640px) {
  .brand-row,
  .toolbar,
  .preview-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-action,
  .preview-actions .secondary-action {
    width: 100%;
  }
}
