:root {
  --bg: #0d1017;
  --panel: #161b26;
  --line: #262d3d;
  --text: #e6e9f0;
  --dim: #8b93a7;
  --accent: #f6c945;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2130, var(--bg));
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  justify-content: center;
  padding: 18px;
}

#app {
  width: min(1500px, 100%);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex: none;
}

h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 3px;
  font-weight: 800;
}
h1 span { color: var(--accent); }

.pill {
  font-size: 12px;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
}
.pill.live { color: #5fd36a; border-color: #2c5c37; }
.pill.down { color: #f4574f; border-color: #5c2c2c; }

.pills { display: flex; gap: 8px; align-items: center; }
#matchInfo { color: var(--accent); border-color: #5c4d1c; }

button.pill {
  font-family: inherit;
  font-weight: 400;
  margin: 0;
  background: none;
  cursor: pointer;
}
button.pill:hover { color: var(--text); border-color: var(--dim); }

main {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 14px;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #313a52;
  border-radius: 12px;
  overflow: hidden;
  background: #10141d;
  line-height: 0;
  /* A lit top edge, a shadow under the whole cabinet, and a faint warm bloom
     around it: the arena reads as a screen you are looking into rather than a
     rectangle sitting on the page. */
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 18px 44px -12px rgba(0, 0, 0, 0.75),
    0 0 70px -30px rgba(246, 201, 69, 0.35);
}

canvas {
  display: block;
  /* Fill the whole stage and let object-fit scale the board up to it while
     keeping the tile aspect ratio: the arena is as big as the window allows
     on every display, not capped at the buffer's intrinsic resolution. */
  width: 100%;
  height: 100%;
  object-fit: contain;
  touch-action: none;
}

#overlay, #matchEnd {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 16, 0.82);
  backdrop-filter: blur(3px);
  line-height: 1.45;
}
#overlay.hidden, #matchEnd[hidden] { display: none; }

#winnerLine {
  font-size: 24px;
  letter-spacing: 1px;
  margin: 0 0 4px;
}
#winnerLine .who { text-shadow: 0 0 18px currentColor; }

.final {
  list-style: none;
  margin: 14px auto 0;
  padding: 0;
  width: 220px;
}
.final li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  border-top: 1px solid var(--line);
}
.final li:first-child { border-top: 0; }
.final .rank { color: var(--dim); width: 14px; text-align: right; }
.final .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.final .kd { color: var(--dim); font-variant-numeric: tabular-nums; font-size: 12px; }
.final li.me .nm { color: var(--accent); font-weight: 700; }

.card {
  text-align: center;
  padding: 26px 30px;
  max-height: 100%;
  overflow-y: auto;
}
.card h2 { margin: 0 0 14px; font-size: 18px; }

input[type="text"], #name {
  width: 200px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0e121a;
  color: var(--text);
  font-size: 14px;
}
#name:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

#createBox {
  width: 280px;
  margin: 14px auto 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#createBox legend {
  padding: 0 8px;
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--dim);
}
#createBox input[type="text"], #createBox input:not([type]),
#lobbyName, #lobbyPassword {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0e121a;
  color: var(--text);
  font-size: 14px;
}
#lobbyName:focus, #lobbyPassword:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#createBox .check {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--dim);
  font-size: 12px;
  cursor: pointer;
}
#createBox button { margin-left: 0; }
#joinHead {
  margin: 18px 0 4px;
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 600;
}

.lobbyList {
  width: 300px;
  margin: 8px auto 0;
  max-height: 220px;
  overflow-y: auto;
  text-align: left;
}
.lobbyRow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 2px;
  border-top: 1px solid var(--line);
}
.lobbyRow:first-child { border-top: 0; }
.lobbyMain { flex: 1; min-width: 0; }
.lobbyTop { display: flex; align-items: center; gap: 6px; min-width: 0; }
.lobbyName { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lobbySub {
  color: var(--dim);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lobbySide { display: flex; align-items: center; gap: 8px; }
.lobbyPwRow { flex-basis: 100%; }
.lobbyPwRow input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0e121a;
  color: var(--text);
  font-size: 13px;
}
.badge {
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
  color: var(--dim);
}
.badge.noBots { color: #9aa0ac; border-color: #3a4256; }
.lobbyCount { color: var(--dim); font-variant-numeric: tabular-nums; font-size: 12px; }
.lobbyJoin {
  margin: 0;
  font-size: 12px;
  font-weight: 400;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: none;
  color: var(--text);
  cursor: pointer;
}
.lobbyJoin:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.lobbyJoin:disabled { color: var(--dim); cursor: default; opacity: 0.6; }

button {
  margin-left: 8px;
  padding: 9px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #241f06;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }

.hint { color: var(--dim); font-size: 12px; margin: 16px 0 0; }
#joinError { color: #f4574f; font-size: 12px; min-height: 16px; margin: 8px 0 0; }

#deadNote {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  background: rgba(10, 12, 18, 0.8);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--accent);
}

#curseNote {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  background: rgba(10, 22, 8, 0.85);
  border: 1px solid #2f6b1f;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  color: #7ddb5f;
  white-space: nowrap;
  animation: cursePulse 1.1s ease-in-out infinite;
}

@keyframes cursePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

#blessNote {
  position: absolute;
  left: 50%;
  bottom: 40px; /* stacks above #curseNote, for the rare moment both apply */
  transform: translateX(-50%);
  background: rgba(30, 26, 6, 0.85);
  border: 1px solid #a3801f;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  color: #ffe066;
  white-space: nowrap;
  animation: blessPulse 1.1s ease-in-out infinite;
}

