:root {
  color-scheme: dark;
  --bg: #000;
  --ink: #dedede;
  --yellow: #ffff00;
  --blue: #2121ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, "Courier New", monospace;
  overflow: hidden;
}

body {
  display: flex;
  justify-content: center;
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 12px;
  overflow: hidden;
}

canvas {
  display: block;
  background: #000;
  touch-action: none;
  box-shadow: 0 0 0 4px #111, 0 0 40px rgba(33, 33, 255, 0.25);
}

.help, .who {
  margin: 0;
  letter-spacing: 0.04em;
  text-align: center;
}

.help {
  font-size: 12px;
  color: #9a9a9a;
}

.who {
  color: #ffff00;
  font-size: 16px;
  letter-spacing: 0.08em;
}

.scores {
  margin: 0;
  color: #fff;
  text-align: center;
  font-size: 14px;
  line-height: 1.3;
}

.scores p {
  margin: 0;
  color: #ffff00;
  font-size: 18px;
  letter-spacing: 0.06em;
}

.scores ol {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.scores li.mine {
  color: #ffff00;
}

.name-dialog {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 0;
  background: rgba(0, 0, 0, 0.78);
}

.name-dialog[hidden] { display: none; }

.fireworks {
  position: fixed;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.fireworks[hidden] { display: none; }

.celebrate {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
}

.celebrate[hidden] { display: none; }

.game-over {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  margin: 0;
  background: #000;
  color: #ff0000;
  font-family: "Share Tech Mono", "Courier New", monospace;
  font-size: clamp(56px, 12vw, 140px);
  letter-spacing: 0.06em;
  text-align: center;
  text-shadow: 0 0 12px #ff0000, 0 0 28px #ff2020;
  animation: game-over-flash 0.32s steps(1, end) infinite;
}

.game-over[hidden] { display: none; }

@keyframes game-over-flash {
  50% { color: transparent; text-shadow: none; }
}

.celebrate p {
  margin: 0;
  max-width: 18ch;
  font-family: "Share Tech Mono", "Courier New", monospace;
  font-size: clamp(32px, 6vw, 72px);
  font-weight: 400;
  line-height: 1.15;
  text-align: center;
  color: #7cff4e;
  text-shadow: 0 0 8px #39ff14, 0 0 22px #39ff14;
  animation: digit-flash 0.4s steps(2, end) infinite;
}

@keyframes digit-flash {
  50% { opacity: 0.12; }
}

.celebrate.hired {
  perspective: 900px;
}

.celebrate.hired p {
  max-width: 14ch;
  color: #fff;
  background: none;
  animation: spin-sign 5.6s linear infinite;
  filter: none;
}

.celebrate.hired p span {
  display: inline-block;
  white-space: nowrap;
}

.celebrate.hired p span span {
  animation: word-colors 1.2s linear infinite;
  text-shadow: 0 0 8px currentColor, 0 0 18px currentColor;
}

@keyframes word-colors {
  0% { color: #ff2a2a; }
  16% { color: #ff8a00; }
  33% { color: #ffd000; }
  50% { color: #7cff4e; }
  66% { color: #3de1ff; }
  83% { color: #ff4fd8; }
  100% { color: #ff2a2a; }
}

@keyframes spin-sign {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(360deg); }
}

body.intro-on main {
  visibility: hidden;
}

.intro {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: #000;
  perspective: 1600px;
}

.intro[hidden] { display: none; }

.intro-stage {
  width: min(84vw, 720px);
  height: min(38vh, 280px);
}

.intro-box {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.intro-box.go {
  animation: intro-turn 16s linear forwards;
}

.intro .face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  align-content: center;
  gap: 0.2em 0.35em;
  padding: 28px;
  background: #000;
  border: 4px solid currentColor;
  box-shadow: 0 0 18px currentColor, inset 0 0 30px currentColor;
  backface-visibility: hidden;
  text-align: center;
  font-family: "Share Tech Mono", "Courier New", monospace;
  font-size: clamp(26px, 4.4vw, 52px);
  line-height: 1.2;
  animation: word-colors 1.2s linear infinite;
}

.intro .face.front { transform: translateZ(var(--half, 220px)); }
.intro .face.right { transform: rotateY(90deg) translateZ(var(--half, 220px)); animation-delay: -0.3s; }
.intro .face.back { transform: rotateY(180deg) translateZ(var(--half, 220px)); animation-delay: -0.6s; }
.intro .face.left { transform: rotateY(-90deg) translateZ(var(--half, 220px)); animation-delay: -0.9s; }

.intro .face span {
  display: inline-block;
  white-space: nowrap;
}

.intro .face span span {
  animation: word-colors 1.2s linear infinite;
  text-shadow: 0 0 8px currentColor, 0 0 18px currentColor;
}

@keyframes intro-turn {
  0%, 16% { transform: rotateY(0deg); }
  28%, 44% { transform: rotateY(-90deg); }
  56%, 72% { transform: rotateY(-180deg); }
  84%, 100% { transform: rotateY(-270deg); }
}

body.finale canvas,
body.finale .help,
body.finale .who {
  display: none;
}

body.finale main {
  justify-content: flex-start;
  padding-top: 10vh;
}

body.finale .scores {
  font-size: 22px;
}

body.finale .scores p {
  font-size: clamp(28px, 5vw, 52px);
}

body.finale .scores ol {
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  font-size: clamp(20px, 3vw, 34px);
}

.name-dialog label {
  color: #ffff00;
  font-size: 22px;
  letter-spacing: 0.08em;
}

.name-dialog input {
  width: min(280px, 80vw);
  padding: 8px 12px;
  border: 2px solid var(--blue);
  background: #000;
  color: #fff;
  font: inherit;
  font-size: 20px;
  text-align: center;
}

.name-dialog button {
  border: 0;
  background: #ffff00;
  color: #000;
  font: inherit;
  font-size: 16px;
  letter-spacing: 0.08em;
  padding: 8px 18px;
  cursor: pointer;
}

@media (max-width: 520px) {
  .help { font-size: 11px; padding: 0 12px; }
}
