:root {
  color-scheme: dark;
  --ink: #fff8ee;
  --muted: #b9c4d8;
  --line: rgba(255, 255, 255, 0.18);
  --panel: rgba(12, 21, 42, 0.94);
  --blue: #54c7ff;
  --store-blue: #1266ff;
  --yellow: #ffd166;
  --green: #42d97b;
  --pink: #ff5ca8;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 14%, rgba(66, 217, 123, 0.2), transparent 28%),
    radial-gradient(circle at 84% 12%, rgba(255, 209, 102, 0.2), transparent 30%),
    linear-gradient(155deg, #08122d 0%, #12335d 50%, #080d19 100%);
  color: var(--ink);
  touch-action: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

.shell {
  display: grid;
  width: 100vw;
  height: 100svh;
  min-height: 100svh;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  place-items: center;
}

@supports (height: 100dvh) {
  .shell {
    height: 100dvh;
    min-height: 100dvh;
  }
}

.game {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: clamp(7px, 1.2dvh, 11px);
  width: min(100%, 540px);
  height: min(100%, 920px);
  min-height: 0;
}

.brand-header {
  display: grid;
  min-height: clamp(40px, 7dvh, 62px);
  place-items: center;
  text-align: center;
}

.merge-logo {
  color: transparent;
  font-size: clamp(1.55rem, min(7.2dvw, 5.6dvh), 3rem);
  font-weight: 1000;
  line-height: 0.9;
  background: linear-gradient(90deg, #ffd166 0%, #42d97b 36%, #54c7ff 72%, #fff8ee 100%);
  background-clip: text;
  -webkit-background-clip: text;
  filter: drop-shadow(0 5px 0 rgba(5, 10, 24, 0.5)) drop-shadow(0 0 16px rgba(84, 199, 255, 0.34));
  letter-spacing: 0;
  text-transform: uppercase;
}

.site-tag {
  margin-top: 3px;
  color: rgba(255, 248, 238, 0.78);
  font-size: clamp(0.62rem, min(2.2dvw, 1.9dvh), 0.88rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.topbar,
.bottombar {
  display: grid;
  align-items: center;
  gap: clamp(6px, 1.3dvw, 10px);
}

.topbar {
  grid-template-columns: repeat(3, 1fr);
}

.bottombar {
  grid-template-columns: 0.78fr 1fr 1fr 0.78fr 1.2fr;
}

.metric {
  min-width: 0;
  padding: clamp(6px, 1dvh, 9px) 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
}

.metric.center {
  text-align: center;
}

.metric.right {
  text-align: right;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 850;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 1px;
  overflow: hidden;
  font-size: clamp(1.02rem, 3.1dvh, 1.42rem);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-wrap {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
}

.merge-board {
  --gap: clamp(6px, 1.7vw, 10px);
  display: grid;
  width: min(100%, 510px, calc(100dvh - 242px));
  aspect-ratio: 1;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: var(--gap);
  padding: var(--gap);
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    rgba(4, 10, 28, 0.84);
  background-size: 34px 34px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 18px 45px rgba(0, 0, 0, 0.3);
}

.cell {
  display: grid;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  place-items: center;
  background: rgba(255, 255, 255, 0.07);
  cursor: pointer;
}

.cell.selected {
  outline: 3px solid var(--yellow);
  outline-offset: -2px;
}

.cell.hint {
  animation: hintPulse 950ms ease-in-out 3;
}

.item {
  display: grid;
  width: 100%;
  height: 100%;
  border: 2px solid rgba(5, 10, 24, 0.74);
  border-radius: 8px;
  place-items: center;
  padding: 5px;
  color: #061225;
  font-weight: 1000;
  text-align: center;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.34), 0 10px 20px rgba(0, 0, 0, 0.22);
}

.item.new {
  animation: popIn 180ms ease-out;
}

.item.merged {
  animation: mergePop 260ms ease-out;
}

.item-shape {
  position: relative;
  display: block;
  width: clamp(24px, 8vw, 42px);
  height: clamp(20px, 6.8vw, 34px);
  border: 3px solid #061225;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.58);
}

.item-shape::before,
.item-shape::after {
  content: "";
  position: absolute;
  border: 3px solid #061225;
}

.level-1 .item-shape::before {
  left: 8px;
  right: 8px;
  top: -10px;
  height: 10px;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}

.level-2 .item-shape {
  transform: rotate(-8deg);
}

.level-2 .item-shape::before {
  left: 8px;
  top: -9px;
  width: 16px;
  height: 14px;
  border-bottom: 0;
  border-radius: 12px 12px 0 0;
}

.level-3 .item-shape {
  border-radius: 50%;
}

.level-3 .item-shape::before {
  inset: 7px;
  border-radius: 50%;
}

.level-4 .item-shape::before {
  left: -4px;
  right: -4px;
  top: 9px;
  border-width: 2px 0 0;
}

.level-4 .item-shape::after {
  left: 10px;
  top: -7px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff8ee;
}

.level-5 .item-shape {
  clip-path: polygon(50% 0, 61% 34%, 98% 35%, 68% 56%, 79% 92%, 50% 70%, 21% 92%, 32% 56%, 2% 35%, 39% 34%);
  border-radius: 0;
}

.level-5 .item-shape::before,
.level-5 .item-shape::after {
  display: none;
}

.level-6 .item-shape {
  border-radius: 50% 50% 8px 8px;
}

.level-6 .item-shape::before {
  left: 5px;
  top: -11px;
  width: 28px;
  height: 14px;
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
}

.level-7 .item-shape {
  transform: rotate(45deg);
}

.level-7 .item-shape::before,
.level-7 .item-shape::after {
  display: none;
}

.level-8 .item-shape {
  border-radius: 8px 8px 16px 16px;
}

.level-8 .item-shape::before {
  left: 7px;
  top: -12px;
  width: 20px;
  height: 14px;
  border-bottom: 0;
  border-radius: 14px 14px 0 0;
}

.item-name {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  max-width: 100%;
  font-size: clamp(0.48rem, min(2.2dvw, 1.4dvh), 0.72rem);
  line-height: 1;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Imported Bleeping Merge artwork fills each card while retaining a compact label. */
.item {
  grid-template-rows: minmax(0, 1fr) auto;
  padding: 2px 2px 4px;
  color: #fff8ee;
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.19), rgba(84, 199, 255, 0.08) 52%, rgba(4, 10, 28, 0.38));
}

.item-image {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35));
}

.item .item-name {
  width: 100%;
  margin-top: 1px;
  font-size: clamp(0.4rem, min(1.8dvw, 1.15dvh), 0.62rem);
  text-shadow: 0 1px 2px #061225, 0 0 4px #061225;
}

.level-1 { background: linear-gradient(145deg, #e9f7ff, #8fd9ff); }
.level-2 { background: linear-gradient(145deg, #fff2bf, #ffd166); }
.level-3 { background: linear-gradient(145deg, #d8ffe3, #42d97b); }
.level-4 { background: linear-gradient(145deg, #ffd4e8, #ff5ca8); color: #200717; }
.level-5 { background: linear-gradient(145deg, #ffe2c7, #ff8a5b); }
.level-6 { background: linear-gradient(145deg, #e7ddff, #a78bfa); }
.level-7 { background: linear-gradient(145deg, #ffffff, #7dd3fc 40%, #f0abfc); }
.level-8,
.level-9,
.level-10 { background: linear-gradient(145deg, #fff8ee, #ffd166 28%, #54c7ff 68%, #42d97b); }

.game-message-slot {
  display: grid;
  height: clamp(36px, 5.4dvh, 46px);
  padding: 0 6px;
  place-items: center;
  overflow: hidden;
}

.toast {
  position: static;
  width: 100%;
  max-width: 100%;
  padding: 3px 10px;
  border-radius: 8px;
  background: rgba(8, 14, 30, 0.76);
  color: var(--yellow);
  font-size: clamp(0.78rem, min(3.2dvw, 1.8dvh), 1rem);
  font-weight: 950;
  line-height: 1.1;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  text-wrap: balance;
  transform: translateY(3px) scale(0.98);
}

.toast.show {
  animation: gameCommentPop 1400ms ease-out;
}

.small-button,
.secondary-button,
.primary-button,
.arcade-button,
.store-button {
  min-height: clamp(38px, 6.2dvh, 48px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.small-button {
  padding: 0 8px;
  font-size: clamp(0.72rem, min(3dvw, 1.75dvh), 0.92rem);
}

.icon-button {
  display: grid;
  place-items: center;
  font-size: 1.2rem;
}

.primary-button {
  width: 100%;
  margin-top: 10px;
  border: 0;
  background: var(--blue);
  color: #081122;
  box-shadow: 0 10px 28px rgba(84, 199, 255, 0.24);
}

.secondary-button,
.arcade-button,
.store-button {
  width: 100%;
  margin-top: 10px;
}

.arcade-button {
  border-color: rgba(84, 199, 255, 0.48);
  background: rgba(84, 199, 255, 0.34);
}

.store-button {
  border-color: rgba(84, 199, 255, 0.42);
  background: rgba(84, 199, 255, 0.14);
}

.buy-button,
.thing-button {
  border-color: rgba(84, 199, 255, 0.62);
  background: rgba(84, 199, 255, 0.24);
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  padding: 18px;
  place-items: center;
  background: rgba(5, 8, 18, 0.68);
  backdrop-filter: blur(10px);
}

.overlay.show {
  display: grid;
}

.panel {
  width: min(100%, 390px);
  max-height: calc(100svh - 32px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  text-align: center;
}

@supports (height: 100dvh) {
  .panel {
    max-height: calc(100dvh - 32px);
  }
}

.kicker {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
}

.panel h1 {
  margin: 0;
  font-size: clamp(2rem, 9dvw, 3.3rem);
  line-height: 0.95;
}

.panel p {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.score-form {
  margin-top: 16px;
}

.score-form label,
.home-scores h2 {
  display: block;
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 950;
  text-transform: uppercase;
}

.initials-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 7px 0 12px;
}

.initials-row input,
.city-input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 12px;
}

.initials-row input {
  text-align: center;
  text-transform: uppercase;
}

.city-input {
  margin-top: 7px;
}

.home-scores {
  margin-top: 16px;
  max-height: min(230px, 32dvh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.06);
}

.home-scores ol {
  margin: 0;
  padding-left: 0;
  list-style-position: inside;
  font-variant-numeric: tabular-nums;
}

.home-scores li {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-form[hidden],
.home-scores[hidden],
.secondary-button[hidden],
.arcade-button[hidden],
.store-button[hidden] {
  display: none;
}

.high-score {
  min-height: 1.35em;
  font-weight: 800;
}

@keyframes popIn {
  0% { transform: scale(0.72); }
  78% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes mergePop {
  0% { transform: scale(0.86); filter: brightness(1.1); }
  62% { transform: scale(1.14); filter: brightness(1.25); }
  100% { transform: scale(1); filter: brightness(1); }
}

@keyframes hintPulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.72), 0 0 24px rgba(255, 209, 102, 0.44); }
}

@keyframes toastPop {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.92); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  76% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.96); }
}

@keyframes gameCommentPop {
  0% { opacity: 0; transform: translateY(3px) scale(0.98); }
  12%, 78% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-2px) scale(1); }
}

@media (max-height: 640px) {
  .shell {
    padding: max(5px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
      max(5px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .game {
    gap: 5px;
  }

  .brand-header {
    min-height: 34px;
  }

  .site-tag {
    display: none;
  }

  .metric {
    padding: 5px 7px;
  }

  .metric-label {
    font-size: 0.62rem;
  }

  .small-button {
    padding: 0 5px;
    font-size: 0.68rem;
    min-height: 36px;
  }

  .panel {
    max-height: calc(100svh - 16px);
    padding: 14px;
  }
}

.pause-action-row {
  display: contents;
}

.pause-action-row:has(> button:not([hidden]) + button:not([hidden])) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.pause-action-row:has(> button:not([hidden]) + button:not([hidden])) > button {
  width: 100% !important;
  min-width: 0;
  margin-top: 0 !important;
  margin-right: 0 !important;
}
.arcade-store-arcade-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.22em;
  width: 100%;
  margin: 0 0 14px;
  border: 2px solid #1266ff;
  background: #ffffff;
  color: #071225;
  box-shadow: 0 0 0 2px rgba(18, 102, 255, 0.16), 0 8px 20px rgba(18, 102, 255, 0.2);
  text-transform: none;
}

.arcade-store-arcade-button span:nth-child(2) {
  color: #1266ff;
  text-transform: uppercase;
}

.arcade-store-arcade-button:hover,
.arcade-store-arcade-button:focus-visible {
  background: #ffffff;
  color: #071225;
  outline: 3px solid rgba(84, 199, 255, 0.55);
  outline-offset: 3px;
}
/* Shared 3D arcade button polish. */
.arcade-store-arcade-button {
  gap: 0;
  border: 2px solid #1266ff;
  background: linear-gradient(180deg, #ffffff 0%, #f2f8ff 44%, #d4e8ff 100%);
  color: #071225;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.95), inset 0 -4px 0 rgba(18,102,255,.2), 0 8px 20px rgba(18,102,255,.22);
  text-shadow: 0 1px 0 rgba(255,255,255,.8);
}

.arcade-store-arcade-button .bleep-blue,
.arcade-store-arcade-button span:nth-child(2) {
  color: #1266ff;
  text-transform: uppercase;
}

.arcade-store-arcade-button:hover,
.arcade-store-arcade-button:focus-visible {
  background: linear-gradient(180deg, #ffffff 0%, #eaf4ff 42%, #bfdcff 100%);
  color: #071225;
  outline: 3px solid rgba(84,199,255,.58);
  outline-offset: 3px;
}

.primary-button {
  background: linear-gradient(180deg, color-mix(in srgb, var(--blue, #54c7ff) 34%, #fff) 0%, var(--blue, #54c7ff) 52%, color-mix(in srgb, var(--blue, #54c7ff) 72%, #071225) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.42), inset 0 -4px 0 rgba(5,10,24,.22), 0 8px 18px rgba(0,0,0,.26);
}

.secondary-button,
.small-button {
  background: linear-gradient(180deg, color-mix(in srgb, var(--yellow, #ffd166) 34%, #fff) 0%, var(--yellow, #ffd166) 54%, color-mix(in srgb, var(--yellow, #ffd166) 72%, #8a5a00) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.48), inset 0 -4px 0 rgba(89,51,0,.22), 0 7px 16px rgba(0,0,0,.24);
}

.store-button,
.buy-button {
  background: linear-gradient(180deg, rgba(255,255,255,.2) 0%, rgba(255,255,255,.1) 50%, rgba(5,10,24,.22) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.2), inset 0 -4px 0 rgba(5,10,24,.22), 0 7px 16px rgba(0,0,0,.22);
}
/* Compact high-score entry row: Initials, City, Save. */
.score-form {
  display: grid;
  grid-template-columns: minmax(4.2rem, 4.9rem) minmax(0, 1fr) auto;
  gap: 6px 8px;
  align-items: end;
}

.score-form label[for="initialsInput"] {
  grid-column: 1;
  grid-row: 1;
}

.score-form label[for="cityInput"] {
  grid-column: 2;
  grid-row: 1;
}

.initials-row {
  display: contents;
}

.initials-row input,
#initialsInput {
  grid-column: 1;
  grid-row: 2;
  width: 4.8rem;
  min-width: 0;
  text-align: center;
}

.city-input,
#cityInput {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
}

.initials-row button,
.score-form button[type="submit"] {
  grid-column: 3;
  grid-row: 2;
  min-width: 4.1rem;
  padding-inline: 10px;
}

.score-form datalist {
  display: none;
}

.score-form .high-score,
#highScoreText {
  grid-column: 1 / -1;
}
/* Keep the Arcade return button visible on initials/end-game overlays. */
.overlay {
  align-items: flex-start !important;
  overflow: auto !important;
  padding-top: max(10px, env(safe-area-inset-top)) !important;
  padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
}

.panel {
  max-height: calc(100dvh - 20px) !important;
}

.arcade-store-arcade-button {
  position: sticky;
  top: 0;
  z-index: 5;
}
