@font-face {
  font-family: 'Press Start 2P';
  src: url('../fonts/PressStart2P-vaV7.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'SpaceInvaders';
  src: url('../fonts/space-invaders-full-version.otf.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'MachineStd';
  src: url('../fonts/MachineStd-Bold.ttf') format('truetype');
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

html, body {
  margin: 0;
  padding: 0;
  background: #000;
}

#game-container {
  width: 100%;
}

.msi-game {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  background: #000;
  font-family: 'Press Start 2P', monospace;
  color: #0f0;
  position: relative;
  box-sizing: border-box;
}

.msi-game .game {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  position: relative;
  padding-top: 44px;
}

.msi-game canvas {
  background: #050505;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 76vh;
  aspect-ratio: 3 / 2;
  outline: none;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.msi-game .play-again {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.msi-game .play-again.visible {
  display: flex;
}

.msi-game .play-again .blink {
  font-size: 16px;
  animation: blnk 1.2s infinite;
}

.msi-game .play-again .countdown {
  font-size: 16px;
  opacity: 0.7;
}

.msi-game .bar {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
  font-size: 16px;
}

.msi-game .score-bar {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  margin-bottom: 0;
  gap: 24px;
}

.msi-game button {
  background: #0f0;
  color: #000;
  border: none;
  padding: 6px 16px;
  font-family: 'Press Start 2P', monospace;
  cursor: pointer;
  font-size: 16px;
}

.msi-game .hsprompt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #000;
  border: 2px solid #0f0;
  padding: 20px;
  text-align: center;
  display: none;
  z-index: 10;
}

.msi-game .hsprompt input {
  background: #000;
  border: 1px solid #0f0;
  color: #0f0;
  font-family: 'Press Start 2P', monospace;
  padding: 4px 8px;
  text-align: center;
  width: 220px;
  margin-bottom: 10px;
  font-size: 16px;
}

.msi-game .hsprompt button {
  margin-top: 8px;
}

.msi-game .login-prompt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #000;
  border: 2px solid #0f0;
  padding: 24px;
  text-align: center;
  display: none;
  z-index: 10;
  max-width: 400px;
}

.msi-game .login-prompt div {
  margin-bottom: 16px;
}

.msi-game .login-prompt .close-x {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  color: #0f0;
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.msi-game .startup {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  z-index: 5;
  transition: opacity 0.3s;
  padding-top: 120px;
  box-sizing: border-box;
  outline: none;
}

.msi-game .startup .logo-text {
  font-family: 'SpaceInvaders', 'Press Start 2P', monospace;
  font-size: 40px;
  color: #d23a37;
  margin-bottom: 12px;
  text-align: center;
  letter-spacing: -6px;
  word-spacing: -18px;
}

.msi-game .startup .logo-text-img {
  max-width: 80%;
  max-height: 32vh;
  margin-bottom: 48px;
  object-fit: contain;
}

.msi-game .startup .blink {
  font-size: 16px;
  animation: blnk 1.2s infinite;
}

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

/* ===== Top Bar ===== */
.msi-game .top-bar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  z-index: 31;
  pointer-events: none;
}

.msi-game .top-bar > * {
  pointer-events: auto;
}

.msi-game .trophy-circle,
.msi-game .player-avatar {
  width: 40px;
  height: 40px;
  border: 2px solid #0f0;
  border-radius: 50%;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 24px;
  font-family: 'Press Start 2P', monospace;
  line-height: 1;
  user-select: none;
  flex-shrink: 0;
  position: relative;
}

.msi-game .trophy-circle span,
.msi-game .player-avatar span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin-left: 2px;
}

.msi-game .trophy-circle:hover,
.msi-game .player-avatar:hover {
  background: #0f0;
  color: #000;
}

/* ===== Leaderboard (top bar) ===== */
.msi-game .lb-top {
  padding: 8px 16px;
  font-size: 8px;
  text-align: center;
}

.msi-game .lb-top h3 {
  margin: 0 0 6px;
  font-size: 16px;
  text-align: center;
  border-bottom: 1px solid #0f0;
  padding-bottom: 4px;
}

.msi-game .lb-top .lb-cols {
  display: flex;
  gap: 24px;
}

.msi-game .lb-top .lb-col {
  min-width: 160px;
}

.msi-game .lb-top .entry {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  gap: 8px;
}

.msi-game .lb-top .entry .rank {
  min-width: 28px;
  text-align: right;
}

.msi-game .lb-top .entry .name {
  flex: 1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msi-game .lb-top .entry .pts {
  min-width: 40px;
  text-align: right;
}

.msi-game .lb-top .you {
  color: #ff0;
}

/* ===== Start Modal (pre-game instructions) ===== */
.msi-game .start-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  z-index: 6;
  gap: 16px;
}

.msi-game .start-modal-table {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.msi-game .start-modal-row {
  display: grid;
  grid-template-columns: 80px 40px 160px;
  align-items: center;
  gap: 16px;
  font-size: 16px;
  font-family: 'Press Start 2P', monospace;
  color: #0f0;
  white-space: nowrap;
  height: 40px;
}

.msi-game .start-modal-row .img-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 80px;
}

.msi-game .start-modal-row img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.msi-game .start-modal-row .eq {
  text-align: center;
}

.msi-game .start-modal-row .pts {
  display: flex;
  justify-content: flex-start;
  gap: 12px;
}

.msi-game .start-modal-row .pts .val {
  width: 80px;
  text-align: right;
  flex-shrink: 0;
}

.msi-game .start-modal-row .pts .label {
  width: 40px;
  text-align: left;
  flex-shrink: 0;
}

.msi-game .start-modal-instructions {
  display: flex;
  gap: 96px;
  align-items: flex-start;
  justify-content: center;
  margin-top: 48px;
}

.msi-game .inst-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  font-size: 16px;
  font-family: 'Press Start 2P', monospace;
  color: #0f0;
  text-align: center;
}

