/* LevelCraft styles. Layout: one centered column. Home lists maps, "new" is a form beside a to-scale preview, the editor is a tool column beside a 3D viewport. Dark theme only. */
:root {
  --bg: #0e1310;
  --panel: #151b16;
  --panel-2: #1b231d;
  --fg: #e7ede5;
  --muted: #94a396;
  --line: #2a342c;
  --accent: #f0905a;
  --accent-fg: #1a0e06;
  --terrain: #1b251d;
  --grid: #2f3d31;
  --danger: #f2877f;
  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  padding-block: 0 4rem;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--bg);
  color: var(--fg);
  font: 400 15px/1.55 var(--font-body);
}
.wrap { max-width: 1180px; margin: 0 auto; }
.narrow { max-width: 980px; margin: 0 auto; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* top bar */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding-block: 1.1rem; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: .6rem; text-decoration: none; font: 700 1.15rem/1 var(--font-display); letter-spacing: -0.02em; }
.brand svg { width: 26px; height: 26px; }
.nav { display: flex; gap: .5rem; align-items: center; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: 600 .9rem/1 var(--font-body); padding: .75rem 1.1rem; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); color: var(--fg); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: default; border-color: var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .5rem .75rem; font-size: .82rem; }

/* home */
.hero { padding-block: 3.2rem 2.2rem; display: grid; gap: 1.1rem; max-width: 40rem; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.05; font-weight: 700; }
.hero p { margin: 0; color: var(--muted); font-size: 1.05rem; max-width: 34rem; }
.hero .btn { justify-self: start; margin-top: .4rem; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 1.6rem 0 .8rem; }
.section-title h2 { font-size: 1.05rem; font-weight: 600; }
.section-title span { color: var(--muted); font: 400 .8rem var(--font-mono); }

.maps { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.map-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 1rem; align-items: center; padding: .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); text-decoration: none; }
.map-row:hover { border-color: var(--muted); }
.thumb { width: 64px; height: 64px; display: block; object-fit: contain; image-rendering: pixelated; background: var(--terrain); border-radius: 3px; }
.map-row .name { font: 600 1rem var(--font-display); overflow-wrap: anywhere; display: block; }
.meta { color: var(--muted); font: 400 .8rem var(--font-mono); }
.map-row .meta { display: block; margin-top: .15rem; }
.arrow { color: var(--muted); padding-right: .4rem; }

.empty { border: 1px dashed var(--line); border-radius: 8px; padding: 1.6rem; display: grid; gap: .5rem; justify-items: start; background: var(--panel); }
.empty strong { font: 600 1rem var(--font-display); }
.empty p { margin: 0; color: var(--muted); max-width: 32rem; }

.roadmap { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .6rem; }
.roadmap li { border: 1px solid var(--line); border-radius: 8px; padding: .8rem .9rem; background: var(--panel); display: grid; gap: .25rem; align-content: start; }
.roadmap b { font: 600 .92rem var(--font-display); }
.roadmap small { color: var(--muted); font-size: .82rem; line-height: 1.4; }
.tag { font: 500 .68rem var(--font-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.roadmap li.now { border-color: var(--accent); }
.roadmap li.now .tag { color: var(--accent); }

/* new map */
.page-head { padding-block: 2rem 1.2rem; display: grid; gap: .35rem; }
.page-head h1 { font-size: clamp(1.6rem, 4.5vw, 2.2rem); font-weight: 700; }
.page-head p { margin: 0; color: var(--muted); }
.back { font-size: .85rem; color: var(--muted); text-decoration: none; justify-self: start; }
.back:hover { color: var(--fg); }

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.4rem; align-items: start; }
@media (max-width: 760px) { .split { grid-template-columns: minmax(0, 1fr); } }
form { display: grid; gap: 1.1rem; }
.field { display: grid; gap: .4rem; }
.field > label, .field > .label { font: 600 .82rem var(--font-body); }
.hint { color: var(--muted); font-size: .8rem; }
.err { color: var(--danger); font-size: .82rem; min-height: 1.2em; }
input[type="text"], input[type="number"] { width: 100%; font: 400 1rem var(--font-body); padding: .7rem .8rem; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); }
input[type="number"] { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
input[readonly] { color: var(--muted); }
.dims { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: .6rem; align-items: end; }
.dims .x { padding-bottom: .75rem; color: var(--muted); font-family: var(--font-mono); }
.check { display: flex; align-items: center; gap: .5rem; font-size: .88rem; }
.check input { width: 1rem; height: 1rem; accent-color: var(--accent); }
.presets { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { font: 500 .82rem var(--font-mono); padding: .45rem .7rem; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); cursor: pointer; }
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

.preview { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 1rem; display: grid; gap: .8rem; position: sticky; top: 1rem; }
.preview svg.plot { width: 100%; height: clamp(190px, 42vw, 300px); display: block; }
.readout { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .3rem 1rem; margin: 0; font-size: .85rem; }
.readout dt { color: var(--muted); }
.readout dd { margin: 0; font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }

/* editor */
.ed-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding-block: 1.4rem .9rem; }
.ed-head h1 { font-size: clamp(1.4rem, 4vw, 1.9rem); font-weight: 700; overflow-wrap: anywhere; }
.ed-head .titles { display: grid; gap: .25rem; min-width: 0; }
.status { font: 400 .8rem var(--font-mono); color: var(--muted); }
.status.bad { color: var(--danger); }

