:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --view: #e6e6e3;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #d9d9d6;
  --accent: #2f6fd6;
  --accent-ink: #ffffff;
  --warn: #a8551c;
  --sel: #e5eefc;
  --mono: ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  --k-clusters: #2a8a5a;
  --k-hlod: #9a5cc6;
  --k-splats: #c0702a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151517;
    --panel: #1d1d20;
    --view: #26262a;
    --ink: #ececee;
    --muted: #9a9aa2;
    --line: #34343a;
    --accent: #6b9ef0;
    --accent-ink: #0d1626;
    --warn: #e39a62;
    --sel: #23324a;
    --k-clusters: #5cc492;
    --k-hlod: #c194ea;
    --k-splats: #eda366;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-columns: 300px 1fr;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, select, input { font: inherit; color: inherit; }
button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
select { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; }

/* Sidebar */
#side {
  overflow-y: auto;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
header h1 { margin: 0; font-size: 20px; letter-spacing: 0.02em; }
header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

#drop {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
  color: var(--muted);
}
#drop strong { color: var(--ink); }
#drop .row { display: flex; gap: 6px; justify-content: center; align-items: center; flex-wrap: wrap; }
body.dragging #drop { border-color: var(--accent); background: var(--sel); }

/* Sample cards in the sidebar */
#samples { display: flex; flex-direction: column; gap: 8px; }
#samples h2 { margin: 0; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
#samples .credit { font-size: 11px; color: var(--muted); }
#samples .credit a { color: inherit; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: stretch; gap: 0;
  padding: 0; border-radius: 8px; text-align: left; background: var(--panel);
}
.card img, .card .noimg {
  display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--view);
}
.card .name { padding: 4px 6px 0; font-size: 12px; font-weight: 600; line-height: 1.25; }
.card .size { padding: 0 6px 5px; font-size: 11px; color: var(--muted); font-family: var(--mono); }
.card:hover { border-color: var(--accent); }
.card:hover img { filter: brightness(1.06); }
.card[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card .bar {
  position: absolute; left: 0; bottom: 0; height: 3px; width: calc(var(--p, 0) * 100%);
  background: var(--accent); transition: width 0.15s; visibility: hidden;
}
.card.loading .bar { visibility: visible; }
.card.loading img { opacity: 0.7; }

#asset h2 { margin: 0 0 6px; font-size: 15px; word-break: break-all; }
#asset dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; font-size: 13px; }
#asset dt { color: var(--muted); }
#asset dd { margin: 0; text-align: right; font-family: var(--mono); font-size: 12px; }
.warn { color: var(--warn); font-size: 13px; margin: 8px 0 0; }

fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 10px 0 0; display: flex; flex-direction: column; gap: 8px; }
legend { padding: 0 6px 0 0; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
label.range { display: grid; grid-template-columns: 1fr auto; row-gap: 2px; }
label.range input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
label.range output { font-family: var(--mono); font-size: 12px; }
label.select { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
label.check { display: flex; gap: 6px; align-items: center; }
label.check input { accent-color: var(--accent); }
.hint { margin: 0 0 6px; font-size: 12px; color: var(--muted); }
.hint code { font-size: 11px; }
form:disabled, form[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

/* Main */
main { display: grid; grid-template-rows: 1fr auto; min-width: 0; min-height: 0; height: 100vh; }
#view { position: relative; background: var(--view); min-height: 0; overflow: hidden; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#empty {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 24px;
  color: var(--muted); font-size: 16px; pointer-events: none; text-align: center;
}

/* Auto mode's magnifier */
#mag {
  position: absolute; right: 12px; top: 40px; margin: 0; pointer-events: none;
  background: var(--view); border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
}
#mag canvas { display: block; width: 160px; height: 160px; image-rendering: pixelated; }
#mag figcaption {
  font-family: var(--mono); font-size: 11px; color: var(--muted); text-align: center;
  padding: 2px 6px; border-top: 1px solid var(--line); background: var(--panel);
}

