/* TerraPuzzle generator — night-map workbench. */
:root {
    --bg: #0a0e13;
    --panel: #10161e;
    --panel-2: #161e28;
    --line: rgba(255, 255, 255, .08);
    --line-2: rgba(255, 255, 255, .14);
    --ink: #e8edf2;
    --muted: #93a1b0;
    --amber: #f5b544;
    --amber-ink: #1d1406;
    --teal: #3ec7b0;
    --danger: #ff6b6b;
    --r: 12px;
    --r-sm: 8px;
    --top: 60px;
    --panel-w: 384px;
    --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    --display: "Space Grotesk", var(--font);
    color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--amber); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---- top bar ---------------------------------------------------------- */
.topbar {
    position: sticky; top: 0; z-index: 30; height: var(--top);
    display: flex; align-items: center; gap: 14px; padding: 0 16px;
    background: rgba(10, 14, 19, .92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); font: 700 19px/1 var(--display); letter-spacing: -.01em; flex: none; }
.search { position: relative; flex: 1 1 340px; max-width: 460px; }
.search > i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 17px; }
.search input { width: 100%; height: 38px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel); padding: 0 12px 0 34px; outline: none; }
.search input:focus { border-color: var(--amber); }
.search-results { position: absolute; top: 44px; left: 0; right: 0; margin: 0; padding: 6px; list-style: none; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); box-shadow: 0 18px 40px -12px rgba(0, 0, 0, .7); z-index: 40; }
.search-results li { padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.search-results li small { color: var(--muted); white-space: nowrap; }
.search-results li[aria-selected="true"], .search-results li:hover { background: rgba(245, 181, 68, .12); }
.toplinks { display: flex; gap: 4px; margin-left: auto; }
.toplinks a { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: var(--r-sm); color: var(--ink); text-decoration: none; white-space: nowrap; }
.toplinks a:hover { background: rgba(255, 255, 255, .06); }
.toplinks i { font-size: 18px; color: var(--amber); }

/* ---- world picker -------------------------------------------------------- */
.world { position: relative; display: inline-flex; align-items: center; flex: none; }
.world select { appearance: none; -webkit-appearance: none; height: 38px; width: 150px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel); padding: 0 30px 0 34px; cursor: pointer; font-weight: 500; text-overflow: ellipsis; }
.world select:hover { border-color: rgba(255, 255, 255, .26); }
.world select:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.world select option, .world select optgroup { background: var(--panel-2); color: var(--ink); }
.world > .bx { position: absolute; pointer-events: none; font-size: 18px; }
.world > .bx-planet { left: 10px; color: var(--amber); }
.world > .bx-chevron-down { right: 8px; color: var(--muted); }

/* ---- segmented controls, buttons -------------------------------------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.seg button { border: 0; background: none; padding: 6px 11px; border-radius: 7px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg button:hover:not(.on) { color: var(--ink); }
.seg-fill { display: flex; width: 100%; }
.seg-fill button { flex: 1; }
.seg-sm button { padding: 4px 9px; font-size: 13px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; font-weight: 600; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { border-color: rgba(255, 255, 255, .26); }
.btn i { font-size: 18px; }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; font-weight: 500; }
.btn.icon { width: 32px; padding: 0; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--amber); color: var(--amber-ink); border-color: transparent; }
.btn.primary:hover { background: #ffc35c; }
.btn.big { height: 48px; width: 100%; font-size: 16px; font-family: var(--display); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 0; }

/* ---- workspace --------------------------------------------------------- */
.workspace { position: relative; height: calc(100dvh - var(--top)); display: flex; }
.stage { position: relative; flex: 1; min-width: 0; }
.map, .preview { position: absolute; inset: 0; }
.preview { background: #0d1218; }
.preview canvas { display: block; touch-action: none; }

.panel { width: var(--panel-w); flex: none; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); z-index: 5; min-height: 0; }
.panel-scroll { flex: 1; overflow-y: auto; padding: 4px 18px 12px; scrollbar-width: thin; }
.sheet-grip { display: none; }
.step { padding: 16px 0 18px; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: 0; }
.step h2 { margin: 0 0 10px; font: 600 16px/1.2 var(--display); display: flex; align-items: center; gap: 10px; letter-spacing: -.005em; }
.step-n { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; background: rgba(245, 181, 68, .14); color: var(--amber); flex: none; }
.lede { margin: 0 0 10px; color: var(--muted); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.field { display: block; margin: 12px 0 0; }
.field-label { display: block; margin-bottom: 6px; color: var(--ink); }
.field-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.field-row output { font: 600 13px var(--display); color: var(--amber); font-variant-numeric: tabular-nums; }
.hint { display: block; color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.hint-inline { color: var(--muted); font-size: 12.5px; }
code { font: 12px/1 ui-monospace, monospace; color: var(--muted); background: rgba(255, 255, 255, .05); padding: 2px 5px; border-radius: 5px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 26px; background: transparent; margin: 2px 0 0; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--amber) var(--p, 50%), rgba(255, 255, 255, .12) var(--p, 50%)); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .12); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--amber); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: var(--ink); border: 3px solid var(--amber); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--ink); border: 3px solid var(--amber); }

