:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #0e1420;
  --muted: #5a6575;
  --line: #d9dee6;
  --accent: #1d5fd0;
  --accent-ink: #ffffff;
  --header: #0b0f17;
  --header-ink: #ffffff;
  --header-muted: #9aa5b6;
  --warn: #1c3a78;
  --warn-bg: #e6eefc;
  --ok: #1d5fd0;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #080b10;
    --panel: #121821;
    --ink: #eef2f7;
    --muted: #97a2b3;
    --line: #262e3a;
    --accent: #4d8dff;
    --accent-ink: #06101f;
    --header: #05070b;
    --warn: #b3ceff;
    --warn-bg: #17284a;
    --ok: #4d8dff;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
[hidden] { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--header); color: var(--header-ink);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent);
  position: relative; flex: none;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--header-muted); font-size: 13px; }

.layout {
  flex: 1; display: grid; grid-template-columns: 380px 1fr; gap: 16px;
  padding: 16px 20px; min-height: 0;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; overflow: auto; max-height: calc(100dvh - 150px);
}
.panel section + section { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }
.row-title { display: flex; justify-content: space-between; align-items: baseline; }
.row-title h2 { margin: 0 0 10px; }

.pieces { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.piece {
  text-align: left; border: 1px solid var(--line); background: transparent; color: inherit;
  border-radius: 10px; padding: 10px 12px; cursor: pointer; font: inherit; font-weight: 600; font-size: 14px;
}
.piece:hover { border-color: var(--accent); }
.piece[aria-checked="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

select, input[type="number"] {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font: inherit;
}
.custom { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.custom label { font-size: 12px; color: var(--muted); display: grid; gap: 4px; }

.params { display: grid; gap: 14px; }
.param label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.param .num { display: flex; align-items: center; gap: 4px; }
.param .num input { width: 72px; padding: 3px 6px; text-align: right; }
.param .num span { color: var(--muted); font-size: 12px; min-width: 18px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; padding: 0; }
.link:hover { text-decoration: underline; }

.stage {
  position: relative; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: var(--panel); min-height: 420px;
}
#view { width: 100%; height: 100%; display: block; touch-action: none; }
.overlay { position: absolute; left: 12px; top: 12px; right: 12px; pointer-events: none; display: grid; gap: 8px; justify-items: start; }
.stats {
  background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; font-size: 13px; font-variant-numeric: tabular-nums;
}
.warnings { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.warnings li { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 6px 10px; font-size: 13px; max-width: 520px; }
.warnings li.bad { background: #fde3df; color: #9b1c0e; }
@media (prefers-color-scheme: dark) { .warnings li.bad { background: #4a1a14; color: #ffb4a8; } }
.actions { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; gap: 8px; align-items: flex-end; justify-content: flex-end; flex-wrap: wrap; }
.namebox { display: grid; gap: 3px; flex: 1 1 200px; max-width: 320px; font-size: 12px; color: var(--muted); margin-right: auto; }
.namebox input { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); font: inherit; }

.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.donate { background: transparent; border-color: #4d8dff; color: #fff; }
.btn.donate:hover { background: #1d5fd0; border-color: #1d5fd0; }
.btn:focus-visible, .piece:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.foot { padding: 6px 20px 16px; color: var(--muted); font-size: 12.5px; }
.foot p { margin: 0; max-width: 900px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .panel { max-height: none; order: 2; }
  .stage { order: 1; min-height: 360px; height: 52dvh; }
  .brand p { display: none; }
  .top { padding: 10px 12px; }
}

input[type="file"] { width: 100%; font: inherit; font-size: 13px; }
.param .hint { margin: 6px 0 0; }