@keyframes blessPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

#freezeNote {
  position: absolute;
  left: 50%;
  bottom: 68px; /* stacks above #blessNote, for the rare moment both apply */
  transform: translateX(-50%);
  background: rgba(8, 24, 32, 0.85);
  border: 1px solid #2f7ba3;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  color: #bfe9ff;
  white-space: nowrap;
  animation: freezePulse 1.1s ease-in-out infinite;
}

@keyframes freezePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.stats b.bad { color: #7ddb5f; }
#scores li.cursed .nm { color: #7ddb5f; }
#clock { font-variant-numeric: tabular-nums; }
#clock.sudden {
  color: #f4574f;
  border-color: #5c2c2c;
  animation: clockPulse 1s ease-in-out infinite;
}

@keyframes clockPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

#suddenBanner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 4px;
  color: #f4574f;
  text-shadow: 0 0 22px rgba(244, 87, 79, 0.7);
  pointer-events: none;
  opacity: 0;
}
#suddenBanner span {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 1px;
  color: var(--text);
  text-shadow: none;
}
#suddenBanner.show { animation: suddenFlash 2.4s ease-out forwards; }

@keyframes suddenFlash {
  0% { opacity: 0; transform: scale(0.85); }
  12% { opacity: 1; transform: scale(1.04); }
  20% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

#streakBanner {
  --c: #f6c945;
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  opacity: 0;
}
#streakBanner .who {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}
#streakBanner .label {
  display: block;
  margin-top: 2px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--c);
  text-shadow: 0 0 18px var(--c);
}
#streakBanner.show { animation: streakFlash 2.2s ease-out forwards; }

@keyframes streakFlash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  25% { transform: translate(-50%, -50%) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; }
}

aside {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 0 0 230px;
  min-height: 0;
  overflow-y: auto;
}
aside section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
aside h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--dim);
}

.stats, #scores, .legend { list-style: none; margin: 0; padding: 0; }
.stats li {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}
.stats span { color: var(--dim); }
.stats b { font-variant-numeric: tabular-nums; }
.stats b.on { color: #c07ef2; }
/* One colour per slot rather than per item: the upgrade slot holds any of four
   differently-coloured pickups, so tinting it by contents would just flicker. */
.stats b#sThrowable.on { color: #4fc3e8; }

.legend li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
}
.legend .chip {
  flex: 0 0 auto;
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--c);
  box-shadow: 0 0 8px -1px var(--c);
}
.legend .lg { color: var(--dim); font-size: 12px; }
.legend .lg b { color: var(--text); font-weight: 700; }

/* Hall of fame - the same rows in the aside and in the join card, so the
   layout is shared and only the join card's own width/centring differ. */
.hof { list-style: none; margin: 0; padding: 0; }
.hof li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  border-top: 1px solid var(--line);
}
.hof li:first-child { border-top: 0; }
.hof .rank { color: var(--dim); width: 14px; text-align: right; }
.hof .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.hof .wins { font-variant-numeric: tabular-nums; font-weight: 700; }
.hof li.me .nm { color: var(--accent); font-weight: 700; }
/* The top three earn a tint; below that the rank number is enough. */
.hof li:nth-child(1) .wins { color: #ffe066; }
.hof li:nth-child(2) .wins { color: #cfd6e4; }
.hof li:nth-child(3) .wins { color: #e0a879; }

#hofCard {
  width: 260px;
  margin: 18px auto 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
#hofCard h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--dim);
  text-align: left;
}
#hofCard .hint { margin-top: 8px; text-align: left; }
#hofCard[hidden], #hofSection[hidden] { display: none; }

.note {
  color: var(--dim);
  font-size: 11px;
  line-height: 1.4;
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

#scores li {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
/* How close this player is to the kill target, drawn behind their row. */
#scores li::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 1px;
  bottom: 1px;
  width: calc(var(--pct, 0) * (100% + 12px));
  background: var(--c, var(--accent));
  opacity: 0.18;
  border-radius: 4px;
}
#scores li.lead::before { opacity: 0.32; }
#scores li > span { position: relative; } /* keep the text above the bar */
#scores .dot, .final .dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}
#scores .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#scores .kd { color: var(--dim); font-variant-numeric: tabular-nums; font-size: 12px; }
#scores li.me .nm { color: var(--accent); font-weight: 700; }
#scores li.dead { opacity: 0.45; }

#soundToggle {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--dim);
  font-size: 12px;
  margin-top: 6px;
}

@media (max-width: 760px) {
  body { height: auto; }
  #app { min-height: 100dvh; }
  main { flex: none; flex-direction: column; }
  /* Portrait: width is the binding constraint and the page scrolls, so the
     stage and board fall back to their natural width-driven sizing. */
  #stage { flex: none; min-height: 0; }
  aside { flex: none; overflow-y: visible; }
  canvas {
    width: 100%;
    height: auto;
    max-width: none;
    max-height: none;
  }
}