.switch { display: flex; align-items: center; gap: 10px; margin-top: 12px; cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 36px; height: 21px; border-radius: 21px; background: rgba(255, 255, 255, .14); position: relative; flex: none; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: var(--ink); transition: transform .15s; }
.switch input:checked { background: var(--teal); }
.switch input:checked::after { transform: translateX(15px); }

details.more { margin-top: 12px; }
details.more summary { cursor: pointer; color: var(--muted); list-style: none; display: inline-flex; align-items: center; gap: 6px; }
details.more summary::before { content: "+"; display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; background: rgba(255, 255, 255, .06); font-weight: 600; }
details.more[open] summary::before { content: "–"; }
details.more summary::-webkit-details-marker { display: none; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tiles button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 6px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; color: var(--muted); font-size: 12px; }
.tiles button svg { width: 44px; height: 30px; }
.tiles button.on { border-color: var(--amber); color: var(--ink); background: rgba(245, 181, 68, .08); }
.tiles button:hover:not(.on) { border-color: var(--line-2); color: var(--ink); }
.tiles-outline { grid-template-columns: repeat(5, 1fr); }
.tiles-outline svg { width: 34px !important; height: 26px !important; }

.ideas { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.ideas button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 5px 11px; cursor: pointer; color: var(--ink); font-size: 13px; }
.ideas button:hover { border-color: var(--amber); }
.ideas .shuffle { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { display: inline-flex; align-items: center; gap: 6px; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line-2); background: transparent; color: var(--muted); cursor: pointer; }
.chips button.on { background: rgba(62, 199, 176, .14); border-color: rgba(62, 199, 176, .55); color: var(--ink); }
.chips button:disabled { opacity: .4; cursor: not-allowed; }

.panel-foot { padding: 12px 18px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.summary { color: var(--muted); margin-bottom: 9px; font-variant-numeric: tabular-nums; }
.progress { margin-top: 10px; }
.progress-bar { height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.progress-bar i { display: block; height: 100%; width: 0; background: var(--amber); transition: width .25s; }
.progress-row { display: flex; justify-content: space-between; margin-top: 6px; color: var(--muted); font-size: 13px; }

/* ---- map extras -------------------------------------------------------- */
.sel-handle { width: 16px; height: 16px; border-radius: 50%; background: var(--amber); border: 3px solid #0a0e13; box-shadow: 0 0 0 1px var(--amber); cursor: nwse-resize; }
.sel-handle-se, .sel-handle-nw { cursor: nesw-resize; }
.maplibregl-ctrl-group { background: var(--panel) !important; border: 1px solid var(--line-2); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line) !important; }
.maplibregl-ctrl-icon { filter: invert(1); }
.maplibregl-ctrl-attrib { background: rgba(10, 14, 19, .7) !important; color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--muted); }

/* ---- result & preview UI --------------------------------------------- */
.viewtabs { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 6; display: flex; padding: 3px; border-radius: 10px; background: rgba(16, 22, 30, .92); border: 1px solid var(--line-2); backdrop-filter: blur(8px); }
.viewtabs button { border: 0; background: none; padding: 7px 16px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.viewtabs button.on { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-2); }
.pv-tools { position: absolute; top: 14px; right: 14px; z-index: 6; display: flex; gap: 6px; }
.pv-tools .btn { background: rgba(16, 22, 30, .9); backdrop-filter: blur(8px); }
.pv-tip { position: absolute; left: 0; top: 0; pointer-events: none; opacity: 0; transition: opacity .12s; background: var(--panel-2); border: 1px solid var(--line-2); padding: 4px 8px; border-radius: 6px; font: 600 12px var(--display); }
.result { position: absolute; left: 16px; right: 16px; bottom: 16px; z-index: 6; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px 12px 18px; border-radius: 14px; background: rgba(16, 22, 30, .94); border: 1px solid var(--line-2); backdrop-filter: blur(10px); box-shadow: 0 24px 50px -20px rgba(0, 0, 0, .8); }
.result h3 { margin: 0; font: 600 17px/1.2 var(--display); }
.result p { margin: 3px 0 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; bottom: 46px; width: 340px; padding: 6px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); box-shadow: 0 24px 50px -16px rgba(0, 0, 0, .8); z-index: 20; }
.menu > button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: var(--r-sm); cursor: pointer; }
.menu > button:hover, .menu > button:focus-visible { background: rgba(245, 181, 68, .1); }
.menu b { display: block; font-weight: 600; }
.menu span { display: block; color: var(--muted); font-size: 12.5px; }
.menu-bed { display: flex; align-items: center; gap: 8px; padding: 2px 10px 8px; font-size: 12.5px; color: var(--muted); }
.menu-bed select { flex: 1; background: var(--panel); border: 1px solid var(--line-2); border-radius: 7px; padding: 4px 6px; }

