* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0d0d1a;
  font-family: 'Press Start 2P', monospace;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  position: absolute;
  top: 0;
  left: 0;
}

#ui-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

#ui-overlay > * {
  pointer-events: auto;
}

.pixel-btn {
  font-family: 'Press Start 2P', monospace;
  background: #2d1b69;
  color: #e0d0ff;
  border: 3px solid #7c5cbf;
  padding: 12px 24px;
  font-size: 11px;
  cursor: pointer;
  position: relative;
  box-shadow: 0 4px 0 #1a0f3d, inset 0 1px 0 rgba(255,255,255,0.1);
  transition: transform 0.05s, box-shadow 0.05s;
  text-transform: uppercase;
  letter-spacing: 1px;
  image-rendering: pixelated;
}

.pixel-btn:hover {
  background: #3d2b89;
  border-color: #9c7cdf;
}

.pixel-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1a0f3d;
}

.pixel-btn.primary {
  background: #1a6b3c;
  border-color: #3cdf7f;
  color: #c0ffd8;
  box-shadow: 0 4px 0 #0d3520, inset 0 1px 0 rgba(255,255,255,0.15);
  font-size: 13px;
  padding: 16px 32px;
}

.pixel-btn.primary:hover {
  background: #2a8b5c;
}

.pixel-btn.small {
  padding: 6px 12px;
  font-size: 8px;
}

.pixel-btn.danger {
  background: #6b1a2a;
  border-color: #df3c5f;
  color: #ffc0cc;
  box-shadow: 0 4px 0 #350d15;
}

.diff-btn {
  font-family: 'Press Start 2P', monospace;
  background: transparent;
  color: #8888aa;
  border: 2px solid #333355;
  padding: 8px 16px;
  font-size: 9px;
  cursor: pointer;
  transition: all 0.15s;
}

.diff-btn.active {
  color: #ffcc00;
  border-color: #ffcc00;
  background: rgba(255, 204, 0, 0.1);
  box-shadow: 0 0 12px rgba(255, 204, 0, 0.2);
}

.diff-btn:hover {
  color: #bbbbdd;
  border-color: #555577;
}

.title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 20px;
  padding: 20px;
}

.title-main {
  font-size: clamp(14px, 4vw, 28px);
  color: #ffcc00;
  text-shadow: 0 0 20px rgba(255, 204, 0, 0.4), 2px 2px 0 #664400;
  text-align: center;
  line-height: 1.6;
  animation: titlePulse 3s ease-in-out infinite;
}

@keyframes titlePulse {
  0%, 100% { text-shadow: 0 0 20px rgba(255, 204, 0, 0.4), 2px 2px 0 #664400; }
  50% { text-shadow: 0 0 40px rgba(255, 204, 0, 0.7), 2px 2px 0 #664400; }
}

.title-sub {
  font-size: clamp(8px, 2vw, 12px);
  color: #7c5cbf;
  letter-spacing: 3px;
}

.stats-display {
  color: #556677;
  font-size: 8px;
  text-align: center;
  line-height: 2;
}

.game-hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: linear-gradient(180deg, rgba(13,13,26,0.95) 0%, rgba(13,13,26,0.7) 80%, transparent 100%);
  z-index: 20;
}

.hud-item {
  color: #8888aa;
  font-size: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.hud-value {
  color: #e0d0ff;
  font-size: 11px;
}

.hud-value.gold { color: #ffcc00; }

.bottom-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 12px;
  gap: 8px;
  background: linear-gradient(0deg, rgba(13,13,26,0.95) 0%, rgba(13,13,26,0.7) 80%, transparent 100%);
  z-index: 20;
}

.completion-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(13, 13, 26, 0.92);
  z-index: 30;
  gap: 16px;
  padding: 20px;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.stars-display {
  font-size: 32px;
  letter-spacing: 8px;
  animation: starsIn 0.8s ease;
}

@keyframes starsIn {
  from { transform: scale(0) rotate(-180deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

.completion-stats {
  color: #8888aa;
  font-size: 8px;
  text-align: center;
  line-height: 2.5;
}

.completion-quote {
  color: #7c5cbf;
  font-size: 8px;
  text-align: center;
  max-width: 400px;
  line-height: 1.8;
  font-style: italic;
}

.menu-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(13, 13, 26, 0.95);
  z-index: 40;
  gap: 16px;
}

.loading-text {
  color: #7c5cbf;
  font-size: 10px;
  animation: loadPulse 1s ease-in-out infinite;
}

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

.footer-link {
  position: absolute;
  bottom: 4px;
  right: 8px;
  z-index: 5;
}

.footer-link a {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: #333355;
  text-decoration: none;
}

.footer-link a:hover {
  color: #555577;
}

/* ========================
   GALLERY STYLES
   ======================== */
.gallery-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: rgba(13, 13, 26, 0.97);
  z-index: 30;
  animation: fadeIn 0.3s ease;
  overflow: hidden;
}

.gallery-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  gap: 8px;
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(13,13,26,1) 0%, rgba(13,13,26,0.9) 100%);
  border-bottom: 1px solid #222244;
}

.gallery-subtitle {
  text-align: center;
  color: #556677;
  font-size: 7px;
  font-family: 'Press Start 2P', monospace;
  padding: 6px 0 2px;
  flex-shrink: 0;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  padding: 12px 16px 60px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 600px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    padding: 16px 24px 60px;
  }
}

@media (min-width: 1000px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    padding: 20px 40px 60px;
  }
}

.gallery-item {
  background: #12122a;
  border: 2px solid #222244;
  border-radius: 4px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
  cursor: default;
  position: relative;
}

.gallery-item:hover {
  border-color: #7c5cbf;
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(124, 92, 191, 0.25);
}

.gallery-thumb {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  border-radius: 2px;
  background: #0a0a15;
}

.gallery-item-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #c0b0e0;
  text-align: center;
  line-height: 1.5;
}

.gallery-item-num {
  font-family: 'Press Start 2P', monospace;
  font-size: 6px;
  color: #444466;
}

.gallery-dl-btn {
  font-size: 7px !important;
  padding: 4px 8px !important;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.gallery-item:hover .gallery-dl-btn {
  opacity: 1;
}

.ref-toggle {
  position: absolute;
  z-index: 25;
  cursor: pointer;
  border: 2px solid #333355;
  border-radius: 2px;
  opacity: 0.85;
  transition: opacity 0.2s;
  image-rendering: pixelated;
}

.ref-toggle:hover {
  opacity: 1;
  border-color: #7c5cbf;
}

.zen-label {
  color: #556677;
  font-size: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.zen-check {
  width: 14px;
  height: 14px;
  accent-color: #7c5cbf;
}