:root {
  --bg: #07140f;
  --pcb: #0c2419;
  --trace: #39ff88;
  --dim: #5f8f78;
  --text: #d8f5e6;
  --copper: #d9a441;
  --power: #ffd23d;
  --comp: #3de0ff;
  --hack: #ff3d7f;
  --junk: #8a8a8a;
  --danger: #ff5050;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace; overscroll-behavior: none; }
body {
  background-image:
    linear-gradient(rgba(57,255,136,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(57,255,136,.04) 1px, transparent 1px);
  background-size: 22px 22px;
  user-select: none; -webkit-user-select: none;
}
#app { max-width: 520px; margin: 0 auto; min-height: 100%; padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
button { font: inherit; color: var(--bg); background: var(--trace); border: 0; border-radius: 8px; padding: 12px 16px; font-weight: 700; letter-spacing: .5px; cursor: pointer; }
button.ghost { background: transparent; color: var(--trace); border: 1px solid var(--trace); }
button:disabled { opacity: .35; }
input { font: inherit; background: var(--pcb); color: var(--text); border: 1px solid var(--dim); border-radius: 8px; padding: 12px; width: 100%; }
h1 { margin: 24px 0 4px; font-size: 44px; letter-spacing: 6px; color: var(--trace); text-shadow: 0 0 18px rgba(57,255,136,.6); text-align: center; }
.tag { text-align: center; color: var(--dim); margin-bottom: 18px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.muted { color: var(--dim); font-size: 13px; }
.big-code { font-size: 56px; letter-spacing: 12px; text-align: center; color: var(--copper); margin: 18px 0; }
.rules { color: var(--dim); font-size: 13px; line-height: 1.5; }
.rules b { color: var(--text); }

/* ---- player bars ---- */
.pbar { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--pcb); border-radius: 8px; border: 1px solid rgba(57,255,136,.15); }
.pbar.active { border-color: var(--trace); box-shadow: 0 0 12px rgba(57,255,136,.25); }
.pbar .name { font-weight: 700; min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fw { display: flex; align-items: center; gap: 6px; flex: 1.4; }
.fw .barbg { flex: 1; height: 10px; background: #1a3328; border-radius: 5px; overflow: hidden; }
.fw .bar { height: 100%; background: var(--trace); transition: width .4s; }
.fw .bar.low { background: var(--danger); }
.fw .num { min-width: 24px; text-align: right; font-weight: 700; }
.stat { font-size: 12px; color: var(--dim); white-space: nowrap; }
.stat b { color: var(--text); }
.shield { color: var(--comp); }
.hit { animation: hit .6s; }
@keyframes hit { 0%,100% { transform: none; } 20% { transform: translateX(-6px); background: rgba(255,80,80,.4); } 60% { transform: translateX(5px); } }

/* ---- boards ---- */
.board { display: flex; align-items: center; gap: 4px; padding: 6px 4px; }
.node { font-size: 11px; font-weight: 800; width: 22px; text-align: center; color: var(--copper); }
.trace { flex: 0 0 6px; height: 3px; background: var(--dim); border-radius: 2px; }
.board.complete .trace { background: var(--trace); box-shadow: 0 0 6px var(--trace); }
.slot { flex: 1; aspect-ratio: 3/4; border: 2px dashed rgba(95,143,120,.5); border-radius: 8px; display: flex; flex-direction: column; justify-content: center; align-items: center; position: relative; font-size: 11px; text-align: center; padding: 3px; }
.slot.filled { border: 2px solid var(--comp); background: rgba(61,224,255,.08); }
.slot .sname { font-weight: 700; font-size: 11px; line-height: 1.1; }
.slot .sicon { font-size: 16px; font-weight: 800; color: var(--comp); }
.slot .charge { position: absolute; top: 2px; right: 4px; color: var(--power); font-size: 11px; }
.slot.target { border-color: var(--hack); box-shadow: 0 0 10px var(--hack); border-style: solid; }
.slot.mine.target { border-color: var(--trace); box-shadow: 0 0 10px var(--trace); }
.slot.pulse { animation: pulse .35s; }
.slot .sig { position: absolute; bottom: -9px; background: var(--trace); color: var(--bg); border-radius: 9px; padding: 0 6px; font-weight: 700; font-size: 12px; }
@keyframes pulse { 50% { transform: scale(1.08); box-shadow: 0 0 18px var(--trace); } }

.center { text-align: center; padding: 4px; min-height: 48px; display: flex; flex-direction: column; justify-content: center; }
.turn { font-weight: 700; color: var(--trace); }
.turn.theirs { color: var(--dim); }
.log { font-size: 12px; color: var(--dim); max-height: 3.9em; overflow: hidden; display: flex; flex-direction: column-reverse; }

/* ---- cards ---- */
.hand { display: flex; gap: 6px; overflow-x: auto; padding: 8px 2px 4px; min-height: 140px; }
.card { flex: 0 0 96px; height: 132px; border-radius: 10px; background: var(--pcb); border: 2px solid var(--c, var(--dim)); padding: 6px; position: relative; display: flex; flex-direction: column; gap: 4px; transition: transform .15s; cursor: pointer; }
.card.k-power { --c: var(--power); }
.card.k-component { --c: var(--comp); }
.card.k-hack { --c: var(--hack); }
.card.k-junk { --c: var(--junk); }
.card .cname { font-weight: 700; font-size: 12px; color: var(--c); padding-right: 20px; line-height: 1.15; }
.card .ctext { font-size: 10.5px; color: var(--text); opacity: .85; line-height: 1.25; }
.card .cost { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 13px; background: var(--power); color: var(--bg); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.card .kind { margin-top: auto; font-size: 10px; color: var(--c); text-transform: uppercase; letter-spacing: 1px; }
.card.sel { transform: translateY(-8px); box-shadow: 0 0 16px var(--c); }
.card.cant { opacity: .45; }
.hint { min-height: 44px; display: flex; gap: 8px; align-items: center; font-size: 13px; }
.hint .txt { flex: 1; color: var(--dim); }

/* ---- market ---- */
.mhead { display: flex; justify-content: space-between; align-items: baseline; }
.credits { font-size: 28px; color: var(--copper); font-weight: 800; }
.timer { height: 6px; background: #1a3328; border-radius: 3px; overflow: hidden; }
.timer > div { height: 100%; background: var(--copper); }
.market { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px; padding-top: 10px; position: relative; }
.market .card { flex: none; width: auto; height: 150px; }
.market .card .cost { background: var(--copper); }
.market .card.empty { border-style: dashed; opacity: .25; cursor: default; }
.market .card.incoming { filter: blur(3px) brightness(.6); pointer-events: none; }
.market .card.pricey .cost { background: #555; color: var(--text); }
.lock { position: absolute; inset: 0; background: rgba(255,80,80,.18); display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--danger); font-size: 22px; border-radius: 10px; pointer-events: none; }
.library { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.library .card { flex: none; height: 110px; }

/* ---- toast ---- */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 10px 16px; border-radius: 8px; font-weight: 700; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; z-index: 10; }
#toast.on { opacity: 1; }
.over { text-align: center; }
.over .result { font-size: 34px; font-weight: 800; color: var(--trace); margin: 30px 0 6px; }
.over .result.lose { color: var(--danger); }
