/* WAR ROBOTS — Ashfall Protocol */

:root {
  --bg: #07090c;
  --panel: rgba(13, 17, 22, 0.92);
  --line: rgba(122, 158, 178, 0.22);
  --amber: #ff9f43;
  --cyan: #48dbfb;
  --red: #ff4d4d;
  --green: #1dd1a1;
  --text: #cfe3ee;
  --dim: #7d93a3;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.hidden { display: none !important; }
.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .desktop-only { display: none; }
body:not(.playing) #touch-zone,
body:not(.playing) #touch-buttons { display: none !important; }

/* ============ LOBBY ============ */

#lobby {
  position: fixed; inset: 0; z-index: 50;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(255, 159, 67, 0.13), transparent 55%),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(0,0,0,0.18) 3px 4px),
    var(--bg);
  padding: calc(16px + var(--sat)) calc(14px + var(--sar)) calc(28px + var(--sab)) calc(14px + var(--sal));
}
.lobby-inner { max-width: 860px; margin: 0 auto; }
#lobby header { text-align: center; margin-bottom: 18px; }
#lobby h1 {
  font-size: clamp(34px, 8vw, 64px);
  letter-spacing: 0.18em;
  color: var(--amber);
  text-shadow: 0 0 24px rgba(255, 159, 67, 0.45);
}
.tagline { color: var(--dim); font-size: 12px; letter-spacing: 0.08em; margin-top: 6px; }

.lobby-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; }
@media (max-width: 700px) { .lobby-grid { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 16px;
  backdrop-filter: blur(4px);
}
.plabel { display: block; font-size: 11px; color: var(--dim); letter-spacing: 0.2em; margin: 14px 0 6px; }
.plabel:first-child { margin-top: 0; }

#pilot-name {
  width: 100%; background: #0b0e12; border: 1px solid var(--line); color: var(--cyan);
  font-family: var(--mono); font-size: 18px; padding: 10px 12px; letter-spacing: 0.12em;
  text-transform: uppercase; outline: none;
}
#pilot-name:focus { border-color: var(--cyan); }

#robot-cards { display: flex; gap: 6px; flex-wrap: wrap; }
.card {
  flex: 1 1 30%;
  min-width: 96px;
  background: #0b0e12;
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  padding: 9px 6px;
  cursor: pointer;
  text-align: left;
}
.card .cname { display: block; font-size: 13px; font-weight: 700; letter-spacing: 0.1em; }
.card .crole { display: block; font-size: 10px; color: var(--dim); margin-top: 3px; }
.card.sel { border-color: var(--amber); background: rgba(255, 159, 67, 0.08); box-shadow: 0 0 12px rgba(255,159,67,0.18) inset; }

.role { font-size: 11px; color: var(--dim); margin: 8px 0 8px; min-height: 14px; }
.srow { display: grid; grid-template-columns: 92px 1fr 44px; gap: 8px; align-items: center; margin: 4px 0; font-size: 10px; color: var(--dim); letter-spacing: 0.1em; }
.sbar { height: 7px; background: #0b0e12; border: 1px solid var(--line); }
.sbar > div { height: 100%; transition: width 0.25s ease; }
.srow i { font-style: normal; color: var(--text); text-align: right; }

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; background: #0b0e12; border: 1px solid var(--line); color: var(--dim);
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.15em; padding: 8px 0; cursor: pointer;
}
.seg button.sel { color: var(--cyan); border-color: var(--cyan); background: rgba(72, 219, 251, 0.07); }

#btn-join {
  width: 100%; margin-top: 18px; padding: 14px;
  font-family: var(--mono); font-size: 18px; font-weight: 700; letter-spacing: 0.3em;
  background: var(--amber); border: none; color: #1b1006; cursor: pointer;
  box-shadow: 0 0 24px rgba(255, 159, 67, 0.35);
}
#btn-join:disabled { opacity: 0.55; cursor: wait; }
#lobby-error { color: var(--red); font-size: 12px; margin-top: 8px; min-height: 14px; }

