:root{
  --bg: #f4f7ff;
  --bg2:#ffffff;
  --ink:#0d1327;
  --muted:#51607d;
  --accent:#3a6cff;
  --accent2:#ff3ad4;
  --panel: rgba(255,255,255,.72);
  --panel2: rgba(255,255,255,.88);
  --stroke: rgba(12,18,38,.10);
  --shadow: 0 10px 40px rgba(16,24,40,.14);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

body.dark{
  --bg: #070a14;
  --bg2:#0b1022;
  --ink:#eaf0ff;
  --muted:#b7c1db;
  --panel: rgba(12,18,38,.64);
  --panel2: rgba(12,18,38,.82);
  --stroke: rgba(255,255,255,.09);
  --shadow: 0 10px 40px rgba(0,0,0,.45);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  background: radial-gradient(1200px 600px at 20% 10%, rgba(58,108,255,.18), transparent 60%),
              radial-gradient(900px 500px at 90% 20%, rgba(255,58,212,.15), transparent 60%),
              linear-gradient(180deg, var(--bg), var(--bg2));
  color:var(--ink);
  font: 14px/1.35 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  overflow:hidden;
}

#app{
  position:fixed; inset:0;
  touch-action:none;
}

/* HUD top */
#hudTop{
  position:fixed;
  top:calc(12px + var(--safe-t));
  left:12px;
  right:12px;
  display:flex;
  gap:12px;
  align-items:center;
  justify-content:space-between;
  z-index:50;
  pointer-events:none;
}

.brand{
  display:flex; align-items:center; gap:10px;
  padding:10px 12px;
  background:var(--panel);
  border:1px solid var(--stroke);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  backdrop-filter: blur(10px);
  pointer-events:auto;
}
.logoDot{
  width:12px; height:12px; border-radius:99px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 0 0 4px rgba(58,108,255,.16), 0 0 0 8px rgba(255,58,212,.08);
}
.brandText .title{ font-weight:800; letter-spacing:.2px; }
.brandText .sub{ color:var(--muted); font-size:12px; }

.topStats{
  display:flex; gap:8px; align-items:center;
  pointer-events:auto;
}
.pill{
  background:var(--panel);
  border:1px solid var(--stroke);
  border-radius:999px;
  padding:9px 12px;
  box-shadow:var(--shadow);
  backdrop-filter: blur(10px);
  display:flex;
  gap:8px;
  align-items:center;
  font-weight:700;
}
.pill .label{ color:var(--muted); font-weight:700; }
.btn{ cursor:pointer; user-select:none }
.btn:active{ transform: translateY(1px) }

/* Event bar */
#eventBar{
  position:fixed;
  top:calc(74px + var(--safe-t));
  left:12px;
  right:12px;
  z-index:48;
  background: linear-gradient(135deg, rgba(58,108,255,.20), rgba(255,58,212,.18));
  border:1px solid rgba(58,108,255,.18);
  border-radius:var(--radius);
  padding:10px 12px;
  display:flex;
  gap:10px;
  align-items:center;
  justify-content:space-between;
  box-shadow:var(--shadow);
  backdrop-filter: blur(10px);
}
#eventBar .eventName{ font-weight:900; }
#eventBar .eventDesc{ color:var(--ink); opacity:.88; font-weight:600; }
#eventBar .eventTimer{ font-variant-numeric: tabular-nums; font-weight:900; }

/* Needs panel */
#needs{
  position:fixed;
  top:calc(132px + var(--safe-t));
  left:12px;
  width:min(260px, 46vw);
  z-index:45;
  display:flex;
  flex-direction:column;
  gap:8px;
  pointer-events:none;
}
.need{
  background:var(--panel);
  border:1px solid var(--stroke);
  border-radius:14px;
  padding:9px 10px;
  box-shadow:var(--shadow);
  backdrop-filter: blur(10px);
  pointer-events:auto;
}
.nlabel{ font-size:12px; color:var(--muted); font-weight:800; margin-bottom:6px; }
.bar{
  height:10px; border-radius:999px;
  background: rgba(0,0,0,.08);
  overflow:hidden;
  border:1px solid rgba(0,0,0,.06);
}
body.dark .bar{ background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.08); }
.fill{
  height:100%;
  width:50%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius:999px;
}

