* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #000000;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#stage {
  position: relative;
  width: 540px;
  height: 960px;
  /* Warm studio fallback so the frame reads before the canvas paints. */
  background: radial-gradient(120% 90% at 50% 32%, #1a2740 0%, #0c1424 55%, #05080f 100%);
  border: 1px solid #1b2740;
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.75), inset 0 0 70px rgba(0,0,0,0.40),
              0 0 40px rgba(120, 150, 220, 0.10);
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}

/* ---------- HUD overlay ---------- */
#hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 64px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12px 16px 0;
  background: linear-gradient(180deg, rgba(6,10,22,0.78), rgba(6,10,22,0));
}
.t-mid { text-align: center; }
.t-title {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 7px;
  opacity: 0.97;
  text-shadow: 0 2px 10px rgba(0,0,0,0.6);
}
.t-sub {
  font-size: 10px;
  letter-spacing: 4px;
  opacity: 0.6;
  margin-top: 3px;
}

/* ---------- Per-team standings ---------- */
#standings {
  position: absolute;
  top: 70px; left: 12px; right: 12px;
  display: flex;
  gap: 8px;
  justify-content: center;
}
.team-card {
  flex: 1;
  max-width: 168px;
  padding: 7px 9px 8px;
  border-radius: 9px;
  background: rgba(8,12,24,0.55);
  border: 1px solid rgba(255,255,255,0.12);
  transition: opacity 0.4s ease, filter 0.4s ease, transform 0.2s ease;
}
.team-card.out { opacity: 0.34; filter: grayscale(0.7); }
.team-card.leader { border-color: rgba(255,255,255,0.55); box-shadow: 0 0 18px rgba(255,255,255,0.12); }
/* Lava nearing a tower's top — pulsing molten warning on the card. */
.team-card.lava-danger {
  border-color: rgba(255,120,40,0.9);
  animation: lavaDanger 0.5s ease-in-out infinite;
}
@keyframes lavaDanger {
  0%,100% { box-shadow: 0 0 10px rgba(255,90,20,0.45); }
  50%     { box-shadow: 0 0 22px rgba(255,120,40,0.95); }
}

