/* Toimitusaika's look: Luckiest Guy for display, Fredoka for text, amber / rust / ink / cream. */
@font-face {
  font-family: 'Luckiest Guy';
  src: url('assets/fonts/LuckiestGuy-Regular.ttf') format('truetype');
  font-display: swap;
}

@font-face {
  font-family: Fredoka;
  src: url('assets/fonts/Fredoka.ttf') format('truetype');
  font-weight: 300 700;
  font-stretch: 75% 125%;
  font-display: swap;
}

:root {
  --amber: #ffb020;
  --amber-hi: #ffc54d;
  --rust: #b4501a;
  --ink: #2a1406;
  --cream: #fff4dc;
  --night: #1c1714;
  --card: rgb(28 24 22 / 94%);
  --cartoon: 'Luckiest Guy', Fredoka, system-ui, sans-serif;
  --pad: clamp(20px, 5vw, 64px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--night);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--cream);
  font-family: Fredoka, system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
}

/* The wordmark: amber face, rust extrusion, ink outline, like the 3D title letters. */
.mark,
.wordmark {
  font-family: var(--cartoon);
  font-weight: 400;
  text-transform: uppercase;
  color: var(--amber);
  -webkit-text-stroke: 0.06em var(--ink);
  paint-order: stroke fill;
}

.mark {
  font-size: 26px;
  letter-spacing: 0.02em;
  text-decoration: none;
  text-shadow:
    0 2px 0 var(--rust),
    0 3px 0 var(--ink);
}

.mark.small {
  font-size: 22px;
}

/* ── The veil: the page starts dark and fades in once the 3D scene is ready (index.html) ── */
.veil {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  pointer-events: none;
  transition:
    opacity 1.2s ease-out,
    visibility 0s linear 1.2s;
}

body.loaded .veil {
  opacity: 0;
  visibility: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .veil {
    transition-duration: 0.3s;
    transition-delay: 0s, 0.3s;
  }
}

/* ── Header ── */
.top {
  position: absolute;
  inset: 0 0 auto;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 20px var(--pad);
}

.top nav {
  display: flex;
  gap: 24px;
}

.top nav {
  align-items: center;
}

/* FI / EN: shaped like the game's language picker, the chosen one in cream. */
.lang {
  display: flex;
  gap: 6px;
}

.lang button {
  padding: 5px 10px 3px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  /* Over the forest an outline alone would vanish: a light fill under it. */
  background: rgb(255 244 220 / 55%);
  color: var(--ink);
  font-family: var(--cartoon);
  font-size: 15px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.12s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.lang button:hover {
  transform: translateY(-2px);
}

.lang button[aria-pressed='true'] {
  background: var(--cream);
  box-shadow: 0 3px 0 var(--rust);
}

.lang button:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}

/* ── Hero: a midday sky over the forest, the 3D wordmark in the middle ── */
.hero {
  position: relative;
  display: grid;
  place-items: center;
  min-height: min(100svh, 920px);
  /* Room at the bottom for the rocks that rise over it (.ledge). */
  padding: 96px var(--pad) 0;
  overflow: hidden;
  color: var(--ink);
  text-align: center;
  /* Midday: deep blue overhead, paling to the haze at the horizon (--horizon, set by title.js where the forest's line is). */
  --haze: #d5e7f3;
  background: linear-gradient(
    180deg,
    #3b7fca 0,
    #6fa9e2 calc(var(--horizon, 45%) * 0.55),
    #a9cdee calc(var(--horizon, 45%) * 0.85),
    var(--haze) calc(var(--horizon, 45%)),
    var(--haze) 100%
  );
}

.hero-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

/*
 * The title: the flat CSS wordmark holds the space and shows until the 3D
 * letters are ready (or for good, without WebGL). The canvas reaches above
 * the title, so the letters fall into view rather than appear mid-air.
 */
.title {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 1100px);
  aspect-ratio: 4 / 1;
  margin: 0;
}

.title .wordmark {
  font-size: clamp(44px, 13.5vw, 200px);
  line-height: 1;
  letter-spacing: 0.05em;
  text-shadow:
    0 0.04em 0 var(--rust),
    0 0.08em 0 var(--rust),
    0 0.11em 0 var(--ink);
  transition: opacity 0.2s;
}

/*
 * The 3D title and the forest it stands in fill the hero, under its text, cut
 * off where the dark games section starts.
 */
#title-3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.6s ease-out;
  /* The hero takes the pointer for it (title.js), so the canvas never covers the text. */
  pointer-events: none;
}

.hero-copy {
  position: relative;
  z-index: 2;
}

