:root {
  --ink: #262459;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: var(--ink);
  font-family: system-ui, sans-serif;
  color: var(--ink);
  display: flex;
  justify-content: center;
}

/* The game screen sits flush against the top and sides, with no frame round
   it; only the strip underneath, where the three buttons live, is shell. */
#device {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  width: 100%;
  max-width: 560px;
  padding: 0 0 max(10px, env(safe-area-inset-bottom));
  position: relative;
}

/* With the LCD filter on, the screen's navy comes out a shade deeper (its own
   shadow is laid over it), so the page around it is set to that same shade. */
body.lcd, body.lcd #bezel { background: #201e4e; }

/* The LCD filter's glass, over the screen and the buttons alike: a sheen at
   the top left and corners that fall away a little. Taps pass through it. */
/* The filter's wash and colour mode go on the buttons as they go on the picture (set from main.js). */
.btn { filter: var(--btn-filter, brightness(1)); position: relative; z-index: 1; }

#glass { display: none; }
body.lcd #glass {
  display: block;
  position: fixed; /* (over the whole page, so a window wider than the game is covered too) */
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(150deg, rgba(255, 255, 255, calc(.10 * var(--gk, 1))) 0%, rgba(255, 255, 255, calc(.03 * var(--gk, 1))) 22%, rgba(255, 255, 255, 0) 42%),
    radial-gradient(ellipse 75% 62% at 50% 50%, rgba(20, 16, 60, 0) 55%, rgba(20, 16, 60, calc(.24 * var(--gk, 1))) 100%);
}
/* ...and the screen's faint cell grid and scanlines carry on over the strip under it */
#controls::after {
  display: none; /* (the strip's grid is now the page-wide #lcdgrid) */
  content: '';
  position: absolute;
  inset: calc(var(--bpx, var(--px, 3px)) * 6) 0 0 0; /* (from the screen's bottom edge down: the screen has its own grid) */
  pointer-events: none;
  background-image: var(--cell, none), var(--scan, none);
  background-size: var(--px, 3px) var(--px, 3px), 100% calc(var(--px, 3px) / 2);
  z-index: 0; /* (behind the buttons, which have the grid and scanlines drawn on them) */
}

/* (the wrapper only keeps the screen clear of a phone's notch, in the status bar's own colour) */
#bezel {
  background: var(--ink);
  padding-top: env(safe-area-inset-top);
  line-height: 0;
}

#screen {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* The strip comes up over the bottom of the screen (by BUTTON_LIFT game pixels,
   see main.js), so the outer buttons nestle beside the room's name. --drop
   moves them down when the page has room to spare. */
#controls {
  align-self: stretch;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 0;
  position: relative;
  z-index: 1;
  margin-top: calc(var(--bpx, var(--px, 3px)) * -6);
  padding-top: var(--drop, 0px);
  pointer-events: none;
}
#buttons { pointer-events: auto; }

/* --px is the size of one game pixel on the page; main.js sets it whenever the
   screen is sized, so the buttons are drawn at the same pixel scale as the game. */
/* (--bpx is the buttons' own pixel size: the same as the game's, or smaller when a short screen has little room under
   the game; the row keeps the game's width either way, so the outer buttons stay beside the room's name) */
#buttons {
  display: flex;
  width: calc(var(--px, 3px) * 122);
  justify-content: space-between;
  align-items: center;
}

/* Pixel-art buttons: the pictures (up, and pressed) are painted in by
   src/art/buttons.js: 64 x 72 fine pixels, so 32 x 36 game pixels on the page. The outer
   two sit higher than the middle one. */
.btn {
  width: calc(var(--bpx, var(--px, 3px)) * 32);
  height: calc(var(--bpx, var(--px, 3px)) * 36);
  transform: translateY(calc(var(--bpx, var(--px, 3px)) * -5));
  border: none;
  padding: 0;
  background: transparent no-repeat center / 100% 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
  touch-action: none;
}
.btn[data-btn="B"] { transform: translateY(calc(var(--bpx, var(--px, 3px)) * 5)); }
/* lights out in the pet's room: the buttons go dark with it */
body.dark .btn { filter: var(--btn-filter, brightness(1)) brightness(0.32) saturate(0.45); }
.btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ----- the page's height on phones whose toolbars come and go (Safari): the dynamic viewport where supported */
@supports (height: 100dvh) { html, body { height: 100dvh; } }

