/* ==========================================================================
   Zombie Survival 3D — layout, HUD, panel
   ========================================================================== */
:root {
  --bg: #050608;
  --panel: #14161f;
  --panel-border: #252a3a;
  --text: #e8eaf2;
  --muted: #8b90a6;
  --accent: #fe2c55;   /* TikTok red */
  --accent-2: #25f4ee; /* TikTok cyan */
  --ok: #3ddc84;
  --warn: #ffb02e;
  --err: #ff5c6c;
  --hud-font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--hud-font);
  font-size: 14px;
  overflow: hidden;
}

body { display: flex; }

/* ---------- Stage: centers the 9:16 viewport ---------- */
#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#viewport {
  position: relative;
  overflow: hidden;
  container-type: size; /* HUD sizes scale with the viewport (cqh units) */
  background: #0a0d14;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 65%, rgba(0, 0, 0, 0.35) 100%);
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: 1.6cqh;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
}

#hud-top {
  position: absolute;
  top: 3cqh;
  left: 3cqw;
  right: 3cqw;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 2cqw;
}

.bars { display: flex; flex-direction: column; gap: 0.6cqh; }

.bar {
  position: relative;
  height: 2.4cqh;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.6cqh;
  overflow: hidden;
}
.bar.likes { height: 1.7cqh; }
.bar span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding-left: 0.8cqw;
  font-weight: 700;
  font-size: 1.3cqh;
  white-space: nowrap;
}
.bar.likes span { font-size: 1.05cqh; }
.fill { height: 100%; transition: width 0.2s; }
.hp-ok { background: linear-gradient(90deg, #1fa85c, #3ddc84); }
.hp-warn { background: linear-gradient(90deg, #d68910, #ffb02e); }
.hp-low { background: linear-gradient(90deg, #b3202f, #ff4d5e); animation: pulse 0.6s infinite alternate; }
#like-fill { background: linear-gradient(90deg, #d6336c, #ff6b9a); }

.center { text-align: center; }
#timer { font-size: 4.4cqh; font-weight: 800; letter-spacing: 0.1cqh; line-height: 1; }
#kills { font-size: 1.5cqh; margin-top: 0.4cqh; opacity: 0.9; white-space: nowrap; }

.weapon { text-align: right; }
#weapon-name { font-weight: 800; font-size: 1.6cqh; color: #ffd84d; text-transform: uppercase; }
#weapon-ammo { font-size: 3cqh; font-weight: 800; line-height: 1.1; }

#shield-chip {
  position: absolute;
  top: 10.5cqh;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.4cqh 1.4cqw;
  border-radius: 99px;
  background: rgba(37, 244, 238, 0.18);
  border: 1px solid rgba(37, 244, 238, 0.6);
  color: #9ff6ff;
  font-weight: 800;
  font-size: 1.4cqh;
}
#shield-chip[hidden] { display: none; }

/* Feed sits under the HUD on the left — away from TikTok's bottom chat overlay. */
#feed {
  position: absolute;
  top: 14cqh;
  left: 3cqw;
  right: 20cqw;
  display: flex;
  flex-direction: column;
  gap: 0.5cqh;
}
.feed-line {
  align-self: flex-start;
  padding: 0.5cqh 1.2cqw;
  border-radius: 0.6cqh;
  background: rgba(0, 0, 0, 0.6);
  font-weight: 700;
  font-size: 1.5cqh;
  animation: slideIn 0.25s ease-out;
  transition: opacity 0.5s;
}
.feed-line.fade { opacity: 0; }

#banner {
  position: absolute;
  top: 36cqh;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 6cqh;
  font-weight: 900;
  letter-spacing: 0.3cqh;
  opacity: 0;
  -webkit-text-stroke: 0.15cqh #000;
}
#banner.show { animation: banner 1.8s ease-out forwards; }

#toast {
  position: absolute;
  top: 46cqh;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 2.6cqh;
  font-weight: 900;
  opacity: 0;
}
#toast.show { animation: toast 1.4s ease-out forwards; }

/* ---------- Game over ---------- */
#game-over {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2cqh;
  background: radial-gradient(ellipse at center, rgba(60, 0, 0, 0.55), rgba(0, 0, 0, 0.88));
  cursor: pointer;
  text-align: center;
  animation: fadeIn 0.6s;
}
#game-over[hidden] { display: none; }
.go-title {
  font-size: 7.5cqh;
  font-weight: 900;
  color: #ff3b3b;
  letter-spacing: 0.4cqh;
  text-shadow: 0 0 3cqh rgba(255, 0, 0, 0.6);
}
#go-stats { font-size: 2.2cqh; line-height: 1.7; }
#go-stats b { color: #fff; }
#go-stats .best { color: #ffd84d; font-weight: 900; }
.go-hint { color: var(--accent-2); font-size: 1.9cqh; font-weight: 700; margin-top: 2cqh; }
#go-countdown { color: var(--muted); font-size: 1.6cqh; }

/* ---------- Loading ---------- */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2cqh;
  background: #07080c;
}
#loading[hidden] { display: none; }
.loading-title { font-size: 4.5cqh; font-weight: 900; color: #ff3b3b; letter-spacing: 0.3cqh; }
.loading-track { width: 50%; height: 0.8cqh; background: #1c1f2a; border-radius: 99px; overflow: hidden; }
#loading-bar { width: 0; height: 100%; background: var(--accent); transition: width 0.3s; }
.loading-sub { color: var(--muted); font-size: 1.6cqh; padding: 0 6cqw; text-align: center; }

@keyframes banner {
  0% { opacity: 0; transform: scale(0.6); }
  15% { opacity: 1; transform: scale(1.05); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.15); }
}
@keyframes toast {
  0% { opacity: 0; transform: translateY(1cqh); }
  15% { opacity: 1; transform: translateY(0); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-2cqh); }
}
@keyframes slideIn { from { opacity: 0; transform: translateX(-2cqw); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.5); } }