.ed { display: grid; grid-template-columns: 256px minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 860px) { .ed { grid-template-columns: minmax(0, 1fr); } .vp { order: -1; } }
.vp { position: relative; height: clamp(380px, 74vh, 800px); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #0b100d; }
.vp canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hud, .hint { position: absolute; font: 400 .75rem/1.4 var(--font-mono); color: var(--muted); background: rgba(14, 19, 16, .78); padding: .3rem .55rem; border-radius: 4px; pointer-events: none; }
.hud { left: .7rem; bottom: .7rem; }
.hint { right: .7rem; bottom: .7rem; text-align: right; max-width: 60%; }
@media (max-width: 560px) { .hint { display: none; } }
.nogl { position: absolute; inset: 0; display: grid; place-content: center; padding: 1.5rem; text-align: center; color: var(--muted); }

.tools { display: grid; gap: .8rem; }
.group { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: .8rem; display: grid; gap: .6rem; }
.group h2 { font: 600 .72rem var(--font-body); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.toolgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; }
.tool { display: grid; gap: .1rem; justify-items: center; padding: .55rem .2rem; border-radius: 6px; border: 1px solid var(--line); background: var(--panel-2); color: var(--fg); font: 600 .8rem var(--font-body); cursor: pointer; }
.tool kbd, .mat kbd { font: 400 .68rem var(--font-mono); color: var(--muted); }
.tool:hover { border-color: var(--muted); }
.tool[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.slider { display: grid; gap: .25rem; }
.slider .row { display: flex; justify-content: space-between; font-size: .8rem; }
.slider .row span:last-child { font-family: var(--font-mono); color: var(--muted); }
.slider input { width: 100%; accent-color: var(--accent); }
.slider.off { opacity: .4; }
.mats { display: grid; gap: .25rem; }
.mat { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto 3.2rem; gap: .5rem; align-items: center; padding: .4rem .5rem; border-radius: 6px; border: 1px solid transparent; background: transparent; color: var(--fg); font: 500 .85rem var(--font-body); text-align: left; cursor: pointer; }
.mat i { width: 18px; height: 18px; border-radius: 3px; border: 1px solid rgba(255, 255, 255, .18); display: block; }
.mat em { font: normal 400 .75rem var(--font-mono); color: var(--muted); text-align: right; }
.mat:hover { background: var(--panel-2); }
.mat[aria-pressed="true"] { border-color: var(--accent); background: var(--panel-2); }
.btnrow { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.btnrow .btn { padding: .55rem .5rem; font-size: .8rem; }

@media (prefers-reduced-motion: no-preference) { .btn, .map-row, .chip, .tool, .mat { transition: border-color .12s, filter .12s, background .12s; } }

/* Editor on desktop: the page itself never scrolls, the viewport fills the screen and the tool column scrolls on its own. */
@media (min-width: 861px) {
  body.editing { height: 100vh; height: 100dvh; overflow: hidden; padding-bottom: 0; }
  body.editing .wrap { height: 100%; display: flex; flex-direction: column; }
  body.editing main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  body.editing .ed-head { padding-block: .9rem .7rem; }
  body.editing .ed { flex: 1; min-height: 0; align-items: stretch; padding-bottom: 1rem; }
  body.editing .tools { overflow-y: auto; min-height: 0; align-content: start; }
  body.editing .vp { height: auto; min-height: 0; }
}

/* Hide-panels mode: the 3D view takes the whole window. H toggles it. */
.headr { display: flex; align-items: center; gap: .8rem; }
.focusbtn kbd { font: 400 .68rem var(--font-mono); color: var(--muted); margin-left: .2rem; }
.focusbar { display: none; position: absolute; top: .7rem; left: .7rem; align-items: center; gap: .7rem; font: 500 .78rem var(--font-mono); color: var(--fg); background: rgba(14, 19, 16, .85); border: 1px solid var(--line); padding: .3rem .35rem .3rem .7rem; border-radius: 6px; }
body.focus .focusbar { display: flex; }
@media (max-width: 860px) { .focusbtn, .focusbar { display: none !important; } }
@media (min-width: 861px) {
  body.editing.focus .bar, body.editing.focus .ed-head, body.editing.focus .tools { display: none; }
  body.editing.focus .ed { grid-template-columns: minmax(0, 1fr); padding-block: .8rem; }
}