.side { display: flex; flex-direction: column; }
#preview { width: 100%; height: 240px; background: radial-gradient(ellipse at 50% 80%, rgba(72,219,251,0.06), transparent 70%); }
.side h3, .howto h3 { font-size: 12px; letter-spacing: 0.25em; color: var(--dim); margin: 12px 0 8px; }

.board { list-style: none; }
.board li { display: grid; grid-template-columns: 22px 1fr auto auto; gap: 8px; font-size: 12px; padding: 5px 2px; border-bottom: 1px dashed rgba(122,158,178,0.12); }
.board .rank { color: var(--amber); }
.board .rb { color: var(--dim); font-size: 10px; align-self: center; }
.board .sc { color: var(--cyan); }
.board .empty { display: block; color: var(--dim); border: none; }
.online { margin-top: auto; padding-top: 10px; color: var(--green); font-size: 11px; letter-spacing: 0.08em; }

.howto { margin-top: 14px; font-size: 12px; line-height: 1.65; color: #a9bdca; }
.howto b { color: var(--text); }
.howto .warn { color: var(--amber); margin-top: 8px; }
.howto .keys { margin-top: 10px; color: var(--dim); font-size: 11px; letter-spacing: 0.06em; }
.howto p + p { margin-top: 6px; }

/* ============ HUD ============ */

#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; font-family: var(--mono); }

#world-name {
  position: absolute; top: calc(8px + var(--sat)); left: 50%; transform: translateX(-50%);
  font-size: 10px; letter-spacing: 0.3em; color: var(--dim);
}
#score {
  position: absolute; top: calc(20px + var(--sat)); left: 50%; transform: translateX(-50%);
  font-size: 30px; font-weight: 700; color: var(--text); text-shadow: 0 0 14px rgba(72,219,251,0.4);
}
#best {
  position: absolute; top: calc(56px + var(--sat)); left: 50%; transform: translateX(-50%);
  font-size: 10px; letter-spacing: 0.2em; color: var(--amber); opacity: 0.85;
}
.dflag { color: var(--amber); letter-spacing: 0.25em; font-size: 14px; margin-top: 8px; animation: pulse 0.9s infinite; }

