/* GLB Tester — dark (OLED) theme. Tokens first, components after. */
:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #12151a;
  --raised: #1a1e25;
  --raised-hover: #222833;
  --line: #262b34;
  --line-strong: #3a414d;
  --fg: #e8eaee;
  --dim: #98a1ae;
  --acc: #4da3ff;
  --acc-ink: #06121f;
  --acc-soft: #4da3ff1f;
  --danger: #f87171;
  --ring: 0 0 0 2px var(--bg), 0 0 0 4px var(--acc);
  --radius: 8px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --fast: 150ms;
  --font: "Fira Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Fira Code", ui-monospace, Consolas, monospace;
}
* { box-sizing: border-box }
body {
  margin: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg); font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--acc); color: var(--acc-ink) }

/* ---------- buttons ---------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 6px 14px;
  background: var(--raised); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius);
  font: 500 13px/1 var(--font); cursor: pointer; user-select: none;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), transform 80ms var(--ease);
}
button:hover, .btn:hover { background: var(--raised-hover); border-color: var(--line-strong) }
button:active, .btn:active { transform: scale(.97) }
button:focus-visible, .btn:focus-within, a:focus-visible { outline: 0; box-shadow: var(--ring) }
button:disabled { opacity: .45; cursor: not-allowed; transform: none }
button.primary { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); font-weight: 600 }
button.primary:hover { background: #6ab4ff; border-color: #6ab4ff }
button.icon { width: 34px; padding: 0; flex: none }
button.icon.danger:hover { color: var(--danger); border-color: var(--danger) }
button svg { width: 16px; height: 16px; flex: none }

/* ---------- top bar ---------- */
header {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
header .title { font-weight: 600; letter-spacing: .01em }
header .file { color: var(--dim); font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.grow { flex: 1; min-width: 0 }

/* segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px }
.seg button { min-height: 30px; padding: 4px 14px; border: 0; background: transparent; color: var(--dim); border-radius: 7px }
.seg button:hover { color: var(--fg); background: var(--raised) }
.seg button.on { background: var(--acc); color: var(--acc-ink); font-weight: 600 }
#tabSeg { display: flex }
#tabSeg button { flex: 1 }

/* ---------- layout ---------- */
main { flex: 1; display: flex; min-height: 0 }
#view { flex: 1; position: relative; min-width: 0 }
canvas { display: block; width: 100%; height: 100% }
#empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; color: var(--dim); text-align: center; padding: 24px;
}
#empty svg { width: 56px; height: 56px; stroke: var(--line-strong) }
#dragVeil {
  position: absolute; inset: 12px; display: none; align-items: center; justify-content: center;
  border: 3px dashed var(--acc); border-radius: 16px; background: var(--acc-soft);
  font-size: 22px; font-weight: 600; pointer-events: none;
}
body.dragging #dragVeil { display: flex }

aside {
  width: 340px; flex: none; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; overflow: auto;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
section { padding: 14px 16px; border-bottom: 1px solid var(--line) }
h3 { margin: 0 0 10px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .09em; color: var(--dim) }
.row { display: flex; align-items: center; gap: 10px; margin: 8px 0 }
.row > label:first-child { width: 82px; flex: none; color: var(--dim) }
.row input[type=range] { flex: 1; min-width: 0 }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px }
#info { color: var(--dim); line-height: 1.7; font-family: var(--mono); font-size: 12px }

body[data-mode=viewer] .edit-only { display: none }
body:not([data-mode=viewer]) .viewer-only { display: none }
body[data-tab=options] .tab-parts, body[data-tab=parts] .tab-options { display: none }

/* ---------- parts tree ---------- */
#tree { padding: 8px 12px; min-height: 140px; max-height: 40vh; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent }
#tree ul { list-style: none; margin: 0; padding-left: 16px; border-left: 1px solid var(--line); margin-left: 8px }
#tree > ul { padding-left: 0; border: 0; margin-left: 0 }
#tree li > div { display: flex; align-items: center; gap: 8px; min-height: 30px; padding: 2px 8px; border-radius: 6px; cursor: pointer; transition: background var(--fast) var(--ease) }
#tree li > div:hover { background: var(--raised) }
#tree li > div.sel { background: var(--acc-soft); box-shadow: inset 2px 0 0 var(--acc) }
#tree .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
#tree .m { margin-left: auto; font: 500 10px var(--mono); color: var(--dim); text-transform: uppercase; letter-spacing: .06em }
#props.off { opacity: .4; pointer-events: none }

