:root {
  --bg: #0c0c0c;
  --ink: #fcfcfc;
  --green: #80d010;
  --blue: #3cbcfc;
  --orange: #fc7c3c;
  --font: "Press Start 2P", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}

#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: none;
  background: #000;
}

/* Camera preview */
#cam {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 220px;
  background: #000;
  border: 2px solid var(--green);
  font-size: 8px;
  line-height: 1.6;
  z-index: 5;
}
#cam[hidden] { display: none; }
#cam .view { position: relative; aspect-ratio: 4 / 3; }
#cam video, #cam canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
#cam video { opacity: 0.6; }

.meter {
  position: relative;
  height: 8px;
  margin: 6px 8px 0;
  background: #222;
}
#meterFill {
  height: 100%;
  width: 0;
  background: var(--orange);
}
.meter .mark {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
}
.meter .fire { background: var(--orange); }
.meter .cock { background: var(--green); }
#camStatus { padding: 6px 8px 8px; color: var(--green); }

/* Start overlay */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.88);
  z-index: 10;
  padding: 16px;
}
.overlay[hidden] { display: none; }
.panel {
  max-width: 560px;
  text-align: center;
  border: 4px solid var(--green);
  padding: 28px 24px;
  background: #000;
}
.panel h1 {
  margin: 0 0 20px;
  font-size: clamp(28px, 7vw, 44px);
  font-weight: normal;
  color: var(--blue);
  text-shadow: 4px 4px 0 var(--orange);
}
.panel p { font-size: 10px; line-height: 2; margin: 0 0 18px; }
.panel .how b { color: var(--orange); font-weight: normal; }
.panel .keys { color: #9c9c9c; font-size: 8px; margin: 18px 0 0; }
.buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
button {
  font: inherit;
  font-size: 11px;
  padding: 12px 16px;
  color: #000;
  background: var(--green);
  border: none;
  cursor: pointer;
  box-shadow: 4px 4px 0 #2c5c00;
}
button.alt { background: var(--ink); box-shadow: 4px 4px 0 #7c7c7c; }
button:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #2c5c00; }
button:disabled { opacity: 0.5; cursor: wait; }
kbd { color: var(--ink); }
.msg { color: var(--orange); min-height: 1em; }

a { color: var(--blue); }
a:hover { color: var(--ink); }
.challenge { color: var(--orange); }
.challenge:empty { display: none; }

/* Share panel */
.panel.share { max-height: calc(100vh - 32px); overflow-y: auto; }
.share h2 { margin: 0 0 16px; font-size: 20px; font-weight: normal; color: var(--blue); }
.share .score { font-size: 28px; color: var(--ink); margin-bottom: 10px; }
.share .detail { color: #9c9c9c; font-size: 9px; margin-bottom: 10px; }
.share .vs { color: var(--orange); }
.share .vs:empty { display: none; }
.share img { display: block; width: 100%; max-width: 420px; margin: 0 auto 14px; image-rendering: pixelated; border: 2px solid #333; }
.share .buttons + .msg { margin-top: 14px; }
.share .buttons button { font-size: 9px; padding: 10px 12px; }
#shareClose { font-size: 11px; padding: 12px 16px; margin-top: 4px; }

/* Corner bar: share, chip in, help. Always on screen, above the start panel. */
#corner {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  z-index: 11;
}
#corner[hidden] { display: none; }
.corner-btn, a.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 9px var(--font);
  line-height: 1;
  padding: 9px 11px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.72);
  border: 2px solid var(--ink);
  box-shadow: none;
  text-decoration: none;
  cursor: pointer;
}
.corner-btn:hover { background: #000; color: var(--green); border-color: var(--green); }
.corner-btn:active { transform: translate(1px, 1px); box-shadow: none; }
.corner-btn.treat, .corner-btn.treat:hover { color: var(--orange); border-color: var(--orange); }
.corner-btn.treat:hover { background: #000; color: var(--ink); }
.ico { width: auto; height: 12px; fill: currentColor; shape-rendering: crispEdges; flex: none; }
/* Narrow screens: icons only. */
@media (max-width: 640px) { .corner-btn span { display: none; } }

/* Chip-in button inside panels */
a.button.treat {
  font-size: 11px;
  padding: 12px 16px;
  color: #000;
  background: var(--orange);
  border: none;
  box-shadow: 4px 4px 0 #8c3c0c;
}
a.button.treat:hover { color: #000; }
a.button.treat .ico { height: 11px; }

/* World leaderboard */
.lb-box { margin: 0 0 16px; }
.lb-box label { display: block; font-size: 9px; color: var(--green); margin-bottom: 10px; }
.lb-row { display: flex; gap: 8px; justify-content: center; }
#lbName {
  font: 12px var(--font);
  width: 15ch;
  padding: 10px;
  color: var(--ink);
  background: #000;
  border: 2px solid var(--ink);
  text-transform: uppercase;
}
#lbName:focus { outline: none; border-color: var(--green); }
.lb-box .msg { margin: 10px 0; font-size: 9px; }
.lb-box .msg:empty { display: none; }
#lbView { font-size: 9px; padding: 9px 12px; margin-top: 10px; }

.panel.board { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; }
.board h2 { margin: 0 0 16px; font-size: 18px; font-weight: normal; color: var(--blue); }
.board table { width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 12px; }
.board th { color: var(--green); font-weight: normal; padding: 0 6px 10px; text-align: left; }
.board td { padding: 7px 6px; border-top: 1px solid #222; text-align: left; }
.board th:nth-child(3), .board td:nth-child(3), .board th:nth-child(4), .board td:nth-child(4) { text-align: right; }
.board td:first-child { color: #9c9c9c; width: 3.5em; }
.board td.gun { color: #9c9c9c; }
.board td.gun.finger { color: var(--green); }
.board tr.me td, .board tr.me td.gun { color: #000; background: var(--orange); }
.board tr.gap td { text-align: center; color: #9c9c9c; border-top: none; }
.board .detail:empty { display: none; }
