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

:root {
  --bg: #0a0e17;
  --panel: #141b2d;
  --accent: #14f195;
  --gold: #fbbf24;
  --text: #e2e8f0;
  --muted: #94a3b8;
}

body {
  font-family: 'VT323', monospace;
  background: transparent;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#gameContainer {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

/* Header HUD */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(20, 27, 45, 0.92);
  border: 3px solid #000;
  border-bottom: none;
}

.back-link {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.45rem;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--accent);
}

.hud-stats {
  display: flex;
  gap: 1rem;
  font-size: 1.1rem;
}

.hud-item {
  white-space: nowrap;
}

.btn-mini {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.4rem;
  background: var(--accent);
  color: #000;
  border: 2px solid #000;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  box-shadow: 2px 2px 0 #000;
}

.btn-mini:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 #000;
}

.btn-help {
  background: var(--gold);
}

/* Live HUD */
.live-hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 0.35rem 0.5rem;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.2) 100%);
  pointer-events: none;
}

.live-quest {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.42rem;
  color: var(--accent);
  line-height: 1.6;
  margin-bottom: 0.25rem;
}

.live-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.action-hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  padding: 0.35rem 0.75rem;
  background: rgba(0, 0, 0, 0.8);
  border: 2px solid var(--accent);
  font-size: 1rem;
  color: var(--text);
  white-space: nowrap;
  max-width: 95%;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

/* Help panel */
.help-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 92%;
  max-width: 400px;
  max-height: 85%;
  overflow-y: auto;
  background: rgba(20, 27, 45, 0.98);
  border: 4px solid #000;
  box-shadow: 6px 6px 0 #000;
  z-index: 25;
}

.help-panel.hidden {
  display: none;
}

.help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 3px solid #000;
  background: rgba(0, 0, 0, 0.3);
}

.help-header h2 {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.55rem;
  color: var(--gold);
}

.help-body {
  padding: 1rem;
  font-size: 1.1rem;
  color: var(--muted);
}

.help-intro {
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

.help-steps {
  margin: 0 0 1rem 1.25rem;
  line-height: 1.5;
}

.help-steps kbd {
  display: inline-block;
  background: #000;
  border: 1px solid #555;
  padding: 0 0.25rem;
  font-family: 'Press Start 2P', cursive;
  font-size: 0.35rem;
}

.help-tools {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid #333;
}

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

.help-loop {
  font-size: 1rem;
  color: var(--text);
}

.help-loop em {
  color: var(--gold);
  font-style: normal;
}

/* Touch controls */
.touch-controls {
  display: none;
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 120px;
  height: 120px;
  z-index: 8;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 4px;
}

.touch-btn {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.5rem;
  background: rgba(20, 27, 45, 0.9);
  color: var(--text);
  border: 2px solid #000;
  box-shadow: 2px 2px 0 #000;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-btn:active {
  background: var(--accent);
  color: #000;
}

.touch-up { grid-column: 2; grid-row: 1; }
.touch-left { grid-column: 1; grid-row: 2; }
.touch-action {
  grid-column: 2;
  grid-row: 2;
  background: rgba(20, 241, 149, 0.25);
  color: var(--accent);
}
.touch-right { grid-column: 3; grid-row: 2; }
.touch-down { grid-column: 2; grid-row: 3; }

@media (pointer: coarse) {
  .touch-controls {
    display: grid;
  }

  .action-hint {
    bottom: 140px;
    white-space: normal;
    text-align: center;
  }
}

.game-socials {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.game-social-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.55rem;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid #000;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color 0.15s, background 0.15s;
  box-shadow: 2px 2px 0 #000;
}

.game-social-link:hover {
  color: var(--accent);
  background: rgba(20, 241, 149, 0.12);
}

.game-header .game-social-link {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.45rem;
  padding: 0.4rem 0.5rem;
}

.game-socials-footer {
  justify-content: center;
  margin-top: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.game-socials-overlay {
  justify-content: center;
  margin-top: 1.25rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Game canvas */
.game-wrapper {
  position: relative;
  border: 3px solid #000;
  background: #000;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  cursor: crosshair;
}

/* Message box */
.message-box {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.85);
  border: 3px solid var(--accent);
  padding: 1rem 1.5rem;
  font-size: 1.3rem;
  text-align: center;
  pointer-events: none;
  z-index: 10;
  animation: fadeIn 0.2s;
}

.message-box.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Shop panel */
.shop-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 360px;
  background: var(--panel);
  border: 4px solid #000;
  box-shadow: 6px 6px 0 #000;
  z-index: 20;
}

.shop-panel.hidden {
  display: none;
}

.shop-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 3px solid #000;
  background: rgba(0, 0, 0, 0.3);
}

