:root {
  --bg: #15171a;
  --panel: #1c1f24;
  --line: #2c3037;
  --text: #e6e8eb;
  --muted: #98a0ab;
  --accent: #5aa9ff;
  --accent-ink: #06182c;
  --warn: #f2b45a;
  --bad: #ff7a7a;
  --sel: #ffcf4a;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, sans-serif; }
#app { display: grid; grid-template-columns: 1fr 340px; height: 100%; }
main { display: flex; flex-direction: column; min-width: 0; }
header { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.hud { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
#stage { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }
#map, #view3d { flex: 1; min-height: 0; position: relative; background: #0d0f11; }
#toast { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); max-width: 80%; z-index: 1000; padding: 8px 14px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0,0,0,.5); }
#toast.error { border-color: var(--bad); color: var(--bad); }
#toast.busy::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border: 2px solid var(--muted); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
#map { cursor: crosshair; }
#map.leaflet-container { background: #0d0f11; }
#map img.leaflet-tile { image-rendering: pixelated; }
#view3d canvas { width: 100%; height: 100%; display: block; }
#empty3d { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
[hidden] { display: none !important; }

aside { background: var(--panel); border-left: 1px solid var(--line); padding: 14px 16px 24px; overflow-y: auto; }
h1 { font-size: 16px; margin: 0 0 2px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
section { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.muted { color: var(--muted); }
.small { font-size: 12px; text-transform: none; letter-spacing: 0; }
p { margin: 6px 0; }

button { font: inherit; color: var(--text); background: #262a31; border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { background: #2e333b; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
button.primary:hover { background: #7bbcff; }
.tab.active, .tool.active, .segmented button.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

input[type=number], input[type=text] { width: 100%; font: inherit; color: var(--text); background: #12141a; border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; color: var(--muted); font-size: 12px; }
label.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0; font-size: 13px; }
label.row input { width: 90px; }
label.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; color: var(--text); }
.grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; }
.segmented button { border-radius: 0; }
.segmented button:first-child { border-radius: 6px 0 0 6px; }
.segmented button:last-child { border-radius: 0 6px 6px 0; }
.spools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 4px; }
.spools label { text-align: center; }
.spools input[type=color] { width: 100%; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: none; cursor: pointer; }
.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 18px; }
.status { min-height: 20px; color: var(--muted); }
.status.error { color: var(--bad); }
.warn { color: var(--warn); font-size: 13px; }
.stat { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed var(--line); font-variant-numeric: tabular-nums; }
.legend { list-style: none; padding: 0; margin: 10px 0 0; }
.legend li { display: grid; grid-template-columns: 20px 1fr auto; gap: 8px; align-items: center; padding: 3px 0; font-size: 13px; }
.swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(255,255,255,.25); }

.handle { background: var(--sel); border: 2px solid #1b1b1b; border-radius: 3px; cursor: move; }
.leaflet-container { font: inherit; }
.leaflet-control-zoom a { color: #222; }

@media (max-width: 800px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 60vh auto; height: auto; }
  aside { border-left: 0; border-top: 1px solid var(--line); }
}

.pill { padding: 3px 10px; border-radius: 999px; background: #262a31; border: 1px solid var(--line); color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
select { width: 100%; max-width: 210px; font: inherit; color: var(--text); background: #12141a; border: 1px solid var(--line); border-radius: 5px; padding: 5px 7px; }
#no-world { position: absolute; inset: 0; z-index: 900; display: grid; place-content: center; justify-items: center; gap: 12px; background: var(--bg); color: var(--muted); }

dialog { width: min(720px, 92vw); max-height: 86vh; padding: 18px 20px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog[open] { display: flex; flex-direction: column; gap: 10px; }
dialog.busy { cursor: progress; }
dialog.busy .filelist, dialog.busy .chips { opacity: .5; pointer-events: none; }
dialog h2 { margin: 0; font-size: 15px; color: var(--text); text-transform: none; letter-spacing: 0; }
code { background: #12141a; padding: 1px 5px; border-radius: 4px; }
.pathrow { display: flex; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 10px; border-radius: 999px; font-size: 12px; }
.crumb { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; min-height: 28px; word-break: break-all; }
.filelist { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 140px; max-height: 40vh; border: 1px solid var(--line); border-radius: 6px; background: #12141a; }
.filelist li { display: grid; grid-template-columns: 20px 1fr auto; gap: 8px; padding: 6px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.filelist li:hover { background: #1f232a; }
.filelist li.sel { background: #163353; }
.filelist li.world span:nth-child(2), .filelist li.zip span:nth-child(2) { color: var(--accent); }
.filelist li.muted { cursor: default; }
.error { color: var(--bad); min-height: 20px; margin: 0; }
.dialog-actions { display: flex; align-items: center; justify-content: space-between; }

/* Present and focusable for the browser, invisible to the eye: display:none would let a browser
   refuse to open the file picker. */
.offscreen { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

/* Last in the header, so it stays pinned right while the HUD's text grows leftwards. Kept a little
   shorter than the buttons beside it: secondary, and it does not change the header's height. */
.support { display: inline-flex; align-items: center; flex: none; }
.support img { height: 30px; width: auto; border: 0; opacity: 0.8; transition: opacity 0.15s; }
.support:hover img, .support:focus-visible img { opacity: 1; }