/* ==========================================================================
   Streamer panel
   ========================================================================== */
#panel {
  width: 320px;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  padding: 16px;
}
body.panel-hidden #panel { display: none; }

#show-panel-btn {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0.25;
  flex: none;
}
#show-panel-btn:hover { opacity: 1; }
body.panel-hidden #show-panel-btn { display: block; }

.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
h1 { font-size: 17px; margin: 0; }
h2 { font-size: 14px; margin: 0 0 10px; color: var(--accent-2); }
h3 { font-size: 12px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
section { padding: 14px 0; border-top: 1px solid var(--panel-border); }
label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.at { color: var(--muted); font-weight: 600; }

input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: #0d0f16;
  color: var(--text);
  font-size: 14px;
}
input:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }

button {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: #20243a;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #2b3050; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #ff4b6e; }
button.small { flex: none; padding: 4px 8px; font-size: 12px; }
button.active { background: #1f6f4a; border-color: var(--ok); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid .wide { grid-column: span 2; }

.status { margin: 4px 0 0; padding: 8px 10px; border-radius: 6px; background: #0d0f16; font-size: 13px; }
.status::before { content: "● "; }
.status-idle::before, .status-disconnected::before { color: var(--muted); }
.status-connecting::before { color: var(--warn); }
.status-connected::before { color: var(--ok); }
.status-error::before { color: var(--err); }
.status-error { color: var(--err); }

.hint { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 8px 0 0; }
.hint a { color: var(--accent-2); }
code { background: #0d0f16; padding: 1px 4px; border-radius: 4px; font-size: 11px; }

/* Home button (panel header) */
.panel-header { gap: 8px; }
.panel-header h1 { flex: 1; }
.home-btn {
  flex: none;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--accent-2, #25f4ee);
  background: rgba(37, 244, 238, 0.12);
  color: var(--text, #e8eaf2);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.home-btn:hover { background: rgba(37, 244, 238, 0.25); }
