/* Spin & Buzz — site styles
   Brand: 14a "Pinion on Track", Retro Cream palette.
   Tokens first; everything else reads from them so light/dark stay in sync. */

/* Space Grotesk, self-hosted (SIL Open Font License, see assets/fonts/OFL.txt) */
@font-face { font-family: "Space Grotesk"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/space-grotesk-400.woff2") format("woff2"); }
@font-face { font-family: "Space Grotesk"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/space-grotesk-500.woff2") format("woff2"); }
@font-face { font-family: "Space Grotesk"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/space-grotesk-700.woff2") format("woff2"); }

:root {
  --cream: #F4EDE1;        /* brand disc colour, page background */
  --paper: #FBF7F0;        /* raised surfaces: inputs, framed media */
  --ink: #2B2B2B;          /* brand charcoal: text, outlines, gear, track */
  --ink-soft: #5C5650;     /* secondary text */
  --rust: #D9541E;         /* brand motion colour: arcs, ampersand, button shadow */
  --rust-text: #A8410F;    /* rust dark enough for small text on cream (5.0:1) */
  --line: #2B2B2B;
  --ok: #2F6B3A;
  --bad: #A8410F;

  --bg: var(--cream);
  --surface: var(--paper);
  --text: var(--ink);
  --muted: var(--ink-soft);
  --accent: var(--rust);
  --accent-text: var(--rust-text);
  --badge-fill: var(--cream);
  --badge-rim: none;
  --btn-bg: var(--ink);
  --btn-text: var(--cream);

  --font: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --measure: 34rem;
  --wrap: 72rem;
  --gutter: clamp(1rem, 4vw, 2.5rem);
  --stroke: 3px;
  --radius: 14px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1F1E1C;
    --surface: #2B2B2B;
    --text: #EFE3CF;
    --muted: #BDB4A8;
    --line: #E6D6BA;
    --accent: #E8703F;
    --accent-text: #F08A5D;
    --badge-rim: #F4EDE1;
    --btn-bg: #E6D6BA;
    --btn-text: #2B2B2B;
    --ok: #7FC48C;
    --bad: #F08A5D;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1F1E1C;
  --surface: #2B2B2B;
  --text: #EFE3CF;          /* warmer than brand cream: pure #F4EDE1 reads as white on dark */
  --muted: #BDB4A8;
  --line: #E6D6BA;          /* gear, track, outlines */
  --accent: #E8703F;
  --accent-text: #F08A5D;
  --badge-rim: #F4EDE1;
  --btn-bg: #E6D6BA;
  --btn-text: #2B2B2B;
  --ok: #7FC48C;
  --bad: #F08A5D;
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
/* Always reserve the scrollbar's space, so short pages (Contact) and long ones
   (Home, Portfolio) center their content in the same width and nothing shifts. */
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.6;
  overflow-x: hidden;
}
img { display: block; max-width: 100%; height: auto; }
a { color: inherit; text-decoration-thickness: 2px; text-underline-offset: 3px; }
a:hover { color: var(--accent-text); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.1; letter-spacing: -0.02em; margin: 0 0 0.5em; font-weight: 700; }
h1 { font-size: clamp(2.25rem, 5vw, 3.5rem); }
h2 { font-size: clamp(1.6rem, 3.2vw, 2.25rem); }
h3 { font-size: 1.25rem; }
p { margin: 0 0 1em; max-width: var(--measure); }
.wrap { width: min(100% - 2 * var(--gutter), var(--wrap)); margin-inline: auto; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 1rem; top: 1rem; z-index: 10; background: var(--surface); padding: .5rem 1rem; }
.amp { color: var(--accent); }

/* ---------- header ---------- */
.site-header { padding-block: 1.25rem; }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: .65rem; text-decoration: none; font-weight: 700; font-size: 1.375rem; letter-spacing: -0.03em; }
.brand:hover { color: inherit; }
.brand svg { width: 44px; height: 44px; flex: none; }
.badge-disc { fill: var(--badge-fill); stroke: #2B2B2B; }
.badge-rim { fill: var(--badge-rim); }
.badge-ink { fill: #2B2B2B; stroke: #2B2B2B; }
.badge-track { stroke: #2B2B2B; }
.badge-hub { fill: var(--badge-fill); }
#brand-gear { transform-box: view-box; transform-origin: 100px 96px; }

.nav { display: flex; gap: clamp(.75rem, 3vw, 2rem); }
.nav a { text-decoration: none; font-weight: 500; padding-block: .25rem; border-bottom: var(--stroke) solid transparent; }
.nav a[aria-current="page"] { border-bottom-color: var(--accent); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font: inherit; font-weight: 700; font-size: 1rem; line-height: 1;
  padding: .9rem 1.4rem;
  border: var(--stroke) solid var(--line);
  border-radius: 999px;
  background: var(--btn-bg); color: var(--btn-text);
  text-decoration: none; cursor: pointer;
  box-shadow: 4px 4px 0 var(--accent);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:hover { color: var(--btn-text); transform: translate(-1px, -1px); box-shadow: 6px 6px 0 var(--accent); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--accent); }
.btn--ghost { background: var(--bg); color: var(--text); box-shadow: 4px 4px 0 var(--line); }
.btn--ghost:hover { color: var(--text); box-shadow: 6px 6px 0 var(--line); }
.btn--ghost:active { box-shadow: 1px 1px 0 var(--line); }
.btn[disabled] { opacity: .6; cursor: progress; transform: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 1rem 1.1rem; margin-top: 1.75rem; }

/* ---------- hero: the pinion rolls in on the track ---------- */
.hero {
  --S: clamp(170px, 28vw, 330px);   /* rendered width of the gear graphic */
  --u: calc(var(--S) / 128);        /* one unit of the gear's viewBox */
  --P: calc(var(--u) * 32);         /* one track period = one tooth of rotation */
  --gx: 76cqw;                      /* where the gear's centre comes to rest */
  container-type: inline-size;
  position: relative;
  overflow: hidden;
  padding-top: clamp(2rem, 7vw, 5.5rem);
}
.hero-copy { position: relative; z-index: 1; padding-bottom: calc(var(--S) * 0.25); }
.hero-title {
  font-size: clamp(3.25rem, 11vw, 8.5rem);
  line-height: .9;
  letter-spacing: -0.055em;
  margin: 0 0 .35em;
}
.hero-lede { font-size: clamp(1.125rem, 2vw, 1.375rem); line-height: 1.5; max-width: 30rem; }
.hero-stage { position: relative; height: calc(var(--S) * 0.82); margin-top: calc(var(--S) * -0.55); }
.track {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--u) * 30);
  background-color: var(--line);
  -webkit-mask: url("../img/track-tile.svg") repeat-x;
  mask: url("../img/track-tile.svg") repeat-x;
  -webkit-mask-size: var(--P) 100%;
  mask-size: var(--P) 100%;
  -webkit-mask-position: calc(var(--gx) - var(--P) / 2) 0;
  mask-position: calc(var(--gx) - var(--P) / 2) 0;
}
/* Whole-pixel track tiles. With a fractional tile width, Safari on iPhone leaves a
   hairline gap where each tile meets the next (VVVV). Rounding the period and the
   start keeps every tile edge on a pixel; the gear still lands within half a pixel
   of the valley. Browsers without round() keep the exact values above. */
@supports (width: round(1.5px, 1px)) {
  .hero { --P: round(calc(var(--u) * 32), 1px); }
  .track {
    -webkit-mask-position: round(calc(var(--gx) - var(--P) / 2), 1px) 0;
    mask-position: round(calc(var(--gx) - var(--P) / 2), 1px) 0;
  }
}
.pinion {
  position: absolute;
  width: var(--S);
  left: calc(var(--gx) - var(--u) * 64);
  bottom: calc(var(--u) * 18);
  overflow: visible;
}
.pinion-gear { transform-box: view-box; transform-origin: 100px 96px; fill: var(--line); stroke: var(--line); }
.pinion-hub { fill: var(--bg); }
.pinion-arcs { stroke: var(--accent); stroke-dasharray: 40; stroke-dashoffset: 0; transform-box: view-box; transform-origin: 100px 96px; }

/* Roll-in. main.js measures how many track periods (--k) it takes to start fully
   off-screen on the left, then adds .is-rolling. Each period turns the gear one
   tooth (30deg), so the teeth stay in step with the track. Without JS the gear
   simply sits in place. */
.js .hero:not(.is-rolling) .pinion { visibility: hidden; }
.hero.is-rolling .pinion { animation: roll var(--dur, 2.6s) cubic-bezier(.22, .68, .25, 1) .15s both; }
.hero.is-rolling .pinion-gear { animation: spin var(--dur, 2.6s) cubic-bezier(.22, .68, .25, 1) .15s both; }
/* arcs draw in once the gear stops, then shake a few times and settle: the "buzz" */
.hero.is-rolling .pinion-arcs {
  stroke-dashoffset: 40;
  animation:
    buzz .5s ease-out calc(var(--dur, 2.6s) + .05s) forwards,
    shake .8s linear calc(var(--dur, 2.6s) + .6s) 1;
}
@keyframes roll { from { transform: translateX(calc(var(--k, 14) * var(--P) * -1)); } to { transform: none; } }
@keyframes spin { from { transform: rotate(calc(var(--k, 14) * -30deg)); } to { transform: none; } }
@keyframes buzz { to { stroke-dashoffset: 0; } }
@keyframes shake {
  0%, 100% { transform: none; }
  10% { transform: rotate(-4deg) scale(1.04); }
  20% { transform: rotate(4deg) scale(1.02); }
  30% { transform: rotate(-3.5deg) scale(1.04); }
  40% { transform: rotate(3deg) scale(1.02); }
  50% { transform: rotate(-2.5deg) scale(1.03); }
  60% { transform: rotate(2deg) scale(1.01); }
  70% { transform: rotate(-1.5deg) scale(1.02); }
  80% { transform: rotate(1deg); }
  90% { transform: rotate(-.5deg); }
}

@media (max-width: 720px) {
  .hero { --gx: 62cqw; }
  .hero-copy { padding-bottom: 0; }
  .hero-stage { margin-top: 2.75rem; height: calc(var(--S) * 0.9); }
}

/* the small track used to separate sections */
.rule {
  height: 12px; margin-block: clamp(3rem, 8vw, 5rem);
  background-color: var(--line);
  -webkit-mask: url("../img/track-tile.svg") repeat-x 0 0 / 16px 100%;
  mask: url("../img/track-tile.svg") repeat-x 0 0 / 16px 100%;
  opacity: .9;
}

/* ---------- sections ---------- */
main { display: block; }
.section { padding-block: clamp(3rem, 8vw, 5.5rem); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 2rem; }
.section-head h2 { margin: 0; }
.page-intro { padding-top: clamp(2rem, 6vw, 4rem); }
.page-intro p { font-size: 1.1875rem; color: var(--muted); }

/* game teasers on the home page */
.teasers { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 22rem), 1fr)); gap: clamp(1.5rem, 4vw, 3rem); }
.teaser { display: flex; flex-direction: column; gap: 1rem; text-decoration: none; }
.teaser:hover { color: inherit; }
.teaser:hover .frame { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--line); }
.teaser h3 { font-size: 1.5rem; margin: 0; }
.teaser p { margin: 0; color: var(--muted); }
.teaser .more { font-weight: 700; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }

