:root {
  --bg: #120a24;
  --ink: #f6eefe;
  --muted: #b9a7d6;
  --pink: #ff4fa3;
  --pink-soft: #ffb3c7;
  --purple: #8b3fd9;
  --deep: #2a1747;
  --gold: #ffd166;
  --green: #3ddc84;
  --red: #ff3b3b;
  --cyan: #8fd3ff;
  --panel: rgba(18, 8, 38, 0.78);
  --font: 'Press Start 2P', ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font);
  background: radial-gradient(ellipse at top, #3a1563 0%, var(--bg) 60%) fixed, var(--bg);
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

button { font-family: inherit; color: inherit; }

/* ---------- Game box ---------- */

#game {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  container-type: inline-size;
  overflow: hidden;
  background: #000;
  border: 4px solid #2c1a4d;
  box-shadow: 0 0 0 4px #000, 0 0 48px rgba(255, 79, 163, 0.35);
}

#game::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px);
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: max(7px, 1.05cqw);
  text-shadow: 0.2cqw 0.2cqw 0 #000;
}

.panel { position: absolute; top: 1.6cqw; width: 33cqw; }
.hero-panel { left: 1.6cqw; display: flex; gap: 1.2cqw; align-items: flex-start; }
.boss-panel { right: 1.6cqw; text-align: right; }
.panel-body { flex: 1; min-width: 0; }

#portrait {
  width: 7cqw;
  aspect-ratio: 16 / 13;
  border: 0.4cqw solid #fff;
  background: #4a7bd8;
  image-rendering: pixelated;
  box-shadow: 0.3cqw 0.3cqw 0 #000;
}

.name { font-size: 1.1em; white-space: nowrap; }
.tag { color: var(--gold); }
.sub { color: var(--muted); margin-top: 0.5em; }
#hero-title { font-size: 0.85em; }
.row { display: flex; justify-content: space-between; gap: 1em; margin-top: 0.5em; }
#hearts { color: var(--pink); letter-spacing: 0.15em; }
#guard { color: var(--cyan); }

