:root {
  --bg:#f2efe6; --ink:#1b1810; --dim:#6e6756; --line:#cfc8b5; --panel:#e8e3d4; --script:#f9f7f1;
  --a:#ff7a2a; --b:#2aa8ff; --yes:#2f8f3a; --no:#c23b2f;
  --move:#4c97ff; --jet:#ff8c1a; --arm:#e6474d; --ctl:#ffbf00;
}
[hidden] { display:none !important; }
@media (prefers-color-scheme: dark) {
  :root { --bg:#15130e; --ink:#eee8d8; --dim:#a39b86; --line:#3b3628; --panel:#211e16; --script:#1b1913; }
}
* { box-sizing:border-box; }
body { margin:0 auto; max-width:1280px; padding:10px 14px 64px; background:var(--bg); color:var(--ink); font:16px/1.45 system-ui, sans-serif; }
h1 { margin:0; font-size:28px; letter-spacing:-0.5px; font-style:italic; font-weight:900; }
header { display:flex; flex-wrap:wrap; gap:10px; align-items:center; }
header nav { display:flex; gap:6px; margin-right:auto; }
.row { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin:8px 0; }
.row.small { margin:4px 0; }
.row.small button { padding:3px 10px; font-size:14px; }
input, select, button { font:inherit; color:inherit; }
input, select { background:var(--panel); border:1px solid var(--line); border-radius:6px; padding:6px 8px; }
button { background:var(--panel); border:1px solid var(--line); border-radius:6px; padding:6px 12px; cursor:pointer; touch-action:manipulation; }
button.primary { background:var(--ink); color:var(--bg); border-color:var(--ink); }
button.quiet { background:none; }
button.fun { font-weight:700; border-width:2px; }
button.on { border-color:var(--ink); font-weight:700; }
button:disabled { opacity:.45; cursor:default; }
.dim { color:var(--dim); font-size:14px; }
#login-form.busy button { opacity:1; cursor:progress; max-width:60vw; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; animation:busy 1.2s ease-in-out infinite; }
@keyframes busy { 50% { background:color-mix(in srgb, var(--b) 25%, var(--panel)); } }
@media (prefers-reduced-motion: reduce) { #login-form.busy button { animation:none; } }
.msg { min-height:1.2em; color:var(--no); font-size:14px; margin:4px 0; }
section { margin-bottom:16px; }
.yes { color:var(--yes); } .no { color:var(--no); }
#bot-name { font-weight:700; min-width:0; flex:1 1 160px; }

/* layout: the fight beside the code on a wide screen, above it (and pinned) on a phone */
.build { display:grid; grid-template-columns:minmax(0, 1.15fr) minmax(0, 1fr); gap:18px; align-items:start; }
.build .left { position:sticky; top:8px; }
@media (max-width: 860px) {
  .build { grid-template-columns:1fr; gap:6px; }
  .build .left { top:0; z-index:5; background:var(--bg); padding-bottom:4px; }
  .build .left .stage { aspect-ratio:auto; height:36vh; }
  .build .left .controls { margin:4px 0; font-size:14px; }
}

/* the 3D stage and its HUD */
.stage { position:relative; width:100%; aspect-ratio:16/10; border-radius:10px; overflow:hidden; background:#2f9bff; }
.stage canvas { display:block; width:100%; height:100%; }
.hud { position:absolute; inset:0; pointer-events:none; color:#fff; font-weight:800; font-style:italic; text-shadow:0 1px 2px #000a; }
.hud .side { position:absolute; top:8px; width:40%; }
.hud .side.a { left:10px; } .hud .side.b { right:10px; text-align:right; }
.hud .nm { display:block; font-size:14px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.hud .bar { height:9px; background:#0007; border:1px solid #fff8; transform:skewX(-20deg); margin-top:3px; overflow:hidden; }
.hud .bar.en { height:5px; }
.hud .bar i { display:block; height:100%; width:100%; transition:width .15s; }
.hud .side.a .hp i { background:linear-gradient(90deg, #ff4a1a, #ffd23a); }
.hud .side.b .hp i { background:linear-gradient(90deg, #2ae0ff, #2a7aff); margin-left:auto; }
.hud .side.b .bar { display:flex; }
.hud .en i { background:#8ff; }
.hud .clock { position:absolute; top:6px; left:50%; transform:translateX(-50%); font-size:24px; font-variant-numeric:tabular-nums; }
.hud .banner { position:absolute; left:0; right:0; top:42%; text-align:center; font-size:clamp(22px, 5vw, 44px); letter-spacing:1px; opacity:0; transform:scale(1.4); transition:opacity .2s, transform .2s; -webkit-text-stroke:1px #0008; padding:0 10px; }
.hud .banner.show { opacity:1; transform:scale(1); }

.controls label { display:flex; gap:6px; align-items:center; }
.controls select { max-width:52vw; }

.evolve { background:var(--panel); border:2px solid var(--ctl); border-radius:8px; padding:8px 10px; margin:8px 0; }

/* the block editor */
.editor { display:grid; grid-template-columns:auto 1fr; gap:10px; align-items:start; }
.palette { display:flex; flex-direction:column; gap:4px; max-height:70vh; overflow:auto; padding-right:4px; }
.palette h4 { margin:6px 0 2px; font-size:12px; text-transform:uppercase; letter-spacing:1px; color:var(--dim); }
.palette .blk { cursor:grab; }
.script-wrap { background:var(--script); border:1px solid var(--line); border-radius:10px; padding:10px; min-height:300px;
  background-image:radial-gradient(var(--line) 1px, transparent 1px); background-size:16px 16px; }
.script { min-height:120px; padding-bottom:40px; }
.hat { display:inline-block; background:var(--ctl); color:#3a2a00; font-weight:700; padding:8px 16px 6px; border-radius:16px 16px 6px 6px; font-size:14px; }
.tip { margin-top:4px; }
@media (max-width: 560px) {
  .editor { grid-template-columns:1fr; }
  .palette { flex-direction:row; flex-wrap:wrap; max-height:none; gap:2px 4px; }
  .palette h4 { display:none; }
  .palette .blk { margin:0 0 5px; }
  .palette .blk > .head { padding:4px 8px; }
}

.blk { position:relative; color:#fff; font-size:14px; font-weight:600; margin:0 0 4px; border-radius:6px; width:max-content; max-width:100%;
  user-select:none; -webkit-user-select:none; touch-action:none; }
.blk > .head { display:flex; flex-wrap:wrap; align-items:center; gap:5px; padding:6px 10px; border-radius:6px; cursor:grab; }
.blk::after { content:""; position:absolute; left:14px; bottom:-5px; width:18px; height:6px; border-radius:0 0 4px 4px; background:inherit; z-index:1; }
.blk select { background:#ffffffe6; color:#222; border:0; border-radius:12px; padding:1px 4px; font-size:13px; font-weight:600; cursor:pointer; }
.cat-move { background:var(--move); }
.cat-jet { background:var(--jet); }
.cat-arm { background:var(--arm); }
.cat-ctl { background:var(--ctl); color:#3a2a00; }
.blk.c { min-width:180px; }
.blk.c > .head { border-radius:6px 6px 0 0; }
.blk .slot { margin-left:14px; min-height:26px; background:var(--script); border-radius:0 6px 6px 0; padding:4px 6px 0; }
.blk .mid { padding:3px 10px; font-size:13px; }
.blk .foot { height:12px; border-radius:0 0 6px 6px; }
.blk.running > .head { box-shadow:0 0 0 3px #fff, 0 0 14px 5px #ffe14a; }
.blk.ghost { position:fixed; z-index:100; pointer-events:none; opacity:.85; transform:rotate(2deg); box-shadow:0 8px 20px #0006; }
.blk.dragging { opacity:.25; }
.drop-line { height:4px; background:#222; border-radius:2px; margin:-2px 0 2px; box-shadow:0 0 0 2px #fff8; }
@media (prefers-color-scheme: dark) { .drop-line { background:#fff; } }
.script-wrap.trash, .palette.trash { outline:3px dashed var(--no); outline-offset:-3px; }

table { border-collapse:collapse; width:100%; font-size:15px; }
th, td { text-align:left; padding:6px 4px; border-top:1px solid var(--line); }
th { font-weight:600; color:var(--dim); font-size:13px; }
td.n { text-align:right; font-variant-numeric:tabular-nums; } th.n { text-align:right; }
tr.mine td:first-child { font-weight:700; }
tr.pick { cursor:pointer; }
.matches td { font-size:14px; }
#viewer { margin:10px 0; max-width:900px; }
.gl dt { font-weight:700; margin-top:6px; } .gl dd { margin:0; color:var(--dim); font-size:14px; }
.gl dt .blk { display:inline-block; margin:0; }
