/* MC Builder: same deepslate/bone/amethyst tokens as the MC Manager dashboard. */
:root {
  --deepslate-0: #1d1e22;
  --deepslate-1: #25272c;
  --deepslate-2: #2e3036;
  --deepslate-3: #393c43;
  --seam: #474a52;
  --bone: #ece6d8;
  --ash: #a8a294;
  --ash-dim: #7a766c;
  --amethyst: #b48cf0;
  --amethyst-deep: #8b5fd0;
  --amethyst-ink: #1c1030;
  --emerald: #4cc38a;
  --gold: #e8b33a;
  --redstone: #e0533f;

  --radius-s: 4px;
  --radius-m: 8px;
  --control-h: 38px;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: ui-rounded, "SF Pro Rounded", "Nunito", var(--font-ui);
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { background: var(--deepslate-1); }
body {
  margin: 0; background: var(--deepslate-1); color: var(--bone);
  font: 15px/1.5 var(--font-ui); -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-family: var(--font-head); font-weight: 650; line-height: 1.2; }
p { margin: 0; }
code { font-family: var(--font-mono); font-size: .88em; }
[hidden] { display: none !important; }
.muted { color: var(--ash); }
.small { font-size: .82rem; }
.hint { color: var(--ash); font-size: .85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--amethyst); outline-offset: 2px; }

