*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { color: var(--ink); font-family: var(--font-read); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* The handheld screen and the patterned letterbox around it. */
body.game {
  height: 100vh; overflow: hidden;
  background-color: var(--letterbox);
  background-image: linear-gradient(45deg, #34387a 25%, transparent 25% 75%, #34387a 75%), linear-gradient(45deg, #34387a 25%, transparent 25% 75%, #34387a 75%);
  background-size: 24px 24px; background-position: 0 0, 12px 12px;
}
.stage-viewport { position: fixed; inset: 0; overflow: hidden; }
.stage {
  position: absolute; left: 0; top: 0; width: 960px; height: 540px; overflow: hidden; transform-origin: 0 0;
  background: var(--sky); color: var(--ink); font-family: var(--font-read); font-size: var(--text-body); line-height: 1.35;
  outline: 4px solid var(--ink);
}
.stage-placeholder { position: absolute; inset: 0; display: grid; place-items: center; }

/* Pixel windows. The border is drawn on a clipped layer behind the element, so the stepped corners
   never clip the element's own focus ring. --fill, --light, and --shade recolor any framed thing. */
.px-frame, .px-button, .px-chip, .px-icon-button, .px-toggle {
  --fill: var(--paper); --light: var(--white); --shade: var(--paper-shade); --edge: var(--ink);
  position: relative; isolation: isolate; border: 4px solid transparent; background: none; color: var(--ink);
}
.px-frame::before, .px-button::before, .px-chip::before, .px-icon-button::before, .px-toggle::before {
  content: ''; position: absolute; inset: -4px; z-index: -1; border: 4px solid var(--edge);
  background:
    linear-gradient(var(--edge) 0 0) top left / 4px 4px no-repeat,
    linear-gradient(var(--edge) 0 0) top right / 4px 4px no-repeat,
    linear-gradient(var(--edge) 0 0) bottom left / 4px 4px no-repeat,
    linear-gradient(var(--edge) 0 0) bottom right / 4px 4px no-repeat,
    linear-gradient(var(--light) 0 0) top left / 100% 3px no-repeat,
    linear-gradient(var(--light) 0 0) top left / 3px 100% no-repeat,
    linear-gradient(var(--shade) 0 0) bottom left / 100% 4px no-repeat,
    var(--fill);
  clip-path: polygon(0 4px, 4px 4px, 4px 0, calc(100% - 4px) 0, calc(100% - 4px) 4px, 100% 4px, 100% calc(100% - 4px), calc(100% - 4px) calc(100% - 4px), calc(100% - 4px) 100%, 4px 100%, 4px calc(100% - 4px), 0 calc(100% - 4px));
}
.px-frame { padding: 12px 16px; }

.px-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; min-width: 48px; padding: 4px 14px;
  font-size: var(--text-command); font-weight: 700; line-height: 1.15; text-align: center;
}
.px-button:hover:not(:disabled) { --fill: var(--white); }
.px-button:active:not(:disabled) { transform: translateY(2px); }
.px-button:disabled { --fill: var(--paper-shade); --light: var(--paper-shade); --shade: #e2cfa5; color: var(--ink-soft); cursor: default; }
.px-button--finish { --fill: var(--finish); --light: var(--finish-light); --shade: var(--finish-shade); color: var(--paper); }
.px-button--finish:hover:not(:disabled) { --fill: #207d57; }   /* paper text stays at 4.8:1 */
.px-button--finish:disabled { color: var(--ink-soft); }

.px-chip {
  --fill: var(--chip, var(--paper)); --light: rgba(255, 255, 255, .55); --shade: rgba(31, 33, 71, .18);
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; font-size: var(--text-small); font-weight: 700; line-height: 1.3;
}
.px-icon-button {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 48px; min-height: 48px; padding: 4px 8px; font-size: var(--text-small); font-weight: 700; line-height: 1.1;
}
.px-icon-button:hover { --fill: var(--white); }
.px-toggle {
  display: inline-flex; align-items: center; gap: 10px; min-height: 48px; padding: 4px 14px;
  font-size: var(--text-command); font-weight: 700; line-height: 1.15;
}
.px-toggle[aria-pressed="true"] { --fill: var(--lantern); --light: #ffe08f; --shade: #e0a92f; }
.px-toggle__state { font-family: var(--font-pixel); font-size: var(--text-small); min-width: 2.5em; text-align: right; }

/* Sprite-sheet figures: one 64×64 frame of a 256×256 sheet, scaled without blur. */
.figure { display: inline-block; flex: none; background-repeat: no-repeat; image-rendering: pixelated; vertical-align: bottom; }
.figure--missing { outline: 2px dashed var(--ink-soft); outline-offset: -2px; }

.px-name { font-family: var(--font-pixel); font-size: var(--text-name); font-weight: 600; letter-spacing: .5px; }
.px-title { font-family: var(--font-pixel); font-size: var(--text-title); font-weight: 700; line-height: 1.1; }

/* One focus ring everywhere: paper inside ink, visible on any background. */
:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; box-shadow: 0 0 0 3px var(--paper); }

/* Saving failed: the game keeps going, and says so. */
.save-off { --fill: var(--lantern); position: absolute; top: 72px; left: 50%; transform: translateX(-50%); z-index: 70; pointer-events: none; padding: 6px 14px; font-size: var(--text-small); font-weight: 700; white-space: nowrap; }

/* Landscape-first: portrait windows get a friendly card, with a way past it. */
.rotate-card { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; background: rgba(43, 45, 92, .92); }
.rotate-card__frame { display: grid; gap: 12px; max-width: 320px; text-align: center; font-size: var(--text-command); font-weight: 700; }
.rotate-card__note { font-size: var(--text-small); font-weight: 400; }

/* Calm motion, from the comfort setting or the device. */
.calm *, .calm *::before, .calm *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  .stage *, .stage *::before, .stage *::after { animation: none !important; transition: none !important; }
}
