:root {
  --bg: #0f0a1c;
  --ink: #f6f1ff;
  --mute: #a99cc4;
  --gold: #ffd447;
  --red: #e0312b;
  --cyan: #52e0ff;
  --panel: #2a1d40;
  --panel2: #3a2858;
  --edge: #07040d;
  --k: 2;
  --bs: clamp(54px, 12.5vmin, 78px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Pixelify Sans', 'Courier New', monospace;
}

body {
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(ellipse 80% 50% at 50% -8%, #3d1f63 0%, transparent 70%),
    radial-gradient(ellipse 70% 40% at 50% 112%, #4a0f1c 0%, transparent 70%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0 2px, transparent 2px 4px),
    var(--bg);
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* header */
.top {
  width: 100%;
  height: 46px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
}
.top h1 {
  margin: 0;
  font-family: 'Silkscreen', monospace;
  font-size: clamp(13px, 3.4vw, 18px);
  letter-spacing: .04em;
  color: var(--gold);
  text-shadow: 2px 2px 0 #8a2a10;
  white-space: nowrap;
}
.back {
  color: var(--mute);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
.back:hover { color: var(--ink); }
.mute {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--panel);
  border: 2px solid #000;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 #000;
}
.mute svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.mute svg path:first-child { fill: currentColor; }
.mute[aria-pressed="true"] { color: var(--mute); }
.mute[aria-pressed="true"] .wave { opacity: 0; }

/* stage */
#stage {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  position: relative;
}
#screen {
  position: relative;
  width: calc(320px * var(--k));
  height: calc(180px * var(--k));
  flex: none;
  border-radius: 4px;
  box-shadow: 0 0 0 3px #000, 0 0 0 7px var(--panel2), 0 0 0 10px #000, 0 24px 60px rgba(0,0,0,.65);
  cursor: pointer;
}
#cv {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  border-radius: 4px;
}
#overlay { position: absolute; inset: 0; pointer-events: none; }
#fade {
  position: absolute; inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  border-radius: 4px;
  transition: opacity var(--fd, .5s) linear;
}

