* {
  box-sizing: border-box;
}

:root {
  --bg: #0b1020;
  --panel: #11182d;
  --border: #d8d8d8;
  --text: #f4f4f4;
  --accent: #ffdc4a;
  --danger: #ff4f64;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, #18203d 0%, #0b1020 42%, #05070d 100%);
  color: var(--text);
  font-family: "Courier New", monospace;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  image-rendering: pixelated;
}

button {
  font: inherit;
}

#app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.screen {
  display: none;
  width: 100%;
  text-align: center;
}

.screen.active {
  display: block;
}

#titleScreen,
#scoreScreen,
#gameOverScreen {
  max-width: 680px;
}

.logo {
  font-size: clamp(54px, 11vw, 100px);
  line-height: 0.82;
  font-weight: 900;
  letter-spacing: -6px;
  color: white;
  text-shadow:
    5px 5px 0 #315bd6,
    10px 10px 0 #d23232;
  margin-bottom: 22px;
}

.logo span {
  color: var(--accent);
}

.subtitle {
  letter-spacing: 5px;
  margin-bottom: 34px;
  opacity: 0.85;
}

.menu-btn,
.small-btn {
  border: 4px solid white;
  background: #111;
  color: white;
  cursor: pointer;
  text-transform: uppercase;
  box-shadow: 5px 5px 0 #000;
}

.menu-btn {
  display: block;
  width: min(420px, 90%);
  margin: 14px auto;
  padding: 15px 18px;
  font-size: 26px;
}

.menu-btn:hover,
.menu-btn.selected {
  background: white;
  color: black;
}

.controls-help {
  margin: 34px auto 0;
  max-width: 420px;
  border-top: 3px solid rgba(255,255,255,0.2);
  padding-top: 22px;
  line-height: 1.8;
  opacity: 0.8;
}

.game-wrap {
  display: grid;
  grid-template-columns: 150px auto 150px;
  gap: 16px;
  justify-content: center;
  align-items: start;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-box {
  background: var(--panel);
  border: 4px solid var(--border);
  padding: 12px 8px;
  box-shadow: 5px 5px 0 #000;
  min-height: 76px;
}

.panel-title {
  color: var(--accent);
  font-size: 14px;
  margin-bottom: 8px;
}

.board-wrap {
  position: relative;
  border: 5px solid white;
  box-shadow: 8px 8px 0 #000;
  background: #050505;
}

#gameCanvas {
  display: block;
  width: 300px;
  height: 600px;
  background: #050505;
}

#nextCanvas {
  width: 120px;
  height: 120px;
  background: #080808;
}

#effectOverlay,
#messageOverlay {
  pointer-events: none;
  position: absolute;
  inset: 0;
}

#effectOverlay.blackout {
  background: rgba(0,0,0,0.96);
}

#messageOverlay {
  display: grid;
  place-items: center;
  font-size: 30px;
  font-weight: 900;
  text-shadow: 3px 3px 0 #000;
  white-space: pre-line;
}

.status-box {
  min-height: 105px;
}

#effectStatus {
  font-size: 13px;
  line-height: 1.45;
}

.small-btn {
  padding: 10px;
  margin-top: 4px;
}

.score-card {
  max-width: 420px;
  margin: 18px auto;
  padding: 20px;
  border: 4px solid white;
  background: #111;
}

.score-card strong,
.final-score strong {
  display: block;
  margin-top: 8px;
  font-size: 36px;
  color: var(--accent);
}

.final-score {
  margin: 28px auto;
}

#finalStats {
  margin-bottom: 24px;
  line-height: 1.8;
}

.shake {
  animation: shake 0.35s steps(2, end);
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-12px); }
  50% { transform: translateX(12px); }
  75% { transform: translateX(-8px); }
  100% { transform: translateX(0); }
}

@media (max-width: 760px) {
  #app {
    padding: 8px;
  }

  .game-wrap {
    grid-template-columns: 90px auto 90px;
    gap: 6px;
  }

  #gameCanvas {
    width: 240px;
    height: 480px;
  }

  .panel-box {
    padding: 8px 4px;
    font-size: 12px;
  }

  #nextCanvas {
    width: 80px;
    height: 80px;
  }

  .small-btn {
    font-size: 12px;
  }
}

@media (max-width: 470px) {
  .game-wrap {
    transform: scale(0.82);
    transform-origin: top center;
    width: 122%;
    margin-left: -11%;
  }
}

/* EXTREME MODE CHAOS */
.board-wrap.shake {
  animation: chaosShake .32s steps(2,end);
}
@keyframes chaosShake {
  0% { transform: translate(0,0) rotate(0deg); }
  20% { transform: translate(-9px,5px) rotate(-1deg); }
  40% { transform: translate(10px,-4px) rotate(1deg); }
  60% { transform: translate(-7px,-3px) rotate(0deg); }
  80% { transform: translate(8px,4px) rotate(1deg); }
  100% { transform: translate(0,0) rotate(0deg); }
}
