:root {
  color-scheme: dark;
  --bg: #0a090f;
  --surface: #100e17;
  --frame: #332937;
  --ink: #f5ebed;
  --muted: #b7a9ba;
  --pink: #ff79b1;
  --plum: #3d1d34;
  --inset: clamp(.85rem, 3vw, 2.4rem);
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, sans-serif;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }

:where(button, a):focus-visible {
  outline: 2px solid #ffc5de;
  outline-offset: 4px;
}

.game {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: min(100%, 106rem);
  min-height: 100vh;
  min-height: 100svh;
  margin-inline: auto;
  padding: 0 max(var(--inset), env(safe-area-inset-right)) max(.7rem, env(safe-area-inset-bottom)) max(var(--inset), env(safe-area-inset-left));
}

.mast, .mission, .mission-stats, .mast-actions {
  display: flex;
  align-items: center;
}

.mast {
  grid-row: 1;
  min-height: 3.48rem;
  justify-content: space-between;
  gap: .5rem;
}

.gallery-link, .top-button {
  color: var(--muted);
  font: 500 .8rem/1.35 var(--mono);
}

.gallery-link {
  padding-block: .62rem;
  text-decoration-color: #ad758d;
  text-underline-offset: .29em;
}

.gallery-link:hover, .top-button:hover { color: var(--ink); }

.mast-actions { gap: .4rem; }

.game[data-embedded] .gallery-link { display: none; }
.game[data-embedded] .mast { justify-content: end; }

.top-button {
  min-height: 2.55rem;
  padding: .45rem .65rem;
  border: 1px solid var(--frame);
  background: var(--surface);
}

.top-button[aria-pressed="true"] {
  border-color: #b45180;
  color: #ffd2e7;
}

.mission {
  grid-row: 2;
  min-height: 4rem;
  justify-content: space-between;
  gap: .6rem 1.15rem;
  padding: .58rem .8rem;
  border: 1px solid var(--frame);
  border-bottom: 0;
  background: #15101b;
}

.mission-objective {
  display: grid;
  gap: .14rem;
  min-width: 0;
}

.mission-objective b { font-size: 1rem; }

.mission-objective span {
  color: var(--muted);
  font-size: .84rem;
  text-wrap: pretty;
}

.mission-stats {
  gap: clamp(.65rem, 3vw, 1.85rem);
  flex-shrink: 0;
}

.stat {
  display: grid;
  gap: .3rem;
  color: var(--muted);
  font: 500 .76rem/1.18 var(--mono);
}

.stat b {
  color: var(--ink);
  font: 700 1.02rem/1 var(--mono);
  font-variant-numeric: tabular-nums;
}

.heat meter {
  display: block;
  width: clamp(3.4rem, 10vw, 7rem);
  height: .66rem;
  border: 0;
  border-radius: 0;
  background: #302333;
  accent-color: var(--pink);
}