/* speech bubbles */
.bub {
  --bf: #fff; --bb: #1a1026;
  position: absolute;
  left: 0; top: 0;
  width: max-content;
  max-width: clamp(170px, calc(var(--k) * 150px), 440px);
  padding: .4em .7em .45em;
  font-size: clamp(13px, calc(var(--k) * 5.6px), 21px);
  line-height: 1.25;
  font-weight: 600;
  color: #1a1026;
  background: var(--bf);
  border: 3px solid var(--bb);
  border-radius: 12px;
  box-shadow: 0 4px 0 rgba(0,0,0,.35);
  animation: pop .22s steps(4) both;
  z-index: 3;
}
.bub::before, .bub::after {
  content: '';
  position: absolute;
  top: 100%;
  clip-path: polygon(0 0, 100% 0, 25% 100%);
}
.bub::before { left: calc(var(--tail, 30px) - 8px); width: 20px; height: 13px; background: var(--bb); }
.bub::after { left: calc(var(--tail, 30px) - 5px); top: calc(100% - 3px); width: 13px; height: 10px; background: var(--bf); }
.bub.flip::before, .bub.flip::after { clip-path: polygon(0 0, 100% 0, 75% 100%); }
.bub.flip::before { left: calc(var(--tail, 30px) - 12px); }
.bub.flip::after { left: calc(var(--tail, 30px) - 8px); }
.bub.demon { --bf: #1b0d12; --bb: #e0312b; color: #ffe14d; }
.bub.shout { font-family: 'Silkscreen', monospace; font-weight: 700; letter-spacing: .02em; }
.bub .more {
  display: inline-block;
  margin-left: .3em;
  font-size: .7em;
  opacity: 0;
}
.bub.done .more { opacity: 1; animation: blink .6s steps(2) infinite; }
.bub.out { animation: popout .14s steps(3) both; }

/* emotes ("!" and "?") */
.emo {
  position: absolute;
  left: 0; top: 0;
  font-family: 'Silkscreen', monospace;
  font-weight: 700;
  font-size: clamp(14px, calc(var(--k) * 8px), 30px);
  color: var(--gold);
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000;
  transform: translate(-50%, -100%);
  animation: pop .2s steps(3) both;
}

/* hint line */
.hint {
  position: absolute;
  left: 50%; top: 5%;
  transform: translateX(-50%);
  padding: .3em .7em;
  font-family: 'Silkscreen', monospace;
  font-size: clamp(11px, calc(var(--k) * 4.6px), 18px);
  white-space: nowrap;
  color: var(--gold);
  background: rgba(10, 6, 20, .78);
  border: 2px solid var(--gold);
  border-radius: 6px;
  opacity: 0;
  transition: opacity .3s;
}
.hint.on { opacity: 1; animation: nudge 1.2s ease-in-out infinite; }

/* HUD life bars */
.hud {
  position: absolute;
  left: 3%; right: 3%; top: 4%;
  display: flex;
  justify-content: space-between;
  gap: 10%;
  opacity: 0;
  transition: opacity .4s;
}
.hud.on { opacity: 1; }
.bar {
  flex: 1;
  max-width: 40%;
  font-family: 'Silkscreen', monospace;
  font-size: clamp(9px, calc(var(--k) * 4px), 15px);
  text-transform: uppercase;
  text-shadow: 1px 1px 0 #000;
}
.bar.boss { text-align: right; }
.bar i {
  position: relative;
  display: block;
  height: clamp(8px, calc(var(--k) * 4.5px), 18px);
  margin-top: 2px;
  overflow: hidden;
  background: #241433;
  border: 2px solid #000;
  box-shadow: inset 0 0 0 2px #3f2a5c;
}
.bar b {
  position: absolute; inset: 0;
  transform-origin: left;
  transform: scaleX(var(--v, 1));
  transition: transform .25s steps(6);
  background: linear-gradient(#bff6ff, #52e0ff 45%, #1f8fc0);
}
.bar.boss b {
  transform: scaleX(var(--v, 0));
  background: linear-gradient(#fff6b8, #ffd447 45%, #e09a14);
}
.bar.boss.full b { animation: flashbar .25s steps(2) infinite; }
.bar.hit i { animation: shakebar .3s steps(4); }

/* cards (title, retry, end) */
.card {
  position: absolute; inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: clamp(6px, calc(var(--k) * 4px), 18px);
  padding: 16px;
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(30, 14, 52, .72), rgba(6, 3, 12, .9));
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .45s;
}
.card.show { opacity: 1; pointer-events: auto; }
.card.clear { background: transparent; }
.card h2 {
  margin: 0;
  font-family: 'Silkscreen', monospace;
  font-size: clamp(24px, calc(var(--k) * 17px), 72px);
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 3px 0 #8a2a10, 0 6px 0 #000, 0 0 28px rgba(255, 212, 71, .45);
}
.card h2 span { display: inline-block; animation: drop .6s cubic-bezier(.2, 1.6, .4, 1) both; }
.card p {
  margin: 0;
  max-width: 34em;
  font-size: clamp(12px, calc(var(--k) * 5px), 19px);
  color: var(--ink);
  text-shadow: 1px 1px 0 #000;
}
.card .keys { color: var(--mute); font-size: clamp(10px, calc(var(--k) * 4px), 15px); }
.btn {
  margin-top: 4px;
  padding: .55em 1.3em;
  font: 700 clamp(14px, calc(var(--k) * 6px), 22px) 'Silkscreen', monospace;
  color: #1a1026;
  background: var(--gold);
  border: 3px solid #000;
  border-radius: 10px;
  box-shadow: 0 5px 0 #000, inset 0 -4px 0 #d99a1e;
  cursor: pointer;
  animation: drop .6s .5s cubic-bezier(.2, 1.6, .4, 1) both;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #000, inset 0 -4px 0 #d99a1e; }

/* control panel ("Pult") */
.pult {
  position: relative;
  flex: none;
  width: min(100% - 32px, max(340px, calc(320px * var(--k))));
  margin: 14px auto 14px;
  padding: 10px 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.03) 0 3px, transparent 3px 9px),
    linear-gradient(#3e2b5f, #241838);
  border: 3px solid #000;
  border-radius: 16px;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.14), 0 6px 0 var(--edge);
  transition: opacity .5s, transform .5s cubic-bezier(.2, 1.4, .4, 1);
}
.pult.off { opacity: 0; transform: translateY(24px); pointer-events: none; }
.pad, .acts { display: flex; gap: clamp(10px, 3vw, 18px); }
.pb {
  --c: #6b5a8e;
  position: relative;
  width: var(--bs); height: var(--bs);
  padding: 0;
  display: grid;
  place-items: center;
  color: #fff;
  border: 3px solid #000;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, color-mix(in srgb, var(--c) 45%, #fff) 0 12%, var(--c) 45%, color-mix(in srgb, var(--c) 60%, #000));
  box-shadow: 0 6px 0 #000, inset 0 -4px 0 rgba(0,0,0,.25);
  cursor: pointer;
  touch-action: none;
  transition: transform .05s, box-shadow .05s, filter .3s;
}
.pb svg { width: 46%; height: 46%; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(1px 2px 0 rgba(0,0,0,.4)); }
.pb.down { transform: translateY(5px); box-shadow: 0 1px 0 #000, inset 0 -2px 0 rgba(0,0,0,.25); }
.pb.dim { filter: saturate(.25) brightness(.6); }
.pb.locked { display: none; }
.pb.new { animation: newbtn .7s cubic-bezier(.2, 1.7, .4, 1) both, glow .9s ease-in-out .7s infinite alternate; }
.pb[data-act="attack"] { --c: #2ab3d9; }
.pb[data-act="shield"] { --c: #e8a91c; }
.pb[data-act="super"] { --c: #e0312b; }
.pb .lbl {
  position: absolute;
  top: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  font: 11px 'Silkscreen', monospace;
  color: var(--mute);
  white-space: nowrap;
}
.pb kbd { display: none; }
@media (hover: hover) and (pointer: fine) {
  .pb kbd {
    display: block;
    position: absolute;
    top: -6px; right: -8px;
    padding: 1px 5px;
    font: 10px 'Silkscreen', monospace;
    color: #fff;
    background: #000;
    border-radius: 5px;
  }
  /* the pixel fonts have no arrow glyphs */
  .pb.dir kbd { font: 700 15px/1 'DejaVu Sans', 'Segoe UI Symbol', sans-serif; padding: 1px 4px 2px; }
}

/* tutorial callout above a new Pult button */
.tip {
  --ax: 50%;
  position: fixed;
  left: 0; top: 0;
  z-index: 20;
  width: max-content;
  max-width: min(330px, calc(100vw - 32px));
  padding: .55em .8em;
  font-size: clamp(15px, 2.4vmin + 6px, 20px);
  font-weight: 700;
  line-height: 1.25;
  color: #1a1026;
  background: var(--gold);
  border: 3px solid #000;
  border-radius: 12px;
  box-shadow: 0 5px 0 #000;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s, transform .35s cubic-bezier(.2, 1.6, .4, 1);
  pointer-events: none;
}
.tip.show { opacity: 1; transform: none; }
.tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: calc(var(--ax) - 10px);
  width: 20px; height: 12px;
  background: #000;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.nojs { position: fixed; inset: auto 16px 16px; text-align: center; }

@keyframes pop { from { transform: scale(.4); opacity: 0; } to { opacity: 1; } }
@keyframes popout { to { transform: scale(.6); opacity: 0; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes nudge { 50% { transform: translateX(-50%) translateY(-3px); } }
@keyframes drop { from { transform: translateY(-60px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes newbtn { from { transform: scale(0) rotate(-40deg); } to { transform: none; } }
@keyframes glow { to { box-shadow: 0 6px 0 #000, 0 0 0 5px var(--gold), 0 0 26px 6px var(--gold); } }
@keyframes flashbar { 50% { filter: brightness(1.6); } }
@keyframes shakebar { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

@media (prefers-reduced-motion: reduce) {
  .hint.on, .pb.new, .card h2 span, .btn { animation: none; }
}
@media (max-height: 430px) {
  .top { height: 36px; }
  .pult { margin: 6px auto 8px; padding: 6px 14px 20px; }
  :root { --bs: clamp(46px, 13vmin, 60px); }
}

/* phone held upright: there is space above the screen, use it for a hint */
.turn { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  .turn {
    display: flex;
    position: absolute;
    top: 8%;
    left: 0; right: 0;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 0;
    text-align: center;
    font-size: 15px;
    line-height: 1.35;
    color: var(--mute);
    pointer-events: none;
  }
  .turn svg {
    width: 40px; height: 40px;
    fill: none;
    stroke: var(--gold);
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    animation: tilt 2.4s ease-in-out infinite;
  }
}
@keyframes tilt {
  0%, 30% { transform: rotate(0); }
  55%, 85% { transform: rotate(-90deg); }
  100% { transform: rotate(0); }
}
@media (prefers-reduced-motion: reduce) {
  .turn svg { animation: none; }
}