/* Chat */
#chat{
  position:fixed;
  right:12px;
  bottom:calc(12px + var(--safe-b));
  width:min(380px, 46vw);
  max-height: 44vh;
  display:flex;
  flex-direction:column;
  gap:8px;
  z-index:60;
}
#chatLog{
  background:var(--panel);
  border:1px solid var(--stroke);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
  backdrop-filter: blur(10px);
  padding:10px 10px;
  overflow:auto;
  flex:1;
}
.msg{ margin:0 0 7px 0; }
.msg .who{ font-weight:900; }
.msg .txt{ color:var(--ink); opacity:.92; }
.msg .meta{ color:var(--muted); font-size:11px; margin-left:6px; }

#chatForm{
  display:flex; gap:8px;
}
#chatInput{
  flex:1;
  border-radius:14px;
  border:1px solid var(--stroke);
  background:var(--panel2);
  color:var(--ink);
  padding:10px 12px;
  outline:none;
}
#chatSend{
  border-radius:14px;
  border:1px solid rgba(58,108,255,.25);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color:white;
  font-weight:900;
  padding:10px 12px;
  cursor:pointer;
}

/* Mobile controls */
#mobileControls{
  position:fixed;
  left:0; right:0;
  bottom:calc(0px + var(--safe-b));
  padding:12px;
  display:none;
  z-index:70;
  pointer-events:none;
}
#mobileControls > *{ pointer-events:auto; }

#stickWrap{
  position:absolute;
  left:12px;
  bottom:12px;
}
#joystick{
  width:140px; height:140px;
  border-radius:999px;
  background: rgba(255,255,255,.18);
  border:1px solid var(--stroke);
  box-shadow:var(--shadow);
  backdrop-filter: blur(10px);
  position:relative;
  touch-action:none;
}
#joyKnob{
  width:54px; height:54px;
  border-radius:999px;
  position:absolute;
  left:50%; top:50%;
  transform: translate(-50%,-50%);
  background: rgba(255,255,255,.55);
  border:1px solid rgba(0,0,0,.06);
}
body.dark #joyKnob{ background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.12); }

#dpad{
  width:160px;
  display:grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap:4px;
}
#dpad button{
  border-radius:14px;
  border:1px solid var(--stroke);
  background:var(--panel);
  color:var(--ink);
  font-weight:900;
  box-shadow:var(--shadow);
}
#dpad button[data-dir="up"]{ grid-column:2; grid-row:1; }
#dpad button[data-dir="left"]{ grid-column:1; grid-row:2; }
#dpad button[data-dir="down"]{ grid-column:2; grid-row:3; }
#dpad button[data-dir="right"]{ grid-column:3; grid-row:2; }

#actions{
  position:absolute;
  right:12px;
  bottom:12px;
  display:flex;
  flex-direction:column;
  gap:10px;
}
.action{
  width:170px;
  padding:12px 14px;
  border-radius:18px;
  border:1px solid rgba(58,108,255,.25);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color:white;
  font-weight:900;
  box-shadow:var(--shadow);
  cursor:pointer;
}
.action.secondary{
  background:var(--panel);
  color:var(--ink);
  border:1px solid var(--stroke);
}

/* Modal */
.modal{
  position:fixed; inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
  background: rgba(0,0,0,.25);
  backdrop-filter: blur(8px);
  z-index:100;
}
.modal.hidden{ display:none; }
.modalCard{
  width:min(520px, 92vw);
  background:var(--panel2);
  border:1px solid var(--stroke);
  border-radius: calc(var(--radius) + 6px);
  padding:18px 18px;
  box-shadow:var(--shadow);
}
.modalCard.wide{ width:min(900px, 95vw); }
.modalHeader{
  display:flex; align-items:center; justify-content:space-between;
  gap:10px;
}
h1,h2,h3{ margin:0 0 10px 0; }
h1{ font-size:22px; letter-spacing:-.2px; }
h2{ font-size:18px; }
h3{ font-size:14px; color:var(--muted); text-transform:uppercase; letter-spacing:.08em; margin-top:2px; }

