/* Colors mirror Hillshade Studio's Palette.cs (OKLCH tokens converted to sRGB). */
:root {
  --bg: #F4F2EE;
  --panel: #FFFFFF;
  --panel-alt: #FAF9F6;
  --border: #E3DED5;
  --border-light: #EEE9DF;
  --border-dashed: #C9C2B4;
  --text: #2A2622;
  --text-mid: #4A453D;
  --text-soft: #6F6A61;
  --text-dim: #9B958A;
  --canvas-bg: #EAE6DC;
  --log-bg: #201E1B;
  --log-text: #D8D2C5;
  --accent: #B6522D;
  --accent-soft: rgba(172, 101, 75, 0.14);
  --done: #287C42;
  --error: #C53443;
  --warn: #C55123;
  --tech: var(--accent);
  --tech-soft: var(--accent-soft);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.brand h1 { margin: 0; font-size: 20px; color: var(--text); letter-spacing: -0.01em; }
.tag { color: var(--text-soft); font-size: 13px; }
.badge {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--text-mid); border: 1px solid var(--border);
}
.badge.ok { background: rgba(40, 124, 66, 0.12); color: var(--done); }

main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 40px; display: grid; gap: 16px; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px;
}
.card h2 { margin: 0 0 12px; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.card h3 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-soft); }
.step {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 600;
}

.muted { color: var(--text-soft); }
.hint { color: var(--text-soft); font-size: 13px; margin: 6px 0; }

/* Boot / fatal */
.boot { display: grid; place-items: center; gap: 10px; padding: 60px 20px; color: var(--text-soft); }
.fatal { max-width: 640px; margin: 40px auto; padding: 24px; background: var(--panel); border: 1px solid var(--error); border-radius: 12px; }
.fatal h2 { margin-top: 0; color: var(--error); }

/* Spinner animates via transform, so it keeps turning even while the main thread is busy. */
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Drop zone */
.dropzone {
  display: grid; gap: 4px; text-align: center; cursor: pointer;
  padding: 22px 16px; border: 2px dashed var(--border-dashed); border-radius: 10px; background: var(--panel-alt);
  transition: background 0.15s, border-color 0.15s;
}
.dropzone span { color: var(--text-soft); font-size: 13px; }
.dropzone:hover, .dropzone.over { background: var(--accent-soft); border-color: var(--accent); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Tile map */
#tile-status { margin: 10px 0 0; min-height: 1.4em; }
#tile-map { display: block; width: 100%; height: 100%; background: var(--canvas-bg); }
.mapframe { position: relative; height: 440px; margin-top: 10px; border-radius: 10px 10px 0 0; overflow: hidden; background: var(--canvas-bg); }
#tile-map .basemap { pointer-events: none; }
#tile-map.osm-on .tile rect.body { fill-opacity: 0.45; }
#tile-map.osm-on .tile.selected rect.body { fill-opacity: 0.6; }
#tile-map .tile text { paint-order: stroke; stroke: rgba(255,255,255,0.9); stroke-width: 0.2em; stroke-linejoin: round; }
#tile-map .tile rect.body { stroke: var(--text-dim); stroke-width: 1; fill: #fff; cursor: pointer; vector-effect: non-scaling-stroke; }
#tile-map .tile.included rect.body { fill: #F7E4DA; stroke: var(--accent); }
#tile-map .tile.selected rect.body { stroke-width: 3; fill: #F1CDBB; }
#tile-map .tile.excluded rect.body { fill: var(--panel-alt); stroke-dasharray: 5 4; }
#tile-map .tile text { font-size: 13px; fill: var(--text-mid); pointer-events: none; text-anchor: middle; }
#tile-map .tile.excluded text { fill: var(--text-dim); }
#tile-map .check { cursor: pointer; }
#tile-map .check rect { fill: #fff; stroke: var(--text-soft); stroke-width: 1; vector-effect: non-scaling-stroke; }
#tile-map .tile.included .check rect { fill: var(--accent); stroke: var(--accent); }
#tile-map .check path { fill: none; stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; display: none; }
#tile-map .tile.included .check path { display: block; }

.warning {
  margin: 8px 0; padding: 8px 12px; border-radius: 8px;
  background: rgba(197, 81, 35, 0.1); border: 1px solid rgba(197, 81, 35, 0.4); color: #8A3A19; font-size: 14px;
}
.error {
  margin-top: 12px; padding: 8px 12px; border-radius: 8px;
  background: rgba(197, 52, 67, 0.1); border: 1px solid rgba(197, 52, 67, 0.4); color: #8E2431;
}

.tile-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 12px; font-size: 13px; }
.tile-list li { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 6px; cursor: pointer; }
.tile-list li.selected { background: var(--accent-soft); }
.tile-list .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-list .pts { color: var(--text-dim); }
.tile-list .rm { border: 0; background: none; color: var(--text-dim); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.tile-list .rm:hover { color: var(--error); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit; font-size: 13px; cursor: pointer; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel-alt); color: var(--text-mid);
  transition: background 0.12s, border-color 0.12s;
}
.chip:hover { border-color: var(--chip, var(--accent)); }
.chip[aria-selected="true"], .chip.on { background: var(--chip-soft, var(--accent-soft)); border-color: var(--chip, var(--accent)); color: var(--text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--chip, var(--accent)); }
.chip:focus-visible { outline: 2px solid var(--chip, var(--accent)); outline-offset: 2px; }
.selectable .chip::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 7px; border-radius: 2px; border: 1.5px solid var(--chip, var(--accent)); vertical-align: baseline; }
.selectable .chip.on::before { background: var(--chip, var(--accent)); }

