* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #080d18;
  color: #fff8d3;
  font-family: Arial, Helvetica, sans-serif;
  touch-action: none;
}

#shell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 20%, rgba(246, 220, 117, 0.15), transparent 34%),
    linear-gradient(180deg, #101927, #060911);
}

canvas {
  /* Reserve a vertical band so the fixed HUD (top) and touch D-pad (bottom)
     never cover playable maze tiles (BUG-005). The board stays 3:2 and centred. */
  --chrome-band: 100px;
  width: min(100vw, calc((100vh - var(--chrome-band)) * 1.5));
  height: min(calc(100vh - var(--chrome-band)), calc(100vw / 1.5));
  max-width: 100vw;
  max-height: calc(100vh - var(--chrome-band));
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(740px, calc(100vw - 24px));
  max-height: calc(100vh - 30px);
  overflow-y: auto;
  transform: translate(-50%, -50%);
  padding: 22px;
  border: 2px solid rgba(246, 220, 117, 0.55);
  border-radius: 12px;
  background: rgba(8, 13, 24, 0.96);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
  text-align: center;
  z-index: 20;
}

.hidden {
  display: none !important;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 5.5vw, 52px);
  color: #ffd166;
  text-shadow: 0 0 16px rgba(255, 209, 102, 0.4);
}

h2 {
  font-size: clamp(22px, 4.5vw, 34px);
  color: #64dfdf;
}

p {
  margin: 8px 0;
  font-weight: 700;
}

.hero-preview-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 10px 0 14px;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(255, 209, 102, 0.08);
  border: 1px dashed rgba(255, 209, 102, 0.35);
  text-align: left;
}

.hero-preview-row img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(255, 209, 102, 0.4));
  flex-shrink: 0;
}

.hero-preview-row .hero-trait {
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  font-size: 14px;
  color: #ffe8a1;
}

.pickers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.full-width-picker {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 6px;
  text-align: left;
  font-weight: 800;
  font-size: 14px;
}

select,
button {
  min-height: 44px;
  border: 2px solid rgba(255, 248, 211, 0.52);
  border-radius: 8px;
  background: #f6dc75;
  color: #101927;
  font: 800 16px Arial, Helvetica, sans-serif;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

select:hover,
button:hover {
  background: #ffea8a;
  transform: translateY(-1px);
}

select:active,
button:active {
  transform: translateY(1px);
  box-shadow: 0 0 12px rgba(100, 223, 223, 0.6);
}

select {
  padding: 0 12px;
  background: #101927;
  color: #fff8d3;
}

.btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* Keep the primary action reachable when the menu scrolls (BUG-004):
   pin the Start / Guide / language row to the bottom of the scrolling panel. */
#menu.panel {
  display: flex;
  flex-direction: column;
}

#menu .btn-row {
  position: sticky;
  bottom: -1px;
  padding: 10px 0 4px;
  background: rgba(8, 13, 24, 0.97);
  box-shadow: 0 -10px 18px 6px rgba(8, 13, 24, 0.95);
  z-index: 3;
}

.btn-secondary {
  background: #48cae4;
  color: #080d18;
}

.btn-secondary:hover {
  background: #64dfdf;
}

.btn-help {
  background: #ff9f1c;
  color: #080d18;
}

.btn-help:hover {
  background: #ffb703;
}

.power-guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin: 16px 0;
  text-align: left;
}

.power-card {
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(246, 220, 117, 0.3);
}

.power-card h3 {
  font-size: 15px;
  color: #ffd166;
  margin-bottom: 6px;
}

.power-card p {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  margin: 0;
  color: rgba(255, 248, 211, 0.9);
}

.power-card .danger-warning {
  margin-top: 6px;
  color: #ff6b6b;
  font-weight: 800;
  font-size: 12px;
}

.message-stats-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin: 14px 0;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 215, 0, 0.08);
  border: 1px solid rgba(255, 215, 0, 0.3);
  text-align: center;
}

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

.stat-value {
  font-size: 18px;
  font-weight: 900;
  color: #ffd166;
}

.stat-label {
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 248, 211, 0.75);
  text-transform: uppercase;
}

