:root {
  --bg: #0f1720;
  --panel: #172230;
  --ink: #e6edf3;
  --muted: #9fb0c0;
  --accent: #2f81f7;
  --ok: #2ea043;
  --bad: #d1242f;
  --line: #2a3a4d;
  --warn: #d29922; /* library review: "not yet approved" accent */
  font-family: system-ui, "Ubuntu", sans-serif;
}
* { box-sizing: border-box; }
/* the hidden attribute must win over display rules like .row{display:flex} */
[hidden] { display: none !important; }
html { background: var(--bg); min-height: 100%; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); }

header {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); background: var(--panel);
}
header h1 { margin: 0; font-size: 1.15rem; }
header small { color: var(--muted); font-weight: 400; }

/* landing-style big-icon tab bar */
nav#tabs { display: flex; align-items: stretch; gap: 0.3rem; flex-wrap: wrap; flex: 1; }
nav#tabs .nav-spacer { flex: 1; }
nav#tabs button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.25rem;
  min-width: 70px; padding: 0.45rem 0.6rem; cursor: pointer; font-size: 0.78rem;
  background: transparent; color: var(--muted); border: 1px solid transparent; border-radius: 8px;
}
nav#tabs button svg { width: 26px; height: 26px; }
nav#tabs button:hover { color: var(--ink); background: var(--bg); }
nav#tabs button.active { color: var(--accent); background: var(--bg); border-color: var(--line); }
#btn-link, #btn-reset { color: var(--muted); }

.thumb-view { max-height: 140px; border: 1px solid var(--line); border-radius: 6px; background: #05080c; }

/* icon-only landing page */
h1[data-tab] { cursor: pointer; }
#tab-home.active { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; max-width: 760px; width: 100%; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
  padding: 1.6rem 1rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; color: var(--ink); cursor: pointer;
  transition: border-color .15s ease, transform .15s ease;
}
.tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.tile svg { width: 48px; height: 48px; color: var(--accent); }
.tile span { font-size: 1.05rem; font-weight: 600; }
.tile small { color: var(--muted); font-size: 0.8rem; text-align: center; }

main { padding: 1rem; max-width: 1100px; margin: 0 auto; }
/* Preview tab uses the full browser width (main is otherwise capped at 1100px) */
body.preview-full main { max-width: none; padding: 0.6rem; }
.tab { display: none; }
.tab.active { display: block; }

.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.5rem 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.6rem; margin: 0.5rem 0; }
label { display: flex; flex-direction: column; gap: 0.2rem; color: var(--muted); font-size: 0.85rem; }

input, textarea, select, button, .btn {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 0.4rem 0.55rem;
}
input[type=range] { padding: 0; }
button, .btn {
  cursor: pointer; background: var(--accent); border-color: var(--accent); color: #fff;
  text-decoration: none; display: inline-block;
}
button:disabled, .btn[hidden] { opacity: 0.5; cursor: default; }
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); }

textarea { width: 100%; min-height: 220px; font-family: ui-monospace, monospace; font-size: 0.85rem; }
#run-log { min-height: 260px; background: #0b1017; }