.shop-header h2 {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.55rem;
}

.shop-items {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
}

.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid #333;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.shop-item:hover {
  border-color: var(--accent);
  background: rgba(74, 222, 128, 0.1);
}

.shop-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.shop-item-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.shop-item-icon {
  font-size: 1.5rem;
}

.shop-item-name {
  font-size: 1.2rem;
}

.shop-item-price {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.45rem;
  color: var(--gold);
}

/* Footer inventory */
.game-footer {
  background: rgba(20, 27, 45, 0.92);
  border: 3px solid #000;
  border-top: none;
  padding: 0.5rem 0.75rem;
}

.inventory {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  margin-bottom: 0.4rem;
}

.inv-slot {
  width: 48px;
  height: 48px;
  background: rgba(0, 0, 0, 0.4);
  border: 3px solid #444;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s;
}

.inv-slot.selected {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
}

.inv-slot .slot-icon {
  font-size: 1.3rem;
}

.inv-slot .slot-key {
  position: absolute;
  top: 1px;
  left: 3px;
  font-family: 'Press Start 2P', cursive;
  font-size: 0.35rem;
  color: var(--muted);
}

.inv-slot .slot-count {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 0.9rem;
  color: var(--gold);
}

.controls-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.controls-hint kbd {
  display: inline-block;
  background: #000;
  border: 1px solid #555;
  padding: 0 0.3rem;
  font-family: 'Press Start 2P', cursive;
  font-size: 0.35rem;
  margin-right: 0.2rem;
}

/* Start overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay.hidden {
  display: none;
}

.overlay-box {
  background: rgba(20, 27, 45, 0.95);
  border: 4px solid #000;
  box-shadow: 8px 8px 0 #000;
  padding: 2rem;
  max-width: 420px;
  text-align: center;
}

.overlay-box h1 {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.9rem;
  margin-bottom: 1rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.title-character {
  height: 56px;
  width: auto;
  image-rendering: pixelated;
  object-fit: contain;
}

.overlay-box p {
  font-size: 1.3rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.overlay-tagline {
  font-size: 1.15rem !important;
  margin-bottom: 1.25rem !important;
}

.how-to-play {
  text-align: left;
  margin-bottom: 1rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid rgba(20, 241, 149, 0.3);
}

.how-to-play h2 {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.5rem;
  color: var(--gold);
  margin-bottom: 0.75rem;
  text-align: center;
}

.overlay-tip {
  font-size: 1rem !important;
  color: var(--accent) !important;
  margin-bottom: 1rem !important;
}

.tutorial-list {
  list-style: none;
  margin-bottom: 0;
  font-size: 1.05rem;
  counter-reset: tut;
}

.tutorial-list li {
  margin-bottom: 0.5rem;
  padding-left: 1.5rem;
  position: relative;
  counter-increment: tut;
}

.tutorial-list li::before {
  content: counter(tut);
  position: absolute;
  left: 0;
  font-family: 'Press Start 2P', cursive;
  font-size: 0.4rem;
  color: #000;
  background: var(--accent);
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #000;
}

.tutorial-list kbd {
  display: inline-block;
  background: #000;
  border: 1px solid #555;
  padding: 0 0.3rem;
  font-family: 'Press Start 2P', cursive;
  font-size: 0.35rem;
}

.overlay-box {
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}

.btn-start {
  font-family: 'Press Start 2P', cursive;
  font-size: 0.65rem;
  background: var(--accent);
  color: #000;
  border: 3px solid #000;
  padding: 1rem 1.5rem;
  cursor: pointer;
  box-shadow: 4px 4px 0 #000;
}

.btn-start:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #000;
}

@media (max-width: 680px) {
  body {
    align-items: flex-start;
  }

  .game-header .game-socials {
    display: none;
  }

  .hud-stats {
    font-size: 0.95rem;
    gap: 0.5rem;
  }

  .inv-slot {
    width: 40px;
    height: 40px;
  }
}
