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

:root {
  --fg: #1a1a1a;
  --fg-dim: #66645f;
  --bg: #f8f7f4;
  --surface: #f1efe9;
  --surface-strong: #ebe7df;
  --border: #dcd8cf;
  --accent: #1f4335;
  --accent-contrast: #f7fbf8;
  --shadow: 0 24px 60px rgba(45, 40, 32, 0.08);
  color-scheme: light dark;
}

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Newsreader', Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 0.75rem;
  left: 0.75rem;
  transform: translateY(-160%);
  padding: 0.65rem 0.85rem;
  background: var(--fg);
  color: var(--bg);
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.75rem;
  text-decoration: none;
}

.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;
}

.site-header,
.shell,
.site-footer {
  width: min(100% - 2rem, 760px);
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  border-bottom: 1px solid var(--border);
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.75rem;
}

.wordmark {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  font-weight: 500;
  letter-spacing: -0.04em;
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: clamp(0.25rem, 3vw, 1.25rem);
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding-inline: 0.5rem;
  color: var(--fg-dim);
  text-decoration: none;
}

.site-nav a:hover { color: var(--fg); }

.hero {
  padding: clamp(4.5rem, 12vw, 8rem) 0 clamp(4rem, 10vw, 7rem);
  animation: rise 0.7s ease-out both;
}

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

.eyebrow,
.project-kicker {
  margin: 0 0 0.8rem;
  color: var(--fg-dim);
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  max-width: 680px;
  margin-bottom: 1rem;
  font-size: clamp(3rem, 10vw, 6rem);
  font-weight: 400;
  letter-spacing: -0.045em;
  line-height: 0.95;
}

.hero-copy {
  max-width: 560px;
  margin-bottom: 2rem;
  color: var(--fg-dim);
  font-size: clamp(1.35rem, 4vw, 2rem);
  line-height: 1.35;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0.7rem 1.05rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--fg);
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease, transform 150ms ease;
}

.button:hover {
  border-color: var(--fg-dim);
  background: var(--surface);
  transform: translateY(-1px);
}

.button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.button-primary:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.section {
  padding: clamp(4rem, 10vw, 6rem) 0;
  border-top: 1px solid var(--border);
}

.section-heading {
  max-width: 560px;
  margin-bottom: 2rem;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: clamp(2rem, 6vw, 3.4rem);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 1.06;
}

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

.project-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(220px, 0.65fr);
  gap: 1rem;
}

.project-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 300px;
  padding: clamp(1.4rem, 4vw, 2rem);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.project-card-featured { background: var(--surface-strong); }

.project-visual {
  display: block;
  margin: 0.25rem 0 1.5rem;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
}

.project-visual img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  transition: transform 180ms ease;
}

.project-visual:hover img,
.project-visual:focus-visible img {
  transform: scale(1.015);
}

.project-card h3 {
  margin-bottom: 0.8rem;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 400;
  letter-spacing: -0.03em;
}

.project-card p:not(.project-kicker) {
  margin-bottom: 1.5rem;
  color: var(--fg-dim);
  font-size: 1.05rem;
  line-height: 1.55;
}

.project-footer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.5rem;
}

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

.tag-list li {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--fg-dim);
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.62rem;
}

.text-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  color: var(--fg);
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.72rem;
  text-underline-offset: 0.25rem;
}

.games-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 2rem;
  font-family: 'DM Mono', ui-monospace, monospace;
}

.games-row a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--fg-dim);
  font-size: 0.7rem;
  text-decoration: none;
}

.games-row a:hover {
  border-color: var(--fg-dim);
  color: var(--fg);
}

.game-card {
  width: min(100%, 430px);
  margin-inline: auto;
  padding: clamp(1rem, 4vw, 2rem);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.game-label,
.game-score,
.game-status,
.text-button,
.name-entry,
.scoreboard {
  font-family: 'DM Mono', ui-monospace, monospace;
}

.game-label,
.game-score {
  margin: 0;
  color: var(--fg-dim);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.05em;
}

.game-score span { color: var(--fg); }

.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: 3px;
  background: var(--border);
  touch-action: none;
  user-select: none;
}

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

.cell-bg {
  width: 56px;
  height: 56px;
  border-radius: 2px;
  background: #e7e2d8;
}

.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: 2px;
  background: #e7e2d8;
  color: var(--fg);
  font-family: 'DM Mono', ui-monospace, monospace;
  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: #eee8da; }
