/* Layout: one centered game column. A 320x180 pixel scene on top (integer scaled),
   a black dialogue box with a thick white border below. Every size is a multiple of --px. */
@font-face {
  font-family: "AlaPixel";
  src: url("fonts/ala-pixel.ttf") format("truetype");
  font-display: block;
}

:root {
  color-scheme: dark;
  --px: 2px;
  --fs: calc(var(--px) * 10);         /* one font pixel = one --px */
  --fs-small: 20px;                   /* 2 css px per font pixel, crisp at every size */
  --portrait: 96px;
  --title-fs: 30px;
  --stage-w: min(100%, 960px);

  --bg: #0b0b22;
  --bg2: #15123a;
  --box: #000000;
  --ink: #ffffff;
  --muted: #9c9ab8;
  --pink: #ff96c4;
  --pink-deep: #d6508a;
  --blue: #96cdff;
  --hover: #ffe07a;
  --shadow: #4a4866;
  --field: #0d0d18;
  --placeholder: #5f5d7a;
  --frame: #3a3850;
  --frame-bg: #10101c;
  --dash: #5a5878;
}
@media (min-width: 720px) {
  :root { --px: 3px; --portrait: 128px; }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 0%, var(--bg2), var(--bg) 70%) fixed, var(--bg);
  color: var(--ink);
  font-family: "AlaPixel", ui-monospace, monospace;
  font-size: var(--fs);
  line-height: 1.3;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  font-synthesis: none;
  -webkit-tap-highlight-color: transparent;
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
  padding-block: max(12px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
}

#game {
  width: var(--stage-w);
  max-width: 100%;
  min-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* ------------------------------------------------ stage */
#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  background: #0a0a24;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
#scene {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  cursor: pointer;
}

#hud {
  position: absolute;
  left: calc(var(--px) * 3);
  top: calc(var(--px) * 3);
  display: flex;
  align-items: center;
  gap: calc(var(--px) * 3);
  font-size: var(--fs-small);
  line-height: 1;
  padding: calc(var(--px) * 1.5) calc(var(--px) * 3);
  background: rgba(0, 0, 0, 0.6);
  border: var(--px) solid var(--ink);
  font-variant-numeric: tabular-nums;
}
#hud .hud-name { color: var(--blue); }
#hpbar {
  position: relative;
  display: inline-block;
  width: calc(var(--px) * 22);
  height: calc(var(--px) * 5);
  background: var(--pink-deep);
}
#hpfill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 75%;
  background: var(--hover);
  transition: width 0.6s steps(6);
}

#sound {
  position: absolute;
  right: calc(var(--px) * 3);
  bottom: calc(var(--px) * 3);
  font: inherit;
  font-size: var(--fs-small);
  line-height: 1;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.6);
  border: var(--px) solid var(--ink);
  padding: calc(var(--px) * 1.5) calc(var(--px) * 3);
  cursor: pointer;
}
#sound[aria-pressed="true"] { color: var(--pink); border-color: var(--pink); }
#sound:hover, #sound:focus-visible { color: var(--hover); outline: none; }

#toast {
  position: absolute;
  left: 50%;
  top: calc(var(--px) * 17);
  transform: translateX(-50%);
  max-width: 82%;
  width: max-content;
  background: var(--box);
  border: var(--px) solid var(--ink);
  padding: calc(var(--px) * 2) calc(var(--px) * 4);
  font-size: var(--fs-small);
  line-height: 1.3;
  text-align: left;
  z-index: 3;
}

#title {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--px) * 4);
  background: rgba(11, 11, 34, 0.62);
  text-align: center;
  transition: opacity 0.8s steps(6);
  z-index: 2;
}
#title.gone { opacity: 0; pointer-events: none; }
#title h1 {
  margin: 0;
  font-weight: 400;
  font-size: var(--title-fs);
  line-height: 1.2;
  color: var(--ink);
  --tp: calc(var(--title-fs) / 10);
  text-shadow: var(--tp) var(--tp) 0 #2a1850, calc(var(--tp) * 2) calc(var(--tp) * 2) 0 #120a28;
}
#title p {
  margin: 0;
  color: var(--pink);
  font-size: var(--fs-small);
}

