/*
  Site styles
  -----------
  1. Colors (light and dark)
  2. Base elements
  3. Layout: main, footer
  4. Page pieces: the content lists (shown only without JavaScript)
  5. The game
  6. Accessibility helpers
*/

/* 1. Colors ------------------------------------------------------------
   Every color on the site comes from these variables.
   Change a value here and it updates everywhere. */
:root {
  --color-bg: #f6f7f4;
  --color-text: #222222;
  --color-muted: #5b605b;
  --color-accent: #2a5b8c;
  --color-on-accent: #ffffff; /* text on top of the accent color */
  --color-line: #e0e3dd;

  --max-width: 42rem;
  --space: 1.5rem;
}

/* Dark mode follows the visitor's system setting. */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #141815;
    --color-text: #e8ece9;
    --color-muted: #9da59f;
    --color-accent: #8ab8e6;
    --color-on-accent: #141815;
    --color-line: #2a302c;
  }
}

/* Arcade font, used for the game and the "under construction" sign. */
@font-face {
  font-family: "Press Start 2P";
  src: url("../fonts/press-start-2p.woff2") format("woff2");
  font-display: swap;
}

/* 2. Base elements ----------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light dark;
  accent-color: var(--color-accent);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent; /* no gray flash on tap */
}

::selection {
  background: var(--color-accent);
  color: var(--color-on-accent);
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  line-height: 1.25;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2rem, 6vw, 2.5rem);
  letter-spacing: -0.02em;
  margin: 0;
}

/* Section headings: "Projects", "Work" */
h2 {
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  margin: 0 0 0.5rem;
}

/* Item headings: a project name, a job title */
h3 {
  font-size: 1.125rem;
  margin: 0 0 0.25rem;
}

p {
  margin: 0 0 1rem;
  text-wrap: pretty;
}