.bar {
  position: relative;
  height: 1.7cqw;
  margin-top: 0.6cqw;
  border: 0.3cqw solid #fff;
  background: #2a0f1f;
  box-shadow: 0.3cqw 0.3cqw 0 #000;
}
.fill { position: absolute; inset: 0 auto 0 0; width: 100%; transition: width 0.35s steps(8); }
.fill.hp { background: linear-gradient(#9dffb6, #2fbf5b); }
.fill.boss { background: linear-gradient(#ff9a8a, #e0322a); }
.boss-panel .fill { inset: 0 0 0 auto; }

.intent { margin-top: 0.6em; color: var(--gold); }

.stage-title {
  position: absolute;
  top: 1.6cqw;
  left: 50%;
  transform: translateX(-50%);
  width: 26cqw;
  text-align: center;
}
.kicker { color: var(--pink); font-size: 1.1em; }
#stage-name { margin-top: 0.5em; font-size: 0.9em; color: var(--ink); }

/* ---------- Banner ---------- */

#banner {
  position: absolute;
  left: 0;
  right: 0;
  top: 38%;
  z-index: 10;
  padding: 1.6cqw 2cqw;
  text-align: center;
  line-height: 1.6;
  font-size: max(12px, 3cqw);
  color: var(--gold);
  text-shadow: 0.35cqw 0.35cqw 0 var(--pink), 0.7cqw 0.7cqw 0 #000;
  background: linear-gradient(90deg, transparent, rgba(18, 8, 38, 0.85) 20%, rgba(18, 8, 38, 0.85) 80%, transparent);
  pointer-events: none;
}
#banner.show { animation: pop 0.35s steps(4); }
@keyframes pop {
  from { transform: scale(1.8); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ---------- Screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2cqw;
  padding: 3cqw;
  overflow: auto;
  text-align: center;
  background: rgba(12, 5, 28, 0.72);
}

.screen h2 {
  margin: 0;
  font-size: max(12px, 2.6cqw);
  color: var(--gold);
  text-shadow: 0.3cqw 0.3cqw 0 var(--pink);
}

.hint { margin: 0; font-size: max(7px, 1.1cqw); color: var(--muted); }

#screen-title { justify-content: flex-end; padding: 0; background: #000; }
.title-art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.title-box {
  position: relative;
  width: 100%;
  padding: 6cqw 3cqw 4cqw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.6cqw;
  background: linear-gradient(to bottom, transparent, rgba(12, 5, 28, 0.92) 45%);
}
.title-box h1 {
  margin: 0;
  font-size: max(13px, 3.2cqw);
  line-height: 1.4;
  color: #fff;
  text-shadow: 0.35cqw 0.35cqw 0 var(--purple), 0.7cqw 0.7cqw 0 #000;
}
.title-box h1 span { color: var(--pink); }

.btn {
  padding: 1.2cqw 2.4cqw;
  font-size: max(10px, 1.7cqw);
  color: #fff;
  background: var(--pink);
  border: 0.4cqw solid #fff;
  box-shadow: 0.5cqw 0.5cqw 0 #000;
  cursor: pointer;
}
.btn:hover, .btn:focus-visible { background: var(--purple); outline: none; }
.btn.secondary { background: var(--deep); }
.blink { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

#end-text {
  max-width: 62ch;
  margin: 0;
  font-size: max(8px, 1.35cqw);
  line-height: 1.8;
}
#end-text b { color: var(--pink-soft); }
#end-actions { display: flex; flex-wrap: wrap; gap: 1.6cqw; justify-content: center; }

/* ---------- Hero select ---------- */

#hero-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1.2cqw;
  width: 100%;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8cqw;
  padding: 1.4cqw 0.8cqw;
  font-size: max(7px, 1cqw);
  line-height: 1.5;
  background: var(--panel);
  border: 0.35cqw solid var(--purple);
  box-shadow: 0.4cqw 0.4cqw 0 #000;
  cursor: pointer;
}
.card:hover, .card:focus-visible { border-color: var(--pink); transform: translateY(-0.4cqw); outline: none; }
.card canvas { width: 6cqw; aspect-ratio: 16 / 24; image-rendering: pixelated; }
.card .cname { font-size: 1.4em; color: #fff; }
.card .ctitle { color: var(--muted); min-height: 3em; }
.card .chp { color: var(--green); }
.card ul { margin: 0; padding: 0; list-style: none; color: var(--pink-soft); }
.card.chosen { border-color: var(--gold); }
.card .badge {
  position: absolute;
  top: -1cqw;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.3cqw 0.6cqw;
  white-space: nowrap;
  color: #000;
  background: var(--gold);
}

@container (max-width: 640px) {
  #hero-grid { grid-template-columns: repeat(3, 1fr); }
  .card { font-size: 8px; }
  .card canvas { width: 40px; }
  .card ul { display: none; }
}

/* ---------- Controls ---------- */

#controls { margin-top: 16px; }

#log {
  min-height: 7.4em;
  padding: 10px 12px;
  font-size: 10px;
  line-height: 1.7;
  background: var(--panel);
  border: 3px solid var(--deep);
}
#log p { margin: 0; color: var(--muted); }
#log p:last-child { color: var(--ink); }
#log b { color: var(--pink-soft); font-weight: normal; }

#moves {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.move {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "key name" "cost cost" "desc desc";
  gap: 6px 8px;
  align-items: center;
  padding: 10px;
  text-align: left;
  font-size: 10px;
  line-height: 1.5;
  background: var(--deep);
  border: 3px solid var(--purple);
  box-shadow: 4px 4px 0 #000;
  cursor: pointer;
}
.move:hover:not(:disabled), .move:focus-visible { border-color: var(--pink); outline: none; }
.move:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #000; }
.move:disabled { opacity: 0.4; cursor: not-allowed; }
.move .key { grid-area: key; color: #000; background: var(--gold); padding: 2px 5px; }
.move .mname { grid-area: name; color: #fff; }
.move .cost { grid-area: cost; color: var(--gold); }
.move .desc { grid-area: desc; color: var(--muted); font-size: 8px; }
.move.finisher { border-color: var(--gold); animation: glow 0.8s steps(2) infinite; }
@keyframes glow { 50% { box-shadow: 4px 4px 0 #000, 0 0 18px var(--gold); } }

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  font-size: 8px;
  color: var(--muted);
}
.link { padding: 0; font-size: 8px; color: var(--pink-soft); background: none; border: 0; cursor: pointer; }

@media (max-width: 700px) {
  #app { padding-inline: 16px; padding-block: 12px; }
  #moves { grid-template-columns: repeat(2, 1fr); }
  #log { font-size: 9px; }
}

/* Phones: the HUD sits below the scene, and tall screens grow the game box. */
@media (max-width: 700px) {
  #game { aspect-ratio: auto; }
  #stage { height: auto; aspect-ratio: 16 / 9; }

  #hud {
    position: static;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 8px;
    font-size: 8px;
    line-height: 1.5;
    background: var(--bg);
  }
  .panel, .stage-title { position: static; width: auto; min-width: 0; transform: none; }
  .stage-title { grid-column: 1 / -1; grid-row: 1; }
  .hero-panel { gap: 6px; }
  .name { white-space: normal; }
  #portrait { width: 28px; border-width: 2px; }
  .bar { height: 10px; margin-top: 4px; border-width: 2px; }
  .row { flex-wrap: wrap; gap: 4px; }

  #banner { top: 18cqw; }

  .card { padding-top: 14px; }
  .card .badge { top: -9px; padding: 2px 4px; font-size: 7px; }

  #screen-select:not([hidden]), #screen-end:not([hidden]) {
    position: relative;
    min-height: 56.25cqw;
    padding: 24px 8px;
    gap: 16px;
  }
  #game:has(#screen-select:not([hidden]), #screen-end:not([hidden])) #stage {
    position: absolute;
    inset: 0;
    height: 100%;
    object-fit: cover;
  }
}

@media (prefers-reduced-motion: reduce) {
  .blink, .move.finisher, #banner.show { animation: none; }
}