/* ------------------------------------------------ dialogue box */
.box {
  position: relative;
  margin: calc(var(--px) * 4) calc(var(--px) * 4) 0;
  background: var(--box);
  border: calc(var(--px) * 2) solid var(--ink);
  padding: calc(var(--px) * 5) calc(var(--px) * 6) calc(var(--px) * 8);
  min-height: calc(var(--px) * 200);     /* tall enough for nearly every state, so nothing jumps */
  display: grid;
  grid-template-columns: 1fr;
  align-content: start;
  gap: calc(var(--px) * 5);
  cursor: pointer;
}
.speaker {
  display: flex;
  align-items: flex-end;
  gap: calc(var(--px) * 5);
}
.speaker[hidden] { display: none; }
#portrait {
  width: var(--portrait);
  height: var(--portrait);
  border: var(--px) solid var(--frame);
  background: var(--frame-bg);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  flex: none;
  box-sizing: content-box;
}
.name {
  color: var(--blue);
  text-decoration: underline;
  text-decoration-thickness: var(--px);
  text-underline-offset: calc(var(--px) * 2);
}

.line {
  margin: 0;
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-height: calc(var(--fs) * 1.3 * 2);
}
.line.star { padding-left: 2ch; text-indent: -2ch; }
.line .hl { color: var(--pink); }

/* wide screens: portrait on the left, text beside it */
@media (min-width: 720px) {
  .box { grid-template-columns: auto 1fr; column-gap: calc(var(--px) * 7); min-height: calc(var(--px) * 80); }
  .box > .speaker { grid-row: 1 / span 4; flex-direction: column; align-items: flex-start; gap: calc(var(--px) * 3); }
  .box > :not(.speaker) { grid-column: 2; }
  .box.narr { grid-template-columns: 1fr; }
  .box.narr > :not(.speaker) { grid-column: 1; }
}

/* ------------------------------------------------ buttons */
.opt {
  position: relative;
  font: inherit;
  font-size: var(--fs);
  line-height: 1.3;
  color: var(--ink);
  background: var(--box);
  border: var(--px) solid var(--ink);
  box-shadow: var(--px) var(--px) 0 var(--shadow);
  padding: calc(var(--px) * 3) calc(var(--px) * 7) calc(var(--px) * 3) calc(var(--px) * 13);
  min-height: calc(var(--px) * 18);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  border-radius: 0;
}
.opt::before {
  content: "\2665";
  position: absolute;
  left: calc(var(--px) * 4);
  top: calc(var(--px) * 3);
  color: var(--pink);
  visibility: hidden;
}
.opt:hover, .opt:focus { color: var(--hover); border-color: var(--pink); outline: none; }
.opt:hover::before, .opt:focus::before { visibility: visible; }
.opt:active { transform: translate(var(--px), var(--px)); box-shadow: none; }
.opt:disabled { opacity: 0.5; cursor: default; }
.opt.primary { color: var(--pink); border-color: var(--pink); }
.opt.primary:hover, .opt.primary:focus { color: var(--hover); }
.opt.quiet { color: var(--muted); border-color: var(--shadow); font-size: var(--fs-small); min-height: calc(var(--px) * 14); padding: calc(var(--px) * 2) calc(var(--px) * 5) calc(var(--px) * 2) calc(var(--px) * 5 + 14px); }
.opt.quiet::before { left: calc(var(--px) * 2); top: calc(var(--px) * 2); }
.opt.quiet:hover, .opt.quiet:focus { color: var(--hover); }
.opt.big { font-size: calc(var(--fs)); }