#vitals { position: absolute; top: calc(14px + var(--sat)); left: calc(14px + var(--sal)); width: min(230px, 38vw); }
.bar { position: relative; height: 16px; background: rgba(5,8,10,0.72); border: 1px solid var(--line); margin-bottom: 5px; transform: skewX(-12deg); overflow: hidden; }
.bar i { position: absolute; left: 6px; top: 2px; font-size: 9px; color: rgba(255,255,255,0.75); z-index: 2; font-style: normal; letter-spacing: 0.15em; }
.bar b { position: absolute; right: 6px; top: 2px; font-size: 10px; color: rgba(255,255,255,0.9); z-index: 2; }
.bar .fill { height: 100%; width: 100%; transition: width 0.18s ease; }
.bar.armour .fill { background: linear-gradient(90deg, #b35e1f, var(--amber)); }
.bar.shield .fill { background: linear-gradient(90deg, #1b7ea3, var(--cyan)); }
.bar.fuel .fill { background: linear-gradient(90deg, #b3941f, #ffd32a); }
.bar.fuel .fill.danger { background: linear-gradient(90deg, #a32222, var(--red)); }
.lvrow { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
#level { font-size: 11px; color: var(--amber); letter-spacing: 0.12em; white-space: nowrap; }
.xpbar { flex: 1; height: 4px; background: rgba(5,8,10,0.72); border: 1px solid var(--line); }
#fill-xp { height: 100%; width: 0; background: var(--amber); transition: width 0.3s ease; }
#buffs { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.buff {
  font-size: 10px; padding: 2px 5px; border: 1px solid var(--c, #fff); color: var(--c, #fff);
  background: rgba(5,8,10,0.7); letter-spacing: 0.08em;
}

#lb-live {
  position: absolute; top: calc(14px + var(--sat)); right: calc(14px + var(--sar));
  list-style: none; width: min(210px, 40vw); font-size: 11px;
}
#lb-live li { display: grid; grid-template-columns: 16px 1fr auto auto; gap: 6px; padding: 3px 6px; background: rgba(5,8,10,0.55); margin-bottom: 2px; }
#lb-live li.me { border-left: 2px solid var(--cyan); }
#lb-live .rank { color: var(--amber); }
#lb-live .wd { color: var(--dim); }
#lb-live .sc { color: var(--cyan); }

#killfeed {
  position: absolute; top: calc(140px + var(--sat)); right: calc(14px + var(--sar));
  list-style: none; text-align: right; font-size: 11px; color: var(--dim);
}
#killfeed li { margin-bottom: 3px; background: rgba(5,8,10,0.5); padding: 2px 6px; transition: opacity 0.6s; }
#killfeed li b { color: var(--text); }
#killfeed li .x { color: var(--red); }
#killfeed li .pol { color: var(--dim); font-size: 9px; }
#killfeed li.fade { opacity: 0; }

#banner {
  position: absolute; top: 22%; left: 50%; transform: translate(-50%, -50%) scale(0.96);
  text-align: center; opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none;
}
#banner.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner-txt { font-size: clamp(26px, 5vw, 44px); letter-spacing: 0.25em; color: var(--amber); text-shadow: 0 0 26px rgba(255,159,67,0.55); }
#banner-sub { font-size: 12px; color: var(--text); margin-top: 6px; letter-spacing: 0.12em; }

#bossbar {
  position: absolute; top: calc(64px + var(--sat)); left: 50%; transform: translateX(-50%);
  width: min(420px, 70vw); display: none; text-align: center;
}
#bossbar.on { display: block; }
#bossbar-name { font-size: 11px; letter-spacing: 0.3em; color: var(--red); }
#bossbar .bb { height: 10px; border: 1px solid rgba(255,77,77,0.6); background: rgba(5,8,10,0.7); margin-top: 3px; }
#fill-boss { height: 100%; background: linear-gradient(90deg, #7e1b1b, var(--red)); transition: width 0.2s ease; }

#gate-timer {
  position: absolute; top: calc(96px + var(--sat)); left: 50%; transform: translateX(-50%);
  font-size: 15px; color: var(--cyan); letter-spacing: 0.15em; display: none;
  text-shadow: 0 0 16px rgba(72,219,251,0.6);
}
#gate-timer.on { display: block; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

#gate-arrow {
  position: absolute; top: 34%; left: 50%; display: none;
  color: var(--cyan); font-size: 26px; text-shadow: 0 0 14px rgba(72,219,251,0.8);
  transform-origin: center 90px;
}

#crosshair {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: rgba(255,255,255,0.85); font-size: 22px; text-shadow: 0 0 6px rgba(0,0,0,0.9);
}
#assist {
  position: absolute; display: none; transform: translate(-50%, -50%);
  color: var(--amber); font-size: 26px; text-shadow: 0 0 10px rgba(255,159,67,0.8);
}
#hitmarker {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: #fff; font-size: 26px; opacity: 0;
}
#hitmarker.on { animation: hm 0.22s ease-out; }
@keyframes hm { 0% { opacity: 1; transform: translate(-50%,-50%) scale(1.4); } 100% { opacity: 0; transform: translate(-50%,-50%) scale(0.8); } }

#vignette {
  position: absolute; inset: 0; opacity: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(255, 30, 30, 0.45) 100%);
}
#vignette.on { animation: vg 0.5s ease-out; }
@keyframes vg { 0% { opacity: 1; } 100% { opacity: 0; } }

#reserve-warning {
  position: absolute; bottom: calc(150px + var(--sab)); left: 50%; transform: translateX(-50%);
  color: var(--red); font-size: 13px; letter-spacing: 0.2em; display: none;
  text-shadow: 0 0 12px rgba(255,77,77,0.7);
}
#reserve-warning.on { display: block; animation: pulse 0.7s infinite; }