.tc-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}
.tc-name { font-size: 13px; font-weight: 900; letter-spacing: 2px; }
.tc-status {
  font-size: 8px; font-weight: 800; letter-spacing: 1.5px;
  opacity: 0.8;
}
.team-card.out .tc-status { color: #ff7a7a; opacity: 1; }

.tc-bar {
  position: relative;
  margin-top: 6px;
  height: 6px;
  border-radius: 4px;
  background: rgba(255,255,255,0.14);
  overflow: hidden;
}
.tc-fill { height: 100%; width: 0%; border-radius: 4px; transition: width 0.3s ease; }
/* Molten tide marker chasing the stack up each team's gauge. */
.tc-lava {
  position: absolute;
  top: -1px; bottom: -1px;
  left: 0%;
  width: 3px;
  margin-left: -1.5px;
  background: linear-gradient(180deg, #ffd86a, #ff5a14);
  box-shadow: 0 0 8px 2px rgba(255,110,30,0.95);
  transition: left 0.2s linear;
}
.tc-h {
  margin-top: 5px;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}
.tc-hu { font-size: 10px; opacity: 0.6; margin-left: 2px; }

.t-amber  .tc-name, .t-amber  .tc-h { color: #ffc24a; text-shadow: 0 0 12px rgba(255,170,40,0.7); }
.t-jade   .tc-name, .t-jade   .tc-h { color: #4af2a8; text-shadow: 0 0 12px rgba(40,230,150,0.7); }
.t-violet .tc-name, .t-violet .tc-h { color: #b48bff; text-shadow: 0 0 12px rgba(150,110,255,0.7); }
.t-amber  .tc-fill { background: linear-gradient(90deg, #c8842a, #ffd06a); box-shadow: 0 0 10px rgba(255,180,60,0.8); }
.t-jade   .tc-fill { background: linear-gradient(90deg, #1fae74, #7dffc4); box-shadow: 0 0 10px rgba(50,230,160,0.8); }
.t-violet .tc-fill { background: linear-gradient(90deg, #7a4ed6, #cbb0ff); box-shadow: 0 0 10px rgba(160,120,255,0.8); }

/* ---------- Leader + timer readout ---------- */
#meta-readout {
  position: absolute;
  top: 162px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: 20px;
  background: rgba(10,16,30,0.55);
  border: 1px solid rgba(180,190,230,0.28);
}
.leader-label { font-size: 9px; font-weight: 800; letter-spacing: 2px; color: #c6cdec; }
.leader-name { font-size: 11px; font-weight: 900; letter-spacing: 2px; min-width: 56px; }
.meta-track {
  width: 110px; height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.16);
  overflow: hidden;
}
.meta-prog {
  height: 100%; width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #ffd06a, #ff8f5a);
  box-shadow: 0 0 12px rgba(255,160,90,0.8);
  transition: width 0.2s linear;
}
.meta-time {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 12px; font-weight: 800; color: #ffe6c2;
  min-width: 34px; text-align: right;
}

/* ---------- Hazard telegraph banner ---------- */
#hazard {
  position: absolute;
  top: 200px; left: 50%;
  transform: translateX(-50%);
  padding: 6px 18px;
  border-radius: 8px;
  font-size: 15px; font-weight: 900; letter-spacing: 5px;
  color: #fff;
  background: rgba(40,20,10,0.5);
  border: 1px solid rgba(255,180,90,0.7);
  text-shadow: 0 0 14px rgba(255,170,60,0.9);
  animation: hazPulse 0.55s ease-in-out infinite;
}
#hazard.tremor {
  background: rgba(30,12,40,0.5);
  border-color: rgba(190,120,255,0.7);
  text-shadow: 0 0 14px rgba(170,110,255,0.9);
}
@keyframes hazPulse {
  0%,100% { transform: translateX(-50%) scale(1); opacity: 0.85; }
  50% { transform: translateX(-50%) scale(1.06); opacity: 1; }
}

/* ---------- Rising-lava climax warning ---------- */
#lava-warn {
  position: absolute;
  top: 232px; left: 50%;
  transform: translateX(-50%);
  padding: 5px 16px;
  border-radius: 8px;
  font-size: 13px; font-weight: 900; letter-spacing: 4px;
  color: #fff;
  background: rgba(50,14,4,0.55);
  border: 1px solid rgba(255,120,40,0.85);
  text-shadow: 0 0 14px rgba(255,110,30,0.95);
  animation: lavaWarnPulse 0.6s ease-in-out infinite;
}
@keyframes lavaWarnPulse {
  0%,100% { transform: translateX(-50%) scale(1); opacity: 0.9; box-shadow: 0 0 10px rgba(255,90,20,0.4); }
  50%     { transform: translateX(-50%) scale(1.05); opacity: 1; box-shadow: 0 0 26px rgba(255,120,40,0.9); }
}

/* ---------- Victory banner ---------- */
#victory-banner {
  position: absolute;
  top: 46%; left: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  text-align: center;
  opacity: 0;
  transition: opacity 0.5s ease, transform 0.6s cubic-bezier(.2,1.3,.4,1);
}
#victory-banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#victory-banner.hidden { display: none !important; }
.vb-sub { font-size: 12px; letter-spacing: 6px; font-weight: 700; opacity: 0.85; }
.vb-name {
  font-size: 70px; font-weight: 900; letter-spacing: 4px;
  line-height: 1; margin: 6px 0;
}
.vb-tag { font-size: 26px; font-weight: 900; letter-spacing: 14px; opacity: 0.95; }
.vb-amber  .vb-name, .vb-amber  .vb-tag { color: #ffc24a; text-shadow: 0 0 30px rgba(255,170,40,0.95); }
.vb-jade   .vb-name, .vb-jade   .vb-tag { color: #5dffb4; text-shadow: 0 0 30px rgba(50,230,160,0.95); }
.vb-violet .vb-name, .vb-violet .vb-tag { color: #c2a4ff; text-shadow: 0 0 30px rgba(160,120,255,0.95); }

/* ---------- Watermark / ticker ---------- */
#watermark {
  position: absolute;
  bottom: 30px; right: 14px;
  font-size: 12px; font-weight: 800; letter-spacing: 1px;
  color: rgba(255,255,255,0.55);
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}
.ticker {
  position: absolute;
  left: 0; right: 0; bottom: 8px;
  text-align: center;
  font-family: "SF Mono", "Menlo", "Courier New", monospace;
  font-size: 11px; letter-spacing: 2px;
  opacity: 0.6;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

#boot-error {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  font-size: 14px;
  line-height: 1.6;
  color: #ff8a8a;
  background: rgba(8,10,20,0.95);
}

/* CRITICAL: an ID selector (#boot-error{display:flex}) would otherwise outrank
   a plain .hidden{display:none}, leaving the full-screen dark overlay visible
   on top of the WebGL canvas. !important keeps it hidden unless we explicitly
   un-hide it on an actual context-creation failure. */
.hidden { display: none !important; }

#stage.shaking { animation: quake 0.28s linear infinite; }
@keyframes quake {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(-4px, 2px); }
  50% { transform: translate(4px, -3px); }
  75% { transform: translate(-3px, -2px); }
}