.tech-desc { margin: 10px 0 12px; color: var(--text-soft); min-height: 1.4em; }
.tech-desc a { white-space: nowrap; }

/* Preview */
.preview-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.preview-frame {
  position: relative; background: var(--canvas-bg); border-radius: 10px; height: min(70vh, 640px); min-height: 280px;
  display: grid; place-items: center; overflow: hidden;
}
.preview-stage { position: relative; overflow: hidden; background: var(--canvas-bg); box-shadow: 0 0 0 1px var(--border); }
.preview-stage img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#preview-base { z-index: 0; }
#preview-img { z-index: 1; }
.preview-stage.with-base #preview-img { mix-blend-mode: multiply; }
#preview-img.pixelated { image-rendering: pixelated; }
.empty { color: var(--text-soft); padding: 40px 16px; text-align: center; }
.busy {
  position: absolute; right: 10px; top: 10px; display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.92); border: 1px solid var(--border); padding: 5px 12px 5px 8px; border-radius: 999px; font-size: 13px;
}
.busy .spinner { width: 16px; height: 16px; border-width: 2px; }
.meta { margin-top: 8px; font-size: 13px; }
.mini-log { margin: 6px 0 0; padding: 8px 10px; font-size: 12px; white-space: pre-wrap; background: var(--panel-alt); border: 1px solid var(--border-light); border-radius: 8px; color: var(--text-mid); }

.settings { border: 1px solid var(--border-light); border-radius: 10px; padding: 4px 14px 14px; background: var(--panel-alt); }
.settings h3:first-child { margin-top: 12px; }
.param { display: grid; gap: 2px; margin-bottom: 10px; }
.param > label { font-size: 13px; color: var(--text-mid); display: flex; justify-content: space-between; gap: 8px; }
.param .ctl { display: grid; grid-template-columns: 1fr 74px; gap: 8px; align-items: center; }
.param.text .ctl { grid-template-columns: 1fr; }
.param small { color: var(--text-dim); }
input[type="number"], input[type="text"], select {
  font: inherit; font-size: 14px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text); min-width: 0; width: 100%;
}
input[type="range"] { width: 100%; accent-color: var(--tech); }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; padding: 0; text-decoration: underline; }

/* Process */
.row { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: center; margin: 12px 0; }
.row label { display: grid; gap: 3px; font-size: 13px; color: var(--text-mid); }
.row label.check { display: flex; align-items: center; gap: 6px; }
.row select { min-width: 190px; width: auto; }
button {
  font: inherit; font-size: 14px; padding: 7px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-dashed); background: #fff; color: var(--text);
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #9C4524; }

.progress-bar { height: 10px; background: var(--border-light); border-radius: 999px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
#progress-fill.indeterminate { width: 35%; animation: slide 1.4s ease-in-out infinite alternate; }
@keyframes slide { from { transform: translateX(0); } to { transform: translateX(185%); } }
#progress-text { margin: 6px 0; font-size: 13px; }
.log {
  margin: 6px 0 0; padding: 10px 12px; max-height: 160px; overflow: auto; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace;
  background: var(--log-bg); color: var(--log-text); border-radius: 8px; white-space: pre-wrap;
}
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin: 12px 0; }
.result-grid figure { margin: 0; background: var(--canvas-bg); border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.result-grid img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; }
.result-grid figcaption { padding: 5px 8px; font-size: 12px; background: var(--panel); color: var(--text-mid); border-top: 1px solid var(--border-light); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text-soft); columns: 2; }

footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 20px; padding: 14px 20px 24px; font-size: 12px; color: var(--text-dim); max-width: 1180px; margin: 0 auto; }

@media (max-width: 820px) {
  .preview-layout { grid-template-columns: 1fr; }
  .file-list { columns: 1; }
  .card { padding: 14px; }
}

/* Map furniture (north arrow, scale bar, attribution, status line) */
.map-north { position: absolute; top: 8px; right: 8px; z-index: 5; width: 30px; display: grid; place-items: center; padding: 3px 0; border-radius: 6px; background: rgba(255,255,255,0.7); cursor: help; }
.map-scale { position: absolute; left: 8px; bottom: 8px; z-index: 5; display: grid; gap: 2px; font-size: 12px; color: var(--text); padding: 2px 6px 3px; border-radius: 4px; background: rgba(255,255,255,0.78); }
.map-scale .bar { height: 6px; border: 2px solid var(--text); border-top: 0; box-sizing: border-box; }
.map-attribution { position: absolute; right: 0; bottom: 0; z-index: 5; font-size: 11px; padding: 1px 6px; background: rgba(255,255,255,0.8); color: #0078A8; text-decoration: none; border-top-left-radius: 4px; }
.map-attribution:hover { text-decoration: underline; }
.statusbar { font-size: 12px; color: var(--text-soft); background: var(--panel-alt); border: 1px solid var(--border-light); border-radius: 0 0 8px 8px; padding: 4px 10px; min-height: 24px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.crs-line { margin-top: 8px; font-size: 14px; color: var(--text-mid); }
.crs-line strong { color: var(--text); }
.crs-row { margin: 8px 0 0; }
.crs-row input[type="number"] { width: 130px; }
.param > label.check-line { display: flex; justify-content: flex-start; align-items: center; gap: 6px; }
.preview-frame { border-radius: 10px 10px 0 0; }
