:root{
  --bg1:#0b1020;
  --bg2:#0a2a6a;
  --card:rgba(255,255,255,.10);
  --stroke:rgba(255,255,255,.18);
  --txt:#ffffff;
  --muted:rgba(255,255,255,.72);
  --good:#22c55e;
  --bad:#fb7185;
  --demo:#60a5fa;
  --gold:#fbbf24;
  --shadow:0 25px 70px rgba(0,0,0,.45);
}

*{box-sizing:border-box}
body{
  margin:0;
  font-family:"Poppins",system-ui,Arial,sans-serif;
  color:var(--txt);
  background:radial-gradient(900px 500px at 20% 0%, #1dd3ff33, transparent 60%),
             radial-gradient(700px 500px at 80% 20%, #a78bfa33, transparent 55%),
             linear-gradient(135deg,var(--bg1),var(--bg2));
  overflow-x:hidden;
}

.bg-spark{
  position:fixed;
  width:380px; height:380px; border-radius:50%;
  filter:blur(30px); opacity:.18;
  animation:float 14s ease-in-out infinite;
  pointer-events:none;
}
.s1{left:-120px; top:-140px; background:#22c55e;}
.s2{right:-140px; top:60px; background:#60a5fa; animation-duration:18s;}
.s3{left:25%; bottom:-220px; background:#fbbf24; animation-duration:22s;}
@keyframes float{0%,100%{transform:translate(0,0)}50%{transform:translate(30px,-25px)}}

.wrap{max-width:1180px; margin:0 auto; padding:22px 18px 40px;}

.top{
  display:flex; align-items:center; justify-content:space-between; gap:14px;
  margin-bottom:16px;
}
.brand{display:flex; align-items:center; gap:12px;}
.logo{
  width:48px; height:48px; border-radius:16px;
  display:grid; place-items:center;
  background:linear-gradient(135deg,#22c55e,#60a5fa);
  box-shadow:0 18px 45px rgba(0,0,0,.35);
  font-size:22px;
}
h1{margin:0; font-size:30px; line-height:1.1}
.sub{margin:3px 0 0; color:var(--muted); font-size:13px}

.mini{display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end}
.chip{
  padding:8px 10px; border-radius:999px;
  background:rgba(255,255,255,.10);
  border:1px solid rgba(255,255,255,.14);
  color:rgba(255,255,255,.85);
  font-size:12px;
}
.chip2{background:rgba(96,165,250,.14); border-color:rgba(96,165,250,.25)}

.card{
  background:var(--card);
  border:1px solid var(--stroke);
  border-radius:22px;
  box-shadow:var(--shadow);
  backdrop-filter: blur(10px);
}

.start{padding:18px}
.startGrid{
  display:grid;
  grid-template-columns: 1.2fr .8fr;
  gap:16px;
  align-items:stretch;
}
.startLeft{padding:10px 10px 10px 12px; text-align:left}
.startLeft h2{margin:6px 0 8px; font-size:24px}
.startLeft p{margin:0 0 12px; color:var(--muted); line-height:1.5}
.rules{margin:0 0 14px; padding-left:18px; color:rgba(255,255,255,.85)}
.rules li{margin:6px 0}
.row{display:flex; gap:10px; flex-wrap:wrap; margin:10px 0 12px}
input, select{
  padding:12px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(0,0,0,.15);
  color:#fff;
  outline:none;
  font-family:inherit;
}
input{width:220px}
select{min-width:220px}

.btn{
  padding:12px 14px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.20);
  background:rgba(255,255,255,.10);
  color:#fff;
  font-weight:700;
  cursor:pointer;
  transition:.18s transform, .18s background;
}
.btn:hover{transform:translateY(-1px); background:rgba(255,255,255,.14)}
.btn:active{transform:translateY(0px) scale(.99)}
.primary{
  border:none;
  background:linear-gradient(135deg,#22c55e,#60a5fa);
  box-shadow:0 18px 45px rgba(34,197,94,.20);
}
.ghost{background:transparent}

.startRight{display:flex; align-items:center; justify-content:center; padding:10px}
.preview{
  width:100%;
  max-width:340px;
  border-radius:20px;
  padding:16px;
  background:rgba(0,0,0,.18);
  border:1px solid rgba(255,255,255,.12);
}
.previewTitle{font-weight:800; font-size:14px; opacity:.9; margin-bottom:10px}
.previewDots{
  display:grid; grid-template-columns:repeat(3,1fr);
  gap:14px; padding:14px;
}
.previewDots span{
  width:56px; height:56px; border-radius:50%;
  background:rgba(255,255,255,.10);
  border:2px solid rgba(255,255,255,.16);
  box-shadow:0 0 20px rgba(96,165,250,.12) inset;
}
.previewNote{font-size:12px; color:var(--muted); margin-top:8px}

.game{
  display:grid;
  grid-template-columns: 320px 1fr;
  gap:16px;
  align-items:start;
}

.panel{
  padding:16px;
  position:sticky;
  top:14px;
}

.pTop{display:flex; gap:12px; align-items:center; margin-bottom:12px}
.avatar{
  width:52px; height:52px; border-radius:18px;
  display:grid; place-items:center;
  background:rgba(0,0,0,.18);
  border:1px solid rgba(255,255,255,.14);
  font-size:24px;
}
.name{font-weight:800; font-size:16px}
.mode{font-size:12px; color:var(--muted)}

.stats{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
  margin:12px 0;
}
.stat{
  padding:12px;
  border-radius:16px;
  background:rgba(0,0,0,.16);
  border:1px solid rgba(255,255,255,.12);
}
.stat .k{font-size:11px; color:var(--muted)}
.stat .v{font-size:18px; font-weight:800; margin-top:4px}
.stat.warn{background:rgba(251,191,36,.12); border-color:rgba(251,191,36,.22)}

.robotBox{
  padding:12px;
  border-radius:16px;
  background:rgba(0,0,0,.20);
  border:1px solid rgba(255,255,255,.12);
}
.robotHead{display:flex; align-items:center; gap:8px; margin-bottom:8px}
.bot{font-size:18px}
.botName{font-weight:800}
.robotMsg{color:rgba(255,255,255,.90); line-height:1.4; min-height:56px}

.actions{display:grid; gap:10px; margin-top:12px}
.tiny{margin-top:12px; font-size:12px; color:var(--muted); line-height:1.4}

.stage{
  padding:16px;
}

.stageTop{
  display:flex; justify-content:space-between; align-items:center;
  margin-bottom:12px;
}
.bigTitle{font-weight:900; font-size:18px}
.status{
  padding:8px 10px;
  border-radius:999px;
  font-size:12px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(0,0,0,.18);
}

/* IMPORTANT: stop board cutting on mobile */
.boardWrap{
  position:relative;
  width:min(740px, 100%);
  margin:0 auto;
  aspect-ratio: 1 / 1;
  border-radius:24px;
  background:linear-gradient(135deg, rgba(255,255,255,.10), rgba(0,0,0,.12));
  border:1px solid rgba(255,255,255,.18);
  box-shadow:0 25px 70px rgba(0,0,0,.35);
  overflow:hidden;
}

#lineCanvas{
  position:absolute; inset:0;
  width:100%; height:100%;
}

.nodes{
  position:absolute; inset:0;
  display:grid;
  grid-template-columns:repeat(3, 1fr);
  grid-template-rows:repeat(3, 1fr);

  /* responsive padding & gap so dots never go off-screen */
  padding:clamp(22px, 6vw, 64px);
  gap:clamp(16px, 6vw, 48px);

  align-items:center;
  justify-items:center;
}

.node{
  width:clamp(56px, 12vw, 92px);
  height:clamp(56px, 12vw, 92px);
  border-radius:50%;
  position:relative;
  background:rgba(255,255,255,.09);
  border:2px solid rgba(255,255,255,.18);
  box-shadow:
    0 0 35px rgba(96,165,250,.14),
    0 0 18px rgba(34,197,94,.10) inset;
  cursor:crosshair;
  transition:.18s transform, .18s box-shadow, .18s background;
  touch-action:none; /* allow touch drawing */
}
.node:hover{transform:translateY(-2px)}
.node::after{
  content:"";
  position:absolute; inset:50% auto auto 50%;
  width:clamp(12px, 2.4vw, 18px);
  height:clamp(12px, 2.4vw, 18px);
  transform:translate(-50%,-50%);
  border-radius:50%;
  background:rgba(255,255,255,.75);
  box-shadow:0 0 18px rgba(255,255,255,.55);
  opacity:.9;
}

.node.on{
  background:rgba(96,165,250,.18);
  border-color:rgba(96,165,250,.35);
  box-shadow:0 0 55px rgba(96,165,250,.45), 0 0 22px rgba(255,255,255,.25) inset;
}
.node.good{
  background:rgba(34,197,94,.18);
  border-color:rgba(34,197,94,.38);
  box-shadow:0 0 60px rgba(34,197,94,.55), 0 0 18px rgba(255,255,255,.22) inset;
}
.node.bad{
  background:rgba(251,113,133,.18);
  border-color:rgba(251,113,133,.40);
  box-shadow:0 0 60px rgba(251,113,133,.55), 0 0 18px rgba(255,255,255,.18) inset;
  animation:shake .28s;
}

@keyframes shake{
  0%{transform:translateX(0)}
  25%{transform:translateX(-7px)}
  50%{transform:translateX(7px)}
  75%{transform:translateX(-6px)}
  100%{transform:translateX(0)}
}

/* overlay popup */
.overlay{
  position:absolute; inset:0;
  display:grid; place-items:center;
  background:rgba(2,6,23,.55);
  backdrop-filter: blur(6px);
}
.pop{
  width:min(420px, 92%);
  border-radius:22px;
  background:rgba(255,255,255,.10);
  border:1px solid rgba(255,255,255,.20);
  box-shadow:0 25px 70px rgba(0,0,0,.45);
  padding:18px;
  text-align:center;
}
.popEmoji{font-size:44px}
.popTitle{font-weight:900; font-size:22px; margin-top:4px}
.popText{color:rgba(255,255,255,.88); margin-top:6px; line-height:1.4}
.popBtns{display:flex; gap:10px; justify-content:center; margin-top:14px; flex-wrap:wrap}

.legend{
  display:flex; gap:16px; justify-content:center;
  margin-top:12px; color:rgba(255,255,255,.82); font-size:12px;
}
.dot{width:12px; height:12px; border-radius:50%; display:inline-block; margin-right:6px}
.dot.ok{background:var(--good)}
.dot.bad{background:var(--bad)}
.dot.demo{background:var(--demo)}

/* modal */
.modal{
  position:fixed; inset:0;
  background:rgba(2,6,23,.62);
  display:grid; place-items:center;
  z-index:50;
}
.modalCard{
  width:min(520px, 92%);
  border-radius:22px;
  background:rgba(255,255,255,.10);
  border:1px solid rgba(255,255,255,.22);
  padding:16px;
  box-shadow:var(--shadow);
}
.modalTop{display:flex; justify-content:space-between; align-items:center}
.mTitle{font-weight:900; font-size:18px}
.x{
  width:38px; height:38px; border-radius:12px;
  border:1px solid rgba(255,255,255,.20);
  background:rgba(0,0,0,.18);
  color:#fff; cursor:pointer;
}
.how{margin:10px 0 14px; color:rgba(255,255,255,.88); line-height:1.6}

/* responsive layout: stop cutting, stack cleanly */
@media (max-width: 980px){
  .startGrid{grid-template-columns:1fr}
  .game{grid-template-columns:1fr}
  .panel{position:relative}
  .top{flex-direction:column; align-items:flex-start}
  .mini{justify-content:flex-start}
}
