/* Berthold City: the home page. A title screen made from the records' art, the games as cartridges, the shop.
   The art is the records' own screenprint layers (assets/art, built by tools/make-art.py). Each layer is a
   stencil: CSS masks it and fills it with an ink color, so one piece of art can be printed in any record's colors.
   Motion is CSS scroll-driven animation where the browser has it, and the page is complete without it. */

:root {
  --ink: #0b0b0b; --paper: #efeadd; --grey: #8a8778;
  --mustard: #e8a92c; --red: #e6114f;
  /* World 1, When Words Are Not Enough */
  --forest: #335847; --forest-deep: #15201e; --teal: #3bc3b1; --orange: #e8742e;
  /* World 2, Where Did We Go Wrong? */
  --maroon: #593232; --maroon-deep: #241a19; --rose: #9b4852; --yellow: #feb71c;
  --accent: var(--mustard);
  --hud-h: 52px;
  --px: "Press Start 2P", ui-monospace, monospace;
  --wide: "Archivo", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: var(--hud-h); }
html, body { margin: 0; background: var(--ink); color: var(--paper); }
body { font-family: var(--wide); font-size: 16px; line-height: 1.5; overflow-x: clip; }
img { max-width: 100%; height: auto; }
a { color: inherit; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 4px solid var(--accent); outline-offset: 4px; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--mustard); color: var(--ink);
        padding: 8px 12px; font-family: var(--px); font-size: 11px; }
.skip:focus { left: 8px; }

/* ---- stencils: art as a mask, filled with an ink color -------------------------------------------------- */
.mask { display: block; background: currentColor; -webkit-mask: var(--m) center / contain no-repeat;
        mask: var(--m) center / contain no-repeat; }
