:root {
  color-scheme: light dark;
  --gutter: 16px;
  --bg: #ffffff;
  --fg: #1d2127;
  --muted: #66707c;
  --line: #d6dae0;
  --panel: #f6f7f9;
  --accent: #1a6fd4;
  --select: #cfe3fb;
  --select-part: #e5f0fd;
  --bad: #c0261e;
  --bad-bg: color-mix(in srgb, var(--bad) 14%, var(--bg));
  --warn: #8a5a00;
  --number: #9a5b00;
  --string: #1a7f37;
  --bytes: #b4411f;
  --enum: #8250df;
  --boolean: #0a7d8c;
  --offset: #66707c;
  --type: #1a6fd4;
  --instance: #66707c;
  --hex-row: 20px;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171b;
    --fg: #e4e7eb;
    --muted: #98a2ae;
    --line: #2c333b;
    --panel: #1b1f24;
    --accent: #6aaeff;
    --select: #234a78;
    --select-part: #1c3858;
    --bad: #ff7b72;
    --warn: #e3b341;
    --number: #e3b341;
    --string: #7ee787;
    --bytes: #ffa657;
    --enum: #d2a8ff;
    --boolean: #56d4dd;
    --offset: #98a2ae;
    --type: #6aaeff;
    --instance: #98a2ae;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 system-ui, sans-serif; }
header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px var(--gutter); padding: 8px var(--gutter); border-bottom: 1px solid var(--line); }
h1 { font-size: 1.1rem; margin: 0; }
h1 small, h2 small { color: var(--muted); font-weight: normal; font-family: var(--mono); font-size: .85em; }
h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; margin: 0; padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--panel); color: var(--muted); display: flex; gap: 10px; align-items: baseline; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.button, button { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 3px 10px; cursor: pointer; }
.button:hover, button:hover { border-color: var(--accent); }
.button input { display: none; }
.button:focus-within, button:focus-visible { outline: 2px solid var(--accent); }
#status { margin: 0; color: var(--muted); font-family: var(--mono); font-size: .9em; flex: 1 1 14rem; }

main { display: grid; gap: var(--gutter); padding: var(--gutter); grid-template-columns: 1fr; }
section { border: 1px solid var(--line); border-radius: 4px; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
#pane-editor, #pane-tree, #pane-hex { height: 60vh; min-height: 16rem; }
#pane-problems { max-height: 14rem; }
#editor, #tree-box, #hex, #problems { flex: 1; min-height: 0; overflow: auto; }
#editor .cm-editor { height: 100%; }
#editor .cm-scroller { font-family: var(--mono); }

@media (min-width: 760px) {
  main { grid-template-columns: 1fr 1fr; grid-template-areas: 'editor tree' 'hex hex' 'problems problems'; }
  #pane-editor { grid-area: editor; } #pane-tree { grid-area: tree; } #pane-hex { grid-area: hex; height: 40vh; } #pane-problems { grid-area: problems; }
}
@media (min-width: 1200px) {
  body { height: 100dvh; display: flex; flex-direction: column; }
  main { flex: 1; min-height: 0; grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr auto; grid-template-areas: 'editor tree hex' 'problems problems problems'; }
  #pane-editor, #pane-tree, #pane-hex { height: auto; min-height: 0; }
}

/* the schemas that are open */
#schemas-box { border-top: 1px solid var(--line); }
.schemas-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; justify-content: space-between; padding: 4px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; margin: 0; color: var(--muted); }
#type-box { display: inline-flex; gap: 4px; align-items: center; max-width: 100%; }
#type-box select { max-width: 16rem; text-overflow: ellipsis; }
#schemas { list-style: none; margin: 0; padding: 0; max-height: 9rem; overflow: auto; font-size: .9em; }
#schemas li { display: flex; align-items: center; gap: 4px; padding: 0 10px; }
#schemas li.active { background: var(--select); }
#schemas .pick { flex: 1; display: flex; flex-wrap: wrap; gap: 0 10px; align-items: baseline; text-align: left; border: 0; border-radius: 0; background: none; padding: 2px 0; min-width: 0; }
#schemas li:not(.active) .pick:hover { background: var(--panel); }
#schemas .id { color: var(--type); font-family: var(--mono); }
#schemas .origin { color: var(--muted); }
#schemas .count { color: var(--bad); font-family: var(--mono); }
#schemas li.missing { padding-top: 2px; padding-bottom: 2px; }
#schemas button[data-remove] { padding: 0 6px; line-height: 1.2; }
#edit-note { margin: 0; padding: 4px 10px; border-top: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: .9em; }
#edit-note[hidden] { display: none; }
#editing { color: var(--muted); font-weight: normal; font-family: var(--mono); text-transform: none; letter-spacing: 0; }