.heat meter::-webkit-meter-bar { border: 0; border-radius: 0; background: #302333; }
.heat meter::-webkit-meter-optimum-value { background: #f479aa; }
.heat meter::-moz-meter-bar { background: #f479aa; }

.playfield {
  grid-row: 3;
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: clamp(24rem, 75vh, 59rem);
  min-height: clamp(24rem, 75svh, 59rem);
  isolation: isolate;
  overflow: hidden;
  border: 1px solid var(--frame);
  background: #0e0e17;
}

.game[data-mode="menu"] .playfield {
  min-height: clamp(30rem, 83vh, 67rem);
  min-height: clamp(30rem, 83svh, 67rem);
}

.bank {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.poster, .interlude {
  z-index: 1;
  grid-area: 1 / 1;
}

.poster {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, .87fr) minmax(0, 1.13fr);
  align-items: center;
  padding: clamp(1.2rem, 5vw, 5rem);
  background:
    linear-gradient(93deg, #100d17fa 12%, #100d17f2 37%, #140b19b8 65%, #140b19bf),
    linear-gradient(#140d17bd, #0c0b11a0);
}

.poster-copy {
  z-index: 1;
  position: relative;
}

.poster-copy h1 {
  margin: 0;
  max-width: 8ch;
  color: #fff2ed;
  font: 400 clamp(4.15rem, 10.3vw, 11.3rem)/.77 Georgia, "Times New Roman", serif;
  letter-spacing: -.094em;
  text-shadow: 0 .07em .22em #10091290;
}

.poster-copy p {
  margin: clamp(1.25rem, 3.4vw, 2.35rem) 0 1.3rem;
  color: #dac6d7;
  font-size: clamp(.95rem, 1.5vw, 1.15rem);
  line-height: 1.52;
  text-shadow: 0 2px .75rem #0a090f;
}

.primary {
  min-height: 3.3rem;
  padding: .8rem 1rem;
  border: 1px solid #ffb1cf;
  background: #ff80b4;
  color: #210e1a;
  box-shadow: 4px 4px #6b3250;
  font: 800 .9rem/1.15 var(--mono);
  text-align: left;
  text-transform: uppercase;
}

.primary:hover { background: #ffa8ca; }
.primary:active { transform: translate(2px, 2px); box-shadow: 2px 2px #6b3250; }

.primary span {
  margin-left: 1.05rem;
  color: #662644;
  font-weight: 600;
  white-space: nowrap;
}

.poster-gem {
  position: relative;
  justify-self: stretch;
  aspect-ratio: 1.02;
  min-width: 0;
  margin-inline: -4% -2%;
  background:
    radial-gradient(ellipse at 55% 50%, #b9186240, #7c1f5327 35%, transparent 65%),
    repeating-linear-gradient(90deg, #f49bc209 0px 1px, transparent 1px 29px);
  mask-image: radial-gradient(ellipse, #000 56%, #000a 75%, transparent 91%);
}

.poster-gem::before, .poster-gem::after {
  position: absolute;
  inset: 7% 7%;
  border: 1px solid #fd7db72c;
  border-radius: 50%;
  content: "";
  pointer-events: none;
}

.poster-gem::after {
  inset: 11% 11%;
  border-style: dashed;
  border-color: #fd7db72a;
}

.gem {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.interlude {
  display: grid;
  place-items: center;
  padding: 1rem;
  background: #100a17d9;
}

.interlude-card {
  width: min(100%, 31rem);
  padding: clamp(1.35rem, 5vw, 2.8rem);
  border: 1px solid #865068;
  background: #1b101e;
  box-shadow: .36rem .36rem #5d2b42;
}

.interlude h2 {
  margin: 0;
  font: 400 clamp(2.6rem, 7vw, 4.35rem)/.92 Georgia, serif;
  letter-spacing: -.06em;
}

.interlude p {
  max-width: 29ch;
  margin: .85rem 0 1.3rem;
  color: #d7bed4;
  line-height: 1.5;
}

.diamond-flash {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background: #ff82b5;
}

.diamond-flash.active { animation: diamond-lift .65s ease-out; }
@keyframes diamond-lift { 0% { opacity: .39; } 100% { opacity: 0; } }

.game[data-phase="escape"] .playfield, .game[data-phase="escape"] .mission {
  border-color: #a74b70;
}

.game[data-phase="escape"] .stat b { color: #ffbad3; }
.game[data-seen] .mission-objective span { color: #ffc097; }

.controls {
  grid-row: 4;
  min-height: 2.7rem;
}

.keyguide {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem 1.4rem;
  padding: .65rem .12rem .05rem;
  color: var(--muted);
  font-size: .83rem;
}

kbd {
  color: #efd7e6;
  font: 600 .8rem/1 var(--mono);
}

.touch-controls {
  display: none;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-block-start: .5rem;
  touch-action: none;
  user-select: none;
}

.dpad {
  display: grid;
  grid-template-areas: ". up ." "left down right";
  grid-template-columns: repeat(3, minmax(3rem, 1fr));
  gap: .25rem;
}

.dpad button, .sneak {
  display: grid;
  place-items: center;
  min-width: 3rem;
  min-height: 3rem;
  border: 1px solid #5e435e;
  border-radius: 0;
  background: #25182a;
  color: #f2d8ec;
  font: 700 1.27rem/1 var(--mono);
  touch-action: none;
}

.dpad button.is-held, .sneak[aria-pressed="true"] {
  border-color: #ff99c3;
  background: #64304f;
  color: #fff4fa;
}

.dpad .up { grid-area: up; }
.dpad .left { grid-area: left; }
.dpad .down { grid-area: down; }
.dpad .right { grid-area: right; }
.sneak { padding: .52rem 1rem; font-size: .92rem; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.no-script { margin: .7rem 0; color: #ffb7d5; }

@media (pointer: coarse), (max-width: 46rem) {
  .touch-controls { display: flex; }
  .game:not([data-mode="menu"]) .keyguide { display: none; }
  .game[data-mode="menu"] .primary span { display: none; }
  .playfield { min-height: max(19rem, calc(100svh - 16.3rem)); }
}

@media (max-width: 43rem) {
  .mast { min-height: 3.18rem; }
  .mission { align-items: flex-start; padding: .48rem .53rem; min-height: 3.9rem; }
  .mission-objective b { font-size: .88rem; }
  .mission-objective span { font-size: .75rem; }
  .mission-stats { gap: .64rem; }
  .stat { font-size: .68rem; }
  .stat b { font-size: .87rem; }

  .game[data-mode="menu"] .playfield { min-height: max(32.5rem, calc(100svh - 7rem)); }
  .poster {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(13.5rem, 1fr) auto;
    align-items: center;
    padding: .55rem clamp(1.05rem, 6vw, 2.4rem) 1.7rem;
    background: linear-gradient(#100d17bd, #100d17dc 58%, #100d17f5 84%);
  }
  .poster-copy { grid-area: 2 / 1; }
  .poster-copy h1 { max-width: none; font-size: clamp(3.6rem, 12vw, 6rem); }
  .poster-copy p { margin-block: 1rem .9rem; }
  .poster-gem {
    grid-area: 1 / 1;
    justify-self: center;
    width: min(115%, 25rem, 54svh);
    margin: -1.1rem 0 -.65rem;
  }
  .desktop-break { display: none; }
}

@media (max-height: 43rem) and (min-width: 44rem) {
  .game[data-mode="menu"] .playfield { min-height: max(22rem, calc(100svh - 6.3rem)); }
  .poster-gem { width: min(108%, 76vh); justify-self: center; }
}

.game[data-embedded][data-mode="menu"] .playfield { min-height: clamp(24rem, calc(100svh - 7rem), 67rem); }
.game[data-embedded] .poster-copy h1 { font-size: clamp(3rem, 8.6vw, 9rem); }

@media (max-width: 43rem) {
  .game[data-embedded][data-mode="menu"] .playfield { min-height: max(26rem, calc(100svh - 6.5rem)); }
  .game[data-embedded] .poster-copy h1 { font-size: clamp(3rem, 10.75vw, 6rem); }
}

@media (max-width: 43rem) and (max-height: 29rem) {
  .game[data-embedded][data-mode="menu"] .playfield { min-height: 0; }
  .game[data-embedded] .poster {
    grid-template-rows: auto auto;
    padding: .4rem 1rem 1rem;
  }
  .game[data-embedded] .poster-gem {
    width: min(65%, 11rem, 37svh);
    margin: -.35rem 0;
  }
  .game[data-embedded] .poster-copy h1 { font-size: clamp(2.15rem, 9vw, 4rem); }
  .game[data-embedded] .poster-copy p { margin-block: .65rem .75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .diamond-flash.active { animation: none; }
}
