:root {
  color-scheme: light;
  --bg-top: #f7efe2;
  --bg-bottom: #e6d3ba;
  --ink-strong: #31251b;
  --ink-soft: #6f5a46;
  --surface: rgba(255, 252, 246, 0.78);
  --surface-strong: rgba(255, 248, 238, 0.92);
  --board-shell: #b78f70;
  --board-cell: rgba(255, 247, 236, 0.24);
  --accent: #bf5c36;
  --accent-deep: #7c3214;
  --line: rgba(49, 37, 27, 0.08);
  --shadow-soft: 0 24px 80px rgba(80, 44, 18, 0.12);
  --shadow-hard: 0 18px 40px rgba(80, 44, 18, 0.18);
  --radius-xl: 32px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --gap: clamp(10px, 1.8vw, 16px);
  --board-size: min(82vw, 540px);
  --tile-font: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  --display-font: "Avenir Next Condensed", "Franklin Gothic Medium", "Arial Narrow", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100svh;
  font-family: var(--tile-font);
  color: var(--ink-strong);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.78), transparent 32%),
    radial-gradient(circle at bottom right, rgba(191, 92, 54, 0.18), transparent 38%),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto;
  border-radius: 999px;
  pointer-events: none;
  z-index: 0;
}

body::before {
  width: 32rem;
  height: 32rem;
  top: -8rem;
  right: -10rem;
  background: rgba(255, 255, 255, 0.22);
  filter: blur(6px);
}

body::after {
  width: 24rem;
  height: 24rem;
  left: -6rem;
  bottom: -8rem;
  background: rgba(191, 92, 54, 0.12);
  filter: blur(4px);
}

button,
kbd,
code {
  font: inherit;
}

button {
  cursor: pointer;
}

.page-shell {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(24px, 5vw, 48px) 0 clamp(40px, 6vw, 72px);
}

.page-topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 18px;
}

.repo-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: min(100%, 420px);
  padding: 12px 16px;
  border-radius: 999px;
  color: var(--ink-strong);
  text-decoration: none;
  background: rgba(255, 252, 246, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.58);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.repo-link:hover {
  transform: translateY(-1px);
  background: rgba(255, 248, 238, 0.92);
  box-shadow: var(--shadow-hard);
}

.repo-link:focus-visible {
  outline: 3px solid rgba(191, 92, 54, 0.24);
  outline-offset: 3px;
}

.repo-link__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  flex: 0 0 auto;
  background: rgba(49, 37, 27, 0.08);
}

.repo-link__icon svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: currentColor;
}

.repo-link__text {
  color: var(--ink-soft);
  font-size: 0.94rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 380px);
  gap: 24px;
  align-items: end;
  margin-bottom: 32px;
}

.hero-copy h1,
.section-heading h2,
.info-block h2,
.status-panel h2 {
  margin: 0;
  font-family: var(--display-font);
  letter-spacing: -0.04em;
}

.hero-copy h1 {
  font-size: clamp(4rem, 12vw, 7.5rem);
  line-height: 0.9;
}

.hero-kicker,
.section-kicker,
.status-kicker {
  margin: 0 0 12px;
  color: var(--accent-deep);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.74rem;
}

.hero-description,
.section-copy,
.info-block p,
.board-meta p,
.status-panel p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.6;
}

.score-strip,
.board-card,
.info-block,
.status-panel {
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: var(--shadow-soft);
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
  border-radius: var(--radius-xl);
}

.score-box {
  padding: 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(49, 37, 27, 0.05);
}

.score-label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink-soft);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.score-value {
  display: block;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1;
}

.action-button {
  border: 0;
  border-radius: 999px;
  padding: 14px 18px;
  font-weight: 700;
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.action-button:focus-visible {
  outline: 3px solid rgba(191, 92, 54, 0.24);
  outline-offset: 3px;
}

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

.action-button--primary {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--accent), #cf7445);
  color: #fff8f2;
  box-shadow: var(--shadow-hard);
}

.action-button--secondary {
  background: rgba(49, 37, 27, 0.08);
  color: var(--ink-strong);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
  gap: 28px;
  align-items: start;
}

.game-column {
  width: min(100%, var(--board-size));
  justify-self: center;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}

.section-heading h2,
.info-block h2,
.status-panel h2 {
  font-size: clamp(1.6rem, 4vw, 2.3rem);
  line-height: 0.98;
}

.board-card {
  border-radius: calc(var(--radius-xl) + 4px);
  padding: clamp(18px, 3vw, 22px);
}