.frame {
  border: var(--stroke) solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: 3px 3px 0 var(--line);
  transition: transform .15s ease, box-shadow .15s ease;
  aspect-ratio: 16 / 8;
}
.frame img { width: 100%; height: 100%; object-fit: cover; }
.frame--dark { background: #161A21; }
.frame--dark img { object-fit: contain; }

.status { display: inline-flex; align-items: center; gap: .5rem; font-size: .9375rem; font-weight: 500; }
.status::before { content: ""; width: .6rem; height: .6rem; border-radius: 50%; background: var(--ok); }
.status--soon::before { background: transparent; border: 2px solid var(--accent); }

/* portfolio entries */
.game { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: clamp(1.5rem, 5vw, 4rem); align-items: start; }
.game + .game { margin-top: 0; }
.game-media { display: grid; gap: 1rem; }
.game-media .frame { aspect-ratio: auto; }
.game-media .frame--square { aspect-ratio: 16 / 11; }
.game-title { display: flex; align-items: center; gap: 1rem; margin-bottom: .75rem; }
.game-title img { width: 64px; height: 64px; border-radius: 14px; border: var(--stroke) solid var(--line); }
.game-title h2 { margin: 0; }
.game .status { margin-bottom: 1.25rem; }
.modes { margin: 1.5rem 0 0; display: grid; gap: .9rem; max-width: var(--measure); }
.modes dt { font-weight: 700; }
.modes dd { margin: 0; color: var(--muted); }
.store-links { display: flex; flex-wrap: wrap; gap: .9rem; margin-top: 2rem; }
.store-links .btn { padding: .75rem 1.15rem; font-size: .9375rem; }
.fine { font-size: .9375rem; color: var(--muted); margin-top: 1.5rem; }

@media (max-width: 860px) {
  .game { grid-template-columns: 1fr; }
}

/* ---------- contact ---------- */
.contact { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: clamp(2rem, 6vw, 5rem); align-items: start; }
.contact-aside p { color: var(--muted); }
.contact-aside h2 { font-size: 1.25rem; margin-top: 2rem; }
@media (max-width: 860px) { .contact { grid-template-columns: 1fr; } }

.form { display: grid; gap: 1.25rem; }
.field { display: grid; gap: .4rem; }
.field label { font-weight: 700; }
.field .hint { font-size: .875rem; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: var(--stroke) solid var(--line);
  border-radius: 10px;
  padding: .75rem .9rem;
  width: 100%;
}
.field textarea { min-height: 11rem; resize: vertical; }
.field select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 1.25rem) 55%, calc(100% - .9rem) 55%; background-size: .35rem .35rem; background-repeat: no-repeat; padding-right: 2.5rem; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.field [aria-invalid="true"] { border-color: var(--bad); }
.field .error { font-size: .875rem; color: var(--bad); font-weight: 500; min-height: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 560px) { .two { grid-template-columns: 1fr; } }
.turnstile:empty { display: none; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

.notice { border: var(--stroke) solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; background: var(--surface); }
.notice h2 { font-size: 1.375rem; margin-bottom: .35rem; }
.notice p { margin: 0; }
.notice--ok { box-shadow: 4px 4px 0 var(--ok); }
.notice--bad { box-shadow: 4px 4px 0 var(--bad); }
.form-status:empty { display: none; }

/* ---------- footer ---------- */
.site-footer { margin-top: clamp(3rem, 8vw, 6rem); padding-block: 0 2.5rem; font-size: .9375rem; color: var(--muted); }
.site-footer .rule { margin-block: 0 2rem; }
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem 2rem; }
.site-footer nav { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.footer-id { display: grid; gap: .2rem; }
address { font-style: normal; }
.site-footer a { text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.theme-toggle { font: inherit; color: inherit; background: none; border: 2px solid currentColor; border-radius: 999px; padding: .3rem .8rem; cursor: pointer; }
.theme-toggle:hover { color: var(--text); }

/* ---------- 404 ---------- */
.lost { text-align: left; }

@media (prefers-reduced-motion: reduce) {
  .hero.is-rolling .pinion, .hero.is-rolling .pinion-gear { animation: none; }
  .hero.is-rolling .pinion-arcs { animation: none; stroke-dashoffset: 0; }
  .btn, .frame { transition: none; }
}