.help,
.credits {
  font-size: 12px;
  line-height: 1.45;
  color: rgba(255, 248, 211, 0.82);
  margin-top: 12px;
}

.credits {
  padding-top: 10px;
  border-top: 1px solid rgba(246, 220, 117, 0.25);
  color: rgba(255, 248, 211, 0.72);
  font-weight: 600;
  text-align: center;
}

.credits-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 16px;
  padding: 14px 16px;
  border-radius: 10px;
  background: rgba(255, 215, 0, 0.05);
  border: 1px solid rgba(246, 220, 117, 0.35);
  text-align: left;
}

.credit-row {
  font-size: 13px;
  line-height: 1.45;
  color: rgba(255, 248, 211, 0.9);
}

.credit-row strong {
  color: #ffd166;
}

.credit-row.legacy-note {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid rgba(246, 220, 117, 0.18);
  font-size: 11.5px;
  color: rgba(255, 248, 211, 0.65);
  font-style: italic;
}

.high-score-badge {
  display: inline-block;
  margin: 4px 0 10px;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255, 215, 0, 0.18);
  border: 1px solid #ffd700;
  font-weight: 900;
  color: #ffd700;
  font-size: 14px;
}

#hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  pointer-events: none;
  z-index: 10;
}

#hud span,
#hud button {
  padding: 6px 12px;
  border: 1px solid rgba(246, 220, 117, 0.42);
  border-radius: 8px;
  background: rgba(8, 13, 24, 0.82);
  font-weight: 900;
  font-size: 14px;
  color: #fff8d3;
  white-space: nowrap;
}

#hud .boss-hud {
  background: rgba(255, 92, 138, 0.25);
  border-color: #ff5c8a;
  color: #ffd166;
  box-shadow: 0 0 12px rgba(255, 92, 138, 0.5);
  animation: pulse-boss 1.2s infinite ease-in-out;
}

@keyframes pulse-boss {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

#hud button {
  pointer-events: auto;
  min-height: auto;
  padding: 6px 12px;
  background: #2a3b5c;
  border-color: #64dfdf;
  color: #64dfdf;
  cursor: pointer;
}

#auraHud {
  background: rgba(100, 223, 223, 0.28) !important;
  border-color: #64dfdf !important;
  color: #64dfdf !important;
  font-weight: 900;
  animation: auraPulse 0.8s infinite alternate ease-in-out;
}

.low-life {
  background: rgba(255, 77, 77, 0.3) !important;
  border-color: #ff4d4d !important;
  color: #ff6b6b !important;
  animation: lowLifePulse 0.6s infinite alternate ease-in-out;
}

@keyframes auraPulse {
  from { box-shadow: 0 0 6px rgba(100, 223, 223, 0.4); transform: scale(1); }
  to { box-shadow: 0 0 16px rgba(100, 223, 223, 0.9); transform: scale(1.04); }
}

@keyframes lowLifePulse {
  from { box-shadow: 0 0 4px rgba(255, 77, 77, 0.4); }
  to { box-shadow: 0 0 14px rgba(255, 77, 77, 0.95); }
}

#touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: none;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  padding: 0 10px;
  z-index: 10;
}

#touch button {
  min-height: 52px;
  opacity: 0.92;
  font-size: 22px;
}

#touch button:active,
#touch button.active-touch {
  background: #64dfdf;
  border-color: #ffffff;
  color: #080d18;
  transform: scale(0.96);
  box-shadow: 0 0 14px rgba(100, 223, 223, 0.8);
}

@media (max-width: 760px), (pointer: coarse) {
  #touch {
    display: grid;
  }

  #hud {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .pickers {
    grid-template-columns: 1fr;
  }
}


/* Kid-Friendly Compact Square Cards with 100% Grid Visibility */
.panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(720px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  transform: translate(-50%, -50%);
  padding: 14px 16px;
  border: 2px solid rgba(246, 220, 117, 0.55);
  border-radius: 12px;
  background: rgba(8, 13, 24, 0.97);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.7);
  text-align: center;
  z-index: 20;
}

.visual-pickers {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 10px;
}

.visual-section {
  text-align: left;
}

