* {
  box-sizing: border-box;
}

:root {
  --page-x: clamp(12px, 4vw, 28px);
  --board-size: min(500px, calc(100svw - (var(--page-x) * 2)));
  --gap: clamp(10px, 3vw, 15px);
  --cell-size: calc((var(--board-size) - (var(--gap) * 5)) / 4);
  --step: calc(var(--cell-size) + var(--gap));
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #050506;
  color: #f8f1df;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 18px;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  padding: clamp(14px, 4svh, 42px) var(--page-x) clamp(24px, 6svh, 54px);
  overflow-x: hidden;
}

.container {
  width: var(--board-size);
  margin: 0 auto;
}

.heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(96px, 28vw, 142px);
  align-items: start;
  gap: clamp(10px, 3vw, 16px);
  margin-bottom: clamp(12px, 2.6svh, 20px);
}

.eyebrow {
  margin: 0 0 4px;
  color: #d6a647;
  font-size: clamp(10px, 2.6vw, 12px);
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
}

h1.title {
  max-width: 100%;
  margin: 0;
  color: #f7e4ad;
  font-size: clamp(34px, 8.6vw, 52px);
  font-weight: 950;
  letter-spacing: -0.055em;
  line-height: 0.94;
  text-wrap: balance;
  overflow-wrap: normal;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.72);
}

.score-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.reward-row {
  margin-bottom: clamp(12px, 2.8vh, 18px);
}

.scores-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  text-align: right;
}

.scores-container-best-only {
  grid-template-columns: 1fr;
}

