/* David Kaing — homepage stylesheet (2026-10-19, revision 4).
   Direction: Apple clarity/deference/depth with Tesla's product-page structure.
   Every region follows the colour scheme — nothing stays black in light mode.
   The hero sits on the page background; the work, play and footer bands share a
   tinted surface; the work panels and the 2048 card are raised surfaces on top of
   them, and the card themes itself with the scheme rather than forcing a light
   island. The board geometry (56px cells, 6px gap, 254px board) is fixed by
   assets/game-2048-20260908-1.js and must not change. */

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

:root {
  color-scheme: light dark;

  --ink: #1d1d1f;
  --ink-2: #6e6e73;
  --ink-3: #8a8a8f;

  --bg: #ffffff;
  --bg-2: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f5f5f7;

  --line: #d2d2d7;
  --line-2: #e8e8ec;

  --accent: #2f6b52;

  /* Hero: white in light mode, black with a green glow in dark. */
  --hero-bg: #ffffff;
  --hero-sheen: none;
  --hero-glow-a: rgba(47, 107, 82, 0.1);
  --hero-glow-b: rgba(29, 29, 31, 0.035);
  --hero-grid: rgba(29, 29, 31, 0.05);

  /* The header follows the colour scheme instead of staying dark. */
  --header-bg: rgba(255, 255, 255, 0.72);
  --header-line: rgba(0, 0, 0, 0.1);
  --header-ink: #1d1d1f;
  --header-ink-dim: rgba(29, 29, 31, 0.68);
  --header-hover: rgba(0, 0, 0, 0.055);
  --header-mark-bg: #1d1d1f;
  --header-mark-ink: #ffffff;

  --radius-l: 24px;
  --radius-m: 18px;
  --radius-s: 12px;
  --pill: 980px;

  --shell: min(100% - 2.5rem, 1120px);
  --pad-section: clamp(4.5rem, 10vw, 8rem);

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 14px 40px rgba(0, 0, 0, 0.07);
  --shadow-hover: 0 2px 6px rgba(0, 0, 0, 0.06), 0 26px 64px rgba(0, 0, 0, 0.13);

  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "DM Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --header-h: 72px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f5f5f7;
    --ink-2: #a1a1a6;
    --ink-3: #8e8e93;
    --bg: #000000;
    --bg-2: #0a0a0c;
    --surface: #1a1a1d;
    --surface-2: #242428;
    --line: #2f2f34;
    --line-2: #222226;
    --accent: #84cdaa;

    --hero-bg: #000000;
    --hero-sheen: linear-gradient(180deg, #000000 0%, #050506 100%);
    --hero-glow-a: rgba(143, 215, 180, 0.18);
    --hero-glow-b: rgba(255, 255, 255, 0.09);
    --hero-grid: rgba(255, 255, 255, 0.045);

    --header-bg: rgba(0, 0, 0, 0.72);
    --header-line: rgba(255, 255, 255, 0.14);
    --header-ink: #f5f5f7;
    --header-ink-dim: rgba(245, 245, 247, 0.72);
    --header-hover: rgba(255, 255, 255, 0.1);
    --header-mark-bg: #f5f5f7;
    --header-mark-ink: #000000;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.6), 0 18px 48px rgba(0, 0, 0, 0.45);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.6), 0 28px 64px rgba(0, 0, 0, 0.55);
  }
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; }
img { max-width: 100%; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

h1, h2, h3, p, ul, figure { margin-top: 0; }
h1, h2, h3 { text-wrap: balance; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

[hidden] { display: none !important; }

.shell {
  width: var(--shell);
  margin-inline: auto;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  transform: translateY(-180%);
  padding: 0.7rem 1rem;
  border-radius: var(--radius-s);
  background: #ffffff;
  color: #1d1d1f;
  border: 1px solid rgba(0, 0, 0, 0.14);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: transform 180ms var(--ease);
}

.skip-link:focus { transform: translateY(0); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------- header */

.site-header {
  position: sticky;
  z-index: 50;
  top: 0;
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--header-line);
  color: var(--header-ink);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--header-h);
}

.wordmark {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--header-mark-bg);
  color: var(--header-mark-ink);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  text-decoration: none;
  transition: transform 220ms var(--ease);
}