a {
  color: var(--color-accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

/* Hover effects only on devices with a mouse, so taps on phones don't "stick". */
@media (hover: hover) and (pointer: fine) {
  a:hover {
    text-decoration-thickness: 2px;
  }
}

ul,
ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* 3. Layout -------------------------------------------------------------
   One centered column for the whole page. */
.container {
  max-width: var(--max-width);
  margin-inline: auto;
  padding-inline: var(--space);
}

.site-footer ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.5rem;
}

/* Footer links are 44px tall so they are easy to tap on a phone. */
.site-footer a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

main {
  padding: 3rem 0 4rem;
}

/* Space between the page's sections. */
.section {
  margin-top: 4rem;
}

.site-footer {
  border-top: 1px solid var(--color-line);
  padding: 0.5rem 0 2rem;
  font-size: 0.9375rem;
}

/* 4. Page pieces ------------------------------------------------------- */

/* Home: the one-line description under your name */
.tagline {
  color: var(--color-muted);
  font-size: 1.25rem;
  margin: 0.5rem 0 2.5rem;
}

/* Every section uses the same list style. */
.entry-list > li {
  padding: 1.5rem 0;
  border-top: 1px solid var(--color-line);
}

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

.meta {
  color: var(--color-muted);
  font-size: 0.9375rem;
  margin-bottom: 0.5rem;
}

.work-list .meta {
  margin-bottom: 0.25rem;
}

/* Several jobs at one workplace: each title with its dates under it. */
.roles li + li {
  margin-top: 0.75rem;
}

.roles .meta {
  margin-bottom: 0;
}

/* Work history: dates sit in a left column on wider screens. */
@media (min-width: 40rem) {
  .work-list > li {
    display: grid;
    grid-template-columns: 8rem 1fr;
    gap: 1.5rem;
  }
}

/* 5. The game ------------------------------------------------------------
   With JavaScript on, <body> gets the class "game-on" and a data-scene
   ("landing", "about", "projects" or "work"). The game is the whole page:
   <main> is hidden (the game shows its text) and everything fits in one
   window, with the footer at the bottom. */
body.game-on {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

body.game-on main {
  display: none;
}

body.game-on .site-footer {
  margin-top: auto;
}

/* Line the footer up with the wider game. */
body.game-on .site-footer .container {
  max-width: 60rem;
}

/* The game is 16:9. On short screens it narrows so the whole start screen
   (game, help line and footer, about 11rem) still fits without scrolling. */
.game {
  width: 100%;
  max-width: min(60rem, (100dvh - 11rem) * 16 / 9 + 2 * var(--space));
  margin: 2rem auto 0;
  padding-inline: var(--space);
}

/* container-type lets the text inside size itself to the game's width,
   so labels stay lined up with the pipes at any screen size. */
.game-stage {
  position: relative;
  container-type: inline-size;
  overflow: hidden;
  border-radius: 8px;
}

.game-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 256 / 144; /* same shape as the canvas */
  background: #0b0b14;
  image-rendering: pixelated;
}

/* The front canvas (player and pipes) sits exactly on top of the back one. */
.game-front {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
}

/* Text drawn over the game. --px is one canvas pixel. */
.game-text,
.game-loading {
  --px: calc(100cqw / 256);
  position: absolute;
  inset: 0;
  margin: 0;
  pointer-events: none;
  font-family: "Press Start 2P", ui-monospace, monospace;
  text-transform: uppercase;
  line-height: 1;
  color: #e8ece9;
  text-shadow: var(--px) var(--px) 0 #000;
}

.game-text[hidden],
.game-loading[hidden] {
  display: none;
}

.game-title,
.game-subtitle {
  position: absolute;
  inset-inline: 0;
  margin: 0;
  text-align: center;
}

.game-title {
  top: calc(12 * var(--px));
  color: #f5c51b;
  font-size: calc(10 * var(--px));
}

.game-subtitle {
  top: calc(28 * var(--px));
  font-size: calc(6 * var(--px));
}

/* The office wall is light, so its hint text is dark to stay readable. */
body[data-scene="work"] .game-room-hint {
  color: #1d2433;
  text-shadow: none;
}

.pipe-label {
  position: absolute;
  left: calc(var(--x) * var(--px));
  top: calc(var(--y) * var(--px));
  translate: -50% 0;
  font-size: calc(8 * var(--px));
}

/* The dialog box: the text for the sign or desk the player is standing
   at, in a dark box with a thick light border like an old RPG. Body text
   uses the normal font so it stays easy to read on a phone. */
.game-dialog {
  --px: calc(100cqw / 256);
  position: absolute;
  top: calc(12 * var(--px));
  left: 50%;
  translate: -50% 0;
  width: calc(208 * var(--px));
  padding: calc(5 * var(--px)) calc(7 * var(--px));
  border: calc(2 * var(--px)) solid #e8ece9;
  outline: var(--px) solid #000;
  background: #0b0b14;
  color: #e8ece9;
  font-size: max(11px, calc(4.5 * var(--px)));
  line-height: 1.4;
}

.game-dialog[hidden] {
  display: none;
}

.game-dialog h3 {
  margin: 0 0 0.5em;
  color: #f5c51b;
  font: max(9px, calc(6 * var(--px))) / 1.3 "Press Start 2P", ui-monospace, monospace;
  text-transform: uppercase;
}

.game-dialog p {
  margin: 0;
}

.game-dialog p + p {
  margin-top: 0.25em;
}

.game-dialog .meta {
  margin-bottom: 0.4em;
  color: #9aa0a6;
  font-size: 0.875em;
}

.game-dialog .meta:last-child {
  margin-bottom: 0;
}

.game-dialog a {
  color: #8fdc6a;
}

/* Several jobs in one dialog: tighter lines so it still fits inside the
   game on a small phone. */
.game-dialog .roles {
  line-height: 1.25;
}

.game-dialog .roles li + li {
  margin-top: 0.3em;
}

/* Each role already shows its own dates, so the workplace's overall
   date range would only repeat them in the small dialog. */
.game-dialog > .meta:has(+ div .roles) {
  display: none;
}

/* The black screen between scenes. The dots appear one at a time. */
.game-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  font-size: calc(8 * var(--px));
}