.score-container,
.best-container {
  position: relative;
  min-width: 0;
  height: clamp(54px, 13vw, 64px);
  padding: clamp(21px, 5vw, 25px) 8px 7px;
  border: 1px solid rgba(214, 166, 71, 0.46);
  border-radius: 3px;
  background: #141216;
  color: #e1b75b;
  font-size: var(--money-score-font, clamp(20px, 5vw, 24px));
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 30px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

.score-container::before,
.best-container::before {
  content: "$";
  margin-right: 1px;
}

.score-container::after,
.best-container::after {
  position: absolute;
  top: 9px;
  left: 0;
  width: 100%;
  color: rgba(246, 240, 223, 0.66);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  line-height: 12px;
  text-align: center;
  text-transform: uppercase;
}

.score-container::after {
  content: "Worth";
}

.best-container::after {
  content: "Best";
}

.reward-tile {
  width: 100%;
  min-height: 72px;
  padding: 10px 14px;
  border: 1px solid rgba(214, 166, 71, 0.38);
  border-radius: 3px;
  background: #121014;
  text-align: left;
}

.reward-main {
  display: grid;
  grid-template-columns: minmax(120px, 150px) minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
}

.reward-worth {
  position: relative;
  padding-right: 14px;
  border-right: 1px solid rgba(248, 241, 223, 0.16);
}

.reward-worth-label,
.reward-label,
.reward-note {
  display: block;
  color: rgba(246, 240, 223, 0.72);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.08em;
  line-height: 1.25;
  text-transform: uppercase;
}

.reward-worth-value {
  display: block;
  margin-top: 4px;
  color: #f7e4ad;
  font-size: var(--money-score-font, clamp(20px, 4vw, 28px));
  font-weight: 950;
  line-height: 1;
  letter-spacing: -0.04em;
  white-space: nowrap;
}

.reward-worth-value::before {
  content: "$";
  margin-right: 1px;
}

.reward-worth .worth-addition {
  position: absolute;
  right: 10px;
  top: 20px;
  z-index: 10;
  color: #efc76b;
  font-size: 20px;
  font-weight: 900;
  line-height: 22px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  animation: move-up 600ms ease-in;
  animation-fill-mode: both;
  pointer-events: none;
}

.reward-title {
  display: block;
  margin: 4px 0;
  color: #e1b75b;
  font-size: clamp(17px, 3.2vw, 21px);
  font-weight: 950;
  line-height: 1.05;
}

.reward-restart-button {
  align-self: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(225, 183, 91, 0.46);
  border-radius: 3px;
  background: #1d1a20;
  color: #f8e6b4;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
  cursor: pointer;
}

.reward-restart-button:hover {
  background: #2a2020;
  border-color: rgba(244, 200, 104, 0.76);
}

.reward-restart-button:focus-visible {
  outline: 2px solid #f8e5a4;
  outline-offset: 3px;
}

.reward-starter {
  background: #121014;
}

.reward-thousandaire {
  background: #17120f;
}

.reward-millionaire {
  background: #1f1512;
}

.reward-billionaire {
  background: #26131d;
}

.score-container .score-addition,
.best-container .score-addition {
  position: absolute;
  right: 12px;
  top: 20px;
  z-index: 100;
  color: #efc76b;
  font-size: 22px;
  font-weight: 900;
  line-height: 24px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  animation: move-up 600ms ease-in;
  animation-fill-mode: both;
}

@keyframes move-up {
  0% {
    top: 20px;
    opacity: 1;
  }
  100% {
    top: -34px;
    opacity: 0;
  }
}

.above-game {
  margin-bottom: clamp(14px, 3vh, 22px);
}

.game-intro,
.game-subtitle,
.game-explanation p {
  margin-top: 0;
  margin-bottom: 10px;
  color: #eee6d2;
  line-height: 1.55;
}

.game-intro {
  max-width: 36rem;
}

.game-subtitle {
  color: rgba(246, 240, 223, 0.72);
}

.game-container {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  padding: var(--gap);
  border: 1px solid rgba(214, 166, 71, 0.34);
  border-radius: 3px;
  background: #141216;
  cursor: default;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
}

.game-container .game-message {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 100;
  border-radius: 3px;
  background: rgba(3, 4, 5, 0.84);
  color: #f7e4ad;
  text-align: center;
  animation: fade-in 500ms ease 700ms;
  animation-fill-mode: both;
}

.game-container .game-message p {
  height: 60px;
  margin-top: calc(var(--board-size) * 0.41);
  font-size: clamp(30px, 10vw, 54px);
  font-weight: 900;
  line-height: 60px;
}

.game-container .game-message .lower {
  display: block;
  margin-top: clamp(26px, 7vw, 44px);
}

.game-container .game-message button {
  display: inline-block;
  height: 42px;
  margin-left: 8px;
  padding: 0 20px;
  border: 0;
  border-radius: 3px;
  background: #d6a647;
  color: #101010;
  font: inherit;
  font-weight: 900;
  line-height: 42px;
  text-decoration: none;
  cursor: pointer;
}

.game-container .game-message button.keep-playing-button {
  display: none;
}

.game-container .game-message.game-won button.keep-playing-button {
  display: inline-block;
}

.game-container .game-message.game-won,
.game-container .game-message.game-over {
  display: block;
}

@keyframes fade-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.grid-container,
.tile-container {
  position: absolute;
}

.grid-container {
  z-index: 1;
}

.tile-container {
  z-index: 2;
}

.grid-row {
  margin-bottom: var(--gap);
}

.grid-row:last-child {
  margin-bottom: 0;
}

.grid-row::after {
  content: "";
  display: block;
  clear: both;
}

.grid-cell {
  float: left;
  width: var(--cell-size);
  height: var(--cell-size);
  margin-right: var(--gap);
  border-radius: 3px;
  background: #181818;
}

.grid-cell:last-child {
  margin-right: 0;
}

.tile,
.tile .tile-inner {
  width: var(--cell-size);
  height: var(--cell-size);
}

.tile {
  position: absolute;
  transition: 100ms ease-in-out;
  transition-property: transform;
}

.tile .tile-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  background: #1f1f24;
  color: #f8f1df;
  font-size: clamp(24px, calc(var(--cell-size) * 0.42), 44px);
  font-weight: 950;
  letter-spacing: -0.06em;
  text-align: center;
}

.tile .tile-inner::before {
  content: "$";
  margin-right: 1px;
  font-size: 0.72em;
  letter-spacing: -0.04em;
}

