/* ===== In-game HUD (play / spectate) ===== */
.hud { font-size: 13px; }
.hud > * { pointer-events: auto; }
.hud-tl, .hud-tr { position: absolute; top: calc(14px + var(--safe-t)); display: flex; flex-direction: column; gap: 8px; }
.hud-tl { left: 14px; align-items: flex-start; }
.hud-tr { right: 14px; align-items: flex-end; }
.hud-tr { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; max-width: 60vw; }
.hpill {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 999px;
  background: rgba(5,7,13,.78); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 12px; white-space: nowrap; color: var(--text);
}
.hpill svg { width: 15px; height: 15px; color: var(--cyan); }
.hpill .sep { width: 1px; height: 14px; background: var(--line-strong); margin: 0 4px; }
.watch-pill { width: 100%; justify-content: flex-end; flex-basis: 100%; max-width: max-content; margin-left: auto; }
.watch-pill a { color: var(--lime); }
.hud[data-mode="play"] .watch-pill { display: none; }
.hud[data-mode="spectate"] .pcard, .hud[data-mode="spectate"] .prompt, .hud[data-mode="spectate"] .act-btn { display: none !important; }
.hbtn { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; color: var(--text); cursor: pointer; background: rgba(5,7,13,.78); border: 1px solid var(--line); }
.hbtn:hover { border-color: var(--line-strong); }
.hbtn svg { width: 17px; height: 17px; }
.gmenu { position: absolute; top: 44px; right: 0; width: 210px; padding: 6px; border-radius: 14px; background: #0a1120; border: 1px solid var(--line-strong); box-shadow: 0 20px 50px -10px rgba(0,0,0,.8); display: grid; }
.gmenu button { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: none; border: 0; color: var(--text); font: 500 14px var(--font); cursor: pointer; text-align: left; }
.gmenu button:hover { background: rgba(0,240,255,.07); }
.gmenu button svg { width: 17px; height: 17px; color: var(--cyan); }
.gmenu kbd { margin-left: auto; }

.pcard { width: 236px; padding: 12px; border-radius: 16px; background: rgba(5,7,13,.8); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); display: grid; gap: 8px; }
.pcard-top { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.pcard-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lv { margin-left: auto; font-size: 10px; padding: 2px 7px; border-radius: 6px; background: var(--grad); color: #03140c; font-weight: 700; }
.bar { height: 6px; border-radius: 6px; background: rgba(255,255,255,.08); overflow: hidden; flex: 1; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; transition: width .4s; }
.bar.xp i { background: var(--grad); }
.bar.en i { background: linear-gradient(90deg, #ffb547, #7cff4f); }
.bar.en.low i { background: var(--pink); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .4; } }
.res { display: flex; gap: 14px; font-size: 13px; }
.res span { display: inline-flex; align-items: center; gap: 5px; }
.res svg { width: 15px; height: 15px; color: var(--cyan); }
.res span + span svg { color: var(--lime); }
.res small { color: var(--muted); }
.energy { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.energy svg { width: 14px; height: 14px; color: var(--warn); }
.energy span { width: 26px; text-align: right; color: var(--muted); }

.hud-bl { position: absolute; left: 16px; bottom: calc(18px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; }
#gMap { width: 150px; height: 150px; border-radius: 50%; border: 3px solid rgba(230,246,255,.85); box-shadow: 0 10px 30px -8px rgba(0,0,0,.8), 0 0 24px -6px rgba(0,240,255,.6); background: #07101e; cursor: pointer; }
.map-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 999px; background: rgba(5,7,13,.85); border: 1px solid var(--line); color: var(--text); font-size: 11px; cursor: pointer; }
.map-chip kbd { background: var(--grad); color: #03140c; border: 0; margin: 0; padding: 1px 6px; }
.hud-bl.big { left: 50%; bottom: 50%; transform: translate(-50%, 50%); z-index: 3; }
.hud-bl.big #gMap { width: min(78vmin, 520px); height: min(78vmin, 520px); }

.helper { position: absolute; right: 16px; bottom: calc(18px + var(--safe-b)); width: 290px; border-radius: 16px; background: rgba(9,14,26,.9); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); overflow: hidden; }
.helper-head { display: flex; align-items: center; gap: 8px; width: 100%; padding: 12px 14px; background: none; border: 0; color: var(--text); font: 600 14px var(--font); cursor: pointer; }
.helper-head .tag { font-size: 9px; letter-spacing: .1em; }
.helper-head .chev { margin-left: auto; width: 16px; height: 16px; color: var(--muted); transition: transform .2s; }
.helper.collapsed .chev { transform: rotate(180deg); }
.helper.collapsed .helper-body { display: none; }
.byte-ico { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #1b2a44, #050a14); border: 2px solid var(--cyan); display: grid; place-items: center; box-shadow: 0 0 10px rgba(0,240,255,.6); }
.byte-ico i { width: 6px; height: 6px; border-radius: 50%; background: var(--lime); animation: blink 2.4s infinite; }
.helper-body { padding: 0 14px 12px; display: grid; gap: 8px; }
.helper-body p { display: flex; gap: 10px; margin: 0; font-size: 13px; color: #c3d6e4; line-height: 1.45; }
.helper-body p + p { padding-top: 8px; border-top: 1px solid var(--line); }
.helper-body svg { width: 16px; height: 16px; flex: none; margin-top: 1px; color: var(--muted); }
#gObjective svg { color: var(--lime); }

.prompt { position: absolute; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); display: inline-flex; align-items: center; gap: 10px; padding: 10px 16px 10px 10px; border-radius: 14px; background: rgba(5,7,13,.88); border: 1px solid rgba(124,255,79,.5); color: var(--text); font: 600 14px var(--font); cursor: pointer; box-shadow: 0 0 30px -8px rgba(124,255,79,.6); animation: pop .25s; white-space: nowrap; }
.prompt kbd { background: var(--grad); color: #03140c; border: 0; font-size: 13px; padding: 3px 9px; margin: 0; }
.prompt small { color: var(--muted); font-weight: 500; }
.feed { position: absolute; left: 50%; bottom: calc(22px + var(--safe-b)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.feed div { display: flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px; background: rgba(5,7,13,.82); border: 1px solid var(--line); font-size: 12px; white-space: nowrap; animation: feedIn 6s forwards; }
.feed div svg { width: 14px; height: 14px; color: var(--cyan); }
.feed div.good { border-color: rgba(124,255,79,.5); }
.feed div.good svg { color: var(--lime); }
@keyframes feedIn { 0% { opacity: 0; transform: translateY(8px); } 6%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.act-btn { position: absolute; right: 22px; bottom: calc(190px + var(--safe-b)); width: 68px; height: 68px; border-radius: 50%; border: 0; background: var(--grad); color: #03140c; font: 700 20px var(--mono); box-shadow: 0 0 30px -4px rgba(124,255,79,.8); }

/* ===== Mission board ===== */
.board, .mg { position: fixed; inset: 0; z-index: 45; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(3,5,10,.55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade .25s; }
.board-card, .mg-card {
  width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; padding: 22px; border-radius: 20px;
  background: linear-gradient(180deg, rgba(14,22,40,.97), rgba(8,13,25,.98)); border: 1px solid var(--line-strong);
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.85), 0 0 60px -20px rgba(0,240,255,.35); position: relative; animation: pop .3s cubic-bezier(.2,.9,.3,1.2);
}
.mg-card { max-width: 720px; }
.mg-head { display: flex; align-items: flex-start; gap: 14px; }
.mg-head h2 { font-size: 24px; margin: 4px 0 0; }
.mg-x { margin-left: auto; width: 34px; height: 34px; border-radius: 10px; background: rgba(255,255,255,.04); border: 1px solid var(--line); color: var(--text); cursor: pointer; flex: none; }
.mg-score { margin-left: auto; font-size: 26px; font-weight: 700; color: var(--lime); }
.mg-score + .mg-x { margin-left: 0; }
.mg-score small { font-size: 14px; color: var(--muted); }
.board-sub { font-size: 12px; margin: 6px 0 14px; }
.missions { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.missions li { display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center; padding: 12px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255,255,255,.02); }
.missions li.done { border-color: rgba(124,255,79,.4); background: rgba(124,255,79,.05); }
.missions .m-ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: rgba(0,240,255,.08); }
.missions .m-ico i { width: 12px; height: 12px; border-radius: 3px; transform: rotate(45deg); }
.missions b { display: block; font-size: 15px; }
.missions small { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.missions .bar { margin-top: 6px; }
.missions .bar i { background: var(--grad); }
.missions button { font-size: 12px; }

/* ===== Minigames ===== */
.mg-timer { height: 4px; border-radius: 4px; background: rgba(255,255,255,.08); margin: 14px 0 10px; overflow: hidden; }
.mg-timer i { display: block; height: 100%; width: 100%; background: var(--grad); transform-origin: left; }
.mg-timer.low i { background: var(--pink); }
.mg-hint { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.mg-body { position: relative; }
.mg-shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* bug squash */
.bug-arena { position: relative; height: 340px; border-radius: 14px; border: 1px solid var(--line); background: #03060c; overflow: hidden; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.bug-arena pre { margin: 0; padding: 14px 16px; font: 13px/1.75 var(--mono); color: #5d7790; pointer-events: none; }
.bug-arena pre .k { color: #3fa6b3; } .bug-arena pre .s { color: #5f9e45; }
.bug { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; border: 0; padding: 0; background: none; cursor: crosshair; color: var(--pink); filter: drop-shadow(0 0 6px rgba(255,61,129,.7)); }
.bug svg { width: 100%; height: 100%; stroke-width: 1.6; }
.bug.gold { color: var(--warn); filter: drop-shadow(0 0 8px rgba(255,181,71,.9)); }
.splat { position: absolute; margin: -20px 0 0 -20px; width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--lime); animation: splat .45s forwards; pointer-events: none; font: 700 12px var(--mono); color: var(--lime); display: grid; place-items: center; }
@keyframes splat { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }

/* code blocks for merge / review */
.codebox { border-radius: 12px; border: 1px solid var(--line); background: #03060c; font: 13px/1.7 var(--mono); overflow-x: auto; }
.codebox .file { padding: 8px 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; }
.codebox .ln { display: block; width: 100%; padding: 1px 14px; white-space: pre; color: #a9c1d3; text-align: left; background: none; border: 0; font: inherit; }
.codebox .ln.add { background: rgba(124,255,79,.07); color: #c9f5b6; }
.codebox .ln.del { background: rgba(255,61,129,.07); color: #ffb3cd; }
.codebox .ln.mark { color: var(--warn); }
.codebox .ln.ours { background: rgba(0,240,255,.07); }
.codebox .ln.theirs { background: rgba(179,107,255,.09); }
.codebox button.ln { cursor: pointer; }
.codebox button.ln:hover { outline: 1px solid var(--cyan); outline-offset: -1px; }
.codebox .ln.wrong { background: rgba(255,61,129,.25); }
.codebox .ln.right { background: rgba(124,255,79,.3); color: #fff; }
.ctx { font-size: 14px; color: #c3d6e4; margin: 0 0 10px; padding: 10px 12px; border-left: 2px solid var(--cyan); background: rgba(0,240,255,.04); border-radius: 0 10px 10px 0; }
.opts { display: grid; gap: 8px; margin-top: 12px; }
.opt { text-align: left; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.03); color: var(--text); font: 13px/1.5 var(--mono); cursor: pointer; white-space: pre-wrap; }
.opt:hover { border-color: rgba(0,240,255,.5); }
.opt.right { border-color: var(--lime); background: rgba(124,255,79,.1); }
.opt.wrong { border-color: var(--pink); background: rgba(255,61,129,.1); }
.round { font: 600 11px var(--mono); color: var(--muted); letter-spacing: .12em; margin-bottom: 8px; }
.explain { margin-top: 10px; font-size: 13px; color: #c9ffb5; }

/* node rebuild */
.rig { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; }
.board-pcb { position: relative; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: linear-gradient(rgba(0,240,255,.05) 1px, transparent 1px) 0 0 / 14px 14px, linear-gradient(90deg, rgba(0,240,255,.05) 1px, transparent 1px) 0 0 / 14px 14px, #04120f; }
.slot { min-height: 82px; border-radius: 12px; border: 2px dashed rgba(124,255,79,.35); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px; color: var(--muted); font: 600 11px var(--mono); text-align: center; background: rgba(0,0,0,.25); cursor: pointer; transition: all .2s; }
.slot svg { width: 26px; height: 26px; color: rgba(124,255,79,.5); }
.slot.ready { border-color: var(--cyan); box-shadow: 0 0 16px -4px var(--cyan); }
.slot.filled { border-style: solid; border-color: var(--lime); color: var(--lime); background: rgba(124,255,79,.1); cursor: default; }
.slot.filled svg { color: var(--lime); }
.tray { display: grid; gap: 8px; align-content: start; }
.part { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.03); color: var(--text); font: 600 13px var(--font); cursor: pointer; text-align: left; }
.part svg { width: 20px; height: 20px; color: var(--cyan); flex: none; }
.part.sel { border-color: var(--cyan); background: rgba(0,240,255,.1); box-shadow: 0 0 14px -4px var(--cyan); }
.part.used { opacity: .25; pointer-events: none; }

/* result */
.result { text-align: center; padding: 18px 0 4px; }
.result .big-ico { width: 74px; height: 74px; margin: 0 auto 10px; border-radius: 22px; display: grid; place-items: center; background: var(--grad); color: #03140c; }
.result.fail .big-ico { background: rgba(255,61,129,.15); color: var(--pink); border: 1px solid rgba(255,61,129,.5); }
.result .big-ico svg { width: 36px; height: 36px; stroke-width: 2.2; }
.result h3 { font-size: 24px; margin: 0 0 4px; }
.rewards { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.rewards span { padding: 8px 14px; border-radius: 12px; border: 1px solid var(--line); font: 600 13px var(--mono); }
.rewards span b { color: var(--lime); }
.result .hero-cta { justify-content: center; }

@media (max-width: 768px) {
  .hud-tl { left: 10px; top: calc(10px + var(--safe-t)); gap: 6px; }
  .hud-tr { right: 10px; top: calc(10px + var(--safe-t)); max-width: 52vw; gap: 6px; }
  .hpill { height: 30px; padding: 0 10px; font-size: 10.5px; }
  .hud-tr .hpill:first-child #gNext, .hud-tr .hpill:first-child .sep { display: none; }
  .hbtn { width: 30px; height: 30px; border-radius: 10px; }
  .hud-tl .hpill .muted { display: none; }
  .pcard { width: 176px; padding: 9px; gap: 6px; border-radius: 14px; }
  .pcard-top { font-size: 12px; }
  .res { font-size: 11px; gap: 10px; }
  .hud-bl { left: auto; right: 10px; bottom: auto; top: calc(86px + var(--safe-t)); }
  #gMap { width: 92px; height: 92px; border-width: 2px; }
  .map-chip { display: none; }
  .helper { left: 10px; right: 10px; width: auto; bottom: auto; top: calc(150px + var(--safe-t)); max-width: 260px; }
  .helper-head { padding: 9px 12px; font-size: 13px; }
  .helper-body p { font-size: 12px; }
  .hud[data-mode="play"] .helper { top: calc(160px + var(--safe-t)); }
  .prompt { bottom: calc(210px + var(--safe-b)); font-size: 13px; }
  .feed { bottom: calc(150px + var(--safe-b)); max-width: 92vw; }
  .feed div { font-size: 11px; white-space: normal; text-align: center; }
  .joystick { left: 22px; bottom: calc(40px + var(--safe-b)); }
  .act-btn { right: 26px; bottom: calc(66px + var(--safe-b)); }

  .board, .mg { padding: 0; align-items: flex-end; }
  .board-card, .mg-card { border-radius: 22px 22px 0 0; max-height: 92vh; padding: 16px 14px calc(16px + var(--safe-b)); animation: sheet .3s cubic-bezier(.2,.9,.3,1); }
  .mg-head h2 { font-size: 20px; }
  .bug-arena { height: 52vh; }
  .bug { width: 52px; height: 52px; margin: -26px 0 0 -26px; }
  .rig { grid-template-columns: 1fr; }
  .board-pcb { grid-template-columns: repeat(3, 1fr); padding: 10px; gap: 8px; }
  .slot { min-height: 70px; font-size: 10px; }
  .tray { grid-template-columns: 1fr 1fr; }
  .part { font-size: 12px; padding: 9px; }
  .codebox { font-size: 11.5px; }
}