/* ---- Controls ---- */
button {
  font: inherit; font-weight: 550; min-height: var(--control-h); padding: 0 14px;
  border-radius: var(--radius-s); border: 1px solid var(--seam); border-bottom-width: 3px;
  background: var(--deepslate-3); color: var(--bone); cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { background: #43464e; }
button:active:not(:disabled) { border-bottom-width: 1px; margin-top: 2px; }
button:disabled { background: transparent; color: var(--ash-dim); border-style: dashed; border-bottom-width: 1px; cursor: not-allowed; }
button.primary { background: var(--amethyst); border-color: var(--amethyst-deep); color: var(--amethyst-ink); }
button.primary:hover:not(:disabled) { background: #c3a2f4; }
button.ghost { background: transparent; border-color: transparent; border-bottom-width: 1px; color: var(--ash); }
button.ghost:hover:not(:disabled) { background: var(--deepslate-3); color: var(--bone); }
.small-btn { min-height: 30px; padding: 0 10px; font-size: .85rem; }

input, select {
  font: inherit; width: 100%; min-height: var(--control-h); padding: 6px 10px;
  border-radius: var(--radius-s); border: 1px solid var(--seam); background: var(--deepslate-0); color: var(--bone);
}
label { display: flex; flex-direction: column; gap: 6px; font-size: .88rem; color: var(--ash); }
kbd {
  font: 600 .72rem var(--font-mono); color: var(--ash); border: 1px solid var(--seam);
  border-radius: 3px; padding: 0 4px; margin-left: 4px;
}

/* ---- Shell ---- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid var(--seam); background: var(--deepslate-2);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--bone); text-decoration: none; font: 650 1.1rem var(--font-head); flex: none; }
.brand img { image-rendering: pixelated; }
.name-input { max-width: 260px; min-width: 110px; flex: 1 1 110px; background: transparent; border-color: transparent; font-weight: 600; }
.name-input:hover, .name-input:focus { border-color: var(--seam); background: var(--deepslate-0); }
.topbar-actions { display: flex; gap: 8px; margin-left: auto; }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr); }
.sidebar { border-right: 1px solid var(--seam); overflow-y: auto; padding: 8px 0 24px; }
.panel { padding: 12px 14px; border-bottom: 1px solid var(--seam); display: flex; flex-direction: column; gap: 10px; }
details.panel { display: block; }
details.panel[open] > :not(summary) { margin-top: 10px; }
.section-title { font-size: .9rem; color: var(--ash); font-weight: 600; font-family: var(--font-ui); }
summary.section-title { cursor: pointer; list-style-position: inside; }

.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tools button { justify-content: space-between; display: flex; align-items: center; padding: 0 10px; }
.tools button[aria-checked="true"] { background: var(--deepslate-0); border-color: var(--amethyst); box-shadow: inset 0 0 0 1px var(--amethyst); }
.tools button[aria-checked="true"] kbd { color: var(--amethyst); border-color: var(--amethyst-deep); }

.current { display: flex; align-items: center; gap: 12px; }
.current-swatch svg { width: 44px; height: 44px; display: block; }
.current-text { display: flex; flex-direction: column; min-width: 0; }
.current-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.current-text code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.current-swatch canvas { width: 44px; height: 44px; display: block; image-rendering: pixelated; }
.pack-picker { flex-direction: row; align-items: center; gap: 8px; white-space: nowrap; }
.pack-picker select { width: auto; max-width: 260px; }
@media (max-width: 1400px) { .pack-label { display: none; } .pack-picker select { max-width: 200px; } }
@media (max-width: 1180px) and (min-width: 761px) { .topbar { flex-wrap: wrap; } .topbar-actions { margin-left: 0; flex-wrap: wrap; } }
.check-row { flex-direction: row; align-items: center; gap: 8px; color: var(--bone); }
.check-row input { width: auto; min-height: 0; accent-color: var(--amethyst); }
.state-props { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.state-props select { min-height: 32px; padding: 4px 8px; }
.loading {
  position: absolute; inset: 0; display: grid; place-items: center; font-weight: 600;
  background: rgba(29, 30, 34, .75); color: var(--bone);
}
.more { margin-top: 10px; }

.palette-panel { gap: 8px; }
.palette-cat { font: 600 .78rem var(--font-ui); color: var(--ash-dim); text-transform: uppercase; letter-spacing: .06em; margin: 10px 0 6px; }
.palette-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 4px; }
.recent:empty { display: none; }
.block-btn canvas { width: 34px; height: 34px; display: block; }
.block-btn {
  min-height: 0; height: 42px; padding: 3px; display: grid; place-items: center;
  background: var(--deepslate-0); border: 1px solid transparent; border-bottom-width: 1px;
}
.block-btn:hover:not(:disabled) { background: var(--deepslate-3); border-color: var(--seam); }
.block-btn:active:not(:disabled) { margin-top: 0; }
.block-btn[aria-pressed="true"] { border-color: var(--amethyst); box-shadow: inset 0 0 0 1px var(--amethyst); }

.size-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; align-items: end; }
.size-form button { grid-column: 1 / -1; justify-self: start; }

.materials { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.materials li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 8px; font-size: .88rem; }
.mat-icon canvas { width: 24px; height: 24px; display: block; }
.mat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mat-count { font-variant-numeric: tabular-nums; text-align: right; }
.mat-count small { display: block; color: var(--ash); font-size: .74rem; line-height: 1.1; }

/* ---- Stage ---- */
.stage { position: relative; min-width: 0; min-height: 0; background: var(--deepslate-0); }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.hud-top { position: absolute; top: 12px; left: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.hud-bottom {
  position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; gap: 8px 16px; flex-wrap: wrap; align-items: center;
  pointer-events: none; font-size: .85rem; color: var(--ash);
}
.hud-bottom > span:not(:empty) { background: rgba(29, 30, 34, .82); padding: 4px 10px; border-radius: var(--radius-s); border: 1px solid var(--seam); }
.hud-count { color: var(--bone); font-weight: 600; }
.hud-pos { font-family: var(--font-mono); font-size: .8rem; white-space: pre; }
.hud-hint { margin-left: auto; }
.toast {
  position: absolute; top: 12px; right: 12px; max-width: min(420px, calc(100% - 24px));
  background: var(--deepslate-2); border: 1px solid var(--seam); border-left: 3px solid var(--emerald);
  padding: 10px 14px; border-radius: var(--radius-s); font-size: .9rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
}
.toast.error { border-left-color: var(--redstone); }
.stage:has(.side-panel:not([hidden])) .toast { top: auto; bottom: 56px; }

/* ---- Side panel: generator and blueprint ---- */
.hud-top button[aria-pressed="true"] { border-color: var(--amethyst); box-shadow: inset 0 0 0 1px var(--amethyst); color: var(--amethyst); }
.side-panel {
  position: absolute; top: 12px; right: 12px; max-height: calc(100% - 68px); width: min(340px, calc(100% - 24px));
  background: var(--deepslate-2); border: 1px solid var(--seam); border-radius: var(--radius-m);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .4); overflow-y: auto;
}
.side-section { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.side-head { display: flex; justify-content: space-between; align-items: center; }
.side-head h2 { font-size: 1.05rem; }
.side-actions { display: flex; justify-content: flex-end; gap: 8px; }
.gen-params { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.gen-field.wide { grid-column: 1 / -1; }
.gen-field input[type=file] { padding: 6px; font-size: .85rem; }
.mat-btn { display: flex; align-items: center; gap: 8px; justify-content: flex-start; padding: 0 8px; font-weight: 500; overflow: hidden; }
.mat-btn canvas { width: 26px; height: 26px; flex: none; }
.mat-btn span { overflow: hidden; text-overflow: ellipsis; }
.gen-pos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.layer-ctl { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.layer-ctl strong { font-variant-numeric: tabular-nums; }
#layer-range { padding: 0; min-height: 24px; accent-color: var(--amethyst); }
.plan-wrap { width: 100%; overflow: auto; max-height: 420px; border: 1px solid var(--seam); border-radius: var(--radius-s); background: var(--deepslate-0); }
#plan { display: block; image-rendering: pixelated; cursor: crosshair; max-width: 100%; }
.plan-info { min-height: 1.2em; font-family: var(--font-mono); font-size: .8rem; }
.print-area { display: none; }
@media print {
  body, html { background: #fff; color: #000; height: auto; }
  .app, dialog { display: none !important; }
  .print-area { display: block; font: 12px/1.4 var(--font-ui); }
  .print-area h1 { font-size: 20px; margin-bottom: 4px; }
  .print-area h2 { font-size: 15px; margin: 0 0 6px; }
  .print-layer { break-inside: avoid; margin-top: 18px; }
  .print-layer img { max-width: 100%; image-rendering: pixelated; border: 1px solid #999; }
  .print-area .materials { columns: 3; display: block; margin-top: 6px; }
  .print-area .materials li { display: flex; gap: 6px; break-inside: avoid; }
  .print-area .mat-icon { display: none; }
  .print-area .mat-count small { display: inline; margin-left: 4px; color: #555; }
}

/* ---- Export dialog ---- */
.dialog {
  width: min(560px, calc(100vw - 32px)); padding: 0; color: var(--bone);
  background: var(--deepslate-2); border: 1px solid var(--seam); border-radius: var(--radius-m);
}
.dialog::backdrop { background: rgba(10, 10, 12, .6); }
.dialog form { padding: 22px 22px 18px; display: flex; flex-direction: column; gap: 14px; }
.formats { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.format { flex-direction: row; align-items: center; gap: 10px; color: var(--bone); padding: 10px 12px; border: 1px solid var(--seam); border-radius: var(--radius-s); cursor: pointer; }
.format:has(input:checked) { border-color: var(--amethyst); box-shadow: inset 0 0 0 1px var(--amethyst); }
.format input { width: auto; min-height: 0; accent-color: var(--amethyst); }
.format span { display: flex; flex-direction: column; font-size: .88rem; color: var(--ash); }
.format strong { color: var(--bone); font-size: 1rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.export-info { background: var(--deepslate-0); border: 1px solid var(--seam); border-radius: var(--radius-s); padding: 12px 14px; font-size: .88rem; display: flex; flex-direction: column; gap: 8px; }
.export-info ul { margin: 0; padding-left: 18px; }
.export-info code { overflow-wrap: anywhere; color: var(--bone); }
.export-info .warn { color: var(--gold); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- Selection ---- */
.sel-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.sel-grid button { padding: 0 6px; }

/* ---- Library ---- */
.dialog-wide { width: min(920px, calc(100vw - 32px)); }
.dialog-body { padding: 18px 22px 20px; display: flex; flex-direction: column; gap: 14px; }
.lib-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lib-actions input { flex: 1; min-width: 160px; width: auto; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; max-height: 60vh; overflow-y: auto; }
.lib-card { background: var(--deepslate-0); border: 1px solid var(--seam); border-radius: var(--radius-m); overflow: hidden; display: flex; flex-direction: column; }
.lib-card.current { border-color: var(--amethyst); box-shadow: inset 0 0 0 1px var(--amethyst); }
.lib-thumb { display: block; width: 100%; aspect-ratio: 32 / 22; object-fit: cover; background: var(--deepslate-1); border: 0; padding: 0; min-height: 0; border-radius: 0; cursor: pointer; }
.lib-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.lib-meta { flex: 1; padding: 8px 10px 0; display: flex; flex-direction: column; min-width: 0; }
.lib-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-buttons { display: flex; gap: 4px; padding: 8px 10px 10px; }
.lib-buttons .open { flex: 1; }
.lib-empty { grid-column: 1 / -1; padding: 24px; text-align: center; }

/* ---- Server dialogs ---- */
.place-fields { display: flex; flex-direction: column; gap: 10px; }
.corner { display: grid; grid-template-columns: 56px repeat(3, 1fr); gap: 8px; align-items: end; }
.corner > span { color: var(--ash); font-size: .88rem; padding-bottom: 9px; }
#wld-info.warn { color: var(--gold); }

/* ---- Small screens: palette above the view ---- */
@media (max-width: 760px) {
  .app { height: auto; min-height: 100vh; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .name-input { order: 3; max-width: none; flex-basis: 100%; }
  .pack-picker { order: 4; flex-basis: 100%; }
  .pack-picker select { flex: 1; max-width: none; }
  .topbar-actions { flex-wrap: wrap; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--seam); max-height: 45vh; }
  .stage { height: 60vh; }
  .hud-hint { display: none; }
  .side-panel { max-height: calc(100% - 24px); }
  .row, .formats { grid-template-columns: 1fr; }
}