.tile.tile-position-1-1 { transform: translate(0, 0); }
.tile.tile-position-1-2 { transform: translate(0, var(--step)); }
.tile.tile-position-1-3 { transform: translate(0, calc(var(--step) * 2)); }
.tile.tile-position-1-4 { transform: translate(0, calc(var(--step) * 3)); }
.tile.tile-position-2-1 { transform: translate(var(--step), 0); }
.tile.tile-position-2-2 { transform: translate(var(--step), var(--step)); }
.tile.tile-position-2-3 { transform: translate(var(--step), calc(var(--step) * 2)); }
.tile.tile-position-2-4 { transform: translate(var(--step), calc(var(--step) * 3)); }
.tile.tile-position-3-1 { transform: translate(calc(var(--step) * 2), 0); }
.tile.tile-position-3-2 { transform: translate(calc(var(--step) * 2), var(--step)); }
.tile.tile-position-3-3 { transform: translate(calc(var(--step) * 2), calc(var(--step) * 2)); }
.tile.tile-position-3-4 { transform: translate(calc(var(--step) * 2), calc(var(--step) * 3)); }
.tile.tile-position-4-1 { transform: translate(calc(var(--step) * 3), 0); }
.tile.tile-position-4-2 { transform: translate(calc(var(--step) * 3), var(--step)); }
.tile.tile-position-4-3 { transform: translate(calc(var(--step) * 3), calc(var(--step) * 2)); }
.tile.tile-position-4-4 { transform: translate(calc(var(--step) * 3), calc(var(--step) * 3)); }

