/* A graphite tray: recessed slots stay still, numbered pieces carry the light. */
.merge-page { --merge-radius: 10px; --merge-gap: 9px; background: #181818; }
.merge-page .play-layout { grid-template-columns: minmax(230px,1fr) minmax(360px,500px); max-width: 1060px; gap: clamp(56px,8vw,120px); align-items: center; }
.merge-page .game-intro > .eyebrow { display: none; }
.merge-page .game-intro h1 { font-family: inherit; font-size: clamp(82px,10.3vw,138px); font-weight: 300; line-height: .94; letter-spacing: -.075em; margin: 0 0 26px; color: #e1e1e1; }
.merge-page .game-intro > p:not(.eyebrow) { max-width: 225px; font-size: 14px; line-height: 1.8; color: #a2a2a2; }
.merge-page .game-help { margin-top: 34px; }
.merge-page .game-help summary { color: #a7a7a7; }
.merge-page .game-help .rules-list { border: 0; }
.merge-page .play-column { min-width: 0; }
.merge-page .game-panel { padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; }
.merge-page .stats-row { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: baseline; gap: 12px; padding: 0 5px 0; }
.merge-page .stats-row > div { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; }
.merge-page .stats-row > div:nth-child(2) { justify-self: center; }
.merge-page .stats-row > div:last-child { justify-self: end; }
.merge-page .stat-label { color: #979797; font-size: 10px; font-weight: 400; line-height: 1.4; letter-spacing: .03em; margin: 0; }
.merge-page .stat-value, .merge-page #best { color: #d9d9d9; font-size: 28px; font-weight: 450; line-height: 1; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.merge-page #score { color: #eeeeee; }
.merge-page .merge-score-gain { position: absolute; z-index: 8; font-size: 11px; font-weight: 500; line-height: 1; color: #d9d9d9; letter-spacing: -.02em; pointer-events: none; white-space: nowrap; }
.merge-page .board-container { width: 100%; padding: 11px; margin: 18px auto 0; border: 0; border-radius: 17px; background: linear-gradient(155deg,#242424,#1b1b1b 62%); box-shadow: 0 16px 40px #00000026,inset 0 1px 2px #ffffff05,inset 0 -2px 4px #00000045; isolation: isolate; }
.merge-page .merge-board { gap: var(--merge-gap); container-type: inline-size; border-radius: var(--merge-radius); contain: layout style; }
.merge-page .merge-slots i { border-radius: var(--merge-radius); background: linear-gradient(160deg,#171717,#1b1b1b); box-shadow: inset 0 3px 6px #00000066,inset 0 -1px 2px #ffffff03; }
.merge-page .merge-cell { --tile-top: #383838; --tile-bottom: #2b2b2b; border: 0; border-radius: var(--merge-radius); font-family: inherit; font-size: clamp(26px,6vw,42px); font-size: clamp(26px,9cqw,42px); font-weight: 500; font-variant-numeric: tabular-nums lining-nums; line-height: 1; letter-spacing: -.035em; color: #ededed; background: linear-gradient(155deg,var(--tile-top),var(--tile-bottom)); text-shadow: 0 1px 2px #00000012; }
.merge-page .merge-cell:not([data-value='0']) { box-shadow: 0 3px 5px #00000045,inset 0 1px 2px #ffffff10,inset 0 -2px 3px #00000026; }
.merge-page .merge-cell[data-value='0'] { background: transparent; box-shadow: none; }
.merge-page .merge-cell { backface-visibility: hidden; }
.merge-page .merge-cell[data-value='2'] { --tile-top: #383838; --tile-bottom: #2b2b2b; }
.merge-page .merge-cell[data-value='4'] { --tile-top: #464646; --tile-bottom: #363636; }
.merge-page .merge-cell[data-value='8'] { --tile-top: #575757; --tile-bottom: #474747; }
.merge-page .merge-cell[data-value='16'] { --tile-top: #6b6b6b; --tile-bottom: #595959; color: #fafafa; }
.merge-page .merge-cell[data-value='32'] { --tile-top: #949494; --tile-bottom: #818181; color: #171717; }
.merge-page .merge-cell[data-value='64'] { --tile-top: #a1a1a1; --tile-bottom: #8e8e8e; color: #181818; }
.merge-page .merge-cell[data-value='128'] { --tile-top: #aeaeae; --tile-bottom: #9c9c9c; color: #191919; }
.merge-page .merge-cell[data-value='256'] { --tile-top: #bebebe; --tile-bottom: #acacac; color: #1b1b1b; }
.merge-page .merge-cell[data-value='512'] { --tile-top: #cecece; --tile-bottom: #bebebe; color: #1c1c1c; }
.merge-page .merge-cell[data-value='1024'] { --tile-top: #dedede; --tile-bottom: #cccccc; color: #222222; }
.merge-page .merge-cell[data-value='2048'] { --tile-top: #eeeeee; --tile-bottom: #dcdcdc; color: #202020; }
.merge-page .merge-cell:is([data-value='128'],[data-value='256'],[data-value='512']) { font-size: clamp(22px,5.5vw,36px); font-size: clamp(22px,7.8cqw,36px); }
.merge-page .merge-cell:is([data-value='1024'],[data-value='2048']) { font-size: clamp(19px,5vw,30px); font-size: clamp(19px,6.5cqw,30px); letter-spacing: -.055em; }
.merge-page .game-panel-bottom { margin: 13px 4px 0; min-height: 44px; gap: 12px; }
.merge-page .game-status { color: #929292; font-size: 11px; font-variant-numeric: tabular-nums; }
.merge-page .game-panel-bottom .solid-button { min-width: 90px; min-height: 44px; height: 44px; padding: 0 13px; gap: 18px; background: linear-gradient(155deg,#292929,#202020); color: #bfbfbf; font-size: 11px; border: 0; box-shadow: 0 2px 4px #00000030,inset 0 1px 1px #ffffff05; }
.merge-page .game-panel-bottom .solid-button > span[aria-hidden] { color: #888888; font-size: 15px; }
.merge-page .game-controls { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); width: 278px; padding: 9px; gap: 8px; margin: 24px auto 0; border-radius: 16px; background: linear-gradient(170deg,#292929,#222222); box-shadow: 0 10px 22px #00000040,inset 0 1px 1px #ffffff07; }
.merge-page .direction-button { width: 100%; height: 54px; min-height: 54px; color: #aaaaaa; border-radius: 9px; background: linear-gradient(150deg,#252525,#1b1b1b); box-shadow: 0 3px 6px #00000065,inset 0 1px 1px #ffffff09,inset 0 -1px 2px #00000035; }
.merge-page .direction-button svg { width: 21px; height: 21px; stroke-width: 1.35; }
.merge-page .game-overlay { padding: 24px; border-radius: 17px; background: #202020e8; backdrop-filter: blur(12px); }
.merge-page .game-overlay h2 { font-size: 32px; font-weight: 350; line-height: 1.15; letter-spacing: -.045em; margin: 0 0 14px; }
.merge-page .game-overlay p { font-size: 13px; margin-bottom: 22px; }
.merge-page .game-overlay .solid-button { min-height: 48px; padding-inline: 18px; border-radius: 10px; }
.merge-page .rank-receipt { margin-top: 16px; font-size: 10px; }
.merge-page .game-footnote { max-width: 1060px; margin-top: 34px; }

/* Keep the board and its keys together inside shorter desktop windows. */
@media (min-width:1001px) and (max-height:900px) {
  .merge-page .header { height: 68px; }
  .merge-page .game-switcher { padding-bottom: 16px; }
  .play-page.merge-page main { padding-top: 18px; }
  .merge-page .play-layout { grid-template-columns: minmax(220px,1fr) minmax(260px,500px); }
  .merge-page .play-column { width: min(100%,max(260px,calc(100dvh - 348px))); max-width: 500px; justify-self: end; }
  .merge-page .board-container { margin-top: 14px; }
  .merge-page .game-panel-bottom { margin-top: 10px; }
  .merge-page .game-controls { margin-top: 14px; }
}

@media (max-width:760px), (max-width:1000px) and (max-height:500px) {
  .play-page.merge-page { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .merge-page { --merge-radius: 9px; --merge-gap: 7px; }
  .merge-page .shell { padding-inline: max(12px,env(safe-area-inset-left)) max(12px,env(safe-area-inset-right)); }
  .play-page.merge-page main { padding-top: 4px; }
  .merge-page .play-layout { display: flex; flex-direction: column; align-items: stretch; gap: 6px; width: 100%; max-width: 480px; margin: 0 auto; }
  .merge-page .play-column { width: 100%; }
  .merge-page .game-intro { display: grid; grid-template-columns: 1fr auto; align-items: center; padding: 0 3px; }
  .merge-page .game-intro h1 { font-size: 32px; line-height: 1; font-weight: 350; letter-spacing: -.065em; margin: 0; }
  .merge-page .game-intro > p:not(.eyebrow) { display: none; }
  .merge-page .game-help { margin: 0; }
  .merge-page .game-help summary { min-height: 44px; padding: 0 5px; font-size: 10px; }
  .merge-page .game-help[open] { padding: 0 18px 18px; }
  .merge-page .game-help[open] summary { min-height: 48px; }
  .merge-page .game-panel { padding: 0; }
  .merge-page .stats-row { gap: 8px; padding: 0 3px; min-height: 39px; align-items: center; }
  .merge-page .stats-row > div { flex-direction: column; align-items: flex-start; gap: 3px; }
  .merge-page .stat-label { font-size: 9px; letter-spacing: 0; }
  .merge-page .stat-value, .merge-page #best { font-size: 24px; line-height: 1.15; }
  .merge-page .board-container { width: min(100%,calc(100dvh - 204px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); padding: 8px; margin-top: 8px; border-radius: 14px; }
  .merge-page .game-panel-bottom { width: min(100%,calc(100dvh - 204px - env(safe-area-inset-top) - env(safe-area-inset-bottom))); margin: 6px auto 0; padding-inline: 3px; }
  .merge-page .game-controls { display: none !important; }
  .merge-page .game-overlay { border-radius: 14px; padding: 18px; }
  .merge-page .game-overlay h2 { font-size: 28px; }
  .merge-page .game-overlay p { font-size: 12px; margin-bottom: 17px; }
  .merge-page .rank-receipt { margin-top: 10px; }
}

@media (max-width:360px), (max-width:760px) and (max-height:620px) {
  .merge-page .play-layout { gap: 4px; }
  .merge-page .game-intro h1 { font-size: 29px; }
  .merge-page .stats-row { min-height: 38px; }
  .merge-page .stats-row > div { gap: 2px; }
  .merge-page .stat-label { font-size: 8px; }
  .merge-page .stat-value, .merge-page #best { font-size: 22px; }
  .merge-page .board-container { margin-top: 6px; padding: 7px; }
  .merge-page .game-panel-bottom { margin-top: 4px; }
  .merge-page .game-status { font-size: 10px; }
  .merge-page .game-panel-bottom .solid-button { font-size: 10px; min-width: 78px; padding-inline: 11px; }
}

/* Use some of a tall phone's spare space above the board, keeping it in reach. */
@media (max-width:760px) and (min-height:740px) and (orientation:portrait) {
  .merge-page .play-column {
    --merge-phone-board: min(480px,calc(100vw - 24px),calc(100dvh - 204px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
    padding-top: clamp(0px,calc((100dvh - var(--merge-phone-board) - 220px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * .5),128px);
  }
}

@media (max-width:1000px) and (max-height:500px) and (orientation:landscape) {
  .play-page.merge-page { padding-bottom: 0; }
  .play-page.merge-page main { padding-top: 5px; }
  .merge-page .play-layout { display: grid; grid-template-columns: minmax(0,1fr) minmax(220px,.68fr); max-width: 900px; gap: 24px; align-items: start; }
  .merge-page .play-column { grid-column: 1; grid-row: 1; }
  .merge-page .game-intro { display: block; grid-column: 2; grid-row: 1; padding: 20px 8px 0; }
  .merge-page .game-intro h1 { font-size: 58px; margin: 0 0 22px; }
  .merge-page .game-help { margin: 0; }
  .merge-page .game-panel { display: grid; grid-template-columns: minmax(0,calc(100dvh - 87px - env(safe-area-inset-top) - env(safe-area-inset-bottom))) minmax(72px,1fr); grid-template-rows: 1fr auto; gap: 16px; align-items: start; }
  .merge-page .board-container { grid-column: 1; grid-row: 1 / 3; width: 100%; margin: 0; padding: 7px; border-radius: 13px; }
  .merge-page .stats-row { display: flex; flex-direction: column; grid-column: 2; grid-row: 1; align-items: flex-start; gap: 17px; padding: 2px 0 0; }
  .merge-page .stats-row > div { flex-direction: column; gap: 3px; }
  .merge-page .stat-label { font-size: 9px; }
  .merge-page .stat-value, .merge-page #best { font-size: 24px; }
  .merge-page .game-panel-bottom { grid-column: 2; grid-row: 2; align-self: end; flex-direction: column; align-items: stretch; width: 100%; margin: 0; padding: 0; gap: 7px; }
  .merge-page .game-panel-bottom .solid-button { min-width: 0; padding-inline: 9px; gap: 10px; }
  .merge-page .game-controls { left: auto; right: max(16px,env(safe-area-inset-right)); width: min(35vw,300px); margin: 0; bottom: max(12px,env(safe-area-inset-bottom)); }
  .merge-page .merge-cell { font-size: clamp(24px,9cqw,36px); }
  .merge-page .game-overlay { padding: 14px; }
  .merge-page .game-overlay h2 { font-size: 24px; }
  .merge-page .game-overlay p { margin-bottom: 12px; }
  .merge-page .rank-receipt { margin-top: 6px; }
}

@media (prefers-reduced-motion:reduce) {
  .merge-page .direction-button { transition: none; }
}