.muted{ color:var(--muted); }
.tiny{ font-size:12px; }

.field{
  display:flex;
  flex-direction:column;
  gap:6px;
  margin:10px 0;
}
.field > span{ font-weight:800; color:var(--muted); font-size:12px; }
.field input, .field select{
  border-radius:14px;
  border:1px solid var(--stroke);
  background:white;
  color:var(--ink);
  padding:10px 12px;
  outline:none;
}
body.dark .field input, body.dark .field select{ background: rgba(255,255,255,.08); }

.row{
  display:flex; gap:10px; flex-wrap:wrap;
  margin-top:10px;
}
.primary{
  border-radius:16px;
  border:1px solid rgba(58,108,255,.25);
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color:white;
  font-weight:900;
  padding:10px 14px;
  cursor:pointer;
}
.ghost{
  border-radius:16px;
  border:1px solid var(--stroke);
  background:transparent;
  color:var(--ink);
  font-weight:900;
  padding:10px 14px;
  cursor:pointer;
}

.settingsGrid{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap:12px;
}
.group{
  padding:12px 12px;
  border-radius:var(--radius);
  border:1px solid var(--stroke);
  background: rgba(255,255,255,.45);
}
body.dark .group{ background: rgba(0,0,0,.18); }
.toggle{
  display:flex; gap:10px; align-items:center;
  margin:8px 0;
  font-weight:800;
}
.toggle input{ width:18px; height:18px; }

#toast{
  position:fixed;
  left:50%;
  bottom:calc(20px + var(--safe-b));
  transform: translateX(-50%);
  background:var(--panel2);
  border:1px solid var(--stroke);
  border-radius:999px;
  padding:10px 14px;
  font-weight:900;
  box-shadow:var(--shadow);
  z-index:110;
}
.hidden{ display:none !important; }

#minimap{
  position:fixed;
  right:12px;
  top:calc(84px + var(--safe-t));
  width:220px; height:220px;
  border-radius:18px;
  background:var(--panel);
  border:1px solid var(--stroke);
  box-shadow:var(--shadow);
  z-index:55;
}

/* Responsive */
@media (max-width: 920px){
  .settingsGrid{ grid-template-columns: 1fr; }
}

@media (max-width: 840px){
  #needs{ display:none; }
  #chat{ width:min(420px, 92vw); }
}

@media (max-width: 680px){
  #mobileControls{ display:block; }
  #chat{ width: calc(100vw - 24px); max-height: 30vh; }
  #hudTop{ top:calc(8px + var(--safe-t)); left:8px; right:8px; }
  .brand{ padding:8px 10px; }
  .pill{ padding:8px 10px; }
  #eventBar{ left:8px; right:8px; }
  #minimap{ right:8px; top:calc(74px + var(--safe-t)); width:170px; height:170px; }
}

/* Build panel */
.build{
  position:fixed;
  left:50%;
  bottom:calc(12px + var(--safe-b) + 176px);
  transform: translateX(-50%);
  width:min(920px, 94vw);
  background:var(--panel2);
  border:1px solid var(--stroke);
  border-radius: calc(var(--radius) + 6px);
  box-shadow:var(--shadow);
  padding:12px;
  z-index:95;
}
@media (max-width: 680px){
  .build{ bottom:calc(12px + var(--safe-b) + 186px); }
}
.buildBar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:10px;
}
.buildTitle{ font-weight:1000; letter-spacing:.2px; }
.buildRight{ display:flex; gap:10px; align-items:center; }
.buildItems{
  display:flex;
  gap:10px;
  overflow:auto;
  padding-bottom:6px;
}
.buildItem{
  min-width:160px;
  background: rgba(255,255,255,.55);
  border:1px solid var(--stroke);
  border-radius:18px;
  padding:10px 10px;
  cursor:pointer;
  user-select:none;
}
body.dark .buildItem{ background: rgba(0,0,0,.18); }
.buildItem .nm{ font-weight:900; margin-bottom:4px; }
.buildItem .cost{ color:var(--muted); font-weight:800; font-size:12px; }
.buildItem.active{
  outline: 3px solid rgba(58,108,255,.35);
}