.toast { position: absolute; left: 50%; top: 70px; transform: translate(-50%, -8px); z-index: 50; background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 14px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: min(520px, 90vw); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(255, 107, 107, .6); }

.dialog { border: 1px solid var(--line-2); border-radius: 16px; background: var(--panel-2); color: var(--ink); padding: 0; width: min(460px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog-body { padding: 20px; }
.dialog h3 { margin: 0 0 6px; font: 600 19px var(--display); }
.dialog input[type=text] { width: 100%; height: 38px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--panel); padding: 0 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.share-link { display: flex; gap: 6px; margin-top: 14px; }

/* ---- about ----------------------------------------------------------- */
.about { border-top: 1px solid var(--line); background: var(--bg); }
.about-inner { max-width: 1080px; margin: 0 auto; padding: 56px 24px 40px; }
.about h2 { font: 700 30px/1.15 var(--display); margin: 0 0 26px; letter-spacing: -.015em; max-width: 18ch; }
.about-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 28px; }
.about h3 { font: 600 16px var(--display); margin: 0 0 6px; color: var(--amber); }
.about p { margin: 0; color: var(--muted); max-width: 60ch; }
.about .credits { margin-top: 40px; font-size: 12.5px; }

/* ---- small screens: settings become a bottom sheet ------------------- */
@media (max-width: 1100px) { .toplinks span { display: none; } .about-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) {
    :root { --top: 56px; }
    .topbar { gap: 8px; padding: 0 10px; }
    .brand span { display: none; }
    .workspace { display: block; }
    .stage { position: absolute; inset: 0; }
    .panel { position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: 46%; border-right: 0; border-top: 1px solid var(--line-2); border-radius: 16px 16px 0 0; transition: height .25s ease; box-shadow: 0 -20px 40px -20px rgba(0, 0, 0, .8); }
    .panel.collapsed { height: 132px; }
    .panel.expanded { height: calc(100% - 12px); }
    .sheet-grip { display: block; width: 100%; height: 20px; border: 0; background: none; cursor: grab; flex: none; position: relative; }
    .sheet-grip::after { content: ""; position: absolute; left: 50%; top: 8px; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: var(--line-2); }
    .panel-scroll { padding-top: 0; }
    .result { left: 8px; right: 8px; bottom: calc(132px + 8px); flex-direction: column; align-items: stretch; gap: 10px; }
    .result-actions { justify-content: stretch; }
    .result-actions > * { flex: 1; }
    .result-actions .btn { width: 100%; }
    .menu { position: fixed; left: 8px; right: 8px; bottom: 150px; width: auto; }
    .viewtabs { left: 10px; transform: none; top: 10px; }
    .pv-tools { top: 10px; right: 10px; }
    .pv-tools .btn span { display: none; }
    .pv-tools .btn { width: 36px; padding: 0; }
    .toast { top: 62px; }
    .about-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .search { flex-basis: 120px; } .world select { width: 104px; } .world > .bx-planet { display: none; } .world select { padding-left: 10px; } }