#minimap {
  position: absolute; bottom: calc(14px + var(--sab)); left: calc(14px + var(--sal));
  width: 148px; height: 148px;
}
body.touch #minimap { width: 104px; height: 104px; opacity: 0.85; bottom: auto; top: calc(118px + var(--sat)); }

#weapons {
  position: absolute; bottom: calc(14px + var(--sab)); right: calc(14px + var(--sar));
  width: min(200px, 36vw); display: flex; flex-direction: column; gap: 4px;
}
body.touch #weapons { bottom: calc(238px + var(--sab)); right: calc(110px + var(--sar)); width: 150px; }
.wrow { display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.wrow span { font-size: 11px; letter-spacing: 0.1em; color: var(--text); text-shadow: 0 0 6px rgba(0,0,0,0.9); white-space: nowrap; }
.wbar { width: 84px; height: 7px; background: rgba(5,8,10,0.72); border: 1px solid var(--line); flex-shrink: 0; }
.wfill { height: 100%; width: 100%; background: var(--cyan); }
body.touch .wrow span { font-size: 10px; }
body.touch .wbar { width: 60px; }

#ping { position: absolute; bottom: calc(2px + var(--sab)); right: calc(14px + var(--sar)); font-size: 9px; color: var(--dim); }

#toasts {
  position: absolute; bottom: 34%; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.toast {
  background: rgba(5,8,10,0.8); border: 1px solid var(--cyan); color: var(--cyan);
  font-size: 12px; letter-spacing: 0.12em; padding: 5px 14px; transition: opacity 0.5s;
}
.toast.fade { opacity: 0; }

#click-hint {
  position: absolute; bottom: 24%; left: 50%; transform: translateX(-50%);
  color: var(--text); font-size: 13px; letter-spacing: 0.25em; display: none;
  background: rgba(5,8,10,0.7); padding: 8px 18px; border: 1px solid var(--line);
}
#click-hint.on { display: block; animation: pulse 1.6s infinite; }

#btn-pause {
  position: absolute; top: calc(14px + var(--sat)); right: calc(14px + var(--sar));
  width: 34px; height: 34px; background: rgba(5,8,10,0.6); border: 1px solid var(--line);
  color: var(--dim); font-size: 16px; cursor: pointer; pointer-events: auto;
  display: none;
}
body.touch #btn-pause { display: block; top: auto; bottom: calc(14px + var(--sab)); right: auto; left: 50%; transform: translateX(-50%); }
body:not(.touch) #btn-pause { display: block; top: calc(150px + var(--sat)); }
body:not(.touch) #lb-live { top: calc(14px + var(--sat)); }

/* ============ TOUCH CONTROLS ============ */

#touch-zone { position: fixed; inset: 0; z-index: 15; touch-action: none; }
#joy-base, #joy-knob, #joy2-base, #joy2-knob {
  position: fixed; z-index: 16; pointer-events: none; display: none;
  border-radius: 50%; transform: translate(-50%, -50%);
}
#joy-base { width: 112px; height: 112px; border: 2px solid rgba(122,158,178,0.4); background: rgba(5,8,10,0.25); }
#joy-knob { width: 52px; height: 52px; background: rgba(72,219,251,0.35); border: 2px solid var(--cyan); }
#joy2-base { width: 120px; height: 120px; border: 2px solid rgba(255,159,67,0.4); background: rgba(10,6,3,0.25); }
#joy2-base::after { content: "+"; position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,159,67,0.55); font-size: 20px; }
#joy2-knob { width: 56px; height: 56px; background: rgba(255,159,67,0.3); border: 2px solid var(--amber); }