.visual-title {
  font-size: 13px;
  font-weight: 900;
  color: #ffd166;
  margin-bottom: 4px;
  text-shadow: 0 0 8px rgba(255, 209, 102, 0.3);
}

.card-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0 4px;
  justify-content: flex-start;
}

.img-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  width: 52px;
  height: 60px;
  padding: 2px 1px;
  border-radius: 8px;
  background: rgba(16, 25, 43, 0.9);
  border: 1.5px solid rgba(255, 248, 211, 0.25);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.12s ease, background 0.12s ease, box-shadow 0.15s ease;
}

.img-card img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6));
  pointer-events: none;
}

.img-card .card-icon {
  font-size: 24px;
  line-height: 32px;
  pointer-events: none;
}

.img-card .card-label {
  font-size: 9px;
  font-weight: 800;
  color: #fff8d3;
  margin-top: 2px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 48px;
  pointer-events: none;
}

.img-card .card-sub {
  font-size: 8px;
  font-weight: 700;
  color: #64dfdf;
  margin-top: 1px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 58px;
  pointer-events: none;
}

.img-card .card-badge {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: 8px;
  font-weight: 900;
  background: rgba(0, 0, 0, 0.75);
  color: #ffd166;
  padding: 1px 3px;
  border-radius: 4px;
  border: 1px solid rgba(255, 209, 102, 0.4);
  pointer-events: none;
}

.img-card:hover {
  transform: translateY(-2px) scale(1.06);
  border-color: rgba(255, 209, 102, 0.8);
  background: rgba(255, 209, 102, 0.18);
}

.img-card:active {
  transform: scale(0.95);
}

.img-card.selected {
  border: 2.5px solid #ffd166;
  background: radial-gradient(circle at 50% 40%, rgba(255, 209, 102, 0.35), rgba(16, 25, 43, 0.95));
  box-shadow: 0 0 14px rgba(255, 209, 102, 0.7), 0 2px 8px rgba(0, 0, 0, 0.6);
  transform: scale(1.08);
}

.img-card.world-card {
  min-width: 62px;
  width: 62px;
  height: 68px;
  padding: 2px;
}

.img-card.world-card img {
  width: 32px;
  height: 32px;
}

.hero-preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 10px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 209, 102, 0.08);
  border: 1px dashed rgba(255, 209, 102, 0.35);
  text-align: left;
}

.hero-preview-row img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(255, 209, 102, 0.4));
  flex-shrink: 0;
}

.hero-preview-row .hero-trait {
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  font-size: 13px;
  color: #ffe8a1;
}

#startButton {
  font-size: 18px;
  font-weight: 900;
  min-height: 46px;
  padding: 0 24px;
  background: linear-gradient(180deg, #ffd166, #ffb703);
  color: #080d18;
  border: 2px solid #fff8d3;
  box-shadow: 0 4px 16px rgba(255, 209, 102, 0.4);
  letter-spacing: 0.5px;
}

#startButton:hover {
  background: linear-gradient(180deg, #ffe082, #ffc107);
  box-shadow: 0 0 24px rgba(255, 209, 102, 0.7);
}

/* Hero Powers Guide & In-Game Button Styles */
.hero-powers-guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
  text-align: left;
}

.hero-power-item {
  background: rgba(16, 25, 43, 0.85);
  border: 1px solid rgba(255, 209, 102, 0.35);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: #fff8d3;
}

.hero-power-item strong {
  color: #ffd166;
}

.hero-power-item em {
  color: #64dfdf;
  font-style: normal;
  font-weight: bold;
}

#specialHud {
  color: #ffd166;
  font-weight: 900;
  text-shadow: 0 0 8px rgba(255, 209, 102, 0.5);
  transition: transform 0.2s ease, color 0.2s ease;
}

#specialHud.ready {
  color: #06d6a0;
  transform: scale(1.08);
  text-shadow: 0 0 12px rgba(6, 214, 160, 0.8);
}

#specialTouch {
  background: linear-gradient(180deg, #ffd166, #ffb703);
  color: #080d18;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 0 12px rgba(255, 209, 102, 0.4);
}

#specialTouch:active {
  transform: scale(0.92);
  box-shadow: 0 0 20px rgba(255, 209, 102, 0.8);
}