.m-logo-ext  { --m: url(assets/art/logo-extended.svg); aspect-ratio: 3000 / 213; }
.m-logo-cond { --m: url(assets/art/logo-condensed.svg); aspect-ratio: 2400 / 458; }
.m-war       { --m: url(assets/art/war.svg); aspect-ratio: 600 / 363; }
.m-cloud     { --m: url(assets/art/w2-cloud.png); aspect-ratio: 1600 / 1558; }
.m-city      { --m: url(assets/art/w1-city.png); aspect-ratio: 2000 / 2093; }
.m-statue    { --m: url(assets/art/w1-statue.png); aspect-ratio: 1400 / 1068; }
.m-rats      { --m: url(assets/art/w3-rats.png); aspect-ratio: 1600 / 1771; }
.ink { width: 100%; }
/* Some art is a hard-edged rectangle (a cropped photo collage): a second mask fades its edges into the page. */
.soft { -webkit-mask: var(--m) center / contain no-repeat, var(--fade, radial-gradient(closest-side, #000 62%, transparent));
  -webkit-mask-composite: source-in;
  mask: var(--m) center / contain no-repeat, var(--fade, radial-gradient(closest-side, #000 62%, transparent));
  mask-composite: intersect; }
.m-city.soft { --fade: radial-gradient(farthest-side at 30% 100%, #000 55%, transparent 98%); }

/* Film grain over everything, like ink on paper. */
.grain { position: fixed; inset: -50%; z-index: 90; pointer-events: none; opacity: .13; mix-blend-mode: overlay;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain .5s steps(4) infinite; }
@keyframes grain { 25% { translate: -3% 2% } 50% { translate: 2% -3% } 75% { translate: -2% -1% } }

/* ---- the HUD -------------------------------------------------------------------------------------------- */
.hud { position: fixed; z-index: 80; inset: 0 0 auto; height: calc(var(--hud-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 16px 0; display: flex; align-items: center; gap: 18px;
  background: color-mix(in srgb, var(--ink) 88%, transparent); border-bottom: 3px solid var(--accent);
  backdrop-filter: blur(6px); font-family: var(--px); font-size: 10px; transition: border-color .4s; }
.hud-logo { width: 150px; color: var(--paper); flex: none; }
.hud-nav { display: flex; gap: 14px; }
.hud-nav a { text-decoration: none; padding: 6px 2px; }
.hud-nav a:hover { color: var(--accent); }
.hud-lives { display: flex; gap: 4px; margin-left: auto; }
.hud-lives i { width: 10px; height: 10px; border-radius: 50%; background: var(--red); }
.hud-sound { font: inherit; color: var(--paper); background: none; border: 2px solid #333; padding: 6px 8px; cursor: pointer; }
.hud-sound[aria-pressed="false"] { color: var(--grey); }
@media (max-width: 520px) { .hud-lives { display: none; } .hud-sound { margin-left: auto; } }
@media (max-width: 520px) { .hud { gap: 10px; padding-inline: 12px; } .hud-logo { width: 96px; } .hud-nav { gap: 8px; font-size: 9px; } }

/* ---- shared ---------------------------------------------------------------------------------------------- */
.pixel-h { font-family: var(--px); font-weight: normal; font-size: clamp(16px, 3.4vw, 30px); color: var(--mustard);
  text-shadow: 4px 4px 0 var(--red); letter-spacing: 1px; text-align: center; margin: 0 0 28px; }
.blink { animation: blink 1.1s steps(2, jump-none) infinite; }
@keyframes blink { 50% { opacity: 0 } }
.layer { position: absolute; pointer-events: none; }

.sprite { display: block; width: calc(128px * var(--s, 2)); height: calc(var(--h) * 1px * var(--s, 2));
  background: var(--src) 0 0 / calc(1280px * var(--s, 2)) 100% no-repeat; image-rendering: pixelated;
  animation: idle .72s steps(4) infinite var(--d, 0s); }
@keyframes idle { to { background-position-x: calc(-512px * var(--s, 2)) } }
.sprite.walking { animation: walk .6s steps(6) infinite; }
@keyframes walk { from { background-position-x: calc(-512px * var(--s, 2)) } to { background-position-x: calc(-1280px * var(--s, 2)) } }

/* ---- title screen ---------------------------------------------------------------------------------------- */
.hero { position: relative; min-height: 100svh; overflow: hidden; display: grid; place-items: center;
  padding: calc(var(--hud-h) + 24px) 16px 0; isolation: isolate;
  background: radial-gradient(ellipse at 50% 35%, #2a1414 0%, var(--ink) 65%); }
.hero-layers { position: absolute; inset: 0; z-index: -1; }
.hero .layer { translate: calc(var(--mx, 0) * var(--depth, 0) * 1px) calc(var(--my, 0) * var(--depth, 0) * 1px); transition: translate .25s ease-out; }
.l-cloud { --depth: 8; width: min(1200px, 125vmin); left: 50%; top: 6%; margin-left: calc(min(1200px, 125vmin) / -2); color: var(--rose); opacity: .85; }
.l-city { --depth: 16; width: min(760px, 70vw); left: -6%; bottom: -16%; color: var(--forest); }
.l-statue { --depth: 28; width: min(520px, 48vw); left: 2%; bottom: 7%; color: var(--orange); }
.l-rats { --depth: 34; width: min(470px, 42vw); right: 0; bottom: 2%; color: var(--paper); }
.l-dots { --depth: 44; inset: 0; }
.l-dots i { position: absolute; width: clamp(18px, 3vw, 34px); aspect-ratio: 1; border-radius: 50%; background: var(--red);
  animation: bob 2.4s ease-in-out infinite; }
.l-dots i:nth-child(1) { left: 22%; top: 30%; }
.l-dots i:nth-child(2) { left: 70%; top: 22%; animation-delay: -.5s; }
.l-dots i:nth-child(3) { left: 82%; top: 48%; animation-delay: -1s; }
.l-dots i:nth-child(4) { left: 12%; top: 58%; animation-delay: -1.5s; }
.l-dots i:nth-child(5) { left: 55%; top: 70%; animation-delay: -2s; }
@keyframes bob { 50% { transform: translateY(-10px) } }

.hero-type { text-align: center; display: flex; flex-direction: column; align-items: center; z-index: 1; padding-bottom: 180px; }
.cover-type { margin: 0; display: grid; grid-template-columns: auto auto; align-items: start; justify-content: center;
  font-family: var(--wide); font-weight: 900; font-stretch: 125%; color: var(--yellow); line-height: .82;
  filter: drop-shadow(5px 4px 0 var(--red)); }
.ct-top { font-size: clamp(34px, min(11.2vw, 19svh), 168px); letter-spacing: -.02em; }
.ct-side { writing-mode: vertical-rl; font-size: clamp(34px, min(11.2vw, 19svh), 168px); margin-top: .02em; letter-spacing: -.02em; }
.hero-sub { display: inline-block; font-family: var(--px); font-size: clamp(8px, 1.3vw, 12px); letter-spacing: 2px;
  margin: 0 0 30px; padding: 10px 12px; line-height: 1.7; color: var(--paper); background: var(--ink); }
.press { display: table; margin: 0 auto; font-family: var(--px); font-size: clamp(14px, 2.4vw, 22px); color: var(--paper);
  text-decoration: none; padding: 14px 18px; text-shadow: 3px 3px 0 var(--red); }
.press:hover, .press:focus-visible { color: var(--yellow); }

.band-row { position: absolute; left: 0; right: 0; bottom: 20px; display: flex; justify-content: center; gap: 0;
  --s: 1.5; z-index: 2; }
.band-row .sprite { margin-inline: -18px; cursor: pointer; pointer-events: auto; }
.hero-floor { position: absolute; left: 0; right: 0; bottom: 0; height: 26px; z-index: 1;
  background: repeating-linear-gradient(90deg, #1d1d1d 0 32px, #262626 32px 64px); border-top: 3px solid var(--mustard); }
@media (max-width: 640px) { .ct-top, .ct-side { font-size: min(10.2vw, 19svh); } .band-row { --s: 1; } .hero-type { padding-bottom: 130px; } .l-statue { bottom: 18%; } }

@media (max-width: 400px) { .band-row { --s: .8; } .band-row .sprite { margin-inline: -14px; } }
/* A phone on its side: short and wide. Everything on the title screen has to fit in about 390px of height. */
@media (max-height: 520px) and (orientation: landscape) {
  .hero { padding-top: calc(var(--hud-h) + 12px); }
  .hero-type { padding-bottom: 104px; }
  .hero-sub { margin-bottom: 10px; padding: 6px 10px; }
  .press { padding: 8px 14px; }
  .band-row { --s: .7; bottom: 14px; }
  .band-row .sprite { margin-inline: -10px; }
  .hero-floor { height: 16px; }
}

/* ---- featured: big news, each one a NEW! box that links to the shop or wherever it lives ------------------ */
.featured { padding: 90px 16px 40px; background: var(--ink); }
.feat-row { display: grid; gap: 24px; max-width: 1000px; margin: 0 auto; }
.feat { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: center; text-decoration: none;
  background: #111; border: 4px solid var(--paper); box-shadow: 0 0 0 4px var(--ink), 0 0 0 8px var(--red);
  transition: transform .1s steps(2); }
.feat:hover, .feat:focus-visible { transform: translateY(-4px); }
.feat-art { position: relative; display: block; align-self: stretch; min-height: 200px; background: #1b1b1b; }
.feat-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.feat-badge { position: absolute; left: 12px; top: 12px; font-family: var(--px); font-size: 12px; color: var(--ink);
  background: var(--yellow); border: 3px solid var(--ink); padding: 7px 9px 6px; }
.feat-body { display: block; padding: clamp(18px, 4vw, 34px); }
.feat-body b { display: block; font-family: var(--px); font-weight: normal; font-size: clamp(14px, 2.6vw, 22px); line-height: 1.4;
  color: var(--mustard); text-shadow: 3px 3px 0 var(--red); }
.feat-body span { display: block; margin-top: 14px; font-size: clamp(15px, 1.8vw, 17px); line-height: 1.5; color: var(--paper); }
.feat-body em { display: inline-block; margin-top: 20px; font-style: normal; font-family: var(--px); font-size: 11px;
  color: var(--ink); background: var(--mustard); padding: 10px 12px; }
@media (max-width: 640px) { .feat { grid-template-columns: 1fr; } .feat-art { aspect-ratio: 16 / 9; min-height: 0; } }

/* ---- games: SNES cartridges ------------------------------------------------------------------------------ */
.games { padding: 110px 16px 70px; background: linear-gradient(#141414, #0b0b0b); text-align: center; position: relative;
  overflow: hidden; isolation: isolate; }
.backdrop { position: absolute; z-index: -1; pointer-events: none; }
.games .backdrop { left: -8%; bottom: -10%; width: min(900px, 90vw); color: #1b2a24; }
.shop .backdrop { right: -6%; top: -20%; width: min(620px, 70vw); color: #1c1a17; }
.games-sub { font-family: var(--px); font-size: 9px; color: var(--grey); margin: -14px 0 40px; letter-spacing: 1px; }
/* One cart per game. The label is the game's tile at its own shape (500 x 168), so the whole art always shows.
   On a phone the shelf swipes sideways, one cart at a time, with the next one peeking in. */
.shelf { display: flex; gap: clamp(18px, 4vw, 34px); justify-content: safe center; overflow-x: auto;
  scroll-snap-type: x mandatory; padding: 26px max(16px, calc((100% - var(--cart-w)) / 2)) 34px; max-width: 1200px;
  margin: 0 auto; scrollbar-width: none; --cart-w: min(400px, calc(100vw - 72px)); }
.shelf::-webkit-scrollbar { display: none; }
@media (min-width: 900px) { .shelf { padding-inline: 20px; } }
.cart { flex: 0 0 auto; width: var(--cart-w); scroll-snap-align: center; text-decoration: none; color: var(--ink);
  position: relative; perspective: 1100px; -webkit-tap-highlight-color: transparent; }
.cart-flip { display: block; position: relative; transform-style: preserve-3d; transition: transform .5s cubic-bezier(.2, .9, .3, 1.2); }
.cart.dealt .cart-flip { animation: deal .7s cubic-bezier(.2, .9, .3, 1.15) backwards var(--d, 0s); }
/* no opacity here: it would flatten the 3D and show a face-down cart's front through its back */
@keyframes deal { from { transform: translateY(-260px) rotateY(180deg) } }
.cart-face { display: block; -webkit-backface-visibility: hidden; backface-visibility: hidden; position: relative;
  border: 4px solid var(--ink); border-radius: 14px 14px 4px 4px; background: linear-gradient(#c6c6ce, #a9a9b3);
  box-shadow: 8px 10px 0 rgba(0,0,0,.6); padding: clamp(38px, 10%, 50px) clamp(12px, 5%, 20px) clamp(26px, 8%, 36px); }
.cart-face::before { content: ""; position: absolute; left: 7%; right: 7%; top: clamp(9px, 3%, 13px); height: clamp(18px, 6%, 26px);
  border-radius: 6px; background: repeating-linear-gradient(90deg, #9a9aa4 0 4px, #b9b9c2 4px 10px); }
.cart-face::after { content: ""; position: absolute; left: 12%; right: 12%; bottom: -4px; height: 14px; background: var(--ink);
  clip-path: polygon(0 100%, 5% 0, 13% 0, 18% 100%, 82% 100%, 87% 0, 95% 0, 100% 100%); }
.cart-label { display: block; background: var(--ink); border: 3px solid #808089; border-radius: 4px; overflow: hidden; }
.cart-label img { display: block; width: 100%; height: auto; aspect-ratio: 500 / 168; object-fit: contain; image-rendering: pixelated; }
.cart-q { display: grid; place-items: center; aspect-ratio: 500 / 168; font-family: var(--px); font-size: clamp(30px, 9vw, 48px); color: #333; }
.cart-label > span:last-child { display: block; font-family: var(--px); font-size: clamp(8px, 2.2vw, 10px); color: var(--mustard);
  padding: 8px 6px 7px; background: var(--ink); line-height: 1.5; border-top: 2px solid #222; }
.cart-back { position: absolute; inset: 0; transform: rotateY(180deg); display: grid; place-items: center; }
.cart-back .sticker { font-family: var(--px); font-size: clamp(9px, 2.6vw, 11px); line-height: 1.7; color: var(--ink);
  background: var(--mustard); border: 3px solid var(--ink); padding: 12px 14px; rotate: -4deg; }
.cart.soon { cursor: pointer; }
.cart.soon .cart-flip { transform: rotateY(180deg); }
.cart.soon.flipped .cart-flip { transform: rotateY(0deg); }
@media (hover: hover) { .cart.soon:hover .cart-flip { transform: rotateY(0deg); } }
.cart.soon .cart-label img { filter: grayscale(1) brightness(.45); }
@media (hover: hover) { .cart:not(.soon):hover .cart-flip { transform: translateY(-12px) rotate(-1.5deg); } }
.cart:not(.soon):focus-visible .cart-flip { transform: translateY(-12px) rotate(-1.5deg); }
.cart.soon:focus-visible .cart-flip { transform: rotateY(0deg); }
.cart:active .cart-face { filter: brightness(.95); }
.cart:focus-visible { outline: none; } .cart:focus-visible .cart-face { outline: 4px solid var(--mustard); outline-offset: 4px; }
.cart-meta { display: block; font-family: var(--px); font-size: clamp(9px, 2.4vw, 10px); color: var(--paper); margin-top: 20px; line-height: 1.7; }
.cart-meta em { font-style: normal; color: var(--grey); display: block; }
.console { margin: 28px auto 0; width: min(480px, 92vw); }
.console svg { width: 100%; height: auto; display: block; }
.console .led { transition: fill .1s; }
.console.on .led { fill: #ff2a3a; }
.console.on .power { translate: 14px 0; }
.flying { position: fixed; z-index: 95; pointer-events: none; margin: 0; }
.flash { position: fixed; inset: 0; z-index: 96; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: crt .5s ease-in forwards; }
@keyframes crt { 0% { opacity: 0; clip-path: inset(49.5% 0) } 40% { opacity: 1; clip-path: inset(49.5% 0) } 100% { opacity: 1; clip-path: inset(0 0) } }

/* ---- item shop ------------------------------------------------------------------------------------------- */
.shop { padding: 40px 16px 110px; background: var(--ink); position: relative; overflow: hidden; isolation: isolate; }
.shop-box { display: block; max-width: 760px; margin: 0 auto; text-decoration: none; background: #111; border: 4px solid var(--paper);
  box-shadow: 0 0 0 4px var(--ink), 0 0 0 8px var(--mustard); padding: 30px 24px 24px; transition: transform .1s steps(2); }
.shop-box:hover, .shop-box:focus-visible { transform: translateY(-4px); }
.shop-say { font-family: var(--px); font-size: clamp(9px, 1.4vw, 12px); line-height: 2; min-height: 4em; margin: 0 0 18px; }
.shopart { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.shopart img { width: 100%; aspect-ratio: 1; object-fit: contain; image-rendering: pixelated; background: #1d1d1d; display: block; }
.shop-go { display: block; text-align: right; font-family: var(--px); font-size: 11px; color: var(--mustard); margin-top: 18px; }

/* ---- credits --------------------------------------------------------------------------------------------- */
.credits { text-align: center; padding: 90px 16px max(60px, env(safe-area-inset-bottom)); background: var(--ink); border-top: 4px solid var(--mustard); }
.credits-logo { width: min(520px, 86%); margin: 0 auto 50px; color: var(--paper); }
.credits dl { margin: 0 auto; max-width: 640px; font-family: var(--px); font-size: 10px; line-height: 2.1; }
.credits dt { color: var(--mustard); margin-top: 22px; }
.credits dd { margin: 4px 0 0; color: var(--paper); }
.credits-war { width: 110px; margin: 50px auto 30px; color: var(--paper); }
.thanks { font-family: var(--px); font-size: 13px; color: var(--yellow); }
.keys { font-family: var(--px); font-size: 8px; color: var(--grey); margin-top: 26px; }

/* ---- scroll-driven motion (Chrome, Edge, Safari 26+; everywhere else the page simply sits still) ---------- */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* title screen: the cloud swells and the layers part as you scroll away */
    .l-cloud .ink { animation: swell linear both; animation-timeline: scroll(root); animation-range: 0 100vh; }
    .l-statue .ink { animation: sink-left linear both; animation-timeline: scroll(root); animation-range: 0 100vh; }
    .l-rats .ink { animation: sink-right linear both; animation-timeline: scroll(root); animation-range: 0 100vh; }
    .hero-type { animation: lift linear both; animation-timeline: scroll(root); animation-range: 0 90vh; }
    @keyframes swell { to { scale: 1.35; translate: 0 12% } }
    @keyframes sink-left { to { translate: -30% 25% } }
    @keyframes sink-right { to { translate: 30% 25% } }
    @keyframes lift { to { translate: 0 -30%; opacity: 0 } }

    /* the cartridges' shelf and the shop drift up a little as they arrive */
    .games .backdrop .ink, .shop .backdrop .ink { animation: depth linear both; animation-timeline: view(); }
    @keyframes depth { from { translate: 0 -12% } to { translate: 0 12% } }
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .cart.soon .cart-flip { transform: none; }
}
