* { 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;
  /* TRON: near-black fallback so the frame reads dark before the canvas paints. */
  background: radial-gradient(120% 90% at 50% 40%, #04080e 0%, #020306 55%, #000000 100%);
  border: 1px solid #0a2230;
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.75), inset 0 0 70px rgba(0,0,0,0.45),
              0 0 40px rgba(0, 180, 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: 70px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12px 16px 0;
  background: linear-gradient(180deg, rgba(4,8,16,0.78), rgba(4,8,16,0));
}
.t-mid { flex: 1; text-align: center; padding-top: 2px; }
.t-title {
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 6px;
  opacity: 0.96;
  text-shadow: 0 0 18px rgba(120, 220, 255, 0.55);
}
.t-sub {
  font-size: 9px;
  letter-spacing: 3px;
  opacity: 0.6;
  margin-top: 4px;
}

/* ---------- Standings chips ---------- */
#standings {
  position: absolute;
  top: 70px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 14px;
  background: rgba(8,12,22,0.45);
}
.cy-chip {
  width: 26px; height: 26px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 900;
  font-family: "SF Mono", Menlo, monospace;
  color: #02060a;
  transition: opacity 0.4s ease, filter 0.4s ease, transform 0.25s ease;
}
.cy-chip.dead { opacity: 0.20; filter: grayscale(1) brightness(0.6); }
.cy-chip.lead { transform: translateY(-2px) scale(1.12); }

/* ---------- Alive readout ---------- */
#alive-readout {
  position: absolute;
  top: 116px; left: 18px;
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.ar-num {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
  color: #d6f6ff;
  text-shadow: 0 0 16px rgba(120,220,255,0.7);
  transition: transform 0.12s ease;
}
.ar-num.bump { transform: scale(1.45); }
.ar-label {
  font-size: 9px;
  letter-spacing: 2px;
  font-weight: 800;
  opacity: 0.55;
}

/* ---------- Grid-closing meter ---------- */
#grid-readout {
  position: absolute;
  top: 122px; right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  padding: 6px 11px;
  border-radius: 14px;
  background: rgba(10,16,28,0.55);
  border: 1px solid rgba(150,200,255,0.28);
}
.grid-label {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 3px;
  color: #c2dcff;
}
.grid-track {
  width: 132px; height: 5px;
  border-radius: 3px;
  background: rgba(255,255,255,0.16);
  overflow: hidden;
}
.grid-prog {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #36b6ff, #ff5a7a);
  box-shadow: 0 0 12px rgba(255,90,122,0.8);
  transition: width 0.2s linear;
}
.grid-time {
  font-family: "SF Mono", Menlo, monospace;
  font-size: 11px;
  font-weight: 800;
  color: #ffd9e4;
  min-width: 34px;
  text-align: right;
}
#grid-readout.urgent { animation: gridPulse 0.65s ease-in-out infinite; }
@keyframes gridPulse {
  0%,100% { box-shadow: 0 0 0 rgba(255,90,122,0); }
  50% { box-shadow: 0 0 22px rgba(255,90,122,0.6); border-color: rgba(255,120,150,0.85); }
}

/* ---------- Victory banner ---------- */
#victory-banner {
  position: absolute;
  top: 44%; 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: 72px;
  font-weight: 900;
  letter-spacing: 4px;
  line-height: 1;
  margin: 6px 0;
  color: #ffffff;
  text-shadow: 0 0 30px rgba(255,255,255,0.6);
}
.vb-tag {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 8px;
  opacity: 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.3s linear infinite; }
@keyframes quake {
  0%,100% { transform: translate(0,0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, -2px); }
}