.tile.tile-2 .tile-inner { background: #24232b; color: #f8f1df; }
.tile.tile-4 .tile-inner { background: #332838; color: #f8f1df; }
.tile.tile-8 .tile-inner { background: #4d2f37; color: #ffe7d3; }
.tile.tile-16 .tile-inner { background: #673530; color: #ffe3c0; }
.tile.tile-32 .tile-inner { background: #87422d; color: #fff0d0; }
.tile.tile-64 .tile-inner { background: #a9542e; color: #fff4dc; }
.tile.tile-128 .tile-inner { background: #c96833; color: #180f07; font-size: clamp(20px, calc(var(--cell-size) * 0.34), 36px); }
.tile.tile-256 .tile-inner { background: #e0833d; color: #180f07; font-size: clamp(20px, calc(var(--cell-size) * 0.34), 36px); }
.tile.tile-512 .tile-inner { background: #efa64f; color: #171007; font-size: clamp(20px, calc(var(--cell-size) * 0.34), 36px); }
.tile.tile-1024 .tile-inner { background: #f4c868; color: #141007; font-size: clamp(16px, calc(var(--cell-size) * 0.29), 31px); }
.tile.tile-2048 .tile-inner { background: #f8e5a4; color: #100d07; font-size: clamp(16px, calc(var(--cell-size) * 0.29), 31px); }
.tile.tile-super .tile-inner { background: #3a1020; color: #ffe7bd; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); border: 1px solid rgba(244, 200, 104, 0.44); }
.tile.tile-4096 .tile-inner { background: #fff2c8; color: #100d07; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-8192 .tile-inner { background: #e9d0a0; color: #100d07; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-16384 .tile-inner { background: #d4aa72; color: #120d08; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-32768 .tile-inner { background: #bf7f51; color: #120d08; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-65536 .tile-inner { background: #a9564a; color: #fff2de; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-131072 .tile-inner { background: #8f3247; color: #ffeaf0; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-262144 .tile-inner { background: #a82f55; color: #ffeaf0; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-524288 .tile-inner { background: #c43961; color: #fff0f4; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-1048576 .tile-inner { background: #df4b6b; color: #18090b; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-2097152 .tile-inner { background: #ee6f76; color: #18090b; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-4194304 .tile-inner { background: #f79a82; color: #160b07; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-8388608 .tile-inner { background: #ffc39a; color: #130d07; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-16777216 .tile-inner { background: #ffe1b3; color: #100d07; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-33554432 .tile-inner { background: #fff1cc; color: #100d07; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-67108864 .tile-inner { background: #e8d9be; color: #100d07; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-134217728 .tile-inner { background: #c7b08b; color: #100d07; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-268435456 .tile-inner { background: #9c7860; color: #120d08; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-536870912 .tile-inner { background: #81485a; color: #ffeaf0; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-1073741824 .tile-inner { background: #b02d56; color: #fff0f4; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }
.tile.tile-2147483648 .tile-inner { background: #f6d37c; color: #100d07; font-size: clamp(14px, calc(var(--cell-size) * 0.25), 27px); }

.tile-new .tile-inner {
  animation: appear 200ms ease 100ms;
  animation-fill-mode: backwards;
}

.tile-merged .tile-inner {
  z-index: 20;
  animation: pop 200ms ease 100ms;
  animation-fill-mode: backwards;
}

@keyframes appear {
  0% { opacity: 0; transform: scale(0); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes pop {
  0% { transform: scale(0); }
  50% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.game-explanation {
  margin-top: clamp(22px, 5vh, 30px);
  padding: clamp(18px, 4vw, 22px);
  border: 1px solid rgba(214, 166, 71, 0.26);
  border-radius: 3px;
  background: #111014;
}

.game-explanation h2 {
  margin: 0 0 10px;
  color: #d6a647;
  font-size: 22px;
  line-height: 1.2;
}

.game-explanation p:last-child {
  margin-bottom: 0;
}

.site-footer {
  margin-top: 20px;
  color: rgba(246, 240, 223, 0.58);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.site-footer p {
  margin: 0;
}

@media screen and (max-width: 560px) {
  :root {
    --page-x: clamp(10px, 4vw, 16px);
    --gap: clamp(8px, 2.7vw, 12px);
  }

  html,
  body {
    font-size: 15px;
  }

  body {
    padding-top: clamp(10px, 3svh, 18px);
  }

  .heading {
    grid-template-columns: minmax(0, 1fr) minmax(82px, 96px);
    gap: 8px;
    margin-bottom: 10px;
  }

  .eyebrow {
    margin-bottom: 3px;
    font-size: 10px;
    letter-spacing: 0.09em;
  }

  h1.title {
    font-size: clamp(30px, 10.8vw, 40px);
    letter-spacing: -0.06em;
  }

  .score-panel {
    width: 100%;
  }

  .score-container,
  .best-container {
    height: 50px;
    padding-top: 20px;
    font-size: var(--money-score-font, clamp(17px, 5vw, 20px));
  }

  .reward-tile {
    min-height: 66px;
    padding: 9px 10px;
  }

  .reward-main {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
  }

  .reward-worth {
    grid-column: 1;
    min-width: 0;
    padding-right: 0;
    padding-bottom: 0;
    border-right: 0;
    border-bottom: 0;
  }

  .reward-status {
    grid-column: 1;
    min-width: 0;
  }

  .reward-restart-button {
    grid-row: 1 / span 2;
    grid-column: 2;
    min-height: 44px;
    padding: 0 12px;
  }

  .above-game {
    margin-bottom: 10px;
  }

  .game-intro {
    margin-bottom: 0;
    line-height: 1.35;
  }
}

@media screen and (max-width: 380px) {
  .heading {
    grid-template-columns: minmax(0, 1fr) 82px;
    gap: 7px;
  }

  .eyebrow {
    font-size: 9px;
  }

  h1.title {
    font-size: clamp(28px, 10.4vw, 34px);
  }

  .score-container,
  .best-container {
    height: 46px;
    padding-top: 19px;
  }

  .score-container::after,
  .best-container::after {
    top: 7px;
    font-size: 10px;
  }

  .reward-title {
    font-size: 16px;
  }

  .reward-note {
    font-size: 10px;
  }
}

@media screen and (max-width: 330px) {
  .heading {
    grid-template-columns: 1fr;
  }

  .score-panel {
    width: min(100%, 120px);
  }
}


@media screen and (max-height: 760px) and (min-width: 700px) {
  body {
    padding-top: 18px;
    padding-bottom: 30px;
  }

  :root {
    --board-size: min(470px, calc(100vw - (var(--page-x) * 2)));
  }

  .above-game {
    margin-bottom: 14px;
  }

  .game-explanation {
    margin-top: 20px;
  }
}

::selection {
  background: rgba(214, 166, 71, 0.28);
  color: #fff3cd;
}

.game-container .game-message button:hover {
  background: #efc76b;
}

.game-container .game-message button:focus-visible {
  outline: 2px solid #f7e4ad;
  outline-offset: 3px;
}

.game-container .game-message.game-won .keep-playing-button {
  background: #d6a647;
  color: #101010;
}

.game-container .game-message.game-won .retry-button {
  border: 1px solid rgba(225, 183, 91, 0.46);
  background: #1d1a20;
  color: #f8e6b4;
}

.game-container .game-message.game-won .retry-button:hover {
  background: #2a2020;
  border-color: rgba(244, 200, 104, 0.76);
  color: #fff2c8;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .tile,
  .tile .tile-inner,
  .game-container .game-message,
  .score-addition,
  .worth-addition {
    animation: none !important;
    transition: none !important;
  }
}