/* Auto mode's distance slider; ticks mark each level's switch distance */
.dist { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dist .track { position: relative; display: block; width: 180px; }
.dist input { width: 100%; display: block; accent-color: var(--accent); margin: 0; }
#ticks { position: absolute; inset: 0; pointer-events: none; }
#ticks i {
  position: absolute; top: -5px; width: 1px; height: 5px; background: var(--muted);
  left: calc(8px + var(--t) * (100% - 16px));
}
#hud {
  position: absolute; left: 12px; top: 10px; right: 12px;
  display: flex; justify-content: space-between; pointer-events: none;
  font-family: var(--mono); font-size: 12px;
}
#hud span { background: color-mix(in srgb, var(--panel) 80%, transparent); padding: 2px 8px; border-radius: 4px; }
#viewbar {
  position: absolute; right: 12px; bottom: 10px; display: flex; gap: 12px; align-items: center;
  flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 24px);
  background: color-mix(in srgb, var(--panel) 85%, transparent); padding: 4px 8px; border-radius: 8px;
}
.seg { display: flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#status {
  position: absolute; left: 12px; bottom: 12px; font-size: 13px; color: var(--muted);
  display: flex; align-items: center; gap: 8px; max-width: 50%;
}
#status.busy::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--accent); border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
#status.error { color: var(--warn); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Download / preparing overlay over the viewport */
#loading {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 5;
  background: color-mix(in srgb, var(--view) 72%, transparent);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade-in 0.15s ease-out;
}
#loading .box {
  display: flex; gap: 16px; align-items: center; width: min(460px, 100%);
  padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  box-shadow: 0 10px 40px rgb(0 0 0 / 0.18);
}
#loading img { width: 96px; height: 96px; border-radius: 8px; object-fit: cover; background: var(--view); flex: none; }
#loading .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
#loading .title { font-size: 17px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#loading .phase { color: var(--muted); font-size: 13px; }
#loading .meter {
  position: relative; height: 10px; border-radius: 5px; overflow: hidden;
  background: color-mix(in srgb, var(--accent) 16%, var(--view));
}
#loading .meter span {
  position: absolute; inset: 0 auto 0 0; width: calc(var(--p, 0) * 100%);
  border-radius: 5px; background: var(--accent); transition: width 0.15s;
}
#loading.indeterminate .meter span { width: 35%; animation: slide 1.1s ease-in-out infinite; transition: none; }
#loading .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#loading .nums { font-family: var(--mono); font-size: 12px; color: var(--muted); }
#loading .cancel { font-size: 12px; padding: 3px 10px; }
@keyframes slide { from { left: -35%; } to { left: 100%; } }
@keyframes fade-in { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  #loading.indeterminate .meter span { animation: none; width: 100%; opacity: 0.5; }
}

#panel {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 16px; align-items: start;
  border-top: 1px solid var(--line); background: var(--panel);
  padding: 10px 16px; max-height: 42vh; overflow: auto;
}
/* The cut panel and the bake panel share the right column (both show in HLOD mode). */
#levels { overflow-x: auto; grid-row: 1 / span 2; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 4px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 4px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.n { text-align: right; font-family: var(--mono); font-size: 12px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: color-mix(in srgb, var(--sel) 50%, transparent); }
tbody tr.selected { background: var(--sel); }
tbody tr.pending td { color: var(--muted); font-style: italic; }
.kind { font-size: 11px; padding: 1px 6px; border-radius: 10px; border: 1px solid var(--line); }
.kind.baked { border-color: var(--accent); color: var(--accent); }
.kind.clusters { border-color: var(--k-clusters); color: var(--k-clusters); }
.kind.hlod { border-color: var(--k-hlod); color: var(--k-hlod); }
.kind.splats { border-color: var(--k-splats); color: var(--k-splats); }
td.label { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
td button { padding: 0 8px; font-size: 12px; }

#cut { width: 280px; display: flex; flex-direction: column; gap: 8px; }
#cut h3 { margin: 0; font-size: 13px; }
#cut .controls { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
#cut dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0; font-size: 12px; }
#cut dt { color: var(--muted); }
#cut dd { margin: 0; text-align: right; font-family: var(--mono); font-size: 12px; }
#cut dd.ok { color: var(--k-clusters); }
#cut dd.bad { color: var(--warn); }

#bake { width: 300px; }
#bake h3 { margin: 0 0 6px; font-size: 13px; }
#bake .tex { display: flex; gap: 8px; }
#bake figure { margin: 0; flex: 1; }
#bake canvas {
  width: 100%; aspect-ratio: 1; display: block; border: 1px solid var(--line); border-radius: 4px;
  image-rendering: pixelated;
  background: repeating-conic-gradient(var(--line) 0 25%, transparent 0 50%) 0 0 / 16px 16px;
}
#bake figcaption { font-size: 12px; color: var(--muted); text-align: center; }
#bake p { font-size: 12px; color: var(--muted); margin: 6px 0 0; font-family: var(--mono); }
#bake.empty canvas { visibility: hidden; }

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; height: auto; }
  #side { border-right: 0; border-bottom: 1px solid var(--line); }
  main { height: auto; grid-template-rows: 70vh auto; }
  #panel { grid-template-columns: 1fr; max-height: none; }
  #bake, #cut { width: auto; }
}
