:root {
  --bg: #14161a;
  --bg-soft: #1a1d22;
  --panel: #20242a;
  --panel-2: #272c33;
  --line: rgba(255, 255, 255, 0.07);
  --text: #f4f1e9;
  --muted: #9299a3;
  --gold: #f2bd46;
  --gold-light: #ffe08a;
  --gold-dark: #9b6813;
  --board-gap: clamp(6px, 1.6vw, 11px);
  --board-pad: clamp(9px, 2.1vw, 14px);
  --cell-size: calc((100% - (3 * var(--board-gap))) / 4);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100svh;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% -10%, rgba(242, 189, 70, 0.08), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button {
  font: inherit;
}

button,
.board {
  -webkit-tap-highlight-color: transparent;
}

svg {
  display: block;
}

.app,
.screen {
  width: 100%;
  min-height: 100svh;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  opacity: 0;
}

.screen.is-active {
  display: flex;
  opacity: 1;
  animation: screen-in 260ms ease-out;
}

/* MAIN MENU */
.menu-screen {
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: max(22px, env(safe-area-inset-top)) 22px max(18px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 50% 24%, rgba(242, 189, 70, 0.1), transparent 29%),
    linear-gradient(180deg, #17191d, #121418 72%);
}

.menu-screen::before,
.menu-screen::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(242, 189, 70, 0.08);
  border-radius: 50%;
  pointer-events: none;
}

.menu-screen::before {
  width: min(74vw, 420px);
  aspect-ratio: 1;
  top: -31%;
  left: -24%;
}

.menu-screen::after {
  width: min(68vw, 380px);
  aspect-ratio: 1;
  right: -28%;
  bottom: -27%;
}

.menu-content {
  position: relative;
  z-index: 1;
  width: min(100%, 390px);
  text-align: center;
}

.hero-coin {
  position: relative;
  width: clamp(106px, 30vw, 148px);
  aspect-ratio: 1;
  margin: 0 auto clamp(18px, 4vh, 30px);
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.32));
  animation: coin-idle 4.6s ease-in-out infinite;
}

.hero-coin::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: rgba(242, 189, 70, 0.12);
  filter: blur(18px);
  z-index: -1;
}

.hero-coin img,
.modal-coin img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.hero-coin span,
.modal-coin span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 950;
  color: #513100;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.36), 0 -1px 0 rgba(70, 40, 0, 0.32);
}

.hero-coin span {
  font-size: clamp(2.4rem, 10vw, 3.7rem);
}

.kicker {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0.23em;
}

.title-block h1 {
  margin: 0;
  font-size: clamp(3.2rem, 14vw, 5rem);
  line-height: 0.78;
  letter-spacing: -0.08em;
  font-weight: 950;
}

.title-block h1::first-line {
  color: var(--gold);
}

.menu-subtitle {
  margin: clamp(18px, 4vh, 28px) 0 0;
  color: var(--muted);
  font-size: clamp(0.86rem, 3.4vw, 1rem);
  line-height: 1.6;
}

.button {
  min-height: 54px;
  border: 0;
  border-radius: 17px;
  padding: 0 22px;
  font-weight: 950;
  font-size: 0.79rem;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: transform 130ms ease, filter 130ms ease, background 130ms ease;
}

.button:active,
.icon-button:active {
  transform: scale(0.96);
}

.button-primary {
  color: #271a05;
  background: var(--gold);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.36), 0 8px 24px rgba(242, 189, 70, 0.18);
}

.button-primary:hover {
  filter: brightness(1.06);
}

.button-secondary {
  color: var(--text);
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px var(--line);
}

.menu-play {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(100%, 280px);
  margin: clamp(24px, 6vh, 44px) auto 0;
}

.menu-play svg {
  width: 19px;
  fill: currentColor;
}

.menu-best {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 11px;
  margin-top: 25px;
}

.menu-best span {
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 850;
  letter-spacing: 0.15em;
}

.menu-best strong {
  color: var(--gold-light);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.brand-footer {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  margin: 0;
  color: #555b64;
  font-size: 0.56rem;
  font-weight: 850;
  letter-spacing: 0.25em;
}

/* GAME */
.game-screen {
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  overflow: auto;
  background:
    radial-gradient(circle at 50% 10%, rgba(242, 189, 70, 0.055), transparent 35%),
    var(--bg);
}

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

.game-header {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  gap: 12px;
  margin-bottom: clamp(10px, 2vh, 16px);
}

.icon-button {
  display: grid;
  width: 46px;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--text);
  background: var(--panel);
  cursor: pointer;
  transition: transform 130ms ease, background 130ms ease;
}