.badge { font-size: 0.8rem; padding: 0.1rem 0.5rem; border-radius: 10px; }
.badge.ok { background: var(--ok); color: #fff; }
.badge.bad { background: var(--bad); color: #fff; }

#renderpanel { position: relative; }
#canvas { width: 100%; height: 100%; min-height: 300px; background: #05080c; border: 1px solid var(--line); border-radius: 8px; }
#canvas canvas { display: block; border-radius: 8px; }
.controls { margin-top: 0.6rem; }

/* Preview layout: canvas fills the left column, controls the right, with a draggable splitter
   between. The layout fills the viewport height so the canvas gets the whole left area. */
.preview-layout { display: flex; align-items: stretch; height: calc(100vh - 110px); min-height: 420px; }
.preview-layout #renderpanel { flex: 0 0 var(--split, 70%); min-width: 120px; }
.preview-layout .controls { flex: 1 1 0; min-width: 0; margin-top: 0; overflow-y: auto; padding-left: 0.4rem; }
.preview-layout .controls .grid3 { grid-template-columns: 1fr; } /* stack X/Y/Z in the narrow column */
#preview-splitter {
  flex: 0 0 8px; align-self: stretch; margin: 0 4px; border-radius: 4px;
  background: var(--line); cursor: col-resize; touch-action: none;
}
#preview-splitter:hover, #preview-splitter.dragging { background: var(--accent); }
@media (max-width: 820px) {
  .preview-layout { flex-direction: column; height: auto; }
  .preview-layout #renderpanel { flex: none; width: 100%; height: 60vh; }
  #preview-splitter { display: none; }
}
#fps { position: absolute; top: 6px; left: 6px; font: 11px/1.4 monospace; color: #9f9; background: rgba(0,0,0,0.45); padding: 1px 5px; border-radius: 3px; pointer-events: none; }
#thumb-preview { height: 48px; border: 1px solid var(--line); border-radius: 4px; vertical-align: middle; }
.thick { width: 56px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, 170px); gap: 0.8rem; justify-content: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.7rem; }
.card img { width: 100%; border-radius: 6px; background: #05080c; }
.card h3 { margin: 0.4rem 0 0.2rem; font-size: 1rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.card .meta { margin-top: 0.4rem; display: flex; justify-content: space-between; align-items: center; }
.card-info { margin-top: 0.4rem; }
#browse-more { display: block; margin: 0.9rem auto 0; }
.card { cursor: pointer; }
.card.selected { outline: 2px solid var(--accent); }
/* library-review cards: amber dashed border = pending (not approved); green = approved */
.card.review { border: 2px dashed var(--warn); }
.card.review.ok { border: 2px solid var(--ok); border-style: solid; }
.card.review.selected { outline-color: var(--warn); }

/* admin review bar + share edit banner */
#admin-bar, #s-edit-banner {
  background: var(--panel); border: 1px solid var(--warn); border-radius: 8px;
  padding: 0.5rem 0.7rem; margin: 0.5rem 0;
}
#admin-bar #admin-secret { min-width: 220px; }
#admin-bar .muted, #s-edit-banner span { color: var(--muted); font-size: 0.9rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.detail-actions button { flex: 1 1 45%; }
button.warn { background: var(--warn); border-color: var(--warn); color: #1b1500; }
#browse-detail .submitter { color: var(--muted); font-size: 0.85rem; margin: 0.3rem 0; }

/* ---- color themes (default :root above = "ocean" dark) ---- */
html[data-theme="light"] {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #1b2733; --muted: #5b6b7b;
  --accent: #2f81f7; --ok: #1a7f37; --bad: #cf222e; --line: #d0d7de;
}
html[data-theme="nord"] {
  --bg: #2e3440; --panel: #3b4252; --ink: #eceff4; --muted: #a9b3c4;
  --accent: #88c0d0; --ok: #a3be8c; --bad: #bf616a; --line: #434c5e;
}
#themes { display: flex; align-items: center; gap: 0.35rem; padding: 0 0.4rem; }
#themes .theme-btn {
  display: inline-block; min-width: 0; width: 18px; height: 18px; padding: 0;
  border-radius: 50%; background: var(--sw); border: 2px solid var(--line); cursor: pointer;
}
#themes .theme-btn.active { border-color: var(--ink); box-shadow: 0 0 0 2px var(--accent); }

/* inline label (colormap picker) */
label.inline { flex-direction: row; align-items: center; gap: 0.35rem; }
label.inline select { padding: 0.25rem 0.4rem; }

/* JSON tab: textarea fills the available height */
#tab-json.active { display: flex; flex-direction: column; min-height: 72vh; }
#json-text { flex: 1; min-height: 300px; }

/* Browse: results grid + sticky side detail panel */
.browse-layout { display: flex; gap: 1rem; align-items: flex-start; }
.browse-layout .browse-main { flex: 1; min-width: 0; } /* holds the grid + the Show-more button (below) */
#browse-more { display: block; margin: 0.9rem auto 0; }
#browse-detail {
  position: sticky; top: 1rem; flex: 0 0 300px; width: 300px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.8rem;
}
#browse-detail img { width: 100%; max-height: none; }
#browse-detail h3 { margin: 0.5rem 0 0.2rem; }
#browse-detail p {
  color: var(--muted); font-size: 0.9rem;
  max-height: 14em; overflow-y: auto; /* a scrollbar ("slider") appears when the text is long */
}
#browse-detail p pre { white-space: pre-wrap; margin: 0.2rem 0; }
#browse-detail .meta { color: var(--muted); font-size: 0.85rem; margin: 0.3rem 0 0.7rem; }
#browse-detail > button:not(.detail-close) { width: 100%; }
.detail-close { position: absolute; top: 0.4rem; right: 0.4rem; width: 1.8rem; padding: 0.1rem 0; }

/* ---- compact @json-editor ('html' theme): de-blue + shrink buttons, tidy nesting ---- */
#editor-form button {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  padding: 0.1rem 0.45rem; font-size: 0.78rem; border-radius: 5px; margin: 0.1rem;
}
#editor-form button:hover { color: var(--ink); border-color: var(--accent); }
/* collapse toggle -> small down-arrow */
#editor-form .json-editor-btntype-toggle {
  border: none; background: transparent; color: var(--muted); font-size: 0; padding: 0 0.25rem;
}
#editor-form .json-editor-btntype-toggle::before { content: '\25be'; font-size: 1rem; } /* ▾ */
/* keep nested boxes within their parent (no overlap) + compact tables */
#editor-form div, #editor-form fieldset, #editor-form table { min-width: 0; max-width: 100%; }
#editor-form fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 0.4rem 0.6rem; margin: 0.35rem 0; }
#editor-form table { width: 100%; border-collapse: collapse; }
#editor-form td, #editor-form th { padding: 0.15rem 0.3rem; }
#editor-form input, #editor-form select { padding: 0.3rem 0.4rem; }
/* category tabs: json-editor sets an INLINE background:white on the active tab (unreadable
   on dark themes) — override it. Inactive tabs stay dimmed via their inline opacity:.5. */
#editor-form .je-tab, #editor-form .je-tab--top {
  background: var(--panel) !important; color: var(--ink) !important;
  border: 1px solid var(--line); border-radius: 5px 5px 0 0; padding: 0.25rem 0.6rem; cursor: pointer;
}
#editor-form .je-tabholder, #editor-form .je-tabholder--top { border-color: var(--line); }
/* array tables (Media / Dimensions): keep cells + inputs inside the box */
#editor-form .je-table { width: 100%; table-layout: fixed; border-collapse: collapse; }
#editor-form .je-table td, #editor-form .je-table th { padding: 0.15rem 0.25rem; overflow: hidden; }
#editor-form .je-table input, #editor-form .je-table select { width: 100%; min-width: 0; }
#editor-form .je-table-hdiv { max-width: 100%; overflow-x: auto; }
