* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: #2a3e24;
  font-family: "Press Start 2P", monospace;
  color: #f0ead8;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
  overflow-x: hidden;
}

/* ---- Layout ---- */

#game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

h1 {
  font-size: 20px;
  margin: 0 0 16px 0;
  text-align: center;
  letter-spacing: 3px;
  color: #e8c040;
  text-shadow: 2px 2px 0 #1a2a14;
}

#game-layout {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}

/* Spacer before canvas to push it to center, sidebar on right balances */
#game-layout::before {
  content: "";
  flex: 1;
}

/* ---- Canvas ---- */

#canvasContainer {
  flex-shrink: 0;
  max-width: 672px;
  width: 672px;
  line-height: 0;
}

#canvasContainer canvas {
  width: 100% !important;
  height: auto !important;
  display: block;
  touch-action: none;
  border: 2px solid #5a7a44;
  image-rendering: pixelated;
  max-width: 100%;
}

/* ---- Sidebar ---- */

#sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 180px;
  flex: 1;
  max-width: 220px;
  margin-left: 24px;
}

#score-panel {
  border: 2px solid #5a7a44;
  padding: 20px;
  background: #243820;
  position: relative;
}

/* pixel-art double border via inset shadow */
#score-panel::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid #7a9a64;
  pointer-events: none;
}

.stat-group {
  margin-bottom: 20px;
}

.stat-group:last-child {
  margin-bottom: 0;
}

.stat-label {
  font-size: 8px;
  color: #a09880;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 20px;
  line-height: 1.3;
  color: #f0ead8;
}

#controls-hint {
  border: 2px solid #4a6a38;
  padding: 16px;
  background: #223420;
}

.control-row {
  font-size: 8px;
  margin-bottom: 10px;
  color: #908878;
}

.control-row:last-child {
  margin-bottom: 0;
}

kbd {
  font-family: "Press Start 2P", monospace;
  background: #344a2e;
  border: 1px solid #5a7a44;
  border-bottom: 2px solid #4a6a38;
  padding: 3px 6px;
  font-size: 7px;
  margin-right: 4px;
  display: inline-block;
  min-width: 40px;
  text-align: center;
  color: #d8ccb4;
}

/* ---- Touch Controls ---- */

#touch-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 16px;
  padding: 16px 0;
  touch-action: none;
}

/* ---- Arrow Keys ---- */

#arrow-keys {
  display: flex;
  flex-direction: row;
  width: 100%;
  flex: 1;
  gap: 4px;
  touch-action: none;
}

.arrow-btn {
  font-size: 24px;
}

.arrow-btn.pressed {
  background: #3a5a32;
  border-color: #7a9a64;
}

#arrow-left,
#arrow-right {
  flex: 1;
}

#arrow-updown {
  flex: 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#arrow-updown .arrow-btn {
  flex: 1;
}

/* ---- Action Buttons ---- */

#touch-actions {
  display: flex;
  flex-direction: row;
  gap: 8px;
  width: 100%;
}

.touch-btn {
  font-family: "Press Start 2P", monospace;
  background: #243820;
  border: 2px solid #5a7a44;
  border-radius: 6px;
  color: #d8ccb4;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background 0.1s, border-color 0.1s;
}

.touch-btn:active {
  background: #3a5a32;
  border-color: #7a9a64;
}

.touch-action {
  flex: 1;
  height: 46px;
  font-size: 12px;
}

#touch-laser {
  border-color: #2a8830;
  color: #40dd50;
}

#touch-laser.ready {
  background: #2a8830;
  border-color: #40dd50;
  color: #fff;
}

#touch-laser:active {
  background: rgba(40, 200, 60, 0.15);
  border-color: #40cc48;
}

#touch-wall {
  border-color: #6a6050;
  color: #c0b098;
}

#touch-wall:active {
  background: rgba(120, 110, 96, 0.2);
  border-color: #8a7a66;
}

.touch-action.disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* ---- Animations ---- */

@keyframes flashTextGold {
  0% { color: #f0ead8; }
  50% { color: #e8c040; }
  100% { color: #f0ead8; }
}

.flashingTextGold {
  animation: flashTextGold 0.5s infinite;
}

/* ---- Mobile (< 900px) ---- */

@media (max-width: 900px) {
  body {
    padding: 10px;
    align-items: center;
  }

  #game-wrapper {
    min-height: 100vh;
    min-height: 100dvh;
    justify-content: flex-start;
  }

  h1 {
    font-size: 18px;
    margin-bottom: 10px;
    letter-spacing: 4px;
    width: 100%;
  }

  #game-layout {
    flex-direction: column;
    align-items: center;
    gap: 10px;
  }

  #game-layout::before {
    display: none;
  }

  #canvasContainer {
    width: 100%;
    max-width: 100%;
  }

  #sidebar {
    flex-direction: row;
    min-width: unset;
    width: 100%;
    max-width: 100%;
    gap: 10px;
    justify-content: center;
    margin-left: 0;
    flex: unset;
  }

  #score-panel {
    flex: 1;
    padding: 12px 16px;
    display: flex;
    gap: 24px;
    align-items: center;
    max-width: 100%;
  }

  .stat-group {
    margin-bottom: 0;
  }

  .stat-value {
    font-size: 16px;
  }

  .stat-label {
    font-size: 7px;
  }

  #controls-hint {
    display: none;
  }

  #touch-controls {
    display: flex;
    flex: 1;
    padding-bottom: 24px;
  }
}

/* ---- Small phones ---- */

@media (max-width: 420px) {
  body {
    padding: 6px;
  }

  h1 {
    font-size: 14px;
    margin-bottom: 8px;
    letter-spacing: 3px;
  }

  .touch-action {
    font-size: 10px;
    height: 40px;
  }

  .stat-value {
    font-size: 14px;
  }
}
