:root {
  --bg: #1b1030;
  --bg2: #0d0818;
  --pad: #3a3450;
  --pad-hi: #4a4462;
  --a: #d84a6a;
  --b: #8b3b9e;
  --sa-top: env(safe-area-inset-top, 0px);
  --sa-bot: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
:root { color-scheme: dark; }
html, body {
  margin: 0; padding: 0; height: 100%;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; }

/* Layout: screen on top, pad below, in a phone-width column on any device */
:root { --btn: 1; }               /* button size scale, set by Settings */
body.size-s { --btn: .85; }
body.size-l { --btn: 1.2; }
#game {
  position: absolute; left: 0; right: 0; top: 0;
  padding-top: var(--sa-top);
  display: flex; justify-content: center; align-items: flex-start;
  background: var(--bg2);
}
#game canvas {
  display: block;
  width: 100vw; height: calc(100vw * 0.9);
  max-height: 58vh; max-width: calc(58vh / 0.9);
  image-rendering: pixelated; image-rendering: crisp-edges;
  background: #000;
}
#controller {
  display: block;
  position: absolute;
  left: 50%; transform: translateX(-50%);
  width: min(100vw, 560px);
  bottom: 0;
  top: calc(var(--sa-top) + min(90vw, 58vh));
  padding-bottom: var(--sa-bot);
  touch-action: none;
}
/* d-pad */
#controller_dpad {
  position: absolute; left: calc(16px + var(--sa-l)); top: 50%;
  width: calc(150px * var(--btn)); height: calc(150px * var(--btn));
  transform: translateY(calc(-50% - var(--sa-bot) / 2));
  touch-action: none;
}
#controller_dpad:before {
  content: ""; position: absolute; left: 33.3%; top: 33.3%; width: 33.4%; height: 33.4%;
  background: var(--pad);
}
#controller_dpad div { position: absolute; width: 33.4%; height: 33.4%; background: var(--pad); pointer-events: none; }
#controller_dpad div:after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 0; height: 0;
  border: 8px solid transparent; transform: translate(-50%, -50%);
}
#controller_up    { left: 33.3%; top: 0;     border-radius: 10px 10px 0 0; }
#controller_down  { left: 33.3%; top: 66.6%; border-radius: 0 0 10px 10px; }
#controller_left  { left: 0;     top: 33.3%; border-radius: 10px 0 0 10px; }
#controller_right { left: 66.6%; top: 33.3%; border-radius: 0 10px 10px 0; }
#controller_up:after    { border-bottom-color: var(--pad-hi); margin-top: -4px; }
#controller_down:after  { border-top-color: var(--pad-hi); margin-top: 4px; }
#controller_left:after  { border-right-color: var(--pad-hi); margin-left: -4px; }
#controller_right:after { border-left-color: var(--pad-hi); margin-left: 4px; }
#controller_dpad div.btnPressed { background: var(--pad-hi); transform: none; box-shadow: none; }

/* A / B */
.roundBtn {
  position: absolute;
  width: calc(76px * var(--btn)); height: calc(76px * var(--btn)); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: calc(28px * var(--btn)); color: rgba(0,0,0,.45);
  box-shadow: 0 4px 0 rgba(0,0,0,.35);
  cursor: pointer; touch-action: none;
}
#controller_a { right: calc(16px + var(--sa-r)); top: 50%; transform: translateY(calc(-80% - var(--sa-bot) / 2)); background: var(--a); }
#controller_b { right: calc(16px + var(--sa-r) + 90px * var(--btn)); top: 50%; transform: translateY(calc(-20% - var(--sa-bot) / 2)); background: var(--b); }

/* Select / Start */
.capsuleBtn {
  position: absolute; bottom: calc(16px + var(--sa-bot));
  width: 100px; height: 30px; border-radius: 15px;
  background: var(--pad);
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: rgba(255,255,255,.75);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
  cursor: pointer; touch-action: none;
}
#controller_select { left: calc(50% - 108px); }
#controller_start  { left: calc(50% + 8px); }

