:root{
  --bg:#eef2f7;
  --card:#ffffff;
  --ink:#0f172a;
  --muted:#64748b;
  --line:#e8edf5;
  --brand:#2f6bff;
  --brand-2:#5b8cff;
  --ally:#0bbf9a;
  --enemy:#f2545b;
  --shadow:0 10px 30px rgba(15,23,42,.07);
  --radius:20px;
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent;}

html,body{height:100%;}

body{
  margin:0;
  background:radial-gradient(1200px 600px at 50% -10%,#ffffff 0%,var(--bg) 62%);
  color:var(--ink);
  font-family:"SF Pro Rounded",ui-rounded,-apple-system,BlinkMacSystemFont,"PingFang SC","HarmonyOS Sans SC","Noto Sans SC","Microsoft YaHei",system-ui,sans-serif;
  -webkit-font-smoothing:antialiased;
  -webkit-text-size-adjust:100%;
  user-select:none;
  -webkit-user-select:none;
  overscroll-behavior:none;
}

.app{
  max-width:560px;
  margin:0 auto;
  min-height:100vh;
  min-height:100dvh;
  display:flex;
  flex-direction:column;
  gap:12px;
  padding:calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
}

/* ---------- top bar ---------- */
.topbar{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 2px;}

.brand{display:flex;align-items:center;gap:10px;min-width:0;}
.brand-mark{
  width:38px;height:38px;flex:none;border-radius:13px;
  background:linear-gradient(135deg,var(--brand),var(--brand-2));
  color:#fff;display:grid;place-items:center;
  box-shadow:0 8px 18px rgba(47,107,255,.26);
}
.brand-mark svg{width:21px;height:21px;}
.brand-text{display:flex;flex-direction:column;line-height:1.2;min-width:0;}
.brand-text b{font-size:16px;letter-spacing:.2px;}
.brand-text small{font-size:11px;color:var(--muted);}

.status{
  display:flex;align-items:center;gap:6px;flex:none;
  background:#fff;border:1px solid var(--line);border-radius:999px;
  padding:7px 12px;font-size:12px;color:var(--muted);
  box-shadow:0 4px 14px rgba(15,23,42,.05);
}
.status i{width:7px;height:7px;border-radius:50%;background:#cbd5e1;flex:none;}
.status[data-s="connecting"] i,.status[data-s="waiting"] i{background:#f59e0b;animation:pulse 1.1s ease-in-out infinite;}
.status[data-s="online"] i{background:#10b981;}
.status[data-s="error"] i{background:#ef4444;}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.25}}

/* ---------- map stage ---------- */
.stage{
  position:relative;width:100%;aspect-ratio:1/1;
  background:var(--card);border:1px solid var(--line);border-radius:var(--radius);
  box-shadow:var(--shadow);overflow:hidden;
}
.stage canvas{width:100%;height:100%;display:block;}

.stage-empty{
  position:absolute;inset:0;
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;
  background:linear-gradient(180deg,#fbfcfe,#f5f8fc);
  color:#94a3b8;font-size:13px;
}
.stage-empty svg{width:38px;height:38px;opacity:.5;}
.stage-empty p{margin:0;}
.stage-empty[hidden]{display:none;}

.map-badge{
  position:absolute;left:12px;top:12px;
  background:rgba(255,255,255,.92);backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);
  border:1px solid var(--line);border-radius:999px;padding:6px 12px;
  font-size:12px;font-weight:600;color:#334155;
  box-shadow:0 4px 14px rgba(15,23,42,.06);
}
.map-badge[hidden]{display:none;}

/* ---------- bottom dock ---------- */
.dock{
  background:var(--card);border:1px solid var(--line);border-radius:var(--radius);
  box-shadow:var(--shadow);padding:12px;
  display:flex;flex-direction:column;gap:10px;
}

.room-row{display:flex;gap:10px;}

.input-wrap{
  flex:1;min-width:0;display:flex;align-items:center;gap:8px;
  background:#f4f6fa;border:1.5px solid transparent;border-radius:14px;
  padding:0 12px;height:48px;
  transition:border-color .15s,background .15s;
}
.input-wrap:focus-within{background:#fff;border-color:var(--brand);}
.input-wrap svg{width:17px;height:17px;color:#94a3b8;flex:none;}
.input-wrap input{
  flex:1;min-width:0;border:0;outline:0;background:transparent;
  font:inherit;font-size:15px;letter-spacing:2.5px;color:var(--ink);
}
.input-wrap input::placeholder{letter-spacing:0;color:#a8b3c4;font-size:14px;}

.btn{
  height:48px;padding:0 20px;flex:none;
  border:0;border-radius:14px;
  background:linear-gradient(135deg,var(--brand),var(--brand-2));
  color:#fff;font:inherit;font-size:15px;font-weight:600;
  box-shadow:0 8px 20px rgba(47,107,255,.26);
  cursor:pointer;
}
.btn:disabled{opacity:.45;box-shadow:none;cursor:default;}
.btn.ghost{background:#eef1f6;color:#475569;box-shadow:none;}

.metrics{display:flex;gap:8px;}
.metrics span{
  flex:1;display:flex;align-items:center;justify-content:center;gap:6px;
  background:#f6f8fc;border-radius:12px;padding:9px 6px;
  font-size:12px;color:var(--muted);white-space:nowrap;
}
.metrics svg{width:14px;height:14px;flex:none;}
.metrics b{color:#1e293b;font-weight:600;}

.hint{margin:0;font-size:11.5px;color:#94a3b8;text-align:center;min-height:15px;line-height:1.4;}
.hint.warn{color:#d97706;}
.hint.err{color:#dc2626;}

/* ---------- desktop ---------- */
@media (min-width:640px){
  body{background:radial-gradient(900px 500px at 50% -5%,#ffffff 0%,var(--bg) 60%);}
  .app{gap:14px;padding-top:22px;padding-bottom:22px;}
  .stage{border-radius:24px;}
}
