:root {
  --paper: #ffffff;
  --ink: #1f2328;
  --muted: #5f6670;

  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  -webkit-font-smoothing: antialiased;
}

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

.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---- The side ---- */

.side-top {
  padding: 18px 24px 4px;
}

.side-bottom {
  padding: 8px 24px 28px;
}

.wordmark {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.lede {
  max-width: 34ch;
  margin: 6px 0 0;
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
}

.lede a,
.credit a {
  color: inherit;
  text-underline-offset: 2px;
}

.lede a:hover,
.credit a:hover {
  color: var(--ink);
}

.settings,
.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings {
  margin-top: 16px;
}

/* A small heading over each part of the side. */
.side-label {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.howto,
.roms {
  padding-top: 18px;
  border-top: 1px solid rgba(31, 35, 40, 0.1);
}

.howto {
  margin-top: 26px;
}

.goal {
  max-width: 36ch;
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.55;
  color: #3a4048;
}

/* Each key, lined up with what it does. */
.keys {
  display: grid;
  gap: 9px;
  margin: 0;
}

.keys div {
  display: grid;
  grid-template-columns: 84px 1fr;
  align-items: center;
}

.keys dt {
  display: flex;
  gap: 4px;
}

.keys dd {
  margin: 0;
  font-size: 14px;
  color: var(--ink);
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 24px;
  padding: 0 6px;
  border: 1px solid rgba(31, 35, 40, 0.18);
  border-bottom-width: 2px;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  background: #f6f7f9;
}

.aside-note {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.pill {
  padding: 8px 14px;
  border: 1px solid rgba(31, 35, 40, 0.16);
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  color: inherit;
  text-decoration: none;
  background: #ffffff;
  cursor: pointer;
  transition:
    background 150ms,
    border-color 150ms;
}

.pill:hover {
  border-color: rgba(31, 35, 40, 0.34);
  background: #f6f7f9;
}

#big[aria-pressed="true"] {
  border-color: rgba(31, 35, 40, 0.45);
}

.now,
.hint {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.now {
  font-size: 14px;
  color: var(--ink);
}

.hint.warn {
  color: #9a3b2e;
}

.text-button {
  padding: 0;
  border: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  background: none;
  cursor: pointer;
}

.credit {
  max-width: 40ch;
  margin: 18px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* Dragging a file over the page. */
.drop {
  position: fixed;
  inset: 12px;
  z-index: 10;
  display: none;
  place-items: center;
  border: 2px dashed rgba(31, 35, 40, 0.4);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.92);
  pointer-events: none;
}

.dropping .drop {
  display: grid;
}

.drop p {
  margin: 0;
  font-family: var(--serif);
  font-size: 30px;
  font-style: italic;
}

/* ---- The SP ---- */

.stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 12px 16px;
}

/* The drawing is 820 by 1560, about 82 by 156 mm for an opened SP. The
   game is laid over it in percentages of that. */
.sp {
  position: relative;
  container-type: inline-size;
  width: min(440px, calc(100vw - 32px), calc((100dvh - 224px) * 0.5256));
  min-width: 250px;
  aspect-ratio: 820 / 1560;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.sp svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  touch-action: none;
  filter: drop-shadow(0 1.5cqw 2cqw rgba(30, 62, 88, 0.22)) drop-shadow(0 10cqw 12cqw rgba(30, 62, 88, 0.22));
}

/* Lettering. The button labels are raised from the plastic, so each is
   drawn twice: a light edge, then the letters. */
.label,
.label-light {
  font-family: var(--sans);
  font-size: 19px;
  font-style: italic;
  font-weight: 800;
  letter-spacing: 1.5px;
}

.label {
  fill: #7fa6be;
}

.label-light {
  fill: #dbe8ef;
}

.emboss,
.emboss-light {
  font-family: var(--sans);
  font-size: 28px;
  font-weight: 800;
}

.emboss {
  fill: #bbbdbe;
}

.emboss-light {
  fill: #dcdddd;
}

.hit {
  fill: transparent;
}

.key,
[data-pad] {
  cursor: pointer;
}

/* Pressing a button sinks it into its hole: it drops a little and shrinks
   from view, its shadow tucks in, and the rim of the hole shades its edge.
   The D-pad rocks toward the side you press. */
.cap,
.cross {
  transform-box: fill-box;
  transform-origin: center;
  transition:
    transform 70ms ease-out,
    filter 70ms ease-out;
}

.pressed .cap {
  transform: translateY(2.5px) scale(0.955);
  filter: url(#drop-pressed);
}

.shade {
  fill: #234f6a;
  opacity: 0;
  transition: opacity 70ms;
}

.pressed .shade {
  opacity: 0.07;
}

.press,
.arm {
  opacity: 0;
  transition: opacity 70ms;
}

.pressed .press,
.arm.pressed {
  opacity: 1;
}

[data-pad]:has(.arm.pressed) .cross {
  filter: url(#drop-pressed);
}

[data-pad]:has([data-dir="up"].pressed) .cross {
  transform: translateY(-1.5px);
}

[data-pad]:has([data-dir="down"].pressed) .cross {
  transform: translateY(1.5px);
}

[data-pad]:has([data-dir="left"].pressed) .cross {
  transform: translateX(-1.5px);
}

[data-pad]:has([data-dir="right"].pressed) .cross {
  transform: translateX(1.5px);
}

.led .dot {
  fill: #3c637c;
  transition: fill 300ms;
}

.led .glow {
  opacity: 0;
  transition: opacity 300ms;
}

.led.on .dot {
  fill: #7dff93;
}

.led.on .glow {
  opacity: 0.4;
}

/* The game fills the lens (660 by 555 at 80, 85 in the drawing), inside
   its thin edge. A Game Boy game is 10 by 9 and the lens about 6 by 5, so the
   picture is stretched a little sideways to fill it. */
.lcd {
  position: absolute;
  top: 5.641%;
  left: 10.122%;
  width: 79.756%;
  height: 35.192%;
  overflow: hidden;
  border-radius: 1.68% / 2%;
  background: #000000;
  transition: filter 250ms;
}

.lcd canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* The light turned off: an older SP in a dim room. */
.lcd.dim {
  filter: brightness(0.5) saturate(0.8);
}

.lcd-note {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 4cqw;
  font-size: 3.2cqw;
  line-height: 1.4;
  text-align: center;
  color: #c9d2dc;
}

/* ---- Layout ---- */

/* Narrow: the side's top, then the SP, then the side's bottom. */
.side {
  display: contents;
}

.side-top {
  order: 1;
}

.stage {
  order: 2;
}

.side-bottom {
  order: 3;
}

/* Wide: the side is a column that stays put while the SP scrolls, with how
   to play at the top and the game files at the bottom. */
@media (min-width: 960px) {
  .page {
    display: grid;
    grid-template-columns: minmax(320px, 1fr) auto minmax(0, 1fr);
    align-items: start;
  }

  .side {
    position: sticky;
    top: 0;
    grid-column: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 24px;
    max-width: 420px;
    height: 100vh;
    height: 100dvh;
    padding: 32px 36px 28px;
  }

  .side-top,
  .side-bottom {
    padding: 0;
  }

  .stage {
    grid-column: 2;
    padding: 24px;
  }

  .sp {
    width: min(460px, calc((100dvh - 48px) * 0.5256));
  }
}

/* Big screen, on computers: the SP is drawn taller than the window, down
   to just below A and B, so the screen is big. The rest of it is a scroll
   away; you play with the keyboard. */
@media (pointer: fine) {
  .page.big .sp {
    width: min(660px, calc(100vw - 32px), calc((100dvh - 40px) * 0.5256 / 0.75));
  }
}

/* Phones: the SP already fills the width, and the keys are for keyboards. */
@media (pointer: coarse) {
  .howto,
  .hint:not(.warn),
  #big {
    display: none;
  }
}

@media (max-width: 600px) {
  .side-top {
    padding: 12px 16px 4px;
  }

  .side-bottom {
    padding: 8px 16px 24px;
  }

  .wordmark {
    font-size: 28px;
  }

  .lede {
    font-size: 14px;
  }

  .settings {
    margin-top: 10px;
  }

  .pill {
    padding: 6px 12px;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cap,
  .cross,
  .shade,
  .press,
  .arm,
  .led .dot,
  .led .glow,
  .lcd {
    transition: none;
  }
}