.btnPressed { filter: brightness(1.35); }
.roundBtn.btnPressed { box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.capsuleBtn.btnPressed { box-shadow: 0 1px 0 rgba(0,0,0,.35); transform: translateY(2px); }

/* Buttons hidden: the screen takes the window */
body.nobuttons #game { bottom: 0; padding: 0; align-items: center; }
body.nobuttons #game canvas { width: auto; height: min(100vh, 100vw * 0.9); max-height: none; max-width: none; }

/* Landscape phones: screen in the middle, pad left, buttons right */
@media (orientation: landscape) and (max-height: 520px) {
  #game { bottom: 0; padding: 0; align-items: center; }
  #game canvas { width: auto; height: 100vh; max-height: 100vh; max-width: 100vw; }
  #controller { top: 0; left: 0; right: 0; width: auto; transform: none; opacity: .9; }
  #controller_dpad { left: calc(3vw + var(--sa-l)); }
  #controller_a { right: calc(3vw + var(--sa-r)); }
  #controller_b { right: calc(3vw + var(--sa-r) + 86px * var(--btn)); }
  #controller_select { left: calc(3vw + var(--sa-l)); bottom: 12px; }
  #controller_start  { right: calc(3vw + var(--sa-r)); left: auto; bottom: 12px; }
}

/* Pixel font spans (js/pxfont.js) */
.px { display: inline-flex; align-items: flex-end; white-space: nowrap; line-height: 1; }
.px i { display: inline-block; background-repeat: no-repeat; image-rendering: pixelated; image-rendering: crisp-edges; pointer-events: none; }
.roundBtn .px i, .capsuleBtn .px i { filter: brightness(0) opacity(.45); }  /* dark glyphs on the coloured buttons */

/* Menu button: faint hamburger just under the screen */
#menuBtn {
  position: fixed; z-index: 15; left: 50%; transform: translateX(-50%);
  top: calc(var(--sa-top) + min(90vw, 58vh) + 6px);
  width: 56px; height: 30px; border: 0; border-radius: 8px; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; opacity: .55; transition: opacity .15s;
}
#menuBtn i { display: block; width: 22px; height: 2px; border-radius: 1px; background: #fff; }
#menuBtn:hover, #menuBtn:active { opacity: .8; }
body.nobuttons #menuBtn { top: auto; bottom: calc(6px + var(--sa-bot)); }
@media (orientation: landscape) and (max-height: 520px) {
  #menuBtn { top: auto; bottom: calc(4px + var(--sa-bot)); }
}