.game-loading::after {
  content: "...";
  animation: loading-dots 900ms steps(4, jump-none) infinite;
}

@keyframes loading-dots {
  from {
    clip-path: inset(0 100% 0 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

.game-help {
  margin: 0.75rem 0 0;
  color: var(--color-muted);
  font-size: 0.875rem;
}

kbd {
  padding: 0 0.3em;
  border: 1px solid var(--color-line);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.8125rem;
}

/* Touch buttons only appear on phones and tablets. */
.help-touch,
.touch-controls {
  display: none;
}

@media (hover: none) and (pointer: coarse) {
  .help-keys {
    display: none;
  }

  .help-touch {
    display: block;
  }

  /* On touch screens the game page behaves like an app, not a document:
     holding a finger down doesn't select text or bring up the
     magnifier, and double-tapping doesn't zoom. Pinch zoom still works. */
  body.game-on {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
  }

  /* The dialog is real content, so it stays selectable. */
  body.game-on .game-dialog {
    user-select: text;
    -webkit-user-select: text;
  }

  /* The game fills the screen so the buttons can sit at the bottom,
     where thumbs rest. The links move up top, out of their way. */
  body.game-on .game {
    display: flex;
    flex-direction: column;
    flex: 1;
    margin-top: 0;
  }

  body.game-on .site-footer {
    order: -1;
    margin-top: 0;
    border-top: 0;
    padding: 0.25rem 0;
  }

  .touch-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Centered in the space between the game and the bottom edge */
    margin-block: auto;
    padding: 1.5rem 0 max(1.5rem, env(safe-area-inset-bottom));
  }
}

/* The whole controls area is a control, not content: no selecting,
   no long-press menu, no tap flash, no scrolling or zooming. */
/* One size for every button. It grows with the screen width,
   so bigger phones get bigger buttons, within sensible limits. */
.touch-controls {
  --button-size: clamp(3.5rem, 18vw, 6rem);
}

.touch-controls,
.touch-controls button {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.touch-controls button {
  padding: 0;
  border: 0;
  font: inherit;
}

/* Left and right: two dark rounded keys */
.move-buttons {
  display: flex;
  gap: 0.5rem;
}

.move-buttons button {
  position: relative;
  width: var(--button-size);
  height: var(--button-size);
  border-radius: 14px;
  background: #2b2f36;
  box-shadow: 0 4px 0 #0d0f12;
}

/* A triangle pointing left or right */
.move-buttons button::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: calc(var(--button-size) * 0.3);
  height: calc(var(--button-size) * 0.3);
  background: #7a808b;
  clip-path: polygon(85% 10%, 85% 90%, 15% 50%);
}

.move-right::after {
  rotate: 180deg;
}

/* Jump and Enter: round maroon buttons */
.ab-buttons {
  display: flex;
  gap: 0.5rem;
}

.ab-buttons button {
  width: var(--button-size);
  height: var(--button-size);
  border-radius: 50%;
  background: #a3245b;
  box-shadow: 0 4px 0 #5e1233;
  color: #f4d7e3;
  font: calc(var(--button-size) * 0.15) "Press Start 2P", ui-monospace, monospace;
  text-transform: uppercase;
}

/* Jump sits higher than Enter, like the slant on a Game Boy */
.button-enter {
  margin-top: calc(var(--button-size) * 0.45);
}

.button-jump {
  margin-bottom: calc(var(--button-size) * 0.45);
}

/* Pressed: the button sinks into its shadow. Uses the data attribute
   from game.js so a finger sliding between buttons shows correctly. */
.touch-controls button[data-pressed] {
  translate: 0 4px;
  box-shadow: none;
}

/* 6. Accessibility helpers ---------------------------------------------- */

/* Hidden on screen, but still read by screen readers. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* A clear outline for keyboard users only. */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Respect visitors who ask for less motion. */
@media (prefers-reduced-motion: reduce) {
  .game-loading::after {
    animation: none;
  }
}