/*
 * The row of rocks between the hero and the games: low-poly boulders (ledge.js), rendered
 * once to an image that tiles. Its line (where the rocks sit) lies on the boundary, so they
 * rise over the forest and sink into the dark below. --ledge is the image's height and
 * --ledge-line where its line is, both as tools/ledge.html reports them.
 */
.ledge {
  --ledge: 288px;
  --ledge-line: 184px;
  position: relative;
  /* In front of everything in the hero, the intro card too (.hero-copy is 2): the card's foot
     sinks behind the rocks, for depth. The card's bottom padding keeps its text above them. */
  z-index: 3;
  height: var(--ledge);
  margin: calc(-1 * var(--ledge-line)) 0 calc(var(--ledge-line) - var(--ledge));
  background: url('assets/img/ledge.webp') repeat-x center top / auto 100%;
  pointer-events: none;
}

/*
 * The bird's speech bubble (bird.js): its tail's tip sits at left/top, over the bird's head,
 * the bubble rising up and to the right of it (to the left with .flip, only where the screen ends first).
 * Over the intro card and the rocks, so nothing covers what it says. It's a link (LinkedIn).
 */
.bird-bubble {
  --tail: 26px;
  --fill: var(--cream);
  position: absolute;
  z-index: 4;
  margin: 0;
  padding: 10px 18px 8px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--fill);
  box-shadow: 0 4px 0 rgb(42 20 6 / 55%);
  color: var(--ink);
  font-family: var(--cartoon);
  font-size: clamp(16px, 1.4vw, 20px);
  line-height: 1.2;
  letter-spacing: 0.03em;
  text-decoration: none;
  /* A line for each sentence (the text breaks between them), wrapping only if it must. */
  white-space: pre-line;
  width: max-content;
  max-width: min(22em, 80vw);
  transform-origin: var(--tail) calc(100% + 14px);
  transform: translate(calc(-1 * var(--tail)), calc(-100% - 14px)) scale(0.2);
  opacity: 0;
  transition:
    transform 0.35s cubic-bezier(0.34, 1.6, 0.64, 1),
    opacity 0.15s ease-out;
}

/* The tail: an ink triangle with a cream one inside it, pointing down at the bird. */
.bird-bubble::before,
.bird-bubble::after {
  content: '';
  position: absolute;
  top: 100%;
  left: calc(var(--tail) - 11px);
  border: 11px solid transparent;
  border-top: 15px solid var(--ink);
  border-bottom: 0;
}

.bird-bubble::after {
  left: calc(var(--tail) - 7px);
  margin-top: -4px;
  border-width: 0 7px;
  border-top: 11px solid var(--fill);
}

/* Hovered or pressed, it colours like the page's buttons (.btn); it doesn't move, as its transform places it. */
@media (hover: hover) {
  .bird-bubble:hover {
    --fill: var(--amber);
    box-shadow: 0 4px 0 var(--rust);
  }
}

.bird-bubble:active {
  --fill: var(--amber);
  box-shadow: 0 1px 0 var(--rust);
}

.bird-bubble .external {
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-left: 0.35em;
  vertical-align: -0.05em;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bird-bubble:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.bird-bubble.flip {
  transform-origin: calc(100% - var(--tail)) calc(100% + 14px);
  transform: translate(calc(-100% + var(--tail)), calc(-100% - 14px)) scale(0.2);
}

.bird-bubble.flip::before {
  left: auto;
  right: calc(var(--tail) - 11px);
}

.bird-bubble.flip::after {
  left: auto;
  right: calc(var(--tail) - 7px);
}

.bird-bubble.shown {
  opacity: 1;
  transform: translate(calc(-1 * var(--tail)), calc(-100% - 14px));
}

.bird-bubble.flip.shown {
  transform: translate(calc(-100% + var(--tail)), calc(-100% - 14px));
}

@media (prefers-reduced-motion: reduce) {
  .bird-bubble {
    transition: opacity 0.2s;
  }
}

/* The letters can be clicked (they hop), anywhere over the title. */
.title.ready {
  cursor: pointer;
}

.title.ready .wordmark {
  opacity: 0;
}

.hero:has(.title.ready) #title-3d {
  opacity: 1;
}

.hero:has(.title.failed) #title-3d {
  display: none;
}

/* The intro: on a card like the game's result cards, so it reads over the forest. */
.intro {
  /* As wide as the games below: their 1280px less the same side padding (the hero has it too). */
  box-sizing: border-box;
  width: 100%;
  max-width: calc(1280px - 2 * var(--pad));
  margin-top: 32px;
  /* The extra at the bottom is the part that sinks behind the rocks (.ledge). */
  padding: 44px 48px 190px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 6px 0 rgb(42 20 6 / 55%);
  color: var(--cream);
  font-size: 19px;
  line-height: 1.7;
  font-weight: 500;
  text-align: left;
}