.msi-game .inst-visual {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.msi-game .inst-visual.arrow-keys {
  font-size: 32px;
}

.msi-game .inst-key {
  margin-top: 32px;
}

.msi-game .key-circle {
  width: 32px;
  height: 32px;
  border: 2px solid #0f0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-family: 'Press Start 2P', monospace;
  color: #0f0;
}

/* ===== Profile Modal ===== */
.msi-game .profile-modal {
  position: absolute;
  top: 60px;
  right: 12px;
  width: 280px;
  max-height: 80vh;
  overflow-y: auto;
  background: #000;
  border: 2px solid #0f0;
  padding: 16px;
  box-sizing: border-box;
  display: none;
  z-index: 21;
  font-size: 8px;
}

.msi-game .profile-modal.visible {
  display: block;
}

.msi-game .profile-modal h3 {
  margin: 0 0 12px;
  font-size: 16px;
  text-align: center;
  border-bottom: 1px solid #0f0;
  padding-bottom: 8px;
}

.msi-game .profile-modal .stat-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #0a0a0a;
}

.msi-game .profile-modal .stat-label {
}

.msi-game .profile-modal .history-list {
  max-height: 120px;
  overflow-y: auto;
  margin-top: 8px;
}

.msi-game .profile-modal .history-entry {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 8px;
}

.msi-game .profile-modal .register-btn {
  width: 100%;
  margin-top: 12px;
  background: #0f0;
  color: #000;
  border: none;
  padding: 8px;
  font-family: 'Press Start 2P', monospace;
  cursor: pointer;
  font-size: 8px;
  animation: blnk 1.2s infinite;
}

.msi-game .profile-modal .close-btn {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  color: #0f0;
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
}

/* ===== Full-screen Leaderboard Modal ===== */
.msi-game .lb-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  z-index: 30;
  padding: 48px 24px 24px;
  box-sizing: border-box;
  overflow-y: auto;
}

.msi-game .lb-modal.visible {
  display: flex;
}

.msi-game .lb-modal h2 {
  margin: 0 0 16px;
  font-size: 24px;
  text-align: center;
  color: #0f0;
  border-bottom: 2px solid #0f0;
  border-top: none;
  padding-bottom: 8px;
  padding-top: 0;
  width: 100%;
  max-width: 1200px;
}

.msi-game .lb-score-table {
  width: 100%;
  max-width: 1200px;
  margin-bottom: 72px;
  padding-bottom: 0;
}

.msi-game .lb-score-table h3 {
  margin: 0 0 32px;
  font-size: 24px;
  text-align: center;
  color: #0f0;
  font-family: 'Press Start 2P', monospace;
}

.msi-game .lb-score-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 32px 56px;
}

.msi-game .lb-score-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
}

.msi-game .lb-score-item img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.msi-game .lb-score-item .eq {
  opacity: 0.8;
}

.msi-game .lb-score-item .pts {
  min-width: 64px;
}

.msi-game .lb-modal .close-btn {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: #0f0;
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}

.msi-game .lb-modal-cols {
  display: flex;
  flex-direction: row;
  gap: 24px;
  width: 100%;
  max-width: 1200px;
  justify-content: center;
}

.msi-game .lb-modal-col {
  flex: 1;
  min-width: 240px;
}

.msi-game .lb-modal-entry {
  display: flex;
  justify-content: space-between;
  margin-bottom: 3px;
  font-size: 16px;
  padding: 2px 4px;
}

.msi-game .lb-modal-entry .rank {
  min-width: 32px;
  text-align: right;
}

.msi-game .lb-modal-entry .name {
  flex: 1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 12px;
}

.msi-game .lb-modal-entry .pts {
  min-width: 56px;
  text-align: right;
}

.msi-game .lb-modal-entry.you {
  color: #ff0;
  background: rgba(255, 255, 0, 0.08);
}
