/* /alba — the calculator is as big as the screen allows and always fits whole:
   on a phone it is all there is (the user's wish: no text, nothing to scroll);
   on a computer the first line of the notes stays in view under it.
   Key zones, pressed-key sprites and the image size (--cw, --ch) are in keys.css. */

@font-face { font-family: "Fira Sans"; font-weight: 400; font-display: swap; src: url(/fonts/fira-400-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF; }
@font-face { font-family: "Fira Sans"; font-weight: 400; font-display: swap; src: url(/fonts/fira-400-cyrillic.woff2) format("woff2"); unicode-range: U+0400-04FF; }

:root {
  --bg: #0c0d0f;
  --ink: #f1efe9;
  --muted: #8f8c85;
  --accent: #ffd500;
  --gutter: 0px;      /* around the calculator */
  --reserve: 0px;     /* screen height kept for the notes */
  color-scheme: dark;
}
footer { display: none; }
@media (min-width: 700px) and (min-height: 560px) {
  :root { --gutter: 16px; --reserve: 44px; }
  footer { display: block; }
}

html, body { margin: 0; background: var(--bg); color: var(--ink); }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
body { font: 400 13px/1.5 "Fira Sans", system-ui, sans-serif; touch-action: manipulation; }

main {
  --top: max(var(--gutter), env(safe-area-inset-top, 0px));
  --bottom: max(var(--gutter), env(safe-area-inset-bottom, 0px));
  --side: max(var(--gutter), env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  min-height: calc(100vh - var(--reserve));
  min-height: calc(100svh - var(--reserve));
  box-sizing: border-box;
  display: grid;
  place-items: center;
  padding: var(--top) var(--side) var(--bottom);
}

.calc {
  position: relative;
  width: min(100vw - 2 * var(--side), (100vh - var(--reserve) - var(--top) - var(--bottom)) * var(--cw) / var(--ch));
  width: min(100vw - 2 * var(--side), (100svh - var(--reserve) - var(--top) - var(--bottom)) * var(--cw) / var(--ch));
  aspect-ratio: var(--cw) / var(--ch);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.calc > img { display: block; width: 100%; height: auto; }
.calc canvas, .calc .cover, .keys, .dpad { position: absolute; }
.calc canvas { outline: none; }
@media (min-resolution: 2dppx) {
  .calc canvas { image-rendering: pixelated; }
}
.keys { inset: 0; pointer-events: none; }
.keys span { position: absolute; display: block; cursor: pointer; touch-action: none; pointer-events: auto; }
.keys span:not(.arrow) {
  background-image: url(pressed.webp);
  background-repeat: no-repeat;
  opacity: 0;
}
.keys span.down { opacity: 1; }

.dpad { pointer-events: none; }
.dpad i {
  position: absolute; inset: 0; background: no-repeat center / 100% 100%; opacity: 0;
  /* the tilted cross is a separate render: fade its edges into the body */
  -webkit-mask: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent),
                linear-gradient(transparent, #000 5%, #000 95%, transparent);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
}
.dpad.left i.left, .dpad.up i.up, .dpad.down i.down, .dpad.right i.right { opacity: 1; }
.dpad i.left { background-image: url(dpad-left.webp); }
.dpad i.up { background-image: url(dpad-up.webp); }
.dpad i.down { background-image: url(dpad-down.webp); }
.dpad i.right { background-image: url(dpad-right.webp); }

.cover { display: none; background: #0b0c0e; }
.calc.loading .cover { display: grid; place-items: center; }
.calc.loading canvas { visibility: hidden; }
.cover::after {
  content: "";
  width: 12%;
  aspect-ratio: 1;
  border: 3px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { .cover::after { animation: none; } }

footer {
  box-sizing: border-box;
  max-width: 64ch;
  margin: 0 auto;
  padding: 12px max(16px, env(safe-area-inset-left, 0px)) max(20px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-right, 0px));
  color: var(--muted);
  text-align: center;
  text-wrap: balance;
}
footer p { margin: 0 0 6px; }
footer a { color: var(--ink); text-decoration-color: var(--accent); text-underline-offset: 2px; }
