:root {
  --bg: #121212;
  --bg-raised: #1b1b1b;
  --ink: #f3efe7;
  --ink-muted: #a9a399;
  --ink-faint: #948e86;
  --rule: rgba(243, 239, 231, 0.14);
  --rule-strong: rgba(243, 239, 231, 0.32);
  --gold: #d6a23e;
  --gold-bright: #e9bd62;
  --red: #e0574b;
  --night: #031021;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --pixel: "Press Start 2P", ui-monospace, monospace;
  --bar: 52px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0 max(16px, env(safe-area-inset-right)) 64px max(16px, env(safe-area-inset-left));
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 var(--sans);
}

a {
  color: inherit;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

a:hover {
  color: var(--gold-bright);
}

:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- page chrome */

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 0;
  font: 500 12px/1.4 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar a {
  text-decoration: none;
  color: var(--ink-muted);
}

.topbar a:hover {
  color: var(--ink);
}

.intro {
  max-width: 960px;
  margin: 24px auto 28px;
}

.kicker {
  margin: 0 0 12px;
  font: 500 12px/1.4 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

h1 {
  margin: 0;
  font: 600 clamp(34px, 6vw, 60px)/1.04 var(--serif);
  letter-spacing: -0.01em;
}

.lede {
  max-width: 62ch;
  margin: 16px 0 0;
  color: var(--ink-muted);
  font-size: 17px;
}

/* ---------- game stage */

.game {
  max-width: 960px;
  margin: 0 auto;
}

.stage {
  position: relative;
  width: 100%;
}

/* The game and its control bar always fit on screen together. */
.frame,
.controlbar {
  width: min(100%, calc((100vh - var(--bar) - 24px) * 1.5)); /* before svh support */
  width: min(100%, calc((100svh - var(--bar) - 24px) * 1.5));
  margin-inline: auto;
}

.frame {
  position: relative;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  background: var(--night);
  border: 1px solid var(--rule);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
  /* Text and spacing inside the frame scale with it (cqw). Each cqw value has a vw
     fallback just before it for browsers without container units (Safari < 16). */
  container-type: inline-size;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.frame:focus {
  outline: none;
}

.frame:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

.game[data-state="title"] .frame {
  cursor: pointer;
}

.frame img,
.frame canvas {
  position: absolute;
  display: block;
  pointer-events: none;
}

.frame canvas {
  inset: 0;
  width: 100%;
  height: 100%;
}

.bg-full {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.frame.night .bg-full,
.bg-forest,
.cast img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

/* Same placement as the forest in the original 900 × 600 background image. */
.bg-forest {
  left: 14.4444%;
  top: 16.6667%;
  width: 72.2222%;
  height: 69.3333%;
}

[hidden] {
  display: none !important;
}

/* ---------- overlay screens */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.2vw;
  gap: 2.2cqw;
  padding: 4vw;
  padding: 4cqw;
  text-align: center;
  font-family: var(--pixel);
  color: var(--ink);
}

.screen p {
  margin: 0;
}

.screen--loading {
  background: var(--night);
  font-size: clamp(10px, 1.6vw, 14px);
  font-size: clamp(10px, 1.6cqw, 14px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.bar {
  width: 40%;
  height: 8px;
  border: 2px solid var(--ink);
  padding: 1px;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.15s linear;
}

.screen--title {
  align-items: flex-end;
  justify-content: flex-end;
  padding: 3.4vw;
  padding: 3.4cqw;
}

.screen--dim {
  background: rgba(6, 8, 14, 0.72);
}

.big {
  font-size: clamp(18px, 4.6vw, 44px);
  font-size: clamp(18px, 4.6cqw, 44px);
  line-height: 1.2;
  text-transform: uppercase;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.6);
}

.big--red {
  color: var(--red);
}

.hint {
  max-width: 34em;
  font-size: clamp(10px, 1.45vw, 13px);
  font-size: clamp(10px, 1.45cqw, 13px);
  line-height: 1.8;
  color: rgba(243, 239, 231, 0.8);
}

.score {
  font-size: clamp(10px, 1.9vw, 18px);
  font-size: clamp(10px, 1.9cqw, 18px);
  color: var(--gold-bright);
  text-transform: uppercase;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 1.2em;
  padding: 1.1em 1.6em;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: var(--ink);
  font: 400 clamp(10px, 1.5vw, 14px)/1.2 var(--pixel);
  font: 400 clamp(10px, 1.5cqw, 14px)/1.2 var(--pixel);
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.pill--ghost {
  background: transparent;
  border-color: rgba(243, 239, 231, 0.55);
}

.screen__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.4vw;
  gap: 1.4cqw;
}

.pill:hover,
.pill:focus-visible {
  background: var(--gold);
  border-color: var(--gold);
  color: #111;
}

.screen--title .pill__icon {
  animation: blink 1.1s steps(2, start) infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

.screen--ending {
  justify-content: space-between;
  padding: 5vw 3vw 3vw;
  padding: 5cqw 3cqw 3cqw;
  background: linear-gradient(to bottom, rgba(3, 6, 20, 0.15), rgba(3, 6, 20, 0.55));
}

.ending-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.8vw;
  gap: 1.8cqw;
}

/* Courtroom-style text box for the closing line */
.dialog {
  width: 100%;
  min-height: 4.4em;
  padding: 1.1em 1.5em;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: linear-gradient(to bottom, rgba(24, 33, 74, 0.94), rgba(10, 14, 38, 0.94));
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.5);
  font-size: clamp(10px, 1.75vw, 17px);
  font-size: clamp(10px, 1.75cqw, 17px);
  line-height: 1.9;
  text-align: left;
}

/* ---------- control bar + touch pads */

.controlbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--bar);
  padding: 8px 0;
}

.keys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0;
  font: 400 12px/1.4 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.keys .sep {
  width: 10px;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border: 1px solid var(--rule-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: 500 12px/1 var(--mono);
  color: var(--ink);
}

.tools {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.tool {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.tool:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold-bright);
}

.tool:disabled {
  opacity: 0.35;
  cursor: default;
}

.tool svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.tool .i-play,
.tool.is-paused .i-pause,
.tool .i-mute,
.tool.is-off .i-sound {
  display: none;
}

.tool.is-paused .i-play,
.tool.is-off .i-mute {
  display: block;
}

.pads {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 4px 0;
}

.pads__group {
  display: flex;
  gap: 14px;
}

.pad {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  padding: 0;
  border: 1.5px solid var(--rule-strong);
  border-radius: 50%;
  background: rgba(243, 239, 231, 0.06);
  color: var(--ink);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.pad svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
}

.pad.is-down {
  background: var(--gold);
  border-color: var(--gold);
  color: #111;
}

.pad--jump {
  width: 80px;
  height: 80px;
}

.only-touch {
  display: none;
}

.rotate-hint {
  display: none;
  margin: 14px 0 0;
  font: 400 12px/1.5 var(--mono);
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  text-align: center;
}

@media (orientation: portrait) {
  .game.touch .rotate-hint {
    display: block;
  }
}

html.embed .rotate-hint {
  display: none !important;
}

.game.touch .only-touch {
  display: inline;
}

.game.touch .only-keys {
  display: none;
}

.game.touch .pads {
  display: flex;
}

/* Phones held sideways: the game fills the height and the pads sit beside it. */
@media (orientation: landscape) and (max-height: 560px) {
  .has-touch .intro {
    display: none;
  }

  .has-touch .topbar {
    padding: 8px 0;
  }

  .game.touch .pads {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(var(--bar) + 8px);
    padding: 0;
    pointer-events: none;
  }

  .game.touch .pad {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.35);
  }
}

/* Embedded on a touch screen: pads over the bottom corners of the frame. */
html.embed .game.touch .pads {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--bar) + 8px);
  padding: 0 8px;
  pointer-events: none;
}

