:root {
  --bg: #131619;
  --panel: #1b1f24;
  --card: #22272e;
  --line: #333a43;
  --text: #d8dde3;
  --dim: #8b949e;
  --accent: #d4763b;
  --accent2: #e8a35a;
  --ok: #5bb974;
  --bad: #e5534b;
  --warn: #d4a72c;
  --radius: 6px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
#app { display: flex; height: 100%; }

/* ---- panel ---- */
#panel {
  width: 340px; flex: 0 0 340px; height: 100%; overflow-y: auto; background: var(--panel);
  border-right: 1px solid var(--line); padding: 8px 10px 16px; scrollbar-width: thin;
}
#app.panel-hidden #panel { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 8px; }
h1 { font-size: 16px; margin: 0; letter-spacing: 0.02em; }
h1::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--accent); margin-right: 8px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--dim); margin: 0 0 8px; display: flex; gap: 6px; align-items: center; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.row.wrap { flex-wrap: wrap; }
.row > label { display: flex; align-items: center; gap: 4px; }
.hint { color: var(--dim); font-size: 12px; margin: 4px 0; line-height: 1.4; }
.panel-foot { display: flex; justify-content: space-between; color: var(--dim); font-size: 11px; padding: 4px 2px; }
.panel-foot a { color: var(--dim); }
.badge { background: var(--line); color: var(--text); border-radius: 8px; padding: 0 6px; font-size: 11px; text-transform: none; letter-spacing: 0; }
.badge.ok { background: #1f4d2b; color: #9be3ae; }
.badge.bad { background: #5c1f1c; color: #ffb4ad; }

input, select, button {
  font: inherit; color: var(--text); background: #2b3139; border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px;
}
input[type=number] { width: 100%; min-width: 0; }
input.narrow { width: 64px; }
.row > label > input[type=number] { width: 110px; }
.row > label > input.narrow { width: 64px; }
#server-maps select { flex: 1; min-width: 0; }
.row > select.grow, .row > label.grow { flex: 1; min-width: 0; }
.row > label.grow select { flex: 1; min-width: 0; }
input[type=checkbox] { accent-color: var(--accent); }
input[type=range] { accent-color: var(--accent); padding: 0; width: 100%; background: none; border: none; }
select { max-width: 100%; }
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: #4b5562; background: #333a43; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #1a1a1a; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent2); }
button.small { padding: 1px 6px; font-size: 11px; }
.icon-btn { background: none; border: none; font-size: 18px; line-height: 1; padding: 2px 6px; color: var(--dim); }
.slider { display: block; margin: 8px 0 2px; }
.slider output { float: right; color: var(--dim); }
.slider.inline { display: flex; align-items: center; gap: 4px; margin: 0; flex: 1; }

.dropzone {
  display: block; border: 1px dashed #4b5562; border-radius: var(--radius); padding: 14px 8px; text-align: center;
  color: var(--dim); cursor: pointer; position: relative;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); color: var(--text); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.progress { position: relative; height: 18px; background: #2b3139; border-radius: 4px; overflow: hidden; margin: 6px 0; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #8a4a22, var(--accent)); transition: width 0.1s; }
.progress .label { position: absolute; inset: 0; font-size: 11px; line-height: 18px; padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* map cards */
.map-card { border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; margin: 6px 0; }
.map-card.active { border-color: var(--accent); }
.map-card header { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.map-card header .title { min-width: 0; overflow-wrap: anywhere; }
.map-card header button { flex: 0 0 auto; }
.map-card .title { font-weight: 600; }
.map-card .meta { color: var(--dim); font-size: 11.5px; line-height: 1.5; margin-top: 2px; }
.map-card .empty { color: var(--warn); }
.map-card .warn { color: var(--warn); font-size: 11.5px; }

/* chips / flags */
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 10px; padding: 1px 7px 1px 4px; font-size: 11.5px; cursor: pointer; user-select: none; }
.chip input { display: none; }
.chip .sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1px solid #0008; }
.chip.off { opacity: 0.4; }
.chip .n { color: var(--dim); }
.flags { display: grid; grid-template-columns: 1fr 1fr; gap: 1px 8px; margin-top: 6px; }
.flags label { display: flex; align-items: center; gap: 4px; font-size: 11.5px; white-space: nowrap; }
.flags .sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.flags .n { color: var(--dim); margin-left: auto; font-size: 10.5px; }
details summary { cursor: pointer; color: var(--dim); font-size: 12px; margin-top: 4px; }

/* compare */
table.stats { width: 100%; border-collapse: collapse; font-size: 11.5px; margin: 6px 0; font-variant-numeric: tabular-nums; }
table.stats th, table.stats td { text-align: right; padding: 2px 4px; border-bottom: 1px solid #2c323a; }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats th { color: var(--dim); font-weight: normal; }
table.stats tr.sel td { background: #2d343d; }
table.stats tr.clickable { cursor: pointer; }
table.stats .ok { color: var(--ok); }
table.stats .bad { color: var(--bad); }
.legend { margin: 6px 0; font-size: 11px; color: var(--dim); }
.legend .ramp { height: 10px; border-radius: 3px; margin: 2px 0; }
.legend .ticks { display: flex; justify-content: space-between; }
.bigstat { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0; }
.bigstat div { background: #1b1f24; border-radius: 4px; padding: 6px; }
.bigstat b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.bigstat span { color: var(--dim); font-size: 11px; }

/* ---- view ---- */
#view { position: relative; flex: 1; min-width: 0; height: 100%; overflow: hidden; }
#gl { display: block; width: 100%; height: 100%; outline: none; touch-action: none; cursor: grab; }
#gl:active { cursor: grabbing; }
.floating { position: absolute; z-index: 5; }
#panel-open { top: 8px; left: 8px; display: none; background: #1b1f24cc; border: 1px solid var(--line); border-radius: 4px; color: var(--text); }
#app.panel-hidden #panel-open { display: block; }
#compass {
  top: 10px; right: 10px; width: 38px; height: 38px; border-radius: 50%; background: #1b1f24cc; border: 1px solid var(--line);
  padding: 0; display: flex; align-items: center; justify-content: center;
}
#compass span { display: block; font-weight: 700; color: var(--accent2); transform-origin: 50% 50%; }
#compass span::before { content: ""; display: block; width: 0; height: 0; margin: 0 auto 1px; border: 5px solid transparent; border-bottom: 8px solid var(--bad); border-top: 0; }
#hud {
  position: absolute; left: 10px; bottom: 10px; z-index: 4; background: #111417dd; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 8px; font-size: 11.5px; line-height: 1.5; max-width: 340px;
  font-variant-numeric: tabular-nums; pointer-events: none;
}
#hud .k { color: var(--dim); }
#hud .d { color: var(--bad); }
#hud .s { color: var(--ok); }
#stats { position: absolute; left: 10px; top: 8px; z-index: 3; color: #8b949e99; font-size: 10.5px; pointer-events: none; font-variant-numeric: tabular-nums; }
#app.panel-hidden #stats { left: 48px; }
#minimap-wrap {
  position: absolute; right: 10px; bottom: 10px; z-index: 4; width: 300px; height: 300px; background: #0a3a46;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: 0 2px 10px #0008;
}
#minimap-wrap.large { width: min(640px, 70vh, 60vw); height: min(640px, 70vh, 60vw); }
#minimap { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
.mm-tools { position: absolute; top: 4px; right: 4px; display: flex; gap: 3px; }
.mm-tools button { background: #111417cc; }
#mm-show { right: 10px; bottom: 10px; }
#empty-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--dim); pointer-events: none; text-align: center; padding: 20px;
}
#empty-hint h2 { font-size: 20px; color: var(--text); text-transform: none; letter-spacing: 0; }
#busy {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 6; background: #111417ee;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; display: flex; gap: 10px; align-items: center;
}
.spinner { width: 18px; height: 18px; border: 3px solid #444; border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#drop-overlay {
  position: fixed; inset: 0; z-index: 20; background: #0d0f12cc; display: flex; align-items: center; justify-content: center;
  font-size: 22px; border: 3px dashed var(--accent); pointer-events: none;
}
#toasts { position: absolute; top: 56px; right: 10px; z-index: 10; display: flex; flex-direction: column; gap: 6px; max-width: min(460px, 80%); }
.toast {
  background: #22272e; border: 1px solid var(--line); border-left: 4px solid var(--dim); border-radius: 4px; padding: 8px 28px 8px 10px;
  position: relative; box-shadow: 0 2px 8px #0008; white-space: pre-wrap; word-break: break-word; font-size: 12px;
}
.toast.error { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
.toast button { position: absolute; top: 4px; right: 4px; background: none; border: none; color: var(--dim); font-size: 14px; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); max-width: 460px; }
dialog::backdrop { background: #0008; }

@media (max-width: 760px) {
  #panel { position: absolute; z-index: 15; width: min(340px, 92vw); box-shadow: 4px 0 16px #000a; }
  #minimap-wrap { width: 170px; height: 170px; }
  #hud { max-width: 60vw; font-size: 10.5px; }
}

/* ---- generate card: seed / size semantics ---- */
.gen-inputs > label { min-width: 0; }
.gen-inputs > label.grow { flex: 1; }
.gen-inputs > label > input { width: 100%; min-width: 0; font-variant-numeric: tabular-nums; }
.gen-inputs > label:not(.grow) > input { width: 76px; }
.gen-inputs > label { display: flex; flex-direction: column; align-items: stretch; gap: 2px; font-size: 11.5px; color: var(--dim); }
.gen-inputs { align-items: flex-end; }
.effective { font-size: 11.5px; line-height: 1.5; color: var(--text); margin: 4px 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.effective .k { color: var(--dim); }
.effective code, .hint code, dialog code { font-size: 11px; background: #2b3139; border-radius: 3px; padding: 0 3px; }
.effective.blocked { color: var(--warn); }
#gen-notes .note { font-size: 11.5px; line-height: 1.4; margin: 2px 0; }
#gen-notes .note.warn { color: var(--warn); }
#gen-notes .note.info { color: var(--dim); }
#gen-notes .note button { margin-left: 4px; }
.hint.env { color: var(--warn); }
details#gen-advanced { margin: 6px 0 2px; }
details#gen-advanced .row input { min-width: 0; }
input.grow { flex: 1; }
label.check { display: block; margin: 6px 0; line-height: 1.4; }
button.help-q { font-size: 10px; padding: 0 5px; border-radius: 50%; line-height: 15px; height: 17px; min-width: 17px; color: var(--dim); text-transform: none; letter-spacing: 0; }
.progress .label { text-shadow: 0 0 3px #000; }

/* ---- compare explanation, help dialog ---- */
details#cmp-explain { margin: 4px 0 6px; }
.explain { font-size: 12px; line-height: 1.5; color: var(--text); }
.explain p { margin: 6px 0; }
.explain ul { margin: 4px 0; padding-left: 18px; }
.explain b { color: #fff; }
dialog#help { max-width: min(640px, 94vw); max-height: 88vh; overflow-y: auto; padding: 8px 18px 14px; line-height: 1.45; }
dialog#help section { margin: 4px 0 12px; }
dialog#help h3 { margin: 10px 0 6px; font-size: 14px; }
dialog#help ul { padding-left: 18px; margin: 4px 0; }
dialog#help p { margin: 6px 0; }
.dialog-close { position: sticky; top: 0; float: right; margin: 0; z-index: 1; }
.dialog-close button { font-size: 16px; line-height: 1; padding: 2px 8px; }
table.keys { border-collapse: collapse; font-size: 12.5px; }
table.keys td { padding: 2px 8px 2px 0; vertical-align: top; }
table.keys td:first-child { white-space: nowrap; }
kbd { display: inline-block; min-width: 18px; padding: 0 4px; border: 1px solid #4b5562; border-bottom-width: 2px; border-radius: 4px;
  background: #2b3139; font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; color: var(--text); }

/* ---- monument labels over the 3D view ---- */
#labels { position: absolute; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
#labels .lbl {
  position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 12px; font-weight: 600; color: #fff; will-change: transform;
  text-shadow: 0 0 3px #000, 0 0 2px #000, 0 1px 2px #000; letter-spacing: 0.01em;
}
#labels .lbl.minor { font-size: 10.5px; font-weight: 500; font-style: italic; color: #d8dde3; }

/* ---- legend ---- */
#legend {
  left: 10px; top: 28px; z-index: 4; width: 210px; max-height: calc(100% - 200px); overflow-y: auto; background: #111417dd;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 8px 6px; font-size: 11px; line-height: 1.35;
  scrollbar-width: thin;
}
#legend header { display: flex; justify-content: space-between; align-items: center; color: var(--dim); text-transform: uppercase;
  letter-spacing: 0.06em; font-size: 10.5px; margin-bottom: 2px; }
#legend h4 { margin: 6px 0 2px; font-size: 11px; font-weight: 600; color: var(--text); }
#legend .it { display: flex; align-items: center; gap: 6px; }
#legend .sw { width: 12px; height: 10px; border-radius: 2px; flex: 0 0 auto; border: 1px solid #0006; }
#legend .sw.dot { border-radius: 50%; width: 10px; }
#legend .sw.line { height: 3px; border: none; border-radius: 2px; }
#legend .sw.hatch { background: repeating-linear-gradient(45deg, #333 0 2px, #777 2px 4px); }
#legend .ramp { height: 9px; border-radius: 2px; margin: 2px 0 1px; }
#legend .ticks { display: flex; justify-content: space-between; color: var(--dim); font-size: 10px; }
#legend .note { color: var(--dim); font-size: 10px; }
#legend-show { left: 10px; top: 28px; }
#app.panel-hidden #legend-show { left: 8px; top: 48px; }
#app.panel-hidden #legend { top: 48px; }

@media (max-width: 760px) {
  #legend { width: 170px; font-size: 10.5px; max-height: 45%; }
  #labels .lbl { font-size: 11px; }
  #labels .lbl.minor { display: none; }
  .gen-inputs > label:not(.grow) > input { width: 64px; }
  input, select, button { padding: 6px 8px; }
  button.small { padding: 4px 8px; }
  #panel { padding-bottom: 60px; }
  .row { flex-wrap: wrap; }
  .row > label { max-width: 100%; }
  .row > label > select { max-width: 200px; }
}
#legend .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 6px; }
.toast a.share-url { color: var(--accent2); word-break: break-all; }
/* the generation label (stage, threads, downloads, elapsed time) wraps instead of being cut off */
#gen-progress { height: auto; min-height: 18px; }
#gen-progress .label { position: relative; display: block; white-space: normal; line-height: 15px; padding: 2px 6px; }

/* ---- glitch finder ---- */
label.btn-file { position: relative; display: inline-flex; align-items: center; font: inherit; color: var(--text); background: #2b3139;
  border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; cursor: pointer; }
label.btn-file:hover { border-color: #4b5562; background: #333a43; }
label.btn-file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
#sec-glitch .badge.warn { background: #4d3b12; color: #f0d58a; }
.gl-producer, .gl-notes { font-size: 11px; }
.gl-notes ul { margin: 2px 0; padding-left: 16px; }
.gl-show label { font-size: 12px; }
#gl-search { min-width: 0; }
.gl-list { max-height: min(46vh, 520px); overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; background: #1d2228;
  margin: 6px 0; scrollbar-width: thin; outline: none; }
.gl-list:focus-visible { border-color: var(--accent); }
.gl-list .empty { color: var(--dim); padding: 8px; font-size: 12px; }
.gl-cat { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 6px; padding: 4px 6px; background: #262c34;
  border-bottom: 1px solid var(--line); font-size: 11.5px; font-weight: 600; cursor: pointer; user-select: none; }
.gl-cat .sw { width: 10px; height: 10px; border-radius: 2px; flex: 0 0 auto; }
.gl-cat .n { color: var(--dim); font-weight: normal; margin-left: auto; }
.gl-cat .tw { color: var(--dim); width: 10px; }
.gl-place { display: flex; align-items: center; gap: 6px; padding: 3px 6px 3px 10px; font-size: 11.5px; color: var(--text);
  border-bottom: 1px solid #262c34; cursor: pointer; user-select: none; background: #20262d; }
.gl-place .n { color: var(--dim); margin-left: auto; }
.gl-place .tw { color: var(--dim); width: 10px; }
.gl-row { display: grid; grid-template-columns: 30px 1fr auto; gap: 2px 6px; align-items: center; padding: 4px 6px 4px 8px;
  border-bottom: 1px solid #262c34; cursor: pointer; }
.gl-row.nested { padding-left: 18px; }
.gl-row:hover { background: #262c34; }
.gl-row.sel { background: #33302a; box-shadow: inset 3px 0 0 var(--accent2); }
.gl-row .sev { grid-row: 1 / span 2; position: relative; height: 26px; border-radius: 3px; background: #2b3139; overflow: hidden; }
.gl-row .sev i { position: absolute; left: 0; right: 0; bottom: 0; display: block; }
.gl-row .sev b { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px;
  font-variant-numeric: tabular-nums; text-shadow: 0 0 3px #000, 0 0 2px #000; }
.gl-row .t1 { font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gl-row .t1 .id { color: var(--dim); font-size: 10.5px; margin-right: 4px; font-variant-numeric: tabular-nums; }
.gl-row .t2 { grid-column: 2 / span 2; font-size: 10.5px; color: var(--dim); display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.gl-row .go { grid-row: 1; grid-column: 3; padding: 0 6px; font-size: 11px; }
.tag { display: inline-block; border-radius: 7px; padding: 0 5px; font-size: 10px; line-height: 14px; background: #2f363f; color: #c3cad2; white-space: nowrap; }
.tag.p { background: #1f4d2b; color: #9be3ae; }
.tag.c { background: #4d3b12; color: #f0d58a; }
.tag.solid { background: #12424d; color: #9adcea; }
.tag.conf4 { background: #1f4d2b; color: #9be3ae; }
.tag.conf3 { background: #234a3a; color: #a6dcc0; }
.tag.conf2 { background: #2f3a4d; color: #b6c8e8; }
.tag.conf1, .tag.conf0 { background: #3a3030; color: #d9b4ae; }
.gl-more { padding: 4px 18px; font-size: 11px; color: var(--accent2); cursor: pointer; border-bottom: 1px solid #262c34; }
.gl-detail { border: 1px solid var(--accent2); border-radius: 4px; padding: 6px 8px; margin: 6px 0; background: #22262b; font-size: 12px; }
.gl-detail header { display: flex; align-items: center; gap: 6px; }
.gl-detail header .ttl { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.gl-detail header .sevb { font-variant-numeric: tabular-nums; border-radius: 3px; padding: 0 5px; color: #111; font-weight: 700; }
.gl-detail .sum { margin: 4px 0; line-height: 1.4; }
.gl-detail .what { color: var(--dim); font-size: 11px; margin: 2px 0 4px; line-height: 1.35; }
.gl-detail table { width: 100%; border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; margin: 4px 0; table-layout: fixed; }
.gl-detail td { padding: 1px 4px 1px 0; vertical-align: top; border-bottom: 1px solid #2c323a; overflow-wrap: anywhere; }
.gl-detail td:first-child { color: var(--dim); width: 78px; overflow-wrap: normal; }
.gl-detail .btns { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.gl-detail canvas { width: 100%; height: 168px; display: block; background: #15191d; border-radius: 3px; margin: 4px 0 2px; }
.gl-detail .cap { color: var(--dim); font-size: 10px; }
.gl-detail details summary { font-size: 11px; }
.gl-explain-cat { display: grid; grid-template-columns: 12px 1fr; gap: 0 6px; margin: 6px 0; }
.gl-explain-cat .sw { width: 10px; height: 10px; border-radius: 2px; margin-top: 4px; }
.gl-explain-cat .basis { font-size: 10px; border-radius: 6px; padding: 0 5px; margin-left: 4px; background: #2f363f; color: var(--dim); font-weight: normal; }
.gl-explain-cat p { margin: 2px 0; }
#hud .g { color: #ffb4ad; }
#legend .sw.diamond { width: 9px; height: 9px; transform: rotate(45deg) scale(0.85); border: 1px solid #f4f4f4; border-radius: 1px; margin: 0 1px; }
.gl-source-note { border-left: 3px solid var(--accent2); padding-left: 6px; }
#gl-vsref table.stats td { white-space: nowrap; }
#gl-vsref table.stats .k { color: var(--dim); font-size: 10.5px; }
