:root {
  --bg: #0f380f;
  --fg: #9bbc0f;
  --ui: #306230;
  --ui-accent: #8bac0f;
  --text-on-bg: #9bbc0f;
  --text-on-ui: #9bbc0f;
  --text-on-accent: #0f380f;
  --bar-track: #306230;
  --bar-fill: #8bac0f;
  --border: #306230;
  --title: #8bac0f;
  --speed: #306230;
  --bubble-text: #0f380f;
  --bubble-bg: #9bbc0f;
}

:root.purple {
  --bg: #2d1261;
  --fg: #9b6eff;
  --ui: #4a1ab5;
  --ui-accent: #6d2ee2;
  --text-on-bg: #9b6eff;
  --text-on-ui: #9b6eff;
  --text-on-accent: #2d1261;
  --bar-track: #4a1ab5;
  --bar-fill: #6d2ee2;
  --border: #4a1ab5;
  --title: #6d2ee2;
  --speed: #4a1ab5;
  --bubble-text: #2d1261;
  --bubble-bg: #9b6eff;
}

@keyframes psychedelic {
  0%   { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

#app.psychedelic {
  animation: psychedelic 2s linear infinite;
}

#app.psychedelic #game-canvas {
  animation: psychedelic 2s linear infinite;
}

@font-face {
  font-family: 'Press Start 2P';
  src: url('../assets/fonts/PressStart2P-Regular.ttf') format('truetype');
}

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

html, body {
  height: 100%;
  height: -webkit-fill-available;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Press Start 2P', monospace;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 10px 14px;
  gap: 6px;
}

#title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 5vh;
  flex-shrink: 0;
}

#title-text {
  font-size: 18px;
  letter-spacing: 4px;
  color: var(--title);
  text-transform: uppercase;
  line-height: 1.4;
  cursor: pointer;
}

#speed-display {
  font-size: 18px;
  color: var(--speed);
  cursor: pointer;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#stats-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  padding: 4px 0;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.s-label {
  font-size: 8px;
  color: var(--fg);
  letter-spacing: 1px;
  text-align: left;
}

.s-track {
  width: 100%;
  height: 10px;
  background: var(--bar-track);
  overflow: hidden;
}

.s-fill {
  height: 100%;
  background: var(--bar-fill);
  width: 100%;
  transition: width 0.3s;
}

#game-area {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

#bubble {
  position: absolute;
  top: 35px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Press Start 2P', monospace;
  font-size: 16px;
  color: var(--bubble-text);
  text-align: center;
  white-space: nowrap;
  z-index: 1;
  display: none;
  pointer-events: none;
}

#bubble.sleep {
  font-size: 12px;
}

#game-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: 100%;
  aspect-ratio: 160 / 160;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 2px solid var(--border);
}

#action-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  width: 100%;
  flex-shrink: 0;
}

.action-btn {
  position: relative;
  background: var(--ui);
  color: var(--text-on-ui);
  border: none;
  padding: 10px 2px;
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  letter-spacing: 1px;
  cursor: pointer;
  text-transform: uppercase;
  min-height: 60px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.action-btn:active,
.action-btn.pressed {
  background: var(--ui-accent);
  color: var(--text-on-accent);
  transform: scale(0.95);
}

.action-btn:disabled {
  opacity: 0.3;
  cursor: default;
  transform: none;
}

@media (min-width: 480px) {
  #app {
    padding: 16px 20px;
    gap: 8px;
  }

  #title-text, #speed-display {
  font-size: 16px;
  }
}

@media (max-height: 640px) {
  #app {
    padding: 4px 6px;
    gap: 4px;
  }

  #title-text, #speed-display {
    font-size: 10px;
  }

  .s-label {
    font-size: 6px;
  }

  .s-track {
    height: 8px;
  }

  .action-btn {
    padding: 6px 2px;
    font-size: 9px;
    min-height: 32px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  #app {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 4px;
  }

  #title-bar {
    width: 100%;
  }

  #game-area {
    width: 55%;
    max-width: 320px;
  }

  #action-bar {
    width: 42%;
    align-self: center;
  }
}