/* resting joystick hints — always on screen so the sticks are discoverable */
.joy-rest {
  position: fixed; z-index: 14; display: none; pointer-events: none;
  width: 116px; height: 116px; border-radius: 50%;
  background: rgba(5,8,10,0.18);
  align-items: center; justify-content: center;
  font-size: 11px; letter-spacing: 0.25em; font-family: var(--mono);
}
#joy-rest-l {
  left: calc(34px + var(--sal)); bottom: calc(96px + var(--sab));
  border: 2px dashed rgba(72,219,251,0.5); color: rgba(72,219,251,0.6);
}
#joy-rest-r {
  right: calc(122px + var(--sar)); bottom: calc(96px + var(--sab));
  border: 2px dashed rgba(255,159,67,0.55); color: rgba(255,159,67,0.65);
}
body.touch.playing .joy-rest { display: flex; }
@media (max-width: 520px) {
  .joy-rest { width: 92px; height: 92px; font-size: 10px; }
  #joy-rest-l { left: calc(26px + var(--sal)); }
  #joy-rest-r { right: calc(104px + var(--sar)); }
}

#touch-buttons { position: fixed; right: calc(12px + var(--sar)); bottom: calc(20px + var(--sab)); z-index: 17; display: none; flex-direction: column; gap: 10px; align-items: flex-end; }
body.touch.playing #touch-buttons { display: flex; }
#touch-buttons button {
  border-radius: 50%; border: 2px solid var(--line); background: rgba(5,8,10,0.45);
  color: var(--text); font-family: var(--mono); letter-spacing: 0.1em; touch-action: none;
}
#btn-fire { width: 88px; height: 88px; font-size: 16px; border-color: rgba(255,159,67,0.7); color: var(--amber); }
#btn-jet { width: 62px; height: 62px; font-size: 12px; border-color: rgba(72,219,251,0.6); color: var(--cyan); }
#btn-boost { width: 52px; height: 52px; font-size: 11px; border-color: rgba(29,209,161,0.6); color: var(--green); }
#touch-buttons button.active { background: rgba(255,255,255,0.18); }

#btn-fire2 {
  position: fixed; left: calc(14px + var(--sal)); bottom: calc(22px + var(--sab)); z-index: 17;
  width: 64px; height: 64px; border-radius: 50%; display: none;
  border: 2px solid rgba(255,159,67,0.7); background: rgba(5,8,10,0.45);
  color: var(--amber); font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; touch-action: none;
}
body.touch.playing #btn-fire2 { display: block; }
#btn-fire2.active { background: rgba(255,255,255,0.18); }

/* ============ OVERLAYS ============ */

.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(4, 6, 9, 0.82);
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--sat)) 16px calc(16px + var(--sab));
}
.obox {
  width: min(440px, 92vw); max-height: 86vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); padding: 22px; text-align: center;
}
.obox h2 { font-size: 34px; letter-spacing: 0.3em; color: var(--red); text-shadow: 0 0 22px rgba(255,77,77,0.5); }
#pause .obox h2 { color: var(--cyan); text-shadow: 0 0 22px rgba(72,219,251,0.4); }
.obox .plabel { text-align: left; }
.dsub { color: var(--dim); font-size: 12px; margin-top: 8px; }
.dscore { margin: 14px 0 2px; font-size: 13px; color: var(--dim); letter-spacing: 0.15em; }
.dscore b { color: var(--amber); font-size: 26px; margin-left: 8px; }
.dnote { font-size: 11px; color: var(--dim); margin-bottom: 12px; }
.obox h3 { font-size: 11px; letter-spacing: 0.25em; color: var(--dim); margin: 10px 0 6px; }
.obox .board { text-align: left; margin-bottom: 14px; }
.obox button {
  width: 100%; margin-top: 10px; padding: 13px; font-family: var(--mono); font-size: 15px;
  font-weight: 700; letter-spacing: 0.25em; background: var(--amber); border: none; color: #1b1006; cursor: pointer;
}
.obox button:disabled { opacity: 0.5; }
.obox button.ghost { background: transparent; border: 1px solid var(--line); color: var(--dim); }
.obox input[type="range"] { width: 100%; accent-color: var(--cyan); }
