:root {
  --bg: #1a1224;
  --panel: #241834;
  --panel2: #2e2042;
  --line: #3d2b56;
  --ink: #f3ecff;
  --muted: #b6a3d4;
  --accent: #ff5aa8;
  --accent2: #7ad0ff;
  --ok: #5ee06a;
  --warn: #ffd93b;
  --danger: #ff5a6a;
  --radius: 10px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #3a1f4d, var(--bg));
  color: var(--ink);
  min-height: 100vh;
}
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: linear-gradient(90deg, #3a1350, #241834);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}
header h1 {
  font-size: 17px;
  margin: 0;
  letter-spacing: .3px;
  white-space: nowrap;
}
header h1 .spark { color: var(--accent); }
header .grow { flex: 1; }
select, input, button, textarea {
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
}
input[type=number] { width: 72px; }
button {
  cursor: pointer;
  background: var(--panel2);
  transition: filter .1s, transform .05s;
}
button:hover { filter: brightness(1.2); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #2a0a1c; font-weight: 600; border-color: transparent; }
button.good { background: var(--ok); color: #0c2410; border-color: transparent; }
button.warn { background: var(--warn); color: #3a2c00; border-color: transparent; }
button.danger { background: var(--danger); color: #340a0e; border-color: transparent; }
button.ghost { background: transparent; }
button:disabled { opacity: .45; cursor: not-allowed; }

.layout {
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  gap: 14px;
  padding: 14px;
  align-items: start;
}
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 0 0 10px;
}
.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.field label { color: var(--muted); font-size: 12px; }
.field input, .field select { flex: 0 0 auto; }
.field input[type=text] { flex: 1 1 auto; width: auto; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.hint { color: var(--muted); font-size: 11px; margin: 4px 0 8px; line-height: 1.4; }

/* Grid canvas */
.board-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
#board {
  display: grid;
  gap: 4px;
  padding: 10px;
  background: #150e1f;
  border: 2px solid #6c3f9e;
  border-radius: 12px;
  box-shadow: 0 0 22px rgba(120,60,180,.45) inset, 0 0 18px rgba(120,60,200,.35);
}
.cell {
  width: 46px;
  height: 46px;
  border-radius: 9px;
  background: #2a2038;
  border: 1px solid #3d2b56;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  user-select: none;
  font-size: 11px;
  font-weight: 700;
  color: #14101c;
  overflow: hidden;
}
.cell.nullcell {
  background: repeating-linear-gradient(45deg, #1b1526, #1b1526 6px, #221a30 6px, #221a30 12px);
  cursor: crosshair;
  color: #55476b;
}
.cell.nullcell .glyph { opacity: .25; }
.cell .glyph { z-index: 2; text-shadow: 0 1px 0 rgba(255,255,255,.25); }
.cell .frost {
  position: absolute; inset: 0; z-index: 3; pointer-events: none;
  border-radius: 8px;
}
.cell .frost.f1 { box-shadow: inset 0 0 0 4px rgba(180,225,255,.55); }
.cell .frost.f2 { box-shadow: inset 0 0 0 4px rgba(180,225,255,.85), inset 0 0 0 8px rgba(140,200,255,.45); }
.cell .wafer {
  position: absolute; inset: 6px; z-index: 4; pointer-events: none;
  background: repeating-linear-gradient(90deg, rgba(210,150,80,.85), rgba(210,150,80,.85) 4px, rgba(170,110,50,.85) 4px, rgba(170,110,50,.85) 8px);
  border-radius: 5px;
}
.cell .badge {
  position: absolute; bottom: 1px; right: 2px; z-index: 5;
  font-size: 8px; color: #fff; text-shadow: 0 0 2px #000;
}
.cell.drop { outline: 2px dashed var(--accent2); outline-offset: -3px; }

.coords { color: var(--muted); font-size: 11px; }

/* Palette */
.palette { display: flex; flex-direction: column; gap: 10px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 34px; height: 34px; border-radius: 8px; border: 2px solid transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: #14101c;
}
.swatch.sel { border-color: #fff; box-shadow: 0 0 8px rgba(255,255,255,.6); }
.tool {
  padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel2); cursor: pointer; font-size: 12px;
}
.tool.sel { border-color: #fff; background: #40305a; }

/* lists */
.list-row {
  display: flex; gap: 6px; align-items: center; margin-bottom: 6px;
  background: var(--panel2); padding: 6px; border-radius: 8px;
}
.list-row select, .list-row input { padding: 4px 6px; }
.list-row input[type=number] { width: 58px; }
.list-row .x { margin-left: auto; }

textarea#json {
  width: 100%; height: 220px; resize: vertical;
  font-family: "JetBrains Mono", ui-monospace, Menlo, monospace;
  font-size: 11px; line-height: 1.4; white-space: pre;
}
.prizes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.prizes label { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); background: var(--panel2); padding: 6px; border-radius: 7px; cursor: pointer; }

.locked-banner {
  display: none; align-items: center; gap: 10px;
  background: #3a2c00; color: var(--warn); border: 1px solid #6b5200;
  padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 13px;
}
body.locked .locked-banner { display: flex; }
body.locked .lockable { opacity: .5; pointer-events: none; }

#toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: #10331a; color: var(--ok); border: 1px solid #1d5c2e;
  padding: 10px 16px; border-radius: 9px; font-size: 13px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50;
}
#toast.show { opacity: 1; }
#toast.err { background: #3a0e12; color: #ffb3ba; border-color: #6b1a20; }
.tiny { font-size: 11px; color: var(--muted); }
.status-dot { display:inline-block; width:8px; height:8px; border-radius:50%; background: var(--muted); margin-right:5px; }
.status-dot.on { background: var(--ok); }
.status-dot.off { background: var(--danger); }