.icon-button:hover {
  background: var(--panel-2);
}

.icon-button svg {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mini-title {
  min-width: 0;
  text-align: center;
  line-height: 1;
}

.mini-title span,
.mini-title strong {
  display: inline;
  font-size: clamp(1rem, 4.4vw, 1.35rem);
  font-weight: 950;
  letter-spacing: -0.05em;
}

.mini-title span {
  color: var(--gold);
}

.score-strip {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 8px;
  margin-bottom: clamp(10px, 2vh, 15px);
}

.score-box,
.goal-pill {
  min-height: 61px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.score-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 8px 10px;
}

.score-box span,
.goal-pill span {
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.14em;
}

.score-box strong,
.goal-pill strong {
  margin-top: 3px;
  font-size: clamp(0.94rem, 4vw, 1.18rem);
  font-variant-numeric: tabular-nums;
}

.score-box em {
  position: absolute;
  right: 9px;
  top: 6px;
  color: var(--gold);
  font-size: 0.65rem;
  font-style: normal;
  font-weight: 900;
  opacity: 0;
}

.score-box em.is-visible {
  animation: score-float 650ms ease-out;
}

.goal-pill {
  display: flex;
  min-width: 68px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 13px;
  border-color: rgba(242, 189, 70, 0.28);
  background: rgba(242, 189, 70, 0.085);
}

.goal-pill strong {
  color: var(--gold-light);
}

.board-card {
  padding: clamp(5px, 1.3vw, 8px);
  border: 1px solid rgba(242, 189, 70, 0.16);
  border-radius: clamp(23px, 5vw, 31px);
  background: #1b1e23;
  box-shadow: var(--shadow);
}

.board {
  --board-size: min(calc(100vw - 36px), 520px, calc(100svh - 190px));
  position: relative;
  width: min(100%, var(--board-size));
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border-radius: clamp(19px, 4vw, 25px);
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.025), transparent 60%),
    #24282e;
  touch-action: none;
  outline: none;
}

.board:focus-visible {
  box-shadow: 0 0 0 3px rgba(242, 189, 70, 0.34);
}

.slot-layer,
.tile-layer,
.motion-layer {
  position: absolute;
  inset: var(--board-pad);
}

.slot-layer {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--board-gap);
}

.coin-slot {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  opacity: 0.46;
}

.coin-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(0.78) saturate(0.65);
}

.tile-layer,
.motion-layer {
  pointer-events: none;
}

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

.motion-layer {
  z-index: 3;
}

.coin {
  position: absolute;
  left: calc(var(--col) * (var(--cell-size) + var(--board-gap)));
  top: calc(var(--row) * (var(--cell-size) + var(--board-gap)));
  width: var(--cell-size);
  height: var(--cell-size);
  isolation: isolate;
  filter: drop-shadow(0 5px 3px rgba(0, 0, 0, 0.18));
  will-change: left, top, transform, opacity;
}

.coin img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.coin-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-top: 1%;
  color: rgba(52, 31, 3, 0.91);
  font-size: clamp(1.05rem, 5.8vw, 2.5rem);
  font-weight: 950;
  letter-spacing: -0.065em;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.42), 0 -1px 0 rgba(69, 36, 0, 0.28);
  font-variant-numeric: tabular-nums;
}

.coin-tone-silver .coin-value {
  color: rgba(38, 43, 48, 0.91);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55), 0 -1px 0 rgba(0, 0, 0, 0.28);
}

.coin-tone-aqua .coin-value,
.coin-tone-violet .coin-value,
.coin-tone-ruby .coin-value {
  color: rgba(245, 250, 252, 0.93);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.22), 0 2px 4px rgba(0, 0, 0, 0.4);
}

.coin[data-value="4096"] .coin-value,
.coin[data-value="8192"] .coin-value,
.coin[data-value="16384"] .coin-value {
  font-size: clamp(0.82rem, 4.7vw, 1.9rem);
}

.coin-motion.is-moving {
  transition:
    left 170ms cubic-bezier(0.2, 0.86, 0.26, 1),
    top 170ms cubic-bezier(0.2, 0.86, 0.26, 1);
}

.coin-motion.will-merge {
  z-index: 4;
}

.coin-motion.is-consumed {
  animation: coin-consume 130ms ease-in forwards;
}

.coin-spawn {
  animation: coin-spawn 220ms cubic-bezier(0.22, 1.45, 0.36, 1);
}

.coin-merged {
  z-index: 5;
  animation: coin-merge 390ms cubic-bezier(0.18, 1.38, 0.3, 1);
}

