/* ── Fonts ────────────────────────────────────────────────────────────────── */
@font-face {
  font-family: 'Movem';
  src: url('../assets/Movem.ttf') format('truetype');
  font-display: swap;
}

/* ── Design tokens ────────────────────────────────────────────────────────── */
:root {
  --hud-height: 70px;
  --top-bar-height: 48px;
  --brand-pink: #eb1588;
  --brand-dark: #ad0063;
  --hud-bg: #1a0011;
}

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

/* ── Base ─────────────────────────────────────────────────────────────────── */
body {
  background: #000;
  color: #fff;
  font-family: 'Movem', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  max-width: 100vw;
  max-height: 100vh;
}

/* ── Main menu ────────────────────────────────────────────────────────────── */
#menuScreen {
  background: url('../assets/MainMenu.png') center/cover no-repeat;
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* Credits block — bottom-left corner, matching Amiga reference style */
.menu-credits {
  position: absolute;
  bottom: 24px;
  left: 28px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-credit-row {
  font-family: 'Movem', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: clamp(10px, 1.3vw, 16px);
  letter-spacing: 1px;
  text-transform: uppercase;
  line-height: 1.4;
}

.credit-role {
  margin-right: 8px;
  background: linear-gradient(to bottom, #ff6ec7, #eb1588, #8a0050);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.credit-name {
  background: linear-gradient(to bottom, #ffffff, #dddddd, #aaaaaa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.menu-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.menu-title {
  font-size: clamp(48px, 10vw, 96px);
  color: #eb1588;
  text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
  letter-spacing: 4px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  font-family: 'Movem', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 20px;
  padding: 10px 32px;
  border: 3px solid #eb1588;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #eb1588;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  letter-spacing: 2px;
  text-transform: uppercase;
  min-width: 160px;
}

.btn:hover, .btn:focus {
  background: #eb1588;
  color: #000;
  outline: none;
}

.btn-small {
  font-size: 16px;
  padding: 6px 18px;
  min-width: 80px;
}

/* Play button using the original pixel-art asset */
.btn-img {
  background: transparent;
  border: none;
  padding: 0;
  min-width: 0;
  cursor: pointer;
  border-radius: 0;
}
.btn-img img {
  display: block;
  image-rendering: pixelated;
  width: clamp(128px, 20vw, 256px);
  height: auto;
}
.btn-img:hover img, .btn-img:focus img {
  filter: brightness(1.3);
  outline: none;
}

/* ── Game screen ──────────────────────────────────────────────────────────── */
#gameScreen {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  background: transparent;
}

/* ── Top controls bar ─────────────────────────────────────────────────────── */
#topControls {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  width: 100%;
  height: var(--top-bar-height);
  padding: 4px 12px;
  background: var(--hud-bg);
  border-bottom: 2px solid var(--brand-pink);
  flex-shrink: 0;
}

/* ── HUD ──────────────────────────────────────────────────────────────────── */
#hud {
  position: relative;
  width: 100%;
  height: var(--hud-height);
  /* Use the original HUD artwork as the bar background */
  background: url('../assets/HUD@2x.png') center/100% 100% no-repeat, var(--hud-bg);
  flex-shrink: 0;
}

/*
 * Each .hud-stat is absolutely positioned over its group of black digit boxes
 * (positions from the original Swift/iOS source):
 *   moves  digits: x=156–360 on a 1024px canvas → left≈15.2%, width≈20%
 *   pushes digits: x=537–741 on a 1024px canvas → left≈52.4%, width≈20%
 *   level  digits: x=920–1020 on a 1024px canvas → left≈89.8%, width≈10%
 * flex space-around distributes each child .hud-digit over its own box.
 */
.hud-stat {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
}

#hudMoves  { left: 13.7%; width: 20.3%; }
#hudPushes { left: 50.9%; width: 20.3%; }
#hudLevel  { left: 88.7%; width: 9.8%;  }

/* Hide the CSS text labels — the HUD image already renders MOVES/PUSHES/LEVEL */
.hud-label {
  display: none;
}

/*
 * One .hud-digit per black box.  Font fills the box (≈4.5vw on a 1024px
 * viewport) and uses a vertical gradient that goes from bright pink at the
 * top to deep pink at the bottom, matching the Amiga/Korge reference.
 */
.hud-digit {
  font-family: 'Movem', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: clamp(16px, 4.5vw, 54px);
  line-height: 1;
  text-align: center;

  /* Gradient text: bright pink → deep pink (top → bottom) */
  background: linear-gradient(to bottom, #ff6ec7 0%, #eb1588 45%, #8a0050 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;

  /* Black outline: a spread-radius drop-shadow gives a thin all-around edge */
  filter: drop-shadow(0 0 2px rgba(0,0,0,0.9));
}

/* ── Canvas wrapper ───────────────────────────────────────────────────────── */
#canvasWrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  width: 100%;
  max-width: 100vw;
}

#gameCanvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  max-width: 100%;
  max-height: calc(100vh - var(--hud-height) - var(--top-bar-height));
  object-fit: contain;
}
#selectScreen {
  width: 100vw;
  height: 100vh;
  background: transparent;
  overflow-y: auto;
  padding: 24px;
  gap: 16px;
}

.select-title {
  font-size: 36px;
  color: #eb1588;
  margin-bottom: 8px;
  letter-spacing: 3px;
}

#levelGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 640px;
}

.level-btn {
  font-family: 'Movem', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 18px;
  width: 56px;
  height: 56px;
  border: 2px solid #eb1588;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: #eb1588;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.level-btn:hover, .level-btn:focus {
  background: #eb1588;
  color: #000;
  outline: none;
}

/* ── Win screen ───────────────────────────────────────────────────────────── */
#winScreen {
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
}

.win-title {
  font-size: clamp(40px, 8vw, 80px);
  color: #ec8829;
  text-shadow: 2px 2px 0 #000;
  letter-spacing: 4px;
}

.win-info {
  font-size: 20px;
  color: #fff;
  text-align: center;
  line-height: 1.8;
}

.win-info span {
  color: #eb1588;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .btn {
    font-size: 16px;
    padding: 8px 20px;
    min-width: 120px;
  }
  /* Reduce font on narrow screens so digits still fit in their boxes */
  .hud-digit {
    font-size: clamp(10px, 2.5vw, 24px);
  }
}

/* ── Level select — completed levels ─────────────────────────────────────── */
.level-btn.completed {
  background: rgba(235, 21, 136, 0.22);
  border-color: #ff6ec7;
  color: #ff6ec7;
}

.level-btn.completed:hover,
.level-btn.completed:focus {
  background: #ff6ec7;
  color: #000;
}

/* ── Hi-Score screen ──────────────────────────────────────────────────────── */
#hiScoreScreen {
  width: 100vw;
  height: 100vh;
  background: transparent;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  gap: 0;
}

#starsCanvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

.hs-panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 28px 36px;
  background: rgba(0, 0, 0, 0.75);
  border: 2px solid rgba(255, 215, 0, 0.5);
  border-radius: 6px;
  max-width: 560px;
  width: 90vw;
  box-shadow: 0 0 40px rgba(255, 215, 0, 0.1), inset 0 0 20px rgba(255, 215, 0, 0.04);
}

.hs-screen-title {
  font-family: 'Movem', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: clamp(28px, 5vw, 52px);
  letter-spacing: 6px;
  text-align: center;
  margin-bottom: 8px;
  color: #cc7700;
  background: linear-gradient(to bottom, #ffd700, #cc7700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#hiScoreTable {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 220px;
}

.hs-level-title {
  font-family: 'Movem', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: clamp(22px, 4vw, 40px);
  letter-spacing: 4px;
  text-align: center;
  margin-bottom: 12px;
  background: linear-gradient(to bottom, #ffd700, #cc7700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hs-empty {
  font-family: 'Movem', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: clamp(13px, 2vw, 18px);
  color: rgba(255, 215, 0, 0.3);
  text-align: center;
  padding: 24px 0;
  letter-spacing: 2px;
}

.hs-row {
  display: flex;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 4px;
  border: 1px solid rgba(255, 215, 0, 0.2);
}

.hs-header {
  border-color: rgba(255, 215, 0, 0.6);
  margin-bottom: 4px;
}

.hs-completed {
  border-color: rgba(255, 215, 0, 0.35);
  background: rgba(255, 215, 0, 0.05);
}

.hs-col {
  font-family: 'Movem', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: clamp(12px, 1.6vw, 18px);
  letter-spacing: 1px;
}

.hs-rank {
  width: 28px;
  text-align: center;
  flex-shrink: 0;
  color: rgba(255, 215, 0, 0.5);
}

.hs-name {
  flex: 2;
  text-align: left;
  color: rgba(255, 255, 255, 0.4);
}

.hs-val {
  flex: 1;
  text-align: center;
  color: rgba(255, 255, 255, 0.4);
}

/* Header uses gold gradient */
.hs-header .hs-col {
  background: linear-gradient(to bottom, #ffd700, #cc7700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Completed row values — gold gradient */
.hs-completed .hs-rank {
  background: linear-gradient(to bottom, #ffd700, #cc7700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hs-completed .hs-name,
.hs-completed .hs-val {
  background: linear-gradient(to bottom, #ffffff, #dddddd, #aaaaaa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Navigation row */
.hs-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 8px;
}

.hs-nav-btn {
  font-size: clamp(11px, 1.4vw, 14px);
  padding: 6px 14px;
  min-width: 90px;
}

.hs-nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.hs-page-indicator {
  font-family: 'Movem', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: clamp(13px, 1.8vw, 18px);
  letter-spacing: 2px;
  background: linear-gradient(to bottom, #ffd700, #cc7700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  min-width: 70px;
  text-align: center;
}