.intro p {
  margin: 0 0 1em;
}

.intro p:last-child {
  margin-bottom: 0;
}

/* A big initial to open the intro: the title's letter in miniature, amber over a rust shadow. */
.intro p:first-child::first-letter {
  float: left;
  margin: 0.08em 0.16em 0 0;
  font-family: var(--cartoon);
  font-size: 5.2em;
  line-height: 0.78;
  color: var(--amber);
  text-shadow: 0 4px 0 var(--rust);
}

/* The paragraphs in two columns, so lines keep a readable length at this width. */
@media (min-width: 861px) {
  .intro {
    columns: 2;
    column-gap: 56px;
  }

  /* A paragraph stays whole in its column. */
  .intro p {
    break-inside: avoid;
  }
}

/* ── Buttons: the game's menu buttons ── */
.btn {
  display: inline-block;
  padding: 11px 22px 9px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--cream);
  box-shadow: 0 4px 0 var(--ink);
  color: var(--ink);
  font-family: var(--cartoon);
  font-size: 18px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-decoration: none;
  transition:
    transform 0.12s cubic-bezier(0.3, 1.6, 0.5, 1),
    background-color 0.12s,
    box-shadow 0.12s;
}

@media (hover: hover) {
  /* It rises on the side the pointer is on: --tilt is set from where it is across the
     button (the script at the end of index.html), the fixed lean until it moves. */
  .btn:hover {
    background: var(--amber);
    box-shadow: 0 4px 0 var(--rust);
    transform: translateY(-2px) rotate(var(--tilt, -0.6deg));
  }
}

.btn:active {
  box-shadow: 0 1px 0 var(--rust);
  transform: translateY(2px);
}

.btn:focus-visible,
.lang button:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* On the dark game cards the ink outline wouldn't show. */
.game-body .btn:focus-visible {
  outline-color: var(--amber);
}

/* ── Games ── */
/*
 * The dirt the games are dug into (underground.js): a 640px tile, rendered once, repeated
 * both ways across the full width. It lies under the rocks (.ledge is 3), whose image runs
 * on in the page's dark for 104px into this section (--ledge less --ledge-line), the dirt's
 * own base colour, so it comes in from transparent there with no seam where that image ends.
 */
.underground {
  position: relative;
}

.underground::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  background: url('assets/img/underground.webp') repeat center top / 640px 640px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 104px, #000 320px);
  mask-image: linear-gradient(to bottom, transparent 104px, #000 320px);
  pointer-events: none;
}

.games {
  /* Over the rocks (.ledge is 3): their image's dark runs on below the line, into this section. */
  position: relative;
  z-index: 4;
  padding: 88px var(--pad) 96px;
  max-width: 1280px;
  margin: 0 auto;
}

.section-title {
  margin: 0 0 32px;
  font-family: var(--cartoon);
  font-weight: 400;
  font-size: clamp(40px, 5vw, 60px);
  line-height: 1;
  text-transform: uppercase;
  color: var(--amber);
  text-shadow: 0 3px 0 var(--rust);
}

.game {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  overflow: hidden;
  margin-bottom: 32px;
  /* A warm brown a few steps up from the page's dark (--night), with a lighter rim, so the
     card stands off the background instead of melting into it. */
  border: 3px solid #4d3a2b;
  border-radius: 18px;
  background: #30251e;
  box-shadow: 0 6px 0 rgb(0 0 0 / 55%);
}

.game-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 32px;
}

.game-body h3 {
  margin: 0;
  font-family: var(--cartoon);
  font-weight: 400;
  font-size: 40px;
  line-height: 1;
  text-transform: uppercase;
  color: var(--amber);
}

.game-body p {
  margin: 0;
}

/* Where a game runs, at the card's foot over the button: an amber-tinted box with a thin
   amber rim, the platform icons on top and a line on what the game needs under them. */
.notice {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-self: stretch;
  margin-top: auto;
  padding: 10px 14px 12px;
  border: 2px solid rgb(255 176 32 / 45%);
  border-radius: 10px;
  background: rgb(255 176 32 / 10%);
  font-size: 15px;
  color: var(--cream);
}

/* The platform icons: little 3D objects (platforms.js, rendered by tools/platforms.html). */
.platforms {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.platforms li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgb(255 244 220 / 78%);
}

.platforms img {
  width: 48px;
  height: 48px;
}

.game-body .btn {
  margin-top: 4px;
}

.tag {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgb(255 244 220 / 78%);
}