.wordmark:hover { transform: scale(1.05); }

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-inline: 0.7rem;
  border-radius: var(--pill);
  color: var(--header-ink-dim);
  font-size: 0.92rem;
  text-decoration: none;
  transition: color 180ms ease, background 180ms ease;
}

.site-nav a:hover {
  color: var(--header-ink);
  background: var(--header-hover);
}

/* ------------------------------------------------------------ buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 48px;
  padding: 0.8rem 1.4rem;
  border: 1px solid transparent;
  border-radius: var(--pill);
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-decoration: none;
  transition: transform 220ms var(--ease), background 220ms ease,
              border-color 220ms ease, color 220ms ease, opacity 220ms ease;
}

.button:active { transform: translateY(0); }

@media (hover: hover) {
  .button:hover { transform: translateY(-1px); }
}

/* Inverts with the colour scheme: white pill on black (dark mode), black pill
   on white (light mode). */
.button-primary {
  background: var(--ink);
  color: var(--bg);
}

.button-primary:hover { opacity: 0.9; }

.button-ghost {
  border-color: var(--line);
  color: var(--ink);
  background: transparent;
}

.button-ghost:hover {
  background: var(--surface);
  border-color: var(--ink-3);
}

.button-small {
  min-height: 40px;
  padding: 0.55rem 1.05rem;
  font-size: 0.88rem;
}

.text-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
  padding-bottom: 1px;
  transition: color 180ms ease, border-color 180ms ease;
}

.text-link:hover { color: var(--accent); }

/* --------------------------------------------------------------- hero */