html.embed .game.touch .pad {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.35);
}

/* ---------- notes */

.notes {
  display: grid;
  grid-template-columns: 1.15fr 1fr 0.9fr;
  gap: 40px;
  max-width: 960px;
  margin: 56px auto 0;
  padding-top: 40px;
  border-top: 1px solid var(--rule);
}

.note h2 {
  margin: 0 0 16px;
  font: 500 12px/1.4 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.note p {
  margin: 0 0 12px;
  color: var(--ink-muted);
  font-size: 15px;
}

.note em {
  color: var(--ink);
}

.note .small {
  font-size: 13px;
  color: var(--ink-faint);
}

.cast {
  display: grid;
  gap: 12px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.cast li {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 12px;
}

.cast img {
  width: 44px;
  height: 44px;
  object-fit: contain;
}

.cast p {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.5;
}

.cast strong {
  color: var(--ink);
  font-weight: 600;
}

dl {
  margin: 0 0 14px;
}

dt {
  font: 500 11px/1.4 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

dd {
  margin: 2px 0 12px;
  font-size: 14.5px;
  color: var(--ink-muted);
}

@media (max-width: 820px) {
  .notes {
    grid-template-columns: 1fr;
    gap: 32px;
  }
}

@media (max-width: 520px) {
  .controlbar {
    flex-wrap: wrap;
  }

  .keys {
    font-size: 11px;
  }
}

/* ---------- embedded in the portfolio (?embed=1) and full screen */

html.embed body {
  padding: 0;
  overflow: hidden;
  background: transparent;
}

html.embed .topbar,
html.embed .intro,
html.embed .notes {
  display: none;
}

html.embed .game {
  max-width: none;
}

html.embed .stage,
.stage:fullscreen {
  display: flex;
  flex-direction: column;
  align-items: center;
}

html.embed .frame,
html.embed .controlbar {
  width: min(100vw, calc((100vh - var(--bar)) * 1.5));
}

html.embed .frame {
  border: 0;
  box-shadow: none;
}

html.embed .controlbar {
  padding: 8px 10px;
}

.stage:fullscreen {
  justify-content: center;
  background: #000;
}

.stage:fullscreen .frame,
.stage:fullscreen .controlbar {
  width: min(100vw, calc((100vh - var(--bar)) * 1.5));
}

.stage:fullscreen .frame {
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .screen--title .pill__icon {
    animation: none;
  }

  .bar span {
    transition: none;
  }
}