.next { justify-self: end; }
.next[hidden] { display: none; }

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: calc(var(--px) * 4) calc(var(--px) * 6);
}
.grid:empty { display: none; }
@media (min-width: 720px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .grid.three { grid-template-columns: 1fr 1fr 1fr; }
  .grid.stack { grid-template-columns: minmax(0, 32em); }
}
#stage.titled #hud { visibility: hidden; }
/* phones: the scene is small, so the corner labels use 1 css px per font pixel */
@media (max-width: 719px) {
  #hud, #sound { font-size: 10px; padding: 3px 5px; border-width: 1px; gap: 5px; }
  #hud { left: 5px; top: 5px; }
  #sound { right: 5px; bottom: 5px; }
  #hpbar { width: 34px; height: 6px; }
  #toast { font-size: 10px; border-width: 1px; padding: 4px 7px; top: 28px; }
}

/* ------------------------------------------------ fields */
.field { display: flex; flex-direction: column; gap: calc(var(--px) * 3); cursor: default; }
.field[hidden] { display: none; }
.field input[type="text"], .field textarea {
  width: 100%;
  font: inherit;
  font-size: var(--fs);
  line-height: 1.3;
  color: var(--ink);
  background: var(--field);
  border: var(--px) solid var(--ink);
  border-radius: 0;
  padding: calc(var(--px) * 3) calc(var(--px) * 4);
  resize: none;
  -webkit-appearance: none;
  appearance: none;
}
.field input::placeholder, .field textarea::placeholder { color: var(--placeholder); opacity: 1; }
.field input:focus, .field textarea:focus { border-color: var(--pink); outline: none; }
.field-meta { display: flex; justify-content: space-between; gap: calc(var(--px) * 4); font-size: var(--fs-small); color: var(--muted); }
.field-meta .count { margin-left: auto; font-variant-numeric: tabular-nums; }
.label { color: var(--muted); font-size: var(--fs-small); }
.row { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: calc(var(--px) * 4) calc(var(--px) * 6); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* ------------------------------------------------ final surprise: the sky opens from the moon */
#reveal {
  --mx: 80%;
  --my: 20%;
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--px) * 5);
  background: rgba(11, 11, 34, 0.9);
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
  padding-block: max(12px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
  clip-path: circle(0px at var(--mx) var(--my));
  transition: clip-path 1.4s steps(14);
}
#reveal[hidden] { display: none; }
#reveal.open { clip-path: circle(150vmax at var(--mx) var(--my)); }
#reveal.closing { transition-duration: 0.9s; transition-timing-function: steps(9); }

#revealTitle {
  margin: 0;
  min-height: 1.2em;
  font-size: var(--title-fs);
  line-height: 1.2;
  color: var(--pink);
  text-align: center;
  --tp: calc(var(--title-fs) / 10);
  text-shadow: var(--tp) var(--tp) 0 #2a1850, calc(var(--tp) * 2) calc(var(--tp) * 2) 0 #120a28;
}
.reveal-frame {
  position: relative;
  width: min(100%, 1280px, calc((100vh - var(--title-fs) * 1.2 - var(--px) * 60 - 28px) * 16 / 9));
  width: min(100%, 1280px, calc((100dvh - var(--title-fs) * 1.2 - var(--px) * 60 - 28px) * 16 / 9));
  border: calc(var(--px) * 2) solid var(--ink);
  box-shadow: calc(var(--px) * 2) calc(var(--px) * 2) 0 var(--shadow);
  background: #000;
}
#song {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}
#loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--px) * 3);
  background: #0a0a24;
  transition: opacity 0.6s steps(4);
}
#loader.gone { opacity: 0; pointer-events: none; }
#loaderArt {
  width: min(70%, calc(96px * 5));
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
#loaderText {
  margin: 0;
  font-size: var(--fs-small);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
#revealClose { align-self: center; }
@media (max-width: 719px) {
  #loaderText { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