.board-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 0.92rem;
}

.board {
  position: relative;
  width: min(100%, var(--board-size));
  aspect-ratio: 1;
  padding: var(--gap);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 24%),
    var(--board-shell);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), var(--shadow-hard);
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.board:focus-visible {
  outline: 4px solid rgba(191, 92, 54, 0.22);
  outline-offset: 6px;
}

.board-background {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  width: 100%;
  height: 100%;
}

.board-cell {
  border-radius: 18px;
  background: var(--board-cell);
}

.tile-layer {
  position: absolute;
  inset: var(--gap);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: var(--gap);
  pointer-events: none;
}

.tile {
  --tile-bg: #eee4da;
  --tile-text: #5a4634;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: 18px;
  background: var(--tile-bg);
  color: var(--tile-text);
  font-weight: 800;
  font-size: clamp(1.35rem, 4vw, 2.4rem);
  line-height: 1;
  transition: filter 150ms ease;
  box-shadow: 0 12px 22px rgba(80, 44, 18, 0.16);
}

.tile[data-digits="4"] {
  font-size: clamp(1.1rem, 3vw, 1.8rem);
}

.tile[data-digits="5"],
.tile[data-digits="6"] {
  font-size: clamp(0.95rem, 2.4vw, 1.35rem);
}

.tile--new {
  animation: tile-pop 160ms ease both;
}

.tile--merged {
  animation: tile-merge 170ms ease both;
}

.tile[data-value="2"] {
  --tile-bg: #f7efe5;
}

.tile[data-value="4"] {
  --tile-bg: #f2e3cf;
}

.tile[data-value="8"] {
  --tile-bg: #f0b67a;
  --tile-text: #fff9f2;
}

.tile[data-value="16"] {
  --tile-bg: #e99863;
  --tile-text: #fff9f2;
}

.tile[data-value="32"] {
  --tile-bg: #e6864e;
  --tile-text: #fff9f2;
}

.tile[data-value="64"] {
  --tile-bg: #db6d3e;
  --tile-text: #fff9f2;
}

.tile[data-value="128"] {
  --tile-bg: #efcf70;
  --tile-text: #fffaf2;
}

.tile[data-value="256"] {
  --tile-bg: #e7c356;
  --tile-text: #fffaf2;
}

.tile[data-value="512"] {
  --tile-bg: #d8ae3f;
  --tile-text: #fffaf2;
}

.tile[data-value="1024"] {
  --tile-bg: #c98a2b;
  --tile-text: #fffaf2;
}

.tile[data-value="2048"] {
  --tile-bg: linear-gradient(135deg, #f0c948, #d38d10);
  --tile-text: #fffaf2;
}

.tile[data-super="true"] {
  --tile-bg: linear-gradient(135deg, #c96a19, #863a1d);
  --tile-text: #fffaf2;
}

.info-column {
  display: grid;
  gap: 18px;
}

.info-block {
  border-radius: var(--radius-xl);
  padding: 22px;
}

.info-block--contrast {
  background: rgba(87, 45, 18, 0.88);
  color: #fff3e6;
}

.info-block--contrast .section-kicker,
.info-block--contrast h2,
.info-block--contrast p {
  color: inherit;
}

.info-list {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
  color: var(--ink-soft);
}

.info-list li {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.info-list li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

kbd,
code {
  padding: 0.14rem 0.4rem;
  border-radius: 999px;
  background: rgba(49, 37, 27, 0.08);
}

.status-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(49, 37, 27, 0.34);
  z-index: 10;
}

.status-overlay.is-hidden {
  display: none;
}

.status-panel {
  width: min(420px, calc(100vw - 32px));
  padding: 28px;
  border-radius: 28px;
  background: var(--surface-strong);
}

.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

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

@keyframes tile-pop {
  0% {
    opacity: 0;
    filter: brightness(1.08);
  }

  100% {
    opacity: 1;
    filter: brightness(1);
  }
}

@keyframes tile-merge {
  0% {
    filter: brightness(1.05);
  }

  55% {
    filter: brightness(1.14);
  }

  100% {
    filter: brightness(1);
  }
}

@media (max-width: 900px) {
  .hero,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .section-heading,
  .board-meta {
    flex-direction: column;
    align-items: flex-start;
  }

  .board {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 20px, 640px);
  }

  .repo-link {
    width: 100%;
  }

  .score-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tile {
    border-radius: 14px;
  }

  .status-panel {
    padding: 22px;
  }
}

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