@font-face {
  font-family: "Fairy Spell";
  src: url("assets/fonts/FairySpell-Regular.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "Futura LT";
  src: url("assets/fonts/FuturaLT-Book.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Futura LT";
  src: url("assets/fonts/FuturaLT-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Futura LT";
  src: url("assets/fonts/FuturaLT-Heavy.ttf") format("truetype");
  font-weight: 900;
  font-display: swap;
}

:root {
  --white: #ffffff;
  --ink: #000000;
  --red: #f20d0d; /* the red of the game's column */

  /* Light theme: black on white. */
  --bg: var(--white);
  --fg: var(--ink);
  --fg-soft: #4d4d4d;
  --dot-a: rgba(0, 0, 0, 0.14);
  --dot-b: rgba(0, 0, 0, 0.06);
  --panel: var(--ink);
  --panel-fg: var(--white);
  --panel-soft: #a6a6a6;
  --key: var(--white);
  --key-fg: var(--ink);
  --key-shadow: #b3b3b3;
  --tile: var(--white);
  --tile-line: var(--white);
  --logo-filter: none;
  --frame-glow: none;
  --wobble: 16px 24px 12px 26px / 26px 12px 22px 16px;
  --wobble-2: 24px 12px 22px 14px / 12px 22px 14px 24px;
  --gap: clamp(20px, 2.6vw, 48px);
  --title: "Fairy Spell", "Futura LT", serif;
  --text: "Futura LT", "Futura", "Trebuchet MS", sans-serif;
  color-scheme: light;
}

/* Dark theme (the default): white on black, with lighter specks. */
:root[data-theme="dark"] {
  --bg: var(--ink);
  --fg: var(--white);
  --fg-soft: #b3b3b3;
  --dot-a: rgba(255, 255, 255, 0.22);
  --dot-b: rgba(255, 255, 255, 0.1);
  --panel: var(--white);
  --panel-fg: var(--ink);
  --panel-soft: #666666;
  --key: var(--ink);
  --key-fg: var(--white);
  --key-shadow: #404040;
  --tile: var(--white);
  --tile-line: var(--ink);
  /* The logo's white letters turn black and its outline white; the flame keeps its red. */
  --logo-filter: invert(1) hue-rotate(180deg);
  --frame-glow: drop-shadow(0 0 1px rgba(255, 255, 255, 0.7));
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100svh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* A one-bit Bayer dither, like the game's background (drawn by main.js). */
.paper {
  position: fixed;
  top: 0;
  left: 0;
  z-index: -1;
  pointer-events: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

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

a { color: inherit; }

button { font: inherit; color: inherit; }

/* ───────────── Base layout: phones and tablets (stacked) ───────────── */

.app {
  --frame: min(calc(100vw - 32px), 640px, calc(100svh - 150px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: max(10px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.intro { display: contents; }

.logo-wrap {
  order: 1;
  margin: 0;
  width: min(72vw, 340px);
  aspect-ratio: 540 / 280;
  line-height: 0;
}
.logo { width: 100%; height: 100%; display: block; filter: var(--logo-filter); }

.stage { order: 2; display: flex; flex-direction: column; align-items: center; gap: 14px; }

.tagline {
  order: 3;
  margin: 0;
  max-width: 34ch;
  text-align: center;
  font-size: 15px;
  color: var(--fg-soft);
  text-wrap: balance;
}

.sound { order: 4; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.guide { order: 5; width: min(100%, 640px); }

.foot { order: 6; }

/* ───────────── The frame and the game inside it ───────────── */

.frame {
  position: relative;
  width: var(--frame);
  aspect-ratio: 900 / 902;
  flex: none;
}

/* The game square sits in the opening of the drawn frame, a little under its edges. */
.game,
.loader {
  position: absolute;
  left: 6.05%;
  top: 4.35%;
  width: 88.5%;
  height: 88.3%;
}

.game {
  display: block;
  background: var(--ink);
  outline: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.marc {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: var(--frame-glow);
}

.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--ink);
  color: var(--white);
  text-align: center;
  transition: opacity 0.5s ease;
}
.app:not([data-state="loading"]) .loader { opacity: 0; pointer-events: none; }
.loader-title { font-family: var(--title); font-size: clamp(22px, 4vw, 34px); letter-spacing: 0.02em; }
.loader-bar {
  width: 52%;
  height: 12px;
  border: 2px solid var(--white);
  border-radius: 8px 10px 7px 11px;
  overflow: hidden;
}
.loader-bar i { display: block; height: 100%; width: 0; background: var(--red); transition: width 0.2s; }
.loader-pct { font-weight: 700; font-size: 13px; letter-spacing: 0.12em; opacity: 0.8; }
.app[data-state="error"] .loader-bar,
.app[data-state="error"] .loader-pct { display: none; }

/* ───────────── Buttons ───────────── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px 7px 11px;
  background: transparent;
  border: 2.5px solid var(--fg);
  border-radius: var(--wobble);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}
.chip svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.chip b { font-weight: 900; }
.chip[aria-pressed="true"] b[data-off],
.chip[aria-pressed="false"] b[data-on] { display: none; }
.chip[aria-pressed="false"] { color: var(--fg-soft); border-style: dashed; }
.chip:hover { background: var(--fg); color: var(--bg); }
:root[data-theme="dark"] .chip [data-light],
:root:not([data-theme="dark"]) .chip [data-dark] { display: none; }
.chip:focus-visible, .pad-btn:focus-visible { outline: 3px solid var(--red); outline-offset: 3px; }

.pad {
  display: none;
  width: var(--frame);
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 10px;
}

.pad-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 70px;
  padding: 8px 6px;
  background: var(--panel);
  color: var(--panel-fg);
  border: none;
  border-radius: var(--wobble);
  box-shadow: inset 0 0 0 2px var(--panel), inset 0 0 0 4px var(--panel-fg);
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  transition: transform 0.06s, background 0.06s;
}
.pad-btn:nth-child(2) { border-radius: var(--wobble-2); }
.pad-btn svg { width: 28px; height: 28px; fill: currentColor; stroke: none; }
.pad-attack svg { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.pad-pause { min-width: 54px; }
.pad-pause svg { fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; }
.pad-btn.is-down, .pad-btn:active { background: var(--red); color: var(--white); box-shadow: none; transform: translateY(2px); }

/* ───────────── How to play ───────────── */

.card {
  container-type: inline-size;
  position: relative;
  background: var(--panel);
  color: var(--panel-fg);
  border-radius: var(--wobble);
  box-shadow: inset 0 0 0 5px var(--panel), inset 0 0 0 7px var(--panel-fg);
  padding: 24px 24px 26px;
}
.card:not([open]) { padding-bottom: 22px; }

.card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  list-style: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.card summary::-webkit-details-marker { display: none; }
.card summary:focus-visible { outline: 3px solid var(--red); outline-offset: 4px; border-radius: 6px; }
.card[open] summary { margin-bottom: 14px; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 4px 10px;
  border: 2px solid currentColor;
  border-radius: 7px 9px 6px 10px / 9px 6px 10px 7px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  flex: none;
}
.toggle svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; transform: rotate(180deg); }
.card:not([open]) .toggle svg { transform: none; }
.card[open] .t-show, .card:not([open]) .t-hide { display: none; }
.card summary:hover .toggle { background: var(--panel-fg); color: var(--panel); }

.card h2 {
  margin: 0;
  white-space: nowrap;
  font-family: var(--title);
  font-weight: 400;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0.01em;
}
.card h3 {
  margin: 22px 0 12px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--panel-soft);
}

.keys { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.keys li { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.keys .caps { display: flex; gap: 5px; flex-wrap: wrap; }
.keys .what { font-weight: 700; font-size: 15px; text-align: right; }
.keys .note { font-size: 14px; color: var(--panel-soft); justify-content: flex-start; }
.keys.only-touch { display: none; }

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  padding: 0 7px 3px;
  background: var(--key);
  color: var(--key-fg);
  border-radius: 7px 9px 6px 10px / 9px 6px 10px 7px;
  box-shadow: inset 0 -4px 0 var(--key-shadow);
  font-family: var(--text);
  font-weight: 900;
  font-size: 14px;
  line-height: 1;
}
kbd.wide { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }

.gesture {
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 10px 5px;
  background: var(--key);
  color: var(--key-fg);
  border-radius: 7px 9px 6px 10px / 9px 6px 10px 7px;
}

.foes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.foes li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 6px;
  background: var(--tile);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--tile-line);
  border-radius: var(--wobble-2);
}
.foes li:nth-child(2n) { border-radius: var(--wobble); }
.foes img { width: 44px; height: 44px; object-fit: contain; flex: none; }
.foes span { min-width: 0; font-size: 13px; line-height: 1.25; }
.foes b { display: block; font-family: var(--title); font-weight: 400; font-size: 18px; line-height: 1; margin-bottom: 3px; }

/* In a narrow card each foe stands above its name. */
@container (max-width: 330px) {
  .card h2 { font-size: 29px; }
  .foes li { flex-direction: column; text-align: center; gap: 4px; padding: 10px 6px 9px; }
  .foes img { width: 52px; height: 40px; }
}

/* ───────────── Footer ───────────── */

.foot {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--fg-soft);
}
.foot a { text-underline-offset: 3px; }

.noscript { text-align: center; font-weight: 700; }

/* ───────────── Touch devices ───────────── */

@media (hover: none) and (pointer: coarse) {
  .pad { display: grid; }
  .keys.only-mouse { display: none; }
  .keys.only-touch { display: grid; }
  .app { --frame: min(calc(100vw - 32px), 640px, calc(100svh - 250px)); }
}

/* Short, wide windows: the tower on the right at full height, the rest beside it. */
@media (orientation: landscape) and (max-height: 600px) and (min-width: 600px) {
  .app {
    --frame: calc(100svh - 24px);
    display: grid;
    grid-template-columns: 1fr var(--frame);
    grid-template-rows: auto auto 1fr auto;
    column-gap: 28px;
    row-gap: 14px;
    align-items: start;
    padding: 12px 24px 16px;
  }
  .intro { display: flex; flex-direction: column; align-items: center; gap: 12px; grid-column: 1; grid-row: 1; }
  .logo-wrap { width: min(100%, 300px); }
  .stage { grid-column: 2; grid-row: 1 / -1; position: sticky; top: 12px; }
  .guide { grid-column: 1; grid-row: 2; width: 100%; max-width: 460px; justify-self: center; }
  .foot { grid-column: 1; grid-row: 4; }
}

/* Phone on its side: buttons either side of the tower, like a gamepad. */
@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  .app {
    --frame: calc(100svh - 24px);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 12px;
  }
  .intro { display: contents; }
  .stage { position: static; }
  .guide { max-width: 640px; }
  .logo-wrap { display: none; }
  .stage {
    display: grid;
    grid-template-columns: 1fr var(--frame) 1fr;
    grid-template-areas: "left frame right";
    align-items: center;
    width: 100%;
    gap: 16px;
  }
  .frame { grid-area: frame; }
  .pad { display: contents; }
  .pad-btn { min-height: 0; height: 26svh; min-width: 0; width: 100%; max-width: 160px; }
  .pad-btn[data-action="jump"] { grid-area: left; align-self: start; justify-self: center; margin-top: 8svh; }
  .pad-btn[data-action="crouch"] { grid-area: left; align-self: end; justify-self: center; margin-bottom: 8svh; }
  .pad-btn[data-action="attack"] { grid-area: right; align-self: start; justify-self: center; margin-top: 8svh; height: 40svh; }
  .pad-btn[data-action="pause"] { grid-area: right; align-self: end; justify-self: center; height: 56px; width: 56px; margin-bottom: 8svh; }
}

/* ───────────── Desktop: the tower in the middle, panels either side ───────────── */

@media (min-width: 1000px) and (min-height: 560px) {
  .app {
    --side: clamp(250px, 22vw, 340px);
    --frame: min(calc(100svh - 96px), calc(100vw - 2 * var(--side) - 2 * var(--gap) - 64px), 960px);
    display: grid;
    grid-template-columns: 1fr var(--frame) 1fr;
    grid-template-rows: 1fr auto;
    column-gap: var(--gap);
    row-gap: 10px;
    min-height: 100svh;
    padding: 24px 32px 14px;
    align-items: center;
  }
  .intro {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 22px;
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
    width: var(--side);
  }
  .logo-wrap { width: 100%; margin-left: -6px; }
  .tagline { text-align: left; font-size: 17px; max-width: none; }
  .sound { justify-content: flex-start; }
  .stage { grid-column: 2; grid-row: 1; }
  .guide { grid-column: 3; grid-row: 1; justify-self: start; width: var(--side); }
  .foot { grid-column: 1 / -1; grid-row: 2; }
}

@media (prefers-reduced-motion: reduce) {
  .loader, .pad-btn { transition: none; }
}