/* the tree */
.tree { padding: 4px 0; font-family: var(--mono); font-size: 13px; outline: none; }
.tree-row { display: flex; align-items: baseline; gap: 8px; padding: 1px 8px 1px calc(8px + var(--depth) * 16px); cursor: pointer; white-space: nowrap; }
.tree-row:hover { background: var(--panel); }
.tree-row.selected { background: var(--select); }
.tree-row.instance .name { font-style: italic; color: var(--instance); }
.tree-row.failed { background: var(--bad-bg); }
.tree-row.failed .flag { color: var(--bad); font-weight: 600; }
.tree-row.more { color: var(--accent); }
.toggle { display: inline-block; width: 1em; color: var(--muted); }
.type { color: var(--type); }
.summary { font-weight: 600; }
.summary.number { color: var(--number); }
.summary.string { color: var(--string); }
.summary.bytes { color: var(--bytes); }
.summary.enum { color: var(--enum); }
.summary.boolean { color: var(--boolean); }
.range { color: var(--muted); font-size: .9em; margin-left: auto; padding-left: 12px; }

/* the bytes */
.hex { position: relative; overflow: auto; height: 100%; font-family: var(--mono); font-size: 13px; outline: none; }
.hex-spacer { position: relative; }
.hex-rows { position: absolute; left: 0; right: 0; top: 0; min-width: max-content; }
.hex-row { height: var(--hex-row); line-height: var(--hex-row); white-space: pre; padding: 0 10px; }
.hex-off { color: var(--offset); margin-right: 1.2ch; }
.hex-bytes { margin-right: 2ch; }
.hex-bytes .b { display: inline-block; width: 3ch; text-align: center; cursor: pointer; }
.hex-text .a { cursor: pointer; }
.hex .sel { background: var(--select); }
.hex .sel.part { background: var(--select-part); text-decoration: underline dotted; }

/* the problems */
.problems { padding: 4px 0; }
.problems .none { margin: 0; padding: 6px 10px; color: var(--muted); }
.problem { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; border-radius: 0; background: none; padding: 3px 10px; align-items: baseline; }
.problem:hover { background: var(--panel); }
.problem .kind { color: var(--bad); font-family: var(--mono); font-size: .85em; min-width: 5em; }
.problem .where { color: var(--muted); font-family: var(--mono); }
.problem .message { white-space: pre-wrap; }

#privacy { margin: 0; padding: 6px 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: .85em; }
#privacy button { margin-left: 6px; padding: 0 8px; }
select { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; }
#types-box, #gallery-box, #theme-box, #radix-box, #field-radix-box { display: inline-flex; gap: 4px; align-items: center; }
#export:disabled { opacity: .5; cursor: default; }
[hidden] { display: none !important; }
header select { max-width: 14rem; text-overflow: ellipsis; }
header label { display: inline-flex; gap: 4px; align-items: center; max-width: 100%; }

.pane-tools { display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 0 8px 4px; font-size: 12px; }
.pane-tools[hidden], #field-radix-box[hidden] { display: none; }

#detect-auto-box { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; }
#detect-report { font-size: 12px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 4px; max-height: 12em; overflow: auto; }
#detect-report[hidden] { display: none; }
#detect-report ul { margin: 2px 0; padding-left: 1.2em; }
#detect-report li.fit { color: var(--string); }

/* the browser of types */
#browse-dialog { width: min(52rem, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: inherit; }
#browse-dialog::backdrop { background: rgba(0, 0, 0, .4); }
#browse-dialog[open] { display: flex; flex-direction: column; }
.browse-bar { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.browse-bar h3 { margin: 0; font-size: 1em; }
#browse-filter { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; min-width: 12rem; }
#browse-count { color: var(--muted); font-size: .85em; }
#browse-list { overflow: auto; padding: 0 12px 12px; }
#browse-list h4 { margin: 12px 0 4px; font-size: .85em; color: var(--muted); }
#browse-list ul { list-style: none; margin: 0; padding: 0; }
#browse-list li { padding: 4px 6px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 0 8px; }
#browse-list li.current { background: var(--select); }
#browse-list .browse-path, #browse-list .browse-doc, #browse-list .browse-error { grid-column: 1; font-size: .85em; overflow-wrap: anywhere; }
#browse-list .browse-path { color: var(--muted); font-family: var(--mono); }
#browse-list .browse-error { color: var(--bad); }
#browse-list .browse-buttons { grid-column: 2; grid-row: 1 / span 3; display: flex; gap: 4px; align-items: start; }
.browse-tag { color: var(--muted); font-size: .8em; }
.browse-empty { color: var(--muted); }
#browse-reader { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
#browse-reader-text { margin: 0; padding: 8px 12px; overflow: auto; font-family: var(--mono); font-size: .85em; white-space: pre; }
#browse-note { margin: 0; padding: 4px 12px; color: var(--muted); font-size: .85em; }
#browse-note:empty { display: none; }
#browse-rank-box { display: inline-flex; gap: 4px; align-items: center; font-size: .85em; }
#browse-list .browse-why { grid-column: 1; font-size: .85em; color: var(--string); }