/* ----- a computer or tablet: the game drawn as a handheld console (main.js sets body.console and sizes it) */
#keys, #turn { display: none; }
body.console {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* a soft backdrop of pale sky with faint dots, the same whatever the hour in the game */
  background: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, .55) 1.2px, transparent 1.6px) 0 0 / 22px 22px,
    linear-gradient(170deg, #cdeefa 0%, #e9f6fb 55%, #fce7ef 100%) !important;
}
body.console #device {
  height: auto;
  width: auto;
  max-width: none;
  flex: none;
  padding: calc(var(--px) * 9) calc(var(--px) * 9) calc(var(--px) * 11);
  border-radius: calc(var(--px) * 14) calc(var(--px) * 14) calc(var(--px) * 30) calc(var(--px) * 14);
  /* moulded cream plastic, lit from the upper left like the game's art */
  background: linear-gradient(155deg, #fffaf0 0%, #f8eedd 45%, #ecdcc4 100%);
  box-shadow: inset calc(var(--px) * 1.2) calc(var(--px) * 1.2) 0 rgba(255, 255, 255, .9),
    inset calc(var(--px) * -1.5) calc(var(--px) * -1.5) 0 rgba(150, 120, 90, .28),
    0 calc(var(--px) * 3) 0 #d9c4a5, 0 calc(var(--px) * 8) calc(var(--px) * 12) rgba(38, 36, 89, .22);
}
/* the screen sits in a dark rounded frame on the shell */
body.console #bezel {
  padding: calc(var(--px) * 4);
  border-radius: calc(var(--px) * 6);
  background: var(--ink) !important;
  box-shadow: inset 0 calc(var(--px) * 1) 0 rgba(0, 0, 0, .35), 0 calc(var(--px) * .8) 0 rgba(255, 255, 255, .8);
}
body.console #controls { margin-top: calc(var(--px) * 9); padding-top: 0; flex: none; }
body.console #controls::after { display: none; }
/* the glass lies over the screen and its frame only */
body.console #glass { position: absolute; inset: auto; left: calc(var(--px) * 9); top: calc(var(--px) * 9); width: var(--bezel-w); height: var(--bezel-h); border-radius: calc(var(--px) * 6); }
body.console #keys {
  display: block;
  margin: calc(var(--px) * 7) 0 0;
  font: 600 13px/1.4 system-ui, sans-serif;
  color: #5a587f;
  letter-spacing: .02em;
}
body.console #keys b { color: var(--ink); }
body.console.touch #keys { display: none; } /* (a tablet has no keyboard to speak of) */

/* ----- a phone held sideways: a card asking for it to be turned (the installed app is locked upright anyway) */
body.turn #device { visibility: hidden; }
body.turn #turn {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 10;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: linear-gradient(170deg, #cdeefa 0%, #fce7ef 100%);
  color: var(--ink);
  font: 700 18px/1.3 system-ui, sans-serif;
  text-align: center;
  padding: 0 24px;
}
body.turn #turn img { width: 72px; height: 72px; image-rendering: pixelated; border-radius: 16px; box-shadow: 0 4px 0 #d9c4a5; }
body.turn #turn p { margin: 0; }

/* the filter's grid and scanlines over the whole page in the phone layout: one canvas, its lines placed by main.js to
   carry on the screen's own, so the screen, the buttons' strip and any space beside them share one grid */
#lcdgrid { display: none; position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }
body.gridpage #lcdgrid { display: block; }
body.console #keys .alpha { display: inline-block; margin-top: 4px; font-weight: 500; color: #8a6f9e; }
body.console #keys .best { display: inline-block; margin-bottom: 4px; font-weight: 700; color: var(--ink); }
