* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #b9b9b9; font-family: Ubuntu, "Trebuchet MS", sans-serif; user-select: none; -webkit-user-select: none; }
canvas#game { display: block; cursor: crosshair; }
.hidden { display: none !important; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
#menu { background: rgba(0, 0, 0, 0.18); }
#death { background: rgba(0, 0, 0, 0.35); }

.menu-box {
  background: rgba(24, 26, 32, 0.88); color: #fff; border-radius: 16px; padding: 26px 28px;
  width: min(460px, 100%); text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,0.35);
}
.title { margin: 0; font-size: 46px; letter-spacing: 2px; font-weight: 700; color: #fff;
  -webkit-text-stroke: 2px #333; paint-order: stroke fill; }
.title span { color: #00b2e1; margin-left: 6px; }
.tag { margin: 4px 0 18px; color: #bbb; font-size: 14px; }
#nameInput {
  width: 100%; padding: 12px 14px; font: 700 18px Ubuntu, sans-serif; border-radius: 10px; border: 3px solid #444;
  background: #f2f2f2; color: #222; outline: none; text-align: center;
}
#nameInput:focus { border-color: #00b2e1; }
.label { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: #999; }
.seg { display: flex; gap: 6px; }
.seg button, .menu-box .ghost, .ed-panel button {
  font: 700 14px Ubuntu, sans-serif; color: #fff; cursor: pointer; border-radius: 8px;
}
.seg button { flex: 1; padding: 10px 6px; background: #3a3d46; border: 3px solid #2a2c33; }
.seg button.on { background: #00b2e1; border-color: #0085a8; }
.seg button:hover:not(.on) { background: #474b55; }
.play {
  margin-top: 20px; width: 100%; padding: 14px; font: 700 22px Ubuntu, sans-serif; color: #fff; cursor: pointer;
  background: #00e16e; border: 4px solid #00a952; border-radius: 12px; letter-spacing: 2px;
}
.play:hover { filter: brightness(1.08); }
.ghost { margin-top: 10px; width: 100%; padding: 10px; background: transparent; border: 3px solid #555; }
.help { margin-top: 18px; font-size: 13px; color: #aaa; line-height: 1.7; }
.help b { color: #eee; }
.small { font-size: 14px; color: #bbb; }
.small.dim { margin-top: 14px; color: #888; font-size: 12px; }
.big { font-size: 30px; font-weight: 700; margin: 6px 0 12px; }
.dstats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0 4px; font-size: 14px; color: #ccc; }
.dstats b { color: #fff; display: block; font-size: 18px; }

/* ---------------- Build editor ---------------- */
#editor { position: fixed; inset: 0; display: flex; background: rgba(18, 20, 26, 0.6); }
.ed-left { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
#edCanvas { cursor: crosshair; border-radius: 50%; }
.ed-hint { margin-top: 10px; color: #ddd; font-size: 13px; text-align: center; text-shadow: 0 1px 2px #000; max-width: 520px; line-height: 1.5; }
.ed-panel {
  width: 360px; flex-shrink: 0; background: rgba(26, 28, 34, 0.97); color: #e8e8e8; overflow-y: auto; padding: 16px;
  font-size: 13px;
}
.ed-head { display: flex; align-items: center; justify-content: space-between; }
.ed-head h2 { margin: 0; font-size: 20px; }
.ed-head button { background: #f14e54; border: 3px solid #b5383d; padding: 4px 12px; }
.pts { display: flex; gap: 8px; margin: 12px 0; }
.pts > div { flex: 1; background: #33363f; border-radius: 8px; padding: 8px; text-align: center; color: #aaa; }
.pts b { display: block; font-size: 22px; color: #fff; }
.pts .bp b { color: #ffde43; }
.pts .sp b { color: #43fff9; }
.sec { background: #23252c; border: 1px solid #353842; border-radius: 10px; padding: 10px; margin-bottom: 10px; }
.sec-t { font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase; color: #8a8f9c; margin-bottom: 8px; display: flex; justify-content: space-between; }
.tools { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.ed-panel button { padding: 8px 6px; background: #3a3d46; border: 3px solid #2a2c33; }
.ed-panel button:hover:not(:disabled) { filter: brightness(1.15); }
.ed-panel button.on { background: #00b2e1; border-color: #0085a8; }
.ed-panel button:disabled { opacity: 0.4; cursor: not-allowed; }
.ed-panel button .c { display: inline-block; margin-left: 4px; color: #ffde43; }
.row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.row label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.snap button { padding: 4px 8px; font-size: 12px; }
.sel-title { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.muted { color: #888; font-weight: 500; font-size: 12px; }
.slider { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.slider span:first-child { width: 52px; color: #aaa; }
.slider input { flex: 1; accent-color: #00b2e1; }
.slider .v { width: 42px; text-align: right; font-weight: 700; }
.types { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin: 8px 0; }
.types button { font-size: 12px; padding: 6px 2px; }
.upg { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.upg .n { width: 74px; color: #ccc; }
.pips { display: flex; gap: 3px; flex: 1; }
.pips i { flex: 1; height: 10px; border-radius: 3px; background: #3a3d46; }
.pips i.f { background: var(--pc, #ffde43); }
.upg button { width: 64px; padding: 4px; font-size: 12px; background: #00b2e1; border-color: #0085a8; }
.readout { margin-top: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; color: #aaa; font-size: 12px; }
.readout b { color: #fff; }
.danger { width: 100%; margin-top: 10px; background: #f14e54 !important; border-color: #b5383d !important; }
.queue { display: flex; justify-content: space-between; align-items: center; color: #ffde43; }
.empty { color: #888; font-style: italic; }

@media (max-width: 760px) {
  #editor { flex-direction: column; }
  .ed-left { flex: 0 0 auto; height: 48%; padding: 8px; }
  .ed-panel { width: 100%; flex: 1; }
  .ed-hint { display: none; }
}
.crumbs { display: flex; align-items: center; gap: 10px; font-weight: 700; color: #ffde43; }
.crumbs button { padding: 4px 10px; }
.note { color: #bbb; line-height: 1.45; font-size: 12px; }
.note b { color: #fff; }
.ed-panel button.drill { width: 100%; margin: 8px 0 2px; background: #8543ff; border-color: #5f2fc0; }

/* ---------------- Custom boss designer ---------------- */
#bossUI { position: fixed; inset: 0; background: rgba(14, 16, 22, 0.72); display: flex; align-items: stretch; justify-content: center; padding: 16px; z-index: 5; }
.bd-wrap { width: min(1280px, 100%); display: flex; flex-direction: column; background: #1c1e25; border-radius: 14px; color: #e8e8e8; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.4); }
.bd-head { display: flex; align-items: center; gap: 16px; padding: 12px 16px; background: #23252c; border-bottom: 1px solid #353842; flex-wrap: wrap; }
.bd-head h2 { margin: 0; font-size: 20px; }
.bd-tabs, .bd-actions { display: flex; gap: 6px; }
.bd-actions { margin-left: auto; }
#bossUI button { font: 700 13px Ubuntu, sans-serif; color: #fff; cursor: pointer; border-radius: 8px; padding: 7px 12px; background: #3a3d46; border: 3px solid #2a2c33; }
#bossUI button:hover:not(:disabled) { filter: brightness(1.15); }
#bossUI button:disabled { opacity: .4; cursor: not-allowed; }
#bossUI button.on { background: #00b2e1; border-color: #0085a8; }
#bossUI .bd-spawn { background: #00e16e; border-color: #00a952; }
.bd-body { flex: 1; display: flex; min-height: 0; }
.bd-side { width: 240px; flex-shrink: 0; padding: 12px; border-right: 1px solid #353842; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
#bdList { display: flex; flex-direction: column; gap: 4px; }
#bossUI .bd-item { text-align: left; display: flex; align-items: center; gap: 8px; }
.bd-item i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(0,0,0,.4); flex-shrink: 0; }
.bd-side-btns { display: flex; gap: 4px; }
#bossUI .bd-side-btns button { flex: 1; padding: 6px 4px; font-size: 12px; }
#bdPreview { width: 100%; aspect-ratio: 1; border-radius: 10px; }
.bd-main { flex: 1; overflow: auto; padding: 14px 16px 40px; }
.bd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.bd-grid label, .bd-lgrid label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: #bbb; }
.bd-grid label b, .bd-lgrid label b { color: #fff; }
.bd-grid input[type=text], .bd-grid input[type=number], .bd-lgrid select, .vin {
  background: #2c2f37; color: #fff; border: 2px solid #3d414c; border-radius: 6px; padding: 6px 8px; font: 500 14px Ubuntu, sans-serif; }
.bd-grid input[type=color], .bd-lgrid input[type=color] { width: 60px; height: 30px; border: none; background: none; padding: 0; }
#bossUI input[type=range] { accent-color: #bf7ff5; }
.bd-note { margin: 10px 0; color: #9aa; font-size: 13px; line-height: 1.5; }
.bd-note b { color: #fff; }
.bd-layer { background: #23252c; border: 1px solid #353842; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.bd-lhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
#bossUI .bd-lhead button { padding: 2px 9px; margin-left: 4px; }
.bd-lgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.bd-lgrid .row { display: flex; align-items: center; gap: 6px; color: #ddd; }
.bd-lsum { margin: 8px 0; color: #aaa; font-size: 12px; }
.bd-lsum b { color: #ffde43; }
.bd-lbtns { display: flex; gap: 6px; flex-wrap: wrap; }
#bossUI button.drill { background: #8543ff; border-color: #5f2fc0; }
#bossUI .bd-addlayer { width: 100%; padding: 10px; }
.bd-scripts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.bd-vars { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.vchip { background: #ff8c1a; color: #fff; border-radius: 12px; padding: 3px 4px 3px 10px; font-weight: 700; display: inline-flex; gap: 4px; align-items: center; }
#bossUI .vchip button { padding: 0 6px; border: none; background: rgba(0,0,0,.2); border-radius: 10px; }
.vin { width: 130px; padding: 4px 8px !important; }

/* blocks */
.blist { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.blist.nested { margin: 2px 0 2px 18px; padding: 4px 0 4px 8px; border-left: 3px solid rgba(255,255,255,.18); min-width: 120px; }
.blk { border-radius: 8px; padding: 4px 6px; color: #fff; box-shadow: 0 2px 0 rgba(0,0,0,.35); max-width: 100%; }
.brow { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; min-height: 28px; }
.bl { font-weight: 700; font-size: 13px; text-shadow: 0 1px 1px rgba(0,0,0,.3); }
.btools { margin-left: auto; padding-left: 10px; display: inline-flex; gap: 2px; opacity: .55; }
.blk:hover > .brow > .btools { opacity: 1; }
#bossUI .btools button { padding: 0 6px; font-size: 12px; border: none; background: rgba(0,0,0,.25); border-radius: 5px; }
#bossUI .badd { padding: 3px 10px; font-size: 12px; background: transparent; border: 2px dashed rgba(255,255,255,.3); color: #ccc; }
.ex { display: inline-flex; align-items: center; gap: 3px; border-radius: 14px; padding: 2px 6px 2px 2px; border: 2px solid rgba(0,0,0,.25); font-size: 12px; font-weight: 700; }
.exl { padding: 0 2px; white-space: nowrap; }
#bossUI .exsw { padding: 0 5px; font-size: 10px; border: none; background: rgba(0,0,0,.25); border-radius: 10px; line-height: 18px; }
.bnum { width: 62px; border: none; border-radius: 10px; padding: 3px 6px; font: 700 12px Ubuntu, sans-serif; background: #fff; color: #222; }
.bsel { border: none; border-radius: 10px; padding: 3px 4px; font: 700 12px Ubuntu, sans-serif; background: rgba(255,255,255,.9); color: #222; }
.c-ctl { background: #ffab19; } .c-var { background: #ff8c1a; } .c-move { background: #4c97ff; } .c-layer { background: #9966ff; }
.c-sense { background: #5cb1d6; } .c-op { background: #59c059; } .c-val { background: #8a8f9c; }
#bdPop { position: fixed; z-index: 10; width: 260px; max-height: 70vh; overflow-y: auto; background: #2a2c33; border: 1px solid #444; border-radius: 10px; padding: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.pop-t { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: #999; margin: 6px 2px 4px; }
#bossUI .pop-i { display: block; width: 100%; text-align: left; margin-bottom: 3px; border: none; padding: 6px 10px; }
@media (max-width: 760px) { .bd-body { flex-direction: column; } .bd-side { width: 100%; border-right: none; } #bdPreview { width: 160px; } }
/* color field: picker + R/G/B + text */
.cfield { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.cfield input[type=color] { width: 44px !important; height: 30px; border: none; background: none; padding: 0; cursor: pointer; }
.cch { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 700; color: #999; }
#bossUI .rgbn { width: 52px; background: #2c2f37; color: #fff; border: 2px solid #3d414c; border-radius: 6px; padding: 4px 5px; font: 500 13px Ubuntu, sans-serif; }
#bossUI .rgbtxt { width: 132px; background: #2c2f37; color: #fff; border: 2px solid #3d414c; border-radius: 6px; padding: 4px 6px; font: 500 13px Ubuntu, monospace; }
#bossUI .rgbtxt.bad { border-color: #f14e54; }
.bd-lgrid .bd-lcolor { grid-column: span 2; }
.cfield { flex-wrap: nowrap; }
@media (max-width: 760px) { .bd-lgrid .bd-lcolor { grid-column: auto; } .cfield { flex-wrap: wrap; } }
.bd-grid .bd-wide { grid-column: span 2; }
@media (max-width: 760px) { .bd-grid .bd-wide { grid-column: auto; } }

/* ---------------- Sandbox spawner ---------------- */
#sbTools { position: fixed; left: 14px; top: 182px; width: 300px; max-height: calc(100vh - 196px); overflow-y: auto; z-index: 3;
  background: rgba(26, 28, 34, 0.94); color: #e8e8e8; border-radius: 12px; padding: 12px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.35); }
.sb-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 15px; }
#sbTools button { font: 700 12px Ubuntu, sans-serif; color: #fff; cursor: pointer; border-radius: 7px; padding: 6px 8px; background: #3a3d46; border: 3px solid #2a2c33; }
#sbTools button:hover { filter: brightness(1.15); }
#sbTools button.on { background: #00b2e1; border-color: #0085a8; }
#sbTools .sb-go { background: #00e16e; border-color: #00a952; }
.sb-sec { background: #23252c; border: 1px solid #353842; border-radius: 10px; padding: 10px; margin-bottom: 10px; }
.sb-t { font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase; color: #8a8f9c; margin-bottom: 8px; }
.sb-shape { display: flex; gap: 10px; align-items: center; }
#sbShapePrev { width: 84px; height: 84px; border-radius: 8px; background: #cdcdcd; flex-shrink: 0; }
.sb-sliders { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.sb-sliders label { display: flex; flex-direction: column; color: #aaa; font-size: 12px; }
.sb-sliders b { color: #fff; }
.sb-sliders input { accent-color: #00b2e1; }
.sb-name { font-weight: 700; color: #ffde43; }
.sb-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 8px; }
.sb-btns .sb-go { grid-column: span 2; }
.sb-check { display: flex; gap: 6px; align-items: center; margin-top: 8px; color: #ccc; cursor: pointer; }
#sbDest { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.sb-note { margin-top: 8px; color: #8a8f9c; font-size: 11.5px; line-height: 1.45; }
.sb-note b { color: #fff; }

/* online options */
.addr { width: 100%; padding: 9px 12px; font: 500 15px Ubuntu, monospace; border-radius: 8px; border: 3px solid #444; background: #f2f2f2; color: #222; outline: none; text-align: center; }
.addr:focus { border-color: #00b2e1; }
.net-status { margin-top: 6px; font-size: 12px; color: #aaa; min-height: 16px; }
.net-status.ok { color: #00e16e; }
.net-status.bad { color: #f14e54; }
.play:disabled { opacity: .6; cursor: wait; }

/* block drag & drop */
.blk > .brow { cursor: grab; }
.blk > .brow input, .blk > .brow select, .blk > .brow button, .blk > .brow .ex { cursor: auto; }
.blk.dragging { opacity: 0.3; }
.bghost { position: fixed; z-index: 20; pointer-events: none; opacity: 0.9; transform: rotate(1.5deg); box-shadow: 0 10px 28px rgba(0,0,0,.5); cursor: grabbing; }
.bdrop { height: 4px; border-radius: 2px; background: #fff; box-shadow: 0 0 8px #00b2e1; align-self: stretch; min-width: 160px; margin: 1px 0; }
.btrash { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 19; padding: 14px 34px; border-radius: 12px;
  background: rgba(60, 20, 24, 0.92); border: 3px dashed #f14e54; color: #ffb3b6; font: 700 15px Ubuntu, sans-serif; }
.btrash.hot { background: #f14e54; color: #fff; border-style: solid; }
#bdMain { touch-action: pan-y; }
.bghost .btools { display: none; }
.aimturn { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; color: #aaa; font-size: 12px; }
.bd-lgrid input[type=range]:disabled { opacity: .35; }
.sb-crystals { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; }
#sbTools .sb-crystals button { font-size: 11px; padding: 6px 2px; }
.sb-dim { color: #8a8f9c; font-size: 11.5px; }
.sb-time { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
#sbTools .sb-time button { font-size: 11px; padding: 5px 2px; }
#sbTools { top: 206px; max-height: calc(100vh - 220px); } /* leave room for the HUD status line (time warp / noclip) */
.sb-select { width: 100%; padding: 7px 8px; border-radius: 7px; border: 2px solid #3d414c; background: #2c2f37; color: #fff; font: 500 13px Ubuntu, sans-serif; }
.siege-note { margin-top: 8px; }
/* spawner: click a button, then click the map */
.sb-shapebtn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 5px !important; flex-shrink: 0; }
.sb-shapebtn .sb-name { font-size: 11px; max-width: 92px; line-height: 1.2; }
.sb-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; }
#sbTools .sb-grid button { font-size: 11px; padding: 6px 2px; line-height: 1.15; }
.sb-grp { font-size: 10.5px; color: #8a8f9c; margin: 8px 0 4px; }
.sb-grp:first-child { margin-top: 0; }
.sb-btns .sb-wide { grid-column: span 2; }
#sbTools button.armed { outline: 2px solid #ffde43; outline-offset: 1px; filter: brightness(1.25); }
.ctrl-tog { display: flex; gap: 6px; align-items: center; margin: 8px 0 4px; cursor: pointer; font-size: 13px; }
.party-note { margin-top: 6px; }
.seg.seg-wrap { flex-wrap: wrap; }
.seg.seg-wrap button { flex: 1 0 30%; padding: 8px 4px; }
#partyCode { margin-top: 8px; text-transform: uppercase; letter-spacing: 4px; font-weight: 700; }
.ctrl-tog .c { color: #ffde43; font-weight: 700; }
.bd-warn { display: block; margin-top: 6px; padding: 6px 8px; border-radius: 6px; background: rgba(255, 170, 0, 0.14); border: 1px solid #c98a00; color: #ffcb57; font-size: 11.5px; line-height: 1.35; font-weight: 500; }
.bd-warn.hidden { display: none; }
.ed-panel button.drill.clone-btn { background: #2f6fd6; border-color: #1f4fa0; }
