:root {
  color-scheme: light;
  --ink: #18221f;
  --muted: #60706b;
  --paper: #fbfcf8;
  --wash: #eef5f2;
  --panel: #ffffff;
  --panel-glass: rgba(255, 255, 255, 0.84);
  --line: #d8e0dc;
  --teal: #0f766e;
  --coral: #b7463b;
  --gold: #c39b37;
  --charcoal: #24302d;
  --shadow: 0 24px 70px rgba(24, 34, 31, 0.14);
  --header-height: 72px;
  --content-max: 1200px;
  --page-x: clamp(18px, 5vw, 72px);
  --board: #9aa99f;
  --cell: #d8e1d9;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100svh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(
      circle at 18% 14%,
      rgba(15, 118, 110, 0.12),
      transparent 28%
    ),
    linear-gradient(135deg, #fbfcf8 0%, #eef5f1 100%);
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
.board:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--header-height);
  padding: 14px max(var(--page-x), calc((100vw - var(--content-max)) / 2));
  background: rgba(251, 252, 248, 0.86);
  border-bottom: 1px solid rgba(216, 224, 220, 0.7);
  backdrop-filter: blur(18px);
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--charcoal);
  font-weight: 800;
  text-decoration: none;
}

.home-link span:first-child {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: #fff;
  background: var(--charcoal);
  border-radius: 8px;
  font-size: 1.5rem;
  line-height: 1;
}

.status-row {
  display: flex;
  gap: 10px;
}

.status-box {
  min-width: 92px;
  padding: 9px 12px;
  text-align: center;
  background: var(--panel-glass);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.status-box span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.status-box strong {
  display: block;
  margin-top: 2px;
  color: var(--charcoal);
  font-size: 1.25rem;
}

.game-shell {
  display: grid;
  place-items: center;
  min-height: calc(100svh - var(--header-height));
  padding: 8px clamp(14px, 4vw, 44px) 42px;
}

.game-panel {
  width: min(100%, 560px);
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 6rem;
  line-height: 0.9;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.ghost-button,
.solid-button,
.direction-pad button {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 800;
  transition:
    transform 150ms ease,
    background 150ms ease,
    color 150ms ease;
}

.ghost-button,
.solid-button {
  padding: 0 16px;
  border: 1px solid var(--line);
}

.ghost-button {
  color: var(--charcoal);
  background: var(--panel-glass);
}

.solid-button {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

.ghost-button:hover,
.solid-button:hover,
.direction-pad button:hover {
  transform: translateY(-2px);
}

.board-shell {
  position: relative;
  padding: clamp(10px, 2.6vw, 14px);
  background: var(--board);
  border: 1px solid rgba(38, 50, 46, 0.08);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(8px, 2.2vw, 12px);
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
}

.cell,
.tile {
  display: grid;
  place-items: center;
  border-radius: 8px;
  aspect-ratio: 1;
}

.cell {
  background: rgba(216, 225, 217, 0.78);
}

.tile {
  color: var(--charcoal);
  font-size: 3.45rem;
  font-weight: 900;
  line-height: 1;
  box-shadow: inset 0 -4px 0 rgba(30, 40, 36, 0.08);
}

.tile[data-value="2"] {
  background: #f3f5ec;
}

.tile[data-value="4"] {
  background: #e8f1e5;
}

.tile[data-value="8"] {
  color: #fff;
  background: #df8a62;
}

.tile[data-value="16"] {
  color: #fff;
  background: var(--coral);
}

.tile[data-value="32"] {
  color: #fff;
  background: #bd4b55;
}

.tile[data-value="64"] {
  color: #fff;
  background: #9c3f53;
}

.tile[data-value="128"] {
  color: #fff;
  background: var(--gold);
  font-size: 2.85rem;
}

.tile[data-value="256"] {
  color: #fff;
  background: #b48129;
  font-size: 2.85rem;
}

.tile[data-value="512"] {
  color: #fff;
  background: #8a7131;
  font-size: 2.85rem;
}

.tile[data-value="1024"],
.tile[data-value="2048"] {
  color: #fff;
  background: var(--teal);
  font-size: 2.25rem;
}

.tile[data-value="4096"],
.tile[data-value="8192"] {
  color: #fff;
  background: var(--charcoal);
  font-size: 2.25rem;
}

.game-message {
  position: absolute;
  inset: clamp(10px, 2.6vw, 14px);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  background: rgba(248, 250, 245, 0.88);
  border-radius: 8px;
  backdrop-filter: blur(6px);
}

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

.game-message strong {
  font-size: 3.6rem;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.direction-pad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.direction-pad button {
  width: 64px;
  padding: 0;
  color: var(--charcoal);
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 1.35rem;
}

.direction-pad button[data-direction="up"] {
  grid-column: 2;
}

.direction-pad button[data-direction="left"] {
  grid-column: 1;
}

.direction-pad button[data-direction="down"] {
  grid-column: 2;
}

.direction-pad button[data-direction="right"] {
  grid-column: 3;
  grid-row: 2;
}

@media (max-width: 560px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
    padding-top: 14px;
  }

  .status-row {
    width: 100%;
  }

  .status-box {
    flex: 1;
  }

  .game-shell {
    place-items: start center;
    min-height: auto;
    padding-bottom: 26px;
  }

  .game-top {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 4.4rem;
  }

  .tile {
    font-size: 2.35rem;
  }

  .tile[data-value="128"],
  .tile[data-value="256"],
  .tile[data-value="512"] {
    font-size: 2rem;
  }

  .tile[data-value="1024"],
  .tile[data-value="2048"],
  .tile[data-value="4096"],
  .tile[data-value="8192"] {
    font-size: 1.55rem;
  }

  .game-message strong {
    font-size: 2.45rem;
  }

  .top-actions {
    width: 100%;
  }

  .ghost-button,
  .solid-button {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ghost-button,
  .solid-button,
  .direction-pad button {
    transition: none;
  }

  .ghost-button:hover,
  .solid-button:hover,
  .direction-pad button:hover {
    transform: none;
  }
}