.coin-merged::after {
  content: "";
  position: absolute;
  inset: 10%;
  z-index: -1;
  border: 2px solid rgba(255, 220, 116, 0.58);
  border-radius: 50%;
  animation: merge-ring 390ms ease-out;
}

.control-hint {
  margin: clamp(9px, 1.8vh, 14px) 0 0;
  color: #686f78;
  text-align: center;
  font-size: 0.62rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mobile-copy {
  display: none;
}

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(9, 10, 12, 0.78);
  backdrop-filter: blur(10px);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  width: min(100%, 390px);
  padding: 27px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 26px;
  background: #20242a;
  box-shadow: var(--shadow);
  text-align: center;
  animation: modal-in 260ms cubic-bezier(0.22, 1.2, 0.36, 1);
}

.modal-coin {
  position: relative;
  width: 112px;
  aspect-ratio: 1;
  margin: 0 auto 17px;
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.25));
}

.modal-coin span {
  font-size: 1.62rem;
}

.modal-card h2 {
  margin: 0;
  font-size: 1.62rem;
  letter-spacing: -0.045em;
}

.modal-card > p:not(.kicker) {
  margin: 11px auto 22px;
  max-width: 290px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.modal-actions .button {
  min-height: 50px;
  padding-inline: 12px;
  font-size: 0.67rem;
}

@keyframes screen-in {
  from { opacity: 0; transform: scale(0.99); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes coin-idle {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-7px) rotate(1deg); }
}

@keyframes coin-spawn {
  0% { opacity: 0; transform: scale(0.28); }
  72% { opacity: 1; transform: scale(1.08); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes coin-consume {
  from { opacity: 1; transform: scale(1); filter: brightness(1.15); }
  to { opacity: 0; transform: scale(0.64); filter: brightness(1.5); }
}

@keyframes coin-merge {
  0% { transform: scale(0.64); filter: brightness(1.4) drop-shadow(0 5px 3px rgba(0, 0, 0, 0.18)); }
  42% { transform: scale(1.17); filter: brightness(1.16) drop-shadow(0 8px 7px rgba(0, 0, 0, 0.2)); }
  72% { transform: scale(0.96); }
  100% { transform: scale(1); }
}

@keyframes merge-ring {
  0% { opacity: 0.7; transform: scale(0.62); }
  100% { opacity: 0; transform: scale(1.45); }
}

@keyframes score-float {
  0% { opacity: 0; transform: translateY(7px); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-17px); }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (pointer: coarse), (max-width: 680px) {
  .desktop-copy {
    display: none;
  }

  .mobile-copy {
    display: inline;
  }
}

@media (max-width: 380px) {
  :root {
    --board-gap: 5px;
    --board-pad: 8px;
  }

  .game-screen {
    padding-inline: 8px;
  }

  .game-header {
    grid-template-columns: 42px 1fr 42px;
  }

  .icon-button {
    width: 42px;
    border-radius: 13px;
  }

  .score-box,
  .goal-pill {
    min-height: 54px;
    border-radius: 14px;
  }

  .goal-pill {
    min-width: 60px;
    padding-inline: 9px;
  }
}

@media (max-height: 650px) and (orientation: portrait) {
  .menu-subtitle {
    display: none;
  }

  .hero-coin {
    width: 90px;
    margin-bottom: 16px;
  }

  .title-block h1 {
    font-size: 3rem;
  }

  .menu-play {
    margin-top: 24px;
  }

  .board {
    --board-size: min(calc(100vw - 36px), calc(100svh - 178px));
  }

  .control-hint {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .game-screen {
    padding: 8px 12px;
  }

  .game-shell {
    display: grid;
    width: min(96vw, 760px);
    grid-template-columns: minmax(180px, 230px) auto;
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "header board"
      "scores board"
      "hint board";
    align-items: center;
    justify-content: center;
    column-gap: 18px;
  }

  .game-header {
    grid-area: header;
    width: 100%;
    margin: 0 0 10px;
  }

  .score-strip {
    grid-area: scores;
    width: 100%;
    grid-template-columns: 1fr 1fr;
    margin: 0;
  }

  .score-strip .goal-pill {
    grid-column: 1 / -1;
    grid-row: 2;
    min-height: 48px;
  }

  .score-box,
  .goal-pill {
    min-height: 52px;
  }

  .board-card {
    grid-area: board;
    width: auto;
    padding: 5px;
  }

  .board {
    --board-size: min(91vh, 390px);
    width: var(--board-size);
  }

  .control-hint {
    grid-area: hint;
    align-self: end;
    margin: 12px 0 4px;
  }

  .menu-screen {
    justify-content: center;
  }

  .menu-content {
    display: grid;
    width: min(92vw, 720px);
    grid-template-columns: 170px 1fr;
    grid-template-areas:
      "coin title"
      "coin play"
      "coin best";
    align-items: center;
    column-gap: 35px;
    text-align: left;
  }

  .hero-coin {
    grid-area: coin;
    width: 160px;
    margin: 0;
  }

  .title-block {
    grid-area: title;
  }

  .title-block h1 {
    font-size: 3.8rem;
  }

  .menu-subtitle {
    display: none;
  }

  .menu-play {
    grid-area: play;
    width: 230px;
    margin: 20px 0 0;
  }

  .menu-best {
    grid-area: best;
    justify-content: flex-start;
    margin-top: 13px;
  }
}

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

/* --------------------------------------------------------------------------
   RESPONSIVE GAME SHELL + NATIVE INTERACTION LOCK
   -------------------------------------------------------------------------- */

html,
body,
.app,
.screen {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overscroll-behavior: none;
}

*,
*::before,
*::after {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

img,
.coin,
.coin-slot,
.board {
  -webkit-user-drag: none;
  user-drag: none;
}

img {
  pointer-events: none;
}

button {
  touch-action: manipulation;
}

.icon {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-play .icon {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
}

.menu-best .icon {
  width: 1rem;
  height: 1rem;
  color: var(--gold);
}

.goal-pill .icon {
  width: 0.92rem;
  height: 0.92rem;
  margin-bottom: 1px;
  color: var(--gold);
}

.control-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.control-hint .icon {
  width: 0.9rem;
  height: 0.9rem;
}

.game-screen {
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
  padding:
    max(8px, env(safe-area-inset-top))
    10px
    max(8px, env(safe-area-inset-bottom));
}

.game-shell {
  --shell-gap: clamp(6px, 1.25vh, 11px);
  width: min(100%, 560px);
  height: calc(100svh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--shell-gap);
}

.game-header {
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  min-height: 40px;
  gap: 9px;
  margin: 0;
}

.icon-button {
  width: 40px;
  height: 40px;
  aspect-ratio: auto;
  border-radius: 13px;
}

.icon-button .icon {
  width: 19px;
  height: 19px;
}

.mini-title span,
.mini-title strong {
  font-size: clamp(0.96rem, 4vw, 1.24rem);
}

.score-strip {
  min-height: 0;
  gap: 7px;
  margin: 0;
}

.score-box,
.goal-pill {
  min-height: clamp(47px, 7.4vh, 57px);
  border-radius: 14px;
}

.score-box {
  padding: 5px 8px;
}

.goal-pill {
  min-width: 65px;
  padding: 4px 10px;
}

.score-box span,
.goal-pill span {
  font-size: clamp(0.5rem, 1.7vw, 0.58rem);
}

.score-box strong,
.goal-pill strong {
  margin-top: 1px;
  font-size: clamp(0.88rem, 3.7vw, 1.1rem);
}

.board-card {
  align-self: start;
  justify-self: center;
  display: grid;
  place-items: center;
  width: var(--runtime-board-size, min(100%, 520px));
  max-width: 100%;
  min-width: 0;
  padding: clamp(4px, 1vw, 7px);
  border-radius: clamp(20px, 4.5vw, 29px);
}

.board {
  --board-size: auto;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1;
  border-radius: clamp(17px, 3.8vw, 23px);
}

.coin {
  --coin-scale: 0.94;
  --coin-offset: calc(var(--cell-size) * ((1 - var(--coin-scale)) / 2));
  left: calc(var(--col) * (var(--cell-size) + var(--board-gap)) + var(--coin-offset));
  top: calc(var(--row) * (var(--cell-size) + var(--board-gap)) + var(--coin-offset));
  width: calc(var(--cell-size) * var(--coin-scale));
  height: calc(var(--cell-size) * var(--coin-scale));
  cursor: default;
}

.coin-value {
  font-size: clamp(0.92rem, 5.25vw, 2.25rem);
}

.coin[data-value="4096"] .coin-value,
.coin[data-value="8192"] .coin-value,
.coin[data-value="16384"] .coin-value {
  font-size: clamp(0.72rem, 4.2vw, 1.68rem);
}

.control-hint {
  min-height: 15px;
  margin: 0;
  align-self: end;
  font-size: clamp(0.52rem, 1.8vw, 0.61rem);
}

.menu-content {
  width: min(100%, 370px);
}

.hero-coin {
  width: clamp(88px, min(29vw, 19vh), 136px);
  margin-bottom: clamp(12px, 2.6vh, 24px);
}

.title-block h1 {
  font-size: clamp(2.9rem, min(13.5vw, 10vh), 4.8rem);
}

.menu-subtitle {
  margin-top: clamp(12px, 2.8vh, 24px);
}

.menu-play {
  min-height: clamp(48px, 7.2vh, 54px);
  margin-top: clamp(18px, 4.2vh, 36px);
}

.menu-best {
  margin-top: clamp(16px, 3.2vh, 25px);
}

@media (orientation: portrait) and (max-height: 720px) {
  .game-shell {
    --shell-gap: 6px;
  }

  .game-header {
    grid-template-columns: 37px minmax(0, 1fr) 37px;
    min-height: 37px;
  }

  .icon-button {
    width: 37px;
    height: 37px;
    border-radius: 12px;
  }

  .score-box,
  .goal-pill {
    min-height: 46px;
  }

  .control-hint {
    min-height: 13px;
  }
}

@media (orientation: portrait) and (max-height: 560px) {
  .game-screen {
    padding-top: max(5px, env(safe-area-inset-top));
    padding-bottom: max(5px, env(safe-area-inset-bottom));
  }

  .game-shell {
    --shell-gap: 4px;
    height: calc(100svh - max(5px, env(safe-area-inset-top)) - max(5px, env(safe-area-inset-bottom)));
  }

  .game-header {
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    min-height: 34px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .score-box,
  .goal-pill {
    min-height: 42px;
  }

  .goal-pill .icon,
  .control-hint {
    display: none;
  }

  .hero-coin {
    width: 78px;
    margin-bottom: 10px;
  }

  .menu-subtitle {
    display: none;
  }

  .title-block h1 {
    font-size: 2.75rem;
  }

  .menu-play {
    margin-top: 18px;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .game-screen {
    align-items: center;
    overflow: hidden;
  }

  .game-shell {
    height: auto;
    grid-template-rows: auto auto 1fr;
    gap: 0;
  }

  .board-card {
    width: auto;
  }

  .board {
    width: var(--runtime-board-size, min(91vh, 390px));
  }
}

/* --------------------------------------------------------------------------
   VIEWPORT FIT FIX V3
   The gameplay remains a compact portrait stack, but its width is derived
   from the real viewport height and width instead of a fixed 560px shell.
   -------------------------------------------------------------------------- */

.game-screen {
  min-height: 100dvh;
  height: 100dvh;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
  padding:
    max(8px, env(safe-area-inset-top))
    10px
    max(8px, env(safe-area-inset-bottom));
}

.game-shell {
  --shell-gap: clamp(6px, 1.2dvh, 11px);
  width: var(--runtime-shell-width, min(calc(100vw - 20px), 560px));
  max-width: calc(100vw - 20px);
  height: auto;
  min-height: 0;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto;
  grid-template-areas:
    "header"
    "scores"
    "board"
    "hint";
  align-content: start;
  align-items: start;
  justify-items: stretch;
  gap: var(--shell-gap);
}

.game-header {
  grid-area: header;
  width: 100%;
  margin: 0;
}

.score-strip {
  grid-area: scores;
  width: 100%;
  margin: 0;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
}

.score-strip .goal-pill {
  grid-column: auto;
  grid-row: auto;
}

.board-card {
  grid-area: board;
  align-self: start;
  justify-self: center;
  width: var(--runtime-board-size, min(calc(100vw - 20px), 560px));
  height: var(--runtime-board-size, min(calc(100vw - 20px), 560px));
  max-width: 100%;
  max-height: 100%;
}

.board {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

.control-hint {
  grid-area: hint;
  align-self: start;
  margin: 0;
}

@media (orientation: landscape) and (max-height: 620px) {
  .game-screen {
    align-items: flex-start;
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  .game-shell {
    width: var(--runtime-shell-width, min(calc(100vw - 20px), 560px));
    height: auto;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "header"
      "scores"
      "board"
      "hint";
    gap: 5px;
  }

  .game-header,
  .score-strip,
  .board-card,
  .control-hint {
    width: 100%;
  }

  .board-card {
    width: var(--runtime-board-size, min(calc(100vw - 20px), 560px));
    height: var(--runtime-board-size, min(calc(100vw - 20px), 560px));
  }

  .board {
    width: 100%;
    height: 100%;
  }

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

  .score-strip .goal-pill {
    grid-column: auto;
    grid-row: auto;
  }
}
