:root {
  --bg: #23092f;
  --panel: #3a1453;
  --line: #6d2c91;
  --text: #fff5ff;
  --muted: #dfb7f0;
  --me: #28d7ff;
  --op: #ff69a8;
  --gold: #ffd942;
  --ok: #3de887;
  --wa: #1faa59;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: radial-gradient(circle at 50% 20%, #4b1868 0%, #23092f 70%, #16051f 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; -webkit-user-select: none; user-select: none;
}
body { position: fixed; inset: 0; overflow: hidden; }
#app {
  height: 100%; max-width: 520px; margin: 0 auto; position: relative;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen { display: none; height: 100%; flex-direction: column; align-items: stretch; gap: 12px; padding: 18px 18px 22px; overflow-y: auto; }
.screen.active { display: flex; }

/* ---------- beranda ---------- */
.logo { text-align: center; margin: 3vh 0 6px; }
.logo-virus { font-size: 62px; line-height: 1; filter: drop-shadow(0 0 20px rgba(255, 92, 138, .75)); animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(8deg); } }
h1 { margin: 8px 0 0; font-size: 31px; font-weight: 900; letter-spacing: 0.5px; line-height: 1.05; text-shadow: 0 3px 14px rgba(255, 70, 160, 0.45); }
h1 span { color: var(--gold); margin-left: 6px; }
h1 em { font-style: normal; color: #2b0b38; background: var(--me); border-radius: 10px; padding: 1px 8px; margin-left: 6px; font-size: 22px; vertical-align: 3px; }
.tag { color: var(--muted); margin: 8px 0 0; font-size: 14.5px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input {
  font: inherit; font-size: 17px; color: var(--text); background: rgba(58, 20, 83, 0.85); border: 1.5px solid var(--line);
  border-radius: 14px; padding: 12px 14px; outline: none; width: 100%; -webkit-user-select: text; user-select: text;
}
input:focus { border-color: var(--me); }
.btn {
  font: inherit; font-weight: 800; font-size: 17px; color: var(--text); border: 0; border-radius: 16px; padding: 14px 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; text-align: center;
  transition: transform .06s ease, filter .15s ease; flex-shrink: 0;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, #ff70b8, #d9267a); box-shadow: 0 5px 0 #8a104a; }
.btn.primary.on { background: linear-gradient(180deg, #46e08e, #1faa59); box-shadow: 0 5px 0 #116b37; }
.btn.primary:disabled { filter: grayscale(.65) brightness(.72); cursor: default; }
.btn.ghost { background: rgba(58, 20, 83, 0.55); border: 1.5px solid var(--line); color: var(--muted); }
.btn.wa { background: var(--wa); box-shadow: 0 5px 0 #116b37; color: #fff; }
.btn.small { font-size: 14px; padding: 11px 12px; box-shadow: none; }
.btn.tiny { font-size: 14px; padding: 0 14px; background: var(--line); border-radius: 10px; }
.rules { margin: 4px 0 0; padding: 13px 14px 13px 28px; background: rgba(45, 14, 66, .78); border: 1px solid var(--line); border-radius: 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.rules b { color: var(--gold); }
.best { text-align: center; color: var(--gold); font-size: 13px; font-weight: 700; margin: 0; }

/* ---------- lobi ---------- */
h2 { margin: 2vh 0 0; text-align: center; font-size: 22px; }
.code { text-align: center; font-size: 34px; font-weight: 900; letter-spacing: 8px; color: var(--gold); font-variant-numeric: tabular-nums; text-shadow: 0 2px 14px rgba(255, 217, 66, .35); }
.hint { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
#share-box { display: flex; flex-direction: column; gap: 10px; }
.linkrow { display: flex; gap: 8px; }
.linkrow input { font-size: 13px; padding: 10px 12px; min-width: 0; }
.versus { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; background: rgba(58, 20, 83, 0.85); border: 1.5px solid var(--line); border-radius: 16px; padding: 14px 10px; }
.who { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; text-align: center; }
.who b { font-size: 16px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who.me b { color: var(--me); }
.who.op b { color: var(--op); }
.who small { color: var(--muted); font-size: 12px; }
.who small.ok { color: var(--ok); font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #734c8f; margin-bottom: 4px; }
.dot.on { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.vs { font-weight: 900; color: var(--gold); font-size: 18px; }
.conn { margin: 0; text-align: center; font-size: 12px; color: var(--muted); min-height: 16px; }

/* ---------- game (Full Arena ala Hago) ---------- */
#game { padding: 0; gap: 0; overflow: hidden; }
.stage { position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; touch-action: none; }
.field { position: relative; flex-shrink: 0; overflow: hidden; border-radius: 10px; box-shadow: 0 0 36px rgba(0, 0, 0, 0.55); }
#cv { display: block; width: 100%; height: 100%; background: #3a1359; touch-action: none; }

/* HUD Atas persis tata letak Hago */
.hago-hud {
  position: absolute; top: 0; left: 0; right: 0; padding: 6px 8px 0;
  pointer-events: none; z-index: 6;
}
.hago-top {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px;
}
.iconbtn {
  pointer-events: auto;
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.2);
  background: rgba(25, 6, 36, 0.52); color: #fff; font-size: 14px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.iconbtn:active { transform: scale(.92); }
.hago-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4px;
}
.hp { display: flex; align-items: center; gap: 5px; min-width: 0; }
.hp.op { justify-content: flex-end; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #2ee3ff, #6b4dff);
  border: 2px solid #9ef2ff; box-shadow: 0 0 10px rgba(46, 227, 255, 0.45);
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.avatar.op {
  background: linear-gradient(135deg, #ff70b8, #7b4dff);
  border-color: #a6e9ff; box-shadow: 0 0 10px rgba(255, 112, 184, 0.45);
}
.pinfo { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.hp.op .pinfo { align-items: flex-end; }
.namepill {
  background: linear-gradient(90deg, #16b8e0, #2bd8f0);
  border-radius: 999px; padding: 1px 8px; max-width: 100%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.hp.op .namepill { background: linear-gradient(270deg, #16b8e0, #2bd8f0); }
.namepill span {
  display: block; font-size: 10.5px; font-weight: 800; color: #fff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}
.scorerow { display: flex; align-items: center; gap: 4px; line-height: 1; }
.scorerow b {
  font-size: 18px; font-weight: 900; color: #ffe03d; font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 4px rgba(40, 4, 24, 0.85);
}
.badge {
  width: 16px; height: 16px; border-radius: 50%; font-style: normal; font-size: 10px;
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
  background: #ff4fa3; box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.badge.op { background: #22b8ff; }

.timer {
  font-size: 36px; font-weight: 900; color: #ffffff; line-height: 1;
  font-variant-numeric: tabular-nums; min-width: 54px; text-align: center;
  text-shadow: 0 0 16px rgba(255, 70, 210, 0.9), 0 3px 6px rgba(35, 5, 45, 0.85);
}
.timer.low { color: #ffeb55; text-shadow: 0 0 20px rgba(255, 30, 50, 0.95); animation: pulse .45s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }

.tug {
  height: 4px; border-radius: 3px; background: rgba(255, 105, 168, 0.78);
  overflow: hidden; margin: 5px 12px 0; box-shadow: 0 1px 4px rgba(0,0,0,0.35);
}
.tug i { display: block; height: 100%; width: 50%; background: #2ee3ff; transition: width .25s ease; }
.tug.solo { display: none; }

.mini {
  position: absolute; top: 96px; right: 8px; width: 20%; max-width: 82px;
  border: 1.5px solid rgba(255, 155, 220, 0.75); border-radius: 9px; overflow: hidden;
  pointer-events: none; opacity: .9; z-index: 5; box-shadow: 0 4px 12px rgba(20, 4, 30, 0.5);
}
.mini canvas { display: block; width: 100%; height: auto; }
.mini span {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: 8.5px; font-weight: 800;
  text-align: center; background: rgba(255, 92, 168, 0.85); color: #fff;
  padding: 1px 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}

.buffs { position: absolute; left: 8px; top: 116px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; z-index: 5; }
.buff {
  display: flex; align-items: center; gap: 5px; background: rgba(34, 8, 52, .78);
  border: 1px solid rgba(255, 190, 240, 0.28); border-radius: 9px; padding: 2px 7px 2px 5px;
  font-size: 11px; font-weight: 800; color: #fff;
}
.buff i { display: block; width: 42px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .2); overflow: hidden; }
.buff i u { display: block; height: 100%; background: var(--gold); }

.netbadge {
  position: absolute; left: 8px; top: 96px; font-size: 9.5px; font-weight: 700;
  color: #f3d2ff; background: rgba(34, 8, 52, .58); border-radius: 6px; padding: 2px 6px;
  pointer-events: none; z-index: 5;
}
.netbadge.bad { color: #ff8e8e; }
.netbadge:empty { display: none; }

.count {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 118px; font-weight: 900; color: var(--gold);
  text-shadow: 0 0 28px rgba(255, 70, 170, 0.9), 0 6px 24px rgba(0, 0, 0, .7);
  pointer-events: none; z-index: 8;
}
.count small { font-size: 15px; color: #fff; font-weight: 700; margin-top: 6px; text-align: center; padding: 0 22px; text-shadow: 0 2px 8px rgba(0,0,0,0.8); }
.count[hidden], .result[hidden], .toast[hidden] { display: none; }
.count b { animation: pop .9s ease-out; display: block; line-height: 1; }
@keyframes pop { from { transform: scale(1.8); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1); } }

/* ---------- hasil ---------- */
.result {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(26, 6, 40, .82); backdrop-filter: blur(4px); padding: 14px; animation: fade .3s ease; z-index: 12;
}
@keyframes fade { from { opacity: 0; } }
.card {
  width: 100%; max-width: 340px; background: linear-gradient(180deg, #4b186d, #2e0d47);
  border: 1.5px solid #8a3cb8; border-radius: 22px; padding: 18px 16px;
  display: flex; flex-direction: column; gap: 10px; max-height: 100%; overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.verdict { text-align: center; font-size: 34px; font-weight: 900; letter-spacing: 1px; }
.verdict.win { color: var(--gold); text-shadow: 0 0 24px rgba(255, 217, 66, .55); }
.verdict.lose { color: #ff7a8a; }
.verdict.draw, .verdict.wait { color: var(--text); font-size: 22px; }
.scores { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; text-align: center; gap: 6px; }
.scores span { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores b { font-size: 34px; font-weight: 900; font-variant-numeric: tabular-nums; }
.scores div:first-child b { color: var(--me); }
.scores div:last-child b { color: var(--op); }
.scores .sep { font-size: 26px; font-weight: 900; color: var(--muted); }
.stats, .record, .rematch-note { margin: 0; text-align: center; font-size: 12.5px; color: var(--muted); }
.record { color: var(--text); font-weight: 700; }
.rematch-note { color: var(--gold); font-weight: 700; min-height: 18px; }

.toast {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #fff; color: #2b0b38; font-weight: 800; font-size: 13.5px;
  padding: 9px 16px; border-radius: 999px; box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  z-index: 20; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis;
}
.mute {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px;
  width: 38px; height: 38px; border-radius: 50%; border: 1.5px solid var(--line);
  background: rgba(58, 20, 83, .82); font-size: 17px; cursor: pointer; z-index: 5;
}
#app.playing .mute { display: none; }

@media (max-height: 620px) {
  .logo-virus { font-size: 42px; }
  h1 { font-size: 25px; }
  .logo { margin-top: 0; }
  .rules { font-size: 12px; }
}