/* Menu open: blur the game, slide the sheet up */
#game, #controller, #menuBtn { transition: filter .25s ease; }
body.menuOpen #game, body.menuOpen #controller, body.menuOpen #menuBtn { filter: blur(6px) brightness(.7); }
.sheet {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(5,3,12,.45);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .25s ease;
}
.sheet.open { opacity: 1; }
.sheet[hidden] { display: none; }
.sheetCard {
  width: min(100vw, 520px); max-height: calc(100vh - 24px); overflow-y: auto;
  background: #211636; color: #f2eefa;
  border-radius: 18px 18px 0 0; padding: 6px 16px calc(18px + var(--sa-bot));
  box-shadow: 0 -10px 40px rgba(0,0,0,.6);
  border: 1px solid rgba(255,255,255,.06); border-bottom: 0;
  font-size: 15px;
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
}
.sheet.open .sheetCard { transform: translateY(0); }
@media (min-width: 560px) and (min-height: 640px) {
  .sheet { align-items: center; }
  .sheetCard { border-radius: 18px; padding-bottom: 18px; border-bottom: 1px solid rgba(255,255,255,.06); transform: translateY(40px); }
  .sheet.open .sheetCard { transform: none; }
}
.sheetHead { display: flex; align-items: center; justify-content: space-between; padding: 12px 0 8px; }
.sheetHead button { border: 0; background: transparent; font-size: 28px; line-height: 1; color: #9a8fb5; padding: 0 4px; cursor: pointer; }
.group { margin-top: 12px; padding: 6px 0 2px; opacity: .7; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 12px 0; border-top: 1px solid rgba(255,255,255,.08);
  background: none; border-left: 0; border-right: 0; border-bottom: 0;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.row:active { background: rgba(255,255,255,.04); }
.row.action .chev { color: #8a7fa6; font-size: 20px; }
.row.danger .px i { filter: sepia(1) saturate(8) hue-rotate(-50deg); }
.row select { font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid rgba(255,255,255,.15); background: #2d2046; color: #fff; }
.row input[type=checkbox] { position: absolute; opacity: 0; width: 0; height: 0; }
.switch { position: relative; flex: none; width: 46px; height: 28px; border-radius: 14px; background: #4a4262; transition: background .15s; }
.switch:before { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4); transition: left .15s; }
.row input:checked + .switch { background: #3bbf63; }
.row input:checked + .switch:before { left: 21px; }
.keys { margin-top: 14px; font-size: 12px; color: #9a8fb5; line-height: 1.4; border-top: 1px solid rgba(255,255,255,.08); padding-top: 10px; }
.about { font-size: 11px; color: #6f6689; margin-top: 6px; }

/* Tap to play */
.overlay {
  position: fixed; inset: 0; z-index: 25;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.overlay img { border-radius: 24px; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
#playBtn {
  margin-top: 14px; border: 0; border-radius: 16px; padding: 16px 48px; cursor: pointer;
  background: #3bbf63; box-shadow: 0 5px 0 #1e7a3a; 
}
#playBtn:active { transform: translateY(3px); box-shadow: 0 2px 0 #1e7a3a; }
#playBtn .px i { filter: brightness(0) opacity(.7); }
.linkBtn { margin-top: 8px; border: 0; background: none; color: #fff; opacity: .7; cursor: pointer; padding: 8px; }
.hint { opacity: .6; }
.overlay.hidden { display: none; }


/* 3D box viewer */
#boxView {
  position: fixed; inset: 0; z-index: 35;
  background: radial-gradient(ellipse at 50% 40%, rgba(60,40,110,.55), rgba(5,3,12,.85));
  opacity: 0; transition: opacity .25s ease; touch-action: none;
}
#boxView.open { opacity: 1; }
#boxView[hidden] { display: none; }
#boxView canvas, #splashBox3d canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; touch-action: none; display: block; }
#boxView canvas:active, #splashBox3d canvas:active { cursor: grabbing; }
#boxView .boxMsg { position: absolute; left: 0; right: 0; bottom: calc(22px + var(--sa-bot)); display: flex; flex-direction: column; align-items: center; gap: 8px; opacity: .6; pointer-events: none; text-align: center; color: #fff; }
#boxClose { position: absolute; top: calc(12px + var(--sa-top)); right: calc(12px + var(--sa-r)); width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.1); color: #fff; font-size: 28px; line-height: 1; cursor: pointer; }

/* Text font choice: plain-text mode for Space Grotesk / OpenDyslexic */
.pxtext { white-space: nowrap; line-height: 1.1; }
html[data-uifont="grotesk"] { --uifont: "Space Grotesk", system-ui, sans-serif; }
html[data-uifont="dyslexic"] { --uifont: "OpenDyslexic", system-ui, sans-serif; }
html[data-uifont="grotesk"] body, html[data-uifont="dyslexic"] body,
html[data-uifont="grotesk"] .row select, html[data-uifont="dyslexic"] .row select { font-family: var(--uifont); }
html[data-uifont="dyslexic"] .pxtext { line-height: 1.35; }

/* Splash: 3D box on top, app UI below */
#tap { justify-content: flex-start; gap: 0; padding-top: var(--sa-top); padding-bottom: var(--sa-bot);
  background: radial-gradient(ellipse at 50% 28%, #34215e 0%, var(--bg) 60%); }
#splashBox3d { position: relative; width: 100%; flex: 1 1 auto; min-height: 0; }
#splashBox3d .boxMsg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; opacity: .6; pointer-events: none; }
.splashUi { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 8px 0 calc(28px + 4vh); }
.splashUi #playBtn { margin-top: 0; }
.splashUi .linkBtn { margin-top: 0; }
@media (orientation: landscape) and (max-height: 520px) {
  #tap { flex-direction: row; }
  #splashBox3d { flex: 1 1 auto; height: 100%; }
  .splashUi { justify-content: center; padding: 0 6vw; }
}

/* iOS: no double-tap zoom on anything tappable (the game pad keeps touch-action: none) */
button, .row, select, label, #menuBtn, #tap { touch-action: manipulation; }

/* Splash link row: Instagram, itch.io, GET THE APP */
.linkRow { display: flex; align-items: stretch; gap: var(--tileGap); }
.splashUi { --tileGap: 16px; gap: 22px !important; }
/* Play spans exactly the row of four tiles under it */
.splashUi #playBtn { width: calc(4 * 48px + 3 * var(--tileGap)); padding-left: 0; padding-right: 0; }
.tileBtn {
  flex: none; display: flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; border-radius: 14px; color: #fff; text-decoration: none;
  box-shadow: 0 4px 0 rgba(0,0,0,.35); touch-action: manipulation;
}
.tileBtn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.35); }
.igBtn { background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fd5949 45%, #d6249f 60%, #285aeb 90%); }
.itchBtn { background: #fa5c5c; }
.getApp { display: flex; gap: var(--tileGap); }
.getApp[hidden] { display: none; }
.getApp .tileBtn { border: 0; padding: 0; cursor: pointer; }
.androidBtn { background: #3ddc84; color: #073b1f; }
.iosBtn { background: #f2f2f7; color: #111; }

/* How-to-install modal */
.howtoCard { padding-bottom: calc(22px + var(--sa-bot)); }
.steps { margin: 6px 0 0; padding-left: 26px; font-size: 16px; line-height: 1.45; }
.steps li { padding: 7px 0; border-top: 1px solid rgba(255,255,255,.08); }
.steps li:first-child { border-top: 0; }
.steps .share { display: inline-block; width: 1.1em; height: 1.1em; vertical-align: -0.2em; }
.howtoNote { margin: 12px 0 0; font-size: 14px; color: #b9b0d0; line-height: 1.4; }
.installNow { margin-top: 16px; width: 100%; border: 0; border-radius: 14px; padding: 14px; background: #3bbf63; box-shadow: 0 4px 0 #1e7a3a; cursor: pointer; }
.installNow .px i { filter: brightness(0) opacity(.7); }
.installNow[hidden] { display: none; }
a.row { text-decoration: none; }

/* Try-out (Keegan 2026-10-28): a game colour as a hard drop shadow under the pad */
:root { --padShadow: #482888; }   /* game shadow purple (Keegan picked it over navy #000048) */
#controller_dpad { filter: drop-shadow(0 5px 0 var(--padShadow)); }
.roundBtn, .capsuleBtn { box-shadow: 0 5px 0 var(--padShadow); }
.roundBtn.btnPressed, .capsuleBtn.btnPressed { box-shadow: 0 2px 0 var(--padShadow); }

/* ===== Menu A: grouped cards (Keegan picked A, 2026-10-28) ===== */
.menuA { background: #1d1430; }
.menuA .lbl { margin: 14px 4px 6px; opacity: .6; }
.menuA .card { background: #2a1e42; border-radius: 14px; overflow: hidden; }
.menuA .row { gap: 12px; padding: 11px 12px; border-top: 1px solid rgba(255,255,255,.07); }
.menuA .card > .row:first-child { border-top: 0; }
.menuA .row > [data-px], .menuA .row > .px, .menuA .row > .pxtext { flex: 1; }
.menuA .ico { width: 28px; height: 28px; border-radius: 8px; flex: none; display: flex; align-items: center; justify-content: center; font-size: 15px; color: #fff; font-style: normal; }
.menuA .row.stack { flex-direction: column; align-items: stretch; gap: 10px; cursor: default; }
.menuA .rowTop { display: flex; align-items: center; gap: 12px; }
/* your save */
.saveCardRow { display: flex; gap: 12px; padding: 12px; align-items: center; }
.saveCardRow .thumb { width: 104px; height: 94px; border-radius: 6px; flex: none; background: #000048 center/cover; image-rendering: pixelated; border: 2px solid #3a3450; }
.saveMeta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.pairBtns { display: flex; gap: 8px; margin-top: 4px; }
.pill { flex: 1; border: 0; border-radius: 10px; padding: 9px 4px; background: #3a2c58; color: #fff; display: flex; justify-content: center; cursor: pointer; box-shadow: 0 3px 0 var(--padShadow, #482888); }
.pill:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--padShadow, #482888); }
/* three-way pickers */
.seg3 { display: flex; gap: 6px; }
.seg3 button { flex: 1; height: 40px; border: 0; border-radius: 9px; padding: 0 2px; background: #3a2c58; color: #cfc6e6; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 14px; font-weight: 600; box-shadow: 0 3px 0 rgba(0,0,0,.35); }
.seg3 button.on { background: #3bbf63; color: #fff; box-shadow: 0 3px 0 #1e7a3a; text-shadow: 0 2px 0 #482888; }
/* custom pixel switch: squared, square knob, purple drop shadow like the pad */
.menuA .switch { width: 54px; height: 28px; border-radius: 6px; background: #4a4262; box-shadow: 0 4px 0 var(--padShadow, #482888); transition: background .12s; }
.menuA .switch:before { top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 3px; background: #f8f8f8; box-shadow: inset 0 -3px 0 #c8c0dc; transition: left .12s; }
.menuA .switch:after { content: ""; position: absolute; top: 11px; right: 9px; width: 6px; height: 6px; background: rgba(255,255,255,.35); transition: all .12s; }
.menuA .row input:checked + .switch { background: #3bbf63; }
.menuA .row input:checked + .switch:before { left: 30px; }
.menuA .row input:checked + .switch:after { right: auto; left: 9px; width: 3px; height: 10px; top: 9px; background: rgba(255,255,255,.75); }
/* erase as a quiet red link under the cards */
.eraseLink { display: block; margin: 16px auto 0; border: 0; background: none; padding: 8px; cursor: pointer; }
.eraseLink .px i { filter: sepia(1) saturate(8) hue-rotate(-50deg); }

/* About page */
.aboutCard { padding-bottom: calc(22px + var(--sa-bot)); }
#aboutCart { position: relative; height: 260px; margin: 4px -16px 6px; background: radial-gradient(ellipse at 50% 45%, #34215e, transparent 70%); }
#aboutCart canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#aboutCart .boxMsg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #9a8fb5; pointer-events: none; }
.aboutText { font-size: 14px; line-height: 1.5; color: #e4def2; }
.aboutText p { margin: 0 0 12px; }
.aboutText a { color: #b8a6ff; }
.aboutText ul { margin: 0 0 12px; padding-left: 18px; }
.aboutText li { margin-bottom: 8px; }
.aboutLbl { font-weight: 700; color: #fff; margin-bottom: 6px !important; }
.aboutSmall { font-size: 12px; color: #9a8fb5; }

/* Splash swap slot: the other model peeks up from the bottom edge, like a cart half in a slot */
#swapSlot {
  position: absolute; left: 50%; bottom: 0; z-index: 2;
  width: 112px; padding: 0; border: 0; background: none; cursor: pointer;
  transform: translate(-50%, 52%); transition: transform .25s cubic-bezier(.2,.8,.2,1);
  touch-action: manipulation;
}
#swapSlot:hover, #swapSlot:focus-visible { transform: translate(-50%, 40%); }
#swapSlot:active { transform: translate(-50%, 46%); }
#swapSlot img { display: block; width: 100%; height: auto; filter: drop-shadow(0 -4px 14px rgba(0,0,0,.5)); }
#swapSlot.isBox img { border-radius: 3px; image-rendering: auto; }
#tap .splashUi { padding-bottom: calc(86px + var(--sa-bot)); }
@media (orientation: landscape) and (max-height: 520px) {
  #swapSlot { left: 27%; width: 84px; }
  #tap .splashUi { padding-bottom: 0; }
}