/* Toimitusaika: one big shot, two small under it. */
/*
 * A game's pictures (gallery.js): the chosen one big, all of them small in a row under it.
 * A small one shows its picture big; the chosen one has an amber rim, the others are dimmed.
 */
.gallery-thumbs {
  /* Four show at a time; the rest are along the row, which scrolls: swiped on touch, its arrows with a mouse. */
  --show: 4;
  --gap: 0px;
  /* Positioned, so gallery.js can read a picture's place along it. */
  position: relative;
  display: grid;
  grid-auto-columns: calc((100% - (var(--show) - 1) * var(--gap)) / var(--show));
  grid-auto-flow: column;
  gap: var(--gap);
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  /* A swipe comes to rest on a picture, not between two. */
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.gallery-thumbs li {
  scroll-snap-align: start;
}

/* The row and its arrows: round buttons over its ends, showing only while the mouse is
   over the row (or one has the keyboard's focus), and only on a side with more to see. */
.gallery-strip {
  position: relative;
}

.gallery-arrow {
  position: absolute;
  top: 50%;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--cream);
  box-shadow: 0 3px 0 var(--rust);
  color: var(--ink);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  translate: 0 -50%;
  transition:
    opacity 0.15s,
    transform 0.12s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.gallery-arrow.prev {
  left: 10px;
}

.gallery-arrow.next {
  right: 10px;
}

.gallery-arrow[hidden] {
  display: none;
}

.gallery-strip:hover .gallery-arrow,
.gallery-arrow:focus-visible {
  opacity: 1;
  pointer-events: auto;
}

.gallery-arrow:hover {
  transform: translateY(-2px);
}

.gallery-arrow:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

.gallery-arrow svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* No mouse, no arrows: the row is swiped, and a half picture at its end shows there's more. */
@media (hover: none) {
  .gallery-arrow {
    display: none;
  }

  .gallery-thumbs {
    --show: 3.5;
  }
}

.gallery-thumbs::-webkit-scrollbar {
  display: none;
}

.gallery-thumbs button {
  display: block;
  position: relative;
  width: 100%;
  padding: 0;
  border: 0;
  background: var(--ink);
  cursor: pointer;
}

.gallery-thumbs img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.gallery-thumbs button:hover img,
.gallery-thumbs button[aria-current='true'] img {
  opacity: 1;
}

/* The rim inside the picture, so it isn't cut off at the card's edge; rounded as the picture is. */
.gallery-thumbs button[aria-current='true']::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 3px solid var(--amber);
  border-radius: inherit;
}

.gallery-thumbs button:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: -6px;
}

/* Toimitusaika's: the big picture fills the card's height, the small ones in a row under it, ink between them all. */
.shots {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--ink);
}

.shots .gallery-main {
  display: block;
  flex: 1;
  width: 100%;
  min-height: 0;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.shots .gallery-thumbs {
  --gap: 3px;
}

.shots .gallery-thumbs button {
  aspect-ratio: 16 / 9;
}

/* On a wide screen the row's first picture in view sits in the card's rounded bottom-left corner
   (gallery.js marks it .corner): it takes the card's inner curve (18px less its 3px border), so
   the amber rim follows the corner instead of being cut off by it. */
@media (min-width: 861px) {
  .gallery-thumbs li.corner button {
    overflow: hidden;
    border-bottom-left-radius: 15px;
  }
}

/* Hakuaika's level picture: pixel art, kept sharp when it's shown big, which scales it up. Only
   there: the screenshots and the map are bigger than where they're shown, and a picture shrunk
   without smoothing keeps only scattered pixels of the original (on hover, when the fade moves
   it onto its own layer, a different scatter: it shimmers). */
.pixel .gallery-main[src*='level00'] {
  image-rendering: pixelated;
}

/* ── Footer ── */
.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 28px var(--pad);
  border-top: 3px solid var(--ink);
  background: #120e0c;
  font-size: 15px;
  color: rgb(255 244 220 / 78%);
}

.foot p {
  margin: 0;
}

/* ── Narrow screens ── */
@media (max-width: 860px) {
  .hero {
    min-height: 0;
    padding: 120px var(--pad) 0;
  }

  .intro {
    padding: 28px 24px 110px;
    font-size: 17px;
  }

  .ledge {
    --ledge: 216px;
    --ledge-line: 138px;
  }

  .game {
    grid-template-columns: 1fr;
  }

  .game-body {
    padding: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .btn {
    animation: none;
    transition: none;
    transform: none !important;
  }

  .gallery-thumbs img,
  .gallery-arrow {
    transition: none;
  }

  .gallery-arrow:hover {
    transform: none;
  }
}