.tile-face[data-v="4"] { background: #ede0c8; }
.tile-face[data-v="8"] { background: #f2b179; color: #f8f7f4; }
.tile-face[data-v="16"] { background: #f59563; color: #f8f7f4; font-size: 0.875rem; }
.tile-face[data-v="32"] { background: #f67c5f; color: #f8f7f4; font-size: 0.875rem; }
.tile-face[data-v="64"] { background: #f65e3b; color: #f8f7f4; font-size: 0.875rem; }
.tile-face[data-v="128"] { background: #edcf72; color: #f8f7f4; font-size: 0.8rem; }
.tile-face[data-v="256"] { background: #edcc61; color: #f8f7f4; font-size: 0.8rem; }
.tile-face[data-v="512"] { background: #edc850; color: #f8f7f4; font-size: 0.8rem; }
.tile-face[data-v="1024"] { background: #edc53f; color: #f8f7f4; font-size: 0.7rem; }
.tile-face[data-v="2048"] { background: #edc22e; color: #f8f7f4; font-size: 0.7rem; }

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

.game-status {
  margin: 0;
  color: var(--fg-dim);
  font-size: 0.66rem;
  line-height: 1.5;
}

.text-button {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  font-size: 0.67rem;
  text-decoration: underline;
  text-underline-offset: 0.2rem;
  white-space: nowrap;
}

.name-entry {
  width: 254px;
  margin: 1rem auto 0;
  color: var(--fg-dim);
  font-size: 0.7rem;
}

.game-fullscreen {
  width: 254px;
  margin: 0.35rem auto 0;
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.66rem;
}

.game-fullscreen .text-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--fg-dim);
  text-decoration: underline;
  text-underline-offset: 0.2rem;
}

.game-fullscreen .text-link:hover { color: var(--fg); }

.name-entry > label {
  display: block;
  margin-bottom: 0.45rem;
}

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

.name-entry input,
.name-entry button {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  color: var(--fg);
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.72rem;
}

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

.name-entry button {
  padding: 0.6rem 0.75rem;
  cursor: pointer;
}

.name-err {
  min-height: 1.2em;
  margin: 0.4rem 0 0;
  color: #a92d24;
  font-size: 0.65rem;
}

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

.scoreboard-title {
  margin-bottom: 0.45rem;
  color: var(--fg-dim);
  letter-spacing: 0.06em;
}

.scoreboard table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.7rem;
}

.scoreboard caption {
  margin-bottom: 0.45rem;
  color: var(--fg-dim);
  letter-spacing: 0.06em;
  text-align: left;
}

.scoreboard th,
.scoreboard td {
  padding: 0.2rem 0.3rem;
  color: var(--fg-dim);
  font-weight: 400;
  text-align: left;
}

.scoreboard th {
  border-bottom: 1px solid var(--border);
  font-size: 0.6rem;
}

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

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

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

.scoreboard tr.me td {
  color: var(--fg);
  font-weight: 500;
}

.scoreboard-empty {
  margin: 0;
  color: var(--fg-dim);
  font-style: italic;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 100px;
  border-top: 1px solid var(--border);
  color: var(--fg-dim);
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 0.65rem;
}

.site-footer p { margin: 0; }

.site-footer a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  text-underline-offset: 0.2rem;
}

.not-found-page {
  display: grid;
  min-height: 100dvh;
  place-items: center;
}

.not-found {
  width: min(100% - 2rem, 560px);
  padding: clamp(2rem, 8vw, 4rem);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  text-align: center;
  box-shadow: var(--shadow);
}

.not-found h1 {
  margin-bottom: 1rem;
  font-size: clamp(3rem, 14vw, 6rem);
}

.not-found p:not(.eyebrow) {
  margin-bottom: 1.5rem;
  color: var(--fg-dim);
  font-size: 1.15rem;
}

.not-found-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

@media (max-width: 640px) {
  .project-grid { grid-template-columns: 1fr; }
  .project-card { min-height: 270px; }
  .section-heading-inline { align-items: flex-start; flex-direction: column; }
  .games-row { gap: 0.4rem; }
  .game-card { padding-inline: max(0.65rem, calc((100% - 274px) / 2)); }
  .site-footer {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding-block: 1.5rem;
  }
}

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

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e5eaf0;
    --fg-dim: #9aa7b7;
    --bg: #0d1117;
    --surface: #141a22;
    --surface-strong: #19211f;
    --border: #2d3748;
    --accent: #7fc6a8;
    --accent-contrast: #07120d;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  }

  .cell-bg, .tile-face { background: #303844; }
  .tile-face[data-v="2"] { background: #45423e; }
  .tile-face[data-v="4"] { background: #584f43; }
  .name-err { color: #ff9d94; }
}