/* ---------- options editor ---------- */
.opt { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 10px 0 }
.opt .row { margin: 6px 0 }
.eff { border-top: 1px solid var(--line); padding: 8px 0 4px; margin-top: 4px; font-size: 12px }
.eff .row { margin: 4px 0 }
.eff .row > label:first-child { width: auto; flex: 1; color: var(--fg) }
.eff .path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12px }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font: 600 11px/1.3 var(--font); background: var(--raised); color: var(--dim); text-transform: uppercase; letter-spacing: .04em }
.chip.bad { background: #4a1d1d; color: #fecaca }
.chip.warn { background: #4a3a14; color: #fde68a }
.pick { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 14px }
.pick button.on { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); font-weight: 600 }
.finding { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 10px 0; background: var(--bg) }
.finding p { margin: 6px 0 0; color: var(--dim) }

/* ---------- custom form controls ---------- */
label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer }

input[type=text] {
  height: 34px; padding: 0 10px; min-width: 0; flex: 1;
  background: var(--bg); color: var(--fg); font: 13px var(--font);
  border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
input[type=text]::placeholder { color: #6b7380 }
input[type=text]:hover { border-color: var(--line-strong) }
input[type=text]:focus { outline: 0; border-color: var(--acc); box-shadow: 0 0 0 3px var(--acc-soft) }

/* checkbox */
input[type=checkbox] {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0;
  width: 18px; height: 18px; display: inline-grid; place-content: center;
  background: var(--bg); border: 1.5px solid var(--line-strong); border-radius: 5px; cursor: pointer;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
input[type=checkbox]:hover { border-color: var(--acc) }
input[type=checkbox]:checked {
  background: var(--acc) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2306121f' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E") center / 14px no-repeat;
  border-color: var(--acc);
}
input[type=checkbox]:focus-visible { outline: 0; box-shadow: var(--ring) }
input[type=checkbox]:disabled { opacity: .4; cursor: not-allowed }

/* color swatch */
input[type=color] {
  appearance: none; -webkit-appearance: none; flex: none; padding: 0; cursor: pointer;
  width: 44px; height: 30px; background: none; border: 1.5px solid var(--line-strong); border-radius: var(--radius); overflow: hidden;
  transition: border-color var(--fast) var(--ease);
}
input[type=color]:hover { border-color: var(--acc) }
input[type=color]:focus-visible { outline: 0; box-shadow: var(--ring) }
input[type=color]:disabled { opacity: .4; cursor: not-allowed }
input[type=color]::-webkit-color-swatch-wrapper { padding: 0 }
input[type=color]::-webkit-color-swatch { border: 0; border-radius: 6px }
input[type=color]::-moz-color-swatch { border: 0; border-radius: 6px }

/* range slider: --p (0-100) is set from JS to paint the filled part */
input[type=range] {
  appearance: none; -webkit-appearance: none; height: 22px; margin: 0; background: transparent; cursor: pointer;
  --p: 50%;
}
input[type=range]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px;
  background: linear-gradient(to right, var(--acc) var(--p), var(--line-strong) var(--p));
}
input[type=range]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--line-strong) }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--acc) }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -5px; border-radius: 50%;
  background: #fff; border: 3px solid var(--acc); box-shadow: 0 1px 4px #0008;
  transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--acc) }
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.12) }
input[type=range]:focus-visible { outline: 0 }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--acc-soft), 0 0 0 2px var(--acc) }
input[type=range]:disabled { opacity: .4; cursor: not-allowed }

/* ---------- modals ---------- */
dialog {
  background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px; max-width: 90vw; box-shadow: 0 24px 80px #000a;
}
dialog[open] { animation: pop 200ms var(--ease) }
dialog::backdrop { background: #000b; backdrop-filter: blur(4px) }
dialog h2 { margin: 0 0 6px; font-size: 18px; font-weight: 600 }
dialog p { color: var(--dim); margin: 0 0 16px }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px }
#upload { width: min(760px, 92vw) }
#zone {
  height: min(380px, 50vh); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border: 2px dashed var(--line-strong); border-radius: 16px; background: var(--bg); text-align: center; cursor: pointer;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
#zone:hover, #zone.over { border-color: var(--acc); background: var(--acc-soft) }
#zone:focus-visible { outline: 0; box-shadow: var(--ring) }
#zone svg { width: 48px; height: 48px; stroke: var(--acc) }
#zone .big { font-size: 24px; font-weight: 600 }
#zone .sub { color: var(--dim) }

@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98) } }

@media (max-width: 760px) {
  main { flex-direction: column }
  aside { width: auto; max-height: 55%; border-left: 0; border-top: 1px solid var(--line) }
  header { flex-wrap: wrap }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important }
}