.hero {
  position: relative;
  overflow: hidden;
  padding: clamp(4.5rem, 11vw, 8.5rem) 0 clamp(4.5rem, 9vw, 7rem);
  background-color: var(--hero-bg);
  background-image:
    var(--hero-sheen),
    radial-gradient(70% 60% at 12% 0%, var(--hero-glow-a), transparent 60%),
    radial-gradient(55% 45% at 92% 4%, var(--hero-glow-b), transparent 62%);
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--hero-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--hero-grid) 1px, transparent 1px);
  background-size: 64px 64px;
  -webkit-mask-image: radial-gradient(120% 95% at 50% 0%, #000 32%, transparent 78%);
  mask-image: radial-gradient(120% 95% at 50% 0%, #000 32%, transparent 78%);
  pointer-events: none;
}

.hero > .shell { position: relative; }

.eyebrow {
  margin-bottom: 1.1rem;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.hero h1 {
  max-width: 15ch;
  margin-bottom: clamp(1.75rem, 4vw, 2.5rem);
  font-size: clamp(2.9rem, 9vw, 7rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 0.98;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  animation: rise 0.7s var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------ sections */

.section { padding: var(--pad-section) 0; }

#work, #play { scroll-margin-top: var(--header-h); }

.section-head { max-width: 40ch; margin-bottom: clamp(2rem, 4vw, 3rem); }

.section-head h2 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5.2vw, 3.6rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.04;
}

.section-head-inline {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1.5rem;
  max-width: none;
}

/* ---------------------------------------------------------------- work */

/* A tinted band, so the white panels read as cards rather than blending in. */
#work { background: var(--bg-2); }

.panel {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: center;
  padding: clamp(1.1rem, 2.6vw, 1.6rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  transition: transform 420ms var(--ease), box-shadow 420ms var(--ease);
}

.panel + .panel { margin-top: 1.25rem; }

/* Lift only where a real pointer can hover, so taps don't leave it stuck. */
@media (hover: hover) {
  .panel:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
}

.panel-media {
  display: block;
  overflow: hidden;
  border-radius: var(--radius-m);
  background: var(--bg-2);
}

.panel-media img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  transition: transform 500ms var(--ease);
}

.panel-media:focus-visible img { transform: scale(1.02); }

@media (hover: hover) {
  .panel-media:hover img { transform: scale(1.02); }
}

.panel-body { padding: clamp(0.5rem, 2vw, 1.5rem) clamp(0.5rem, 2vw, 1.25rem); }

.project-kicker {
  margin-bottom: 0.7rem;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-body h3 {
  margin-bottom: 0.75rem;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.panel-body > p:not(.project-kicker) {
  margin-bottom: 1.4rem;
  color: var(--ink-2);
  font-size: 1.02rem;
  line-height: 1.6;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
}

.tag-list li {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-wide { grid-template-columns: 1fr; align-items: start; }

/* ---------------------------------------------------------------- play */

/* The work, play and footer bands share the tinted surface so the white panels
   and the 2048 card read as raised surfaces on top of them. */
#play {
  background: var(--bg-2);
  border-top: 1px solid var(--line-2);
}

.games-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 clamp(2rem, 4vw, 3rem);
  padding: 0;
  list-style: none;
}

.games-row a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  transition: color 180ms ease, border-color 180ms ease, background 180ms ease;
}

.games-row a:hover {
  color: var(--ink);
  border-color: var(--ink-3);
  background: var(--surface);
}

/* The 2048 card follows the colour scheme: a white card sitting on the dark
   band in light mode, and a dark card in dark mode so it never flashes white.
   The board geometry (56px cells, 6px gap, 254px board) must not change. */
.game-card {
  --card-bg: #ffffff;
  --card-ink: #1d1d1f;
  --card-ink-2: #6e6e73;
  --card-line: #e3e3e7;
  --card-surface: #f2f1ee;
  --card-board: #ded7c9;
  --card-cell: #ebe5d8;
  --card-tile-2: #eee8da;
  --card-tile-4: #ede0c8;
  --card-tile-ink: #1d1d1f;
  --card-err: #a92d24;

  /* Keep the generic tokens on-palette for anything reused inside the card. */
  --ink: var(--card-ink);
  --ink-2: var(--card-ink-2);
  --line: var(--card-line);
  --bg: var(--card-bg);
  --surface: var(--card-surface);
  --accent: #2f6b52;

  width: min(100%, 430px);
  margin-inline: auto;
  padding: clamp(1.5rem, 4vw, 2.25rem) clamp(1rem, 4vw, 1.75rem);
  border: 1px solid var(--card-line);
  border-radius: var(--radius-l);
  background: var(--card-bg);
  color: var(--card-ink);
  box-shadow: var(--shadow-card);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  .game-card {
    --card-bg: #1a1a1d;
    --card-ink: #f5f5f7;
    --card-ink-2: #a1a1a6;
    --card-line: #33333a;
    --card-surface: #26262b;
    --card-board: #232327;
    --card-cell: #2c2c32;
    --card-tile-2: #34343c;
    --card-tile-4: #3f3f49;
    --card-tile-ink: #f5f5f7;
    --card-err: #ff9d94;
    --accent: #84cdaa;
    color-scheme: dark;
  }
}

.game-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  width: 254px;
  margin: 0 auto 1rem;
}

.game-label {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.game-score {
  margin: 0;
  color: var(--card-ink-2);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.game-score span { color: var(--card-ink); font-weight: 600; }

.board {
  display: grid;
  position: relative;
  grid-template-columns: repeat(4, 56px);
  grid-template-rows: repeat(4, 56px);
  gap: 6px;
  width: 254px;
  margin-inline: auto;
  padding: 6px;
  border-radius: var(--radius-m);
  background: var(--card-board);
  touch-action: none;
  user-select: none;
}

.board:focus-visible { outline-offset: 6px; }

.cell-bg {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: var(--card-cell);
}

.tile {
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  width: 56px;
  height: 56px;
  transition: transform 120ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
  touch-action: none;
  will-change: transform;
}

.tile-face {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: var(--card-cell);
  color: var(--card-tile-ink);
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 500;
}

@keyframes tile-appear {
  from { opacity: 0; transform: scale(0); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes tile-pop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.4); }
}

.tile-new .tile-face { animation: tile-appear 120ms cubic-bezier(0.175, 0.885, 0.32, 1.275) both; }
.tile-pop .tile-face { animation: tile-pop 180ms ease-in-out; }
.tile-face[data-v="2"] { background: var(--card-tile-2); }
.tile-face[data-v="4"] { background: var(--card-tile-4); }
.tile-face[data-v="8"] { background: #f2b179; color: #ffffff; }
.tile-face[data-v="16"] { background: #f59563; color: #ffffff; font-size: 0.875rem; }
.tile-face[data-v="32"] { background: #f67c5f; color: #ffffff; font-size: 0.875rem; }
.tile-face[data-v="64"] { background: #f65e3b; color: #ffffff; font-size: 0.875rem; }
.tile-face[data-v="128"] { background: #edcf72; color: #ffffff; font-size: 0.8rem; }
.tile-face[data-v="256"] { background: #edcc61; color: #ffffff; font-size: 0.8rem; }
.tile-face[data-v="512"] { background: #edc850; color: #ffffff; font-size: 0.8rem; }
.tile-face[data-v="1024"] { background: #edc53f; color: #ffffff; font-size: 0.7rem; }
.tile-face[data-v="2048"] { background: #edc22e; color: #ffffff; font-size: 0.7rem; }

.game-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 254px;
  margin: 1rem auto 0;
}

.game-status {
  margin: 0;
  color: var(--card-ink-2);
  font-size: 0.72rem;
  line-height: 1.5;
}

.text-button {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--card-ink);
  font-size: 0.76rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 0.25rem;
  cursor: pointer;
  white-space: nowrap;
}

.game-fullscreen {
  width: 254px;
  margin: 0.5rem auto 0;
  font-size: 0.74rem;
}

.game-fullscreen .text-link {
  min-height: 44px;
  color: var(--card-ink-2);
  border-bottom-color: var(--card-line);
  font-size: 0.78rem;
}

.game-fullscreen .text-link:hover { color: var(--card-ink); border-bottom-color: var(--card-ink-2); }

.name-entry {
  width: 254px;
  margin: 1.25rem auto 0;
  color: var(--card-ink-2);
  font-size: 0.78rem;
}

.name-entry > label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.name-entry-controls { display: flex; gap: 0.5rem; }

.name-entry input,
.name-entry button {
  min-height: 44px;
  border: 1px solid var(--card-line);
  border-radius: var(--radius-s);
  background: var(--card-bg);
  color: var(--card-ink);
  font-size: 0.82rem;
}

.name-entry input {
  min-width: 0;
  flex: 1;
  padding: 0.6rem 0.75rem;
}

.name-entry button {
  padding: 0.6rem 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 180ms ease;
}

.name-entry button:hover { background: var(--surface); }

.name-err {
  min-height: 1.2em;
  margin: 0.45rem 0 0;
  color: var(--card-err);
  font-size: 0.7rem;
}

.scoreboard {
  width: 254px;
  margin: 1.75rem auto 0;
  font-size: 0.8rem;
}

.scoreboard-title {
  margin-bottom: 0.6rem;
  color: var(--card-ink-2);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.scoreboard table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.scoreboard caption {
  margin-bottom: 0.6rem;
  color: var(--card-ink-2);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-align: left;
  text-transform: uppercase;
}

.scoreboard th,
.scoreboard td {
  padding: 0.3rem 0.35rem;
  color: var(--card-ink-2);
  font-weight: 400;
  font-size: 0.78rem;
  text-align: left;
}

.scoreboard th {
  border-bottom: 1px solid var(--card-line);
  font-size: 0.64rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.scoreboard td:first-child,
.scoreboard th:first-child {
  width: 2rem;
  color: var(--card-ink);
  text-align: right;
}

.scoreboard td:nth-child(2) { color: var(--card-ink); }

.scoreboard td:last-child,
.scoreboard th:last-child { text-align: right; }

.scoreboard tr.me td { color: var(--card-ink); font-weight: 600; }

.scoreboard-empty {
  margin: 0;
  color: var(--card-ink-2);
  font-style: italic;
}

/* -------------------------------------------------------------- footer */

.site-footer {
  background: var(--bg-2);
  border-top: 1px solid var(--line-2);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 96px;
  color: var(--ink-2);
}

.footer-inner p { margin: 0; }

.footer-inner a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink-2);
  text-decoration: none;
  transition: color 180ms ease;
}

.footer-inner a:hover { color: var(--ink); }

/* ---------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .panel { grid-template-columns: 1fr; }
  .panel-body { padding-inline: clamp(0.25rem, 1.5vw, 1rem); }
}

@media (max-width: 720px) {
  body { font-size: 16px; }
  .section-head-inline { align-items: flex-start; flex-direction: column; gap: 0.5rem; }
  .game-card { padding-inline: max(1rem, calc((100% - 278px) / 2)); }
  .footer-inner {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding-block: 1.5rem;
  }
}

@media (max-width: 620px) {
  .header-cta { display: none; }
  .hero h1 { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
