* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #1a1a2e;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  font-family: 'Courier New', monospace;
  color: #e0e0e0;
  overflow: hidden;
}

.game-wrapper { text-align: center; }

.main-layout {
  display: flex;
  align-items: flex-start;
  gap: 20px;
}

.game-column {
  flex-shrink: 0;
}

.side-column {
  flex-shrink: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
  background: linear-gradient(90deg, #00ff88, #00ccff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.score-board {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 15px;
  font-size: 1.2rem;
}

.score-board span {
  color: #00ff88;
  font-weight: bold;
}

.timer-area .lives-display {
  font-size: 1.8rem;
  letter-spacing: 5px;
  white-space: nowrap;
  line-height: 1;
  flex-shrink: 0;
}

.timer-area .lives-display span {
  color: #ff4444 !important;
  text-shadow: 0 0 10px rgba(255, 68, 68, 0.7);
  font-family: sans-serif;
}

/* Timer area (캔버스 바로 위) */
.timer-area {
  width: 606px;
  margin: 0 auto 6px auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.timer-bar-wrap {
  flex: 1;
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  overflow: hidden;
}

.timer-bar-fill {
  width: 100%;
  height: 100%;
  border-radius: 5px;
  background: #00ff88;
  transition: background 0.5s;
}

.timer-bar-fill.warning {
  background: #ffaa00;
  box-shadow: 0 0 8px rgba(255, 170, 0, 0.5);
}

.timer-bar-fill.danger {
  background: #ff4444;
  box-shadow: 0 0 10px rgba(255, 68, 68, 0.6);
  animation: barPulse 0.5s infinite;
}

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

.timer-display {
  color: #00ff88;
  font-weight: bold;
  font-size: 1.4rem;
  letter-spacing: 1px;
  white-space: nowrap;
  min-width: 80px;
  text-align: right;
  transition: color 0.3s, text-shadow 0.3s;
}

.timer-display.warning {
  color: #ffaa00;
  text-shadow: 0 0 8px rgba(255, 170, 0, 0.5);
}

.timer-display.danger {
  color: #ff4444;
  text-shadow: 0 0 12px rgba(255, 68, 68, 0.7);
  animation: timerBlink 0.5s infinite;
}

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

.canvas-container {
  position: relative;
  display: inline-block;
}

canvas {
  border: 3px solid #00ff88;
  border-radius: 8px;
  box-shadow: 0 0 30px rgba(0, 255, 136, 0.2);
  display: block;
  margin: 0 auto;
}

.info {
  margin-top: 6px;
  font-size: 0.8rem;
  color: #666;
}

/* Game Over Overlay */
.overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 10;
  display: none;
}

.overlay.active { display: block; }

.overlay h2 {
  font-size: 3rem;
  color: #ff4444;
  margin-bottom: 15px;
  text-shadow: 0 0 20px rgba(255, 68, 68, 0.5);
}

.overlay p {
  font-size: 1.3rem;
  color: #aaa;
}

.overlay .restart {
  margin-top: 20px;
  padding: 12px 30px;
  font-size: 1.1rem;
  background: #00ff88;
  color: #1a1a2e;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  font-family: 'Courier New', monospace;
  transition: background 0.2s;
}

.overlay .restart:hover { background: #00cc66; }

/* Start Overlay */
.start-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 10;
}

.start-overlay h2 {
  font-size: 2.5rem;
  color: #00ff88;
  margin-bottom: 20px;
  text-shadow: 0 0 20px rgba(0, 255, 136, 0.5);
}

.start-overlay p {
  font-size: 1.2rem;
  color: #aaa;
  margin-bottom: 10px;
}

.start-overlay .blink {
  animation: blink 1s infinite;
  font-size: 1.4rem;
  color: #00ccff;
  margin-top: 20px;
}

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

/* Leaderboard */
.leaderboard {
  background: rgba(0, 255, 136, 0.05);
  border: 1px solid rgba(0, 255, 136, 0.2);
  border-radius: 8px;
  padding: 15px 20px;
  width: 220px;
}

.leaderboard h3 {
  color: #00ff88;
  font-size: 1.2rem;
  margin-bottom: 10px;
}

.leaderboard table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard th {
  color: #00ccff;
  font-size: 0.85rem;
  padding: 5px 10px;
  border-bottom: 1px solid rgba(0, 255, 136, 0.2);
  text-align: left;
}

.leaderboard th:last-child { text-align: right; }

.leaderboard td {
  padding: 6px 10px;
  font-size: 0.9rem;
  color: #ccc;
}

.leaderboard td:first-child {
  color: #00ff88;
  font-weight: bold;
  width: 30px;
}

.leaderboard td:last-child {
  text-align: right;
  color: #ffd700;
  font-weight: bold;
}

.leaderboard tr.rank-1 td { color: #ffd700; }
.leaderboard tr.rank-2 td { color: #c0c0c0; }
.leaderboard tr.rank-3 td { color: #cd7f32; }
.leaderboard tr.highlight td { color: #00ff88; text-shadow: 0 0 8px rgba(0,255,136,0.5); }

/* ===== 모바일 대응 ===== */
@media (max-width: 900px) {
  body {
    display: block;
    align-items: initial;
    justify-content: initial;
    padding: 64px 8px 260px;
    height: auto !important;
    overflow-x: hidden;
  }

  .game-wrapper {
    width: 100%;
    max-width: 100%;
  }

  .main-layout {
    flex-direction: column;
    gap: 12px;
    width: 100%;
    align-items: stretch;
  }

  .game-column,
  .side-column {
    width: 100%;
    max-width: 100%;
    flex-shrink: 1;
    padding-top: 1px; /* prevent margin collapse with ancestors */
  }

  h1 {
    font-size: 1.6rem;
    margin-top: 4px;
    margin-bottom: 8px;
  }

  .score-board {
    gap: 16px;
    font-size: 1rem;
    margin-bottom: 10px;
    flex-wrap: wrap;
  }

  .timer-area {
    width: 100%;
    max-width: 100%;
    gap: 8px;
    padding: 0 4px;
  }

  .timer-display {
    font-size: 1.1rem;
    min-width: 56px;
  }

  .timer-area .lives-display {
    font-size: 1.3rem;
    letter-spacing: 3px;
  }

  .canvas-container {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  canvas {
    width: auto !important;
    height: auto !important;
    max-width: calc(100vw - 16px) !important;
    /* 상단 헤더/타이머 + 하단 컨트롤 영역(약 240px)을 제외한 높이로 제한 */
    max-height: calc(100vh - 360px) !important;
    aspect-ratio: 1 / 1;
    border-width: 2px;
  }

  .info {
    font-size: 0.7rem;
    padding: 0 8px;
    white-space: normal;
    word-break: keep-all;
  }

  .leaderboard {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 10px 14px;
  }

  .overlay h2,
  .start-overlay h2 {
    font-size: 1.8rem;
  }

  .overlay p,
  .start-overlay p {
    font-size: 0.95rem;
  }

  /* 모든 버튼을 한 줄로 정렬 */
  #mc-controls {
    align-items: flex-end;
    gap: 8px;
    padding: 10px 8px calc(env(safe-area-inset-bottom, 0px) + 10px);
  }

  #mc-controls .mc-dpad {
    display: flex;
    gap: 4px;
  }

  #mc-controls .mc-dpad .mc-btn {
    width: 48px;
    height: 48px;
    font-size: 16px;
    grid-column: auto !important;
    grid-row: auto !important;
  }

  #mc-controls .mc-dpad .mc-up    { order: 2; }
  #mc-controls .mc-dpad .mc-left  { order: 1; }
  #mc-controls .mc-dpad .mc-down  { order: 3; }
  #mc-controls .mc-dpad .mc-right { order: 4; }

  #mc-controls .mc-actions {
    display: flex;
    gap: 6px;
    align-items: flex-end;
  }

  #mc-controls .mc-actions .mc-btn {
    width: 56px;
    height: 48px;
    font-size: 13px;
  }
}
