*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0d1117;
  --tile-bg: #161b22;
  --tile-border: #30363d;
  --tile-border-inner: rgba(255, 255, 255, 0.07);
  --branch: #4ade80;
  --branch-end: #86efac;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #238636;
  --accent-strong: #2ea043;
  --modal-bg: #1c2128;
  --radius: 8px;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tg-viewport-height, 100dvh);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ── Background reveal ── */
.bg-layer {
  position: fixed;
  inset: 0;
  background-image: var(--bg-url);
  background-size: cover;
  background-position: center;
  z-index: 0;
  opacity: 0;
  transition: opacity 900ms ease;
  pointer-events: none;
}

.bg-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1;
  opacity: 1;
  transition: opacity 900ms ease;
  pointer-events: none;
}

body.is-solved .bg-layer {
  opacity: 1;
}

body.is-solved .bg-overlay {
  opacity: 0;
}

body.is-solved .game {
  opacity: 0.25;
  transition: opacity 900ms ease;
  pointer-events: none;
}

/* ── Game shell ── */
.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  width: 100%;
  max-width: 520px;
  min-height: var(--tg-viewport-height, 100dvh);
  justify-content: center;
  position: relative;
  z-index: 2;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 0.25rem;
}

.game-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--branch);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ── Level controls ── */
.level-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
}

.level-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  min-height: 1rem;
  text-align: center;
}

/* ── Difficulty tabs ── */
.diff-tabs {
  display: flex;
  gap: 0.4rem;
  width: min(100%, 420px);
}

.btn-diff {
  flex: 1;
  height: 2rem;
  background: #161b22;
  border: 1px solid var(--tile-border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 120ms, border-color 120ms, background 120ms;
  letter-spacing: 0.02em;
  font-family: inherit;
  touch-action: manipulation;
}

.btn-diff.active,
.btn-diff[aria-selected="true"] {
  color: var(--branch);
  border-color: var(--branch);
  background: rgba(74, 222, 128, 0.07);
}

.btn-diff:not(.active):hover {
  color: var(--text);
  border-color: #4a5568;
}

.btn-diff:disabled,
.btn-diff[aria-disabled="true"] {
  color: #4b5563;
  border-color: #26303b;
  background: #111820;
  cursor: not-allowed;
  opacity: 0.55;
}

.btn-diff:disabled:hover,
.btn-diff[aria-disabled="true"]:hover {
  color: #4b5563;
  border-color: #26303b;
}

.btn-diff:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
}

/* ── Level nav row (‹ progress ›) ── */
.level-controls {
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr) 2.4rem 2.4rem;
  gap: 0.4rem;
  width: min(100%, 420px);
}

.btn-level-nav {
  height: 2.2rem;
  color: var(--text);
  background: #161b22;
  border: 1px solid var(--tile-border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.55rem;
  line-height: 1;
  cursor: pointer;
}

.btn-level-nav:disabled {
  color: #59636e;
  cursor: default;
  opacity: 0.65;
}

.btn-level-nav:not(:disabled):active {
  background: #253040;
}

.btn-level-nav:focus-visible {
  border-color: var(--branch);
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.22);
}

.diff-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: 0.02em;
}

/* ── Board ── */
.board {
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  gap: 4px;
  background: var(--tile-border);
  border: 4px solid var(--tile-border);
  border-radius: var(--radius);
  overflow: hidden;
  width: min(calc(100vw - 1.5rem), calc(var(--tg-viewport-height, 100dvh) - 12rem), 480px);
  aspect-ratio: 1;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.ad-slot {
  width: min(calc(100vw - 1.5rem), 480px);
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed rgba(229, 231, 235, 0.22);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.55);
  color: var(--text-muted);
  font-size: 0.78rem;
}

.ad-slot.hidden {
  display: none;
  min-height: 0;
}

.ad-slot-win {
  width: 100%;
  min-height: 56px;
}

/* ── Tile ── */
.tile {
  background: var(--tile-bg);
  box-shadow: inset 0 0 0 1px var(--tile-border-inner);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  position: relative;
  transition: background 80ms, box-shadow 80ms, opacity 150ms ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.tile:not(.tile--empty) {
  cursor: pointer;
}

@media (hover: hover) {
  .tile:not(.tile--empty):hover {
    background: #1c2430;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.13);
  }
}

.tile:not(.tile--empty):active {
  background: #253040;
  box-shadow: inset 0 0 0 2px rgba(74, 222, 128, 0.35);
  transition: none;
}

.tile--disconnected {
  opacity: 0.45;
}

.tile__svg {
  display: block;
  width: 90%;
  height: 90%;
  transition: transform 150ms cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-box: fill-box;
  transform-origin: center;
  will-change: transform;
  overflow: visible;
}

/* ── Win modal ── */
.win-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  z-index: 100;
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
  animation: fade-in 200ms ease;
}

.win-modal.hidden {
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.win-content {
  background: var(--modal-bg);
  border: 1px solid var(--tile-border);
  border-radius: 16px;
  padding: 2rem 2rem 1.75rem;
  text-align: center;
  max-width: 300px;
  width: 90%;
  animation: pop-in 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.win-emoji {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.win-heading {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--branch);
  margin-bottom: 1.25rem;
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1rem;
}

.win-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.win-stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.win-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.win-daily-countdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  margin: 0 0 1.1rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid rgba(74, 222, 128, 0.28);
  border-radius: 12px;
  background: rgba(74, 222, 128, 0.06);
}

.win-daily-countdown.hidden { display: none; }

.win-countdown-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.win-countdown-timer {
  color: var(--branch);
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
}

.win-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: stretch;
}

.btn-next {
  background: var(--accent-strong);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 120ms;
  letter-spacing: 0.02em;
}

.btn-next.hidden { display: none; }
.btn-next:hover { opacity: 0.88; }
.btn-next:active { opacity: 0.75; }

.btn-restart {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.65rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 120ms;
  letter-spacing: 0.02em;
}

.btn-restart.hidden { display: none; }
.btn-restart:hover { opacity: 0.88; }
.btn-restart:active { opacity: 0.75; }

/* ── Floating controls (shown after modal is dismissed in solved state) ── */
.floating-controls {
  position: fixed;
  bottom: max(1.5rem, calc(env(safe-area-inset-bottom) + 0.5rem));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.floating-controls.hidden { display: none; }

.btn-floating-continue,
.btn-floating-share {
  background: rgba(28, 33, 40, 0.9);
  border-radius: 24px;
  padding: 0.5rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 120ms;
  letter-spacing: 0.02em;
}

.btn-floating-continue {
  color: var(--text);
  border: 1px solid var(--tile-border);
}

.btn-floating-share {
  color: var(--branch);
  border: 1px solid var(--branch);
}

.btn-floating-share.hidden { display: none; }
.btn-floating-continue:hover,
.btn-floating-share:hover { opacity: 0.85; }
.btn-floating-continue:active,
.btn-floating-share:active { opacity: 0.7; }

/* ── Level extras row (best stat + gallery button) ── */
.level-extras {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: min(100%, 420px);
  min-height: 1.4rem;
}

.level-best {
  font-size: 0.7rem;
  color: var(--branch);
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
}

.btn-gallery {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  letter-spacing: 0.03em;
  transition: color 120ms;
  font-family: inherit;
  text-decoration: none;
  display: inline-block;
  touch-action: manipulation;
}

.btn-gallery:hover { color: var(--text); }
.btn-gallery:active { color: var(--branch); }

.btn-daily {
  background: transparent;
  border: none;
  color: var(--branch);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  letter-spacing: 0.03em;
  transition: color 120ms;
  font-family: inherit;
  touch-action: manipulation;
}

.btn-daily:hover { color: var(--text); }
.btn-daily:active { opacity: 0.7; }

.btn-share {
  background: transparent;
  color: var(--branch);
  border: 1px solid var(--branch);
  border-radius: 8px;
  padding: 0.6rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 120ms;
  letter-spacing: 0.02em;
}

.btn-share.hidden { display: none; }
.btn-share:hover { opacity: 0.8; }
.btn-share:active { opacity: 0.65; }

/* ── Gallery modal ── */
.gallery-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 200ms ease;
}

.gallery-modal.hidden {
  display: none;
}

/* CSS fallback: show gallery when URL hash matches, even if JS class toggle fails */
#gallery:target {
  display: flex;
}

body.gallery-open {
  pointer-events: none;
}

body.gallery-open .gallery-modal,
body.gallery-open .gallery-fullscreen {
  pointer-events: auto;
}

.gallery-content {
  background: #1c2128;
  border: 1px solid #444c56;
  border-radius: 16px;
  width: min(90vw, 360px);
  max-height: min(85dvh, var(--tg-viewport-stable-height, 85dvh), 560px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop-in 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* Bottom-sheet on small screens */
@media (max-width: 480px) {
  .gallery-modal {
    align-items: flex-end;
  }

  .gallery-content {
    width: 100%;
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: min(80dvh, var(--tg-viewport-stable-height, 80dvh));
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--tile-border);
  flex-shrink: 0;
}

/* ── Gallery difficulty tabs ── */
.gallery-tabs {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 1rem 0;
  flex-shrink: 0;
}

.btn-gallery-tab {
  flex: 1;
  height: 1.9rem;
  background: #161b22;
  border: 1px solid var(--tile-border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 120ms, border-color 120ms, background 120ms;
  letter-spacing: 0.02em;
  font-family: inherit;
  touch-action: manipulation;
}

.btn-gallery-tab.active,
.btn-gallery-tab[aria-selected="true"] {
  color: var(--branch);
  border-color: var(--branch);
  background: rgba(74, 222, 128, 0.07);
}

.btn-gallery-tab:not(.active):hover {
  color: var(--text);
  border-color: #4a5568;
}

.btn-gallery-tab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
}

.gallery-heading {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.btn-gallery-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  line-height: 1;
  transition: color 120ms;
  font-family: inherit;
}

.btn-gallery-close:hover { color: var(--text); }

.gallery-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  align-content: start;
}

.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 2.5rem 1rem;
}

.gallery-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--tile-bg);
  border: 1px solid var(--tile-border);
  cursor: pointer;
  transition: opacity 120ms, border-color 120ms;
  touch-action: manipulation;
}

.gallery-item:hover { opacity: 0.85; }
.gallery-item:active { opacity: 0.7; }

.gallery-item-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: #0d1117;
  background-image: var(--item-bg);
  background-size: cover;
  background-position: center;
}

.gallery-item-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.5rem 0.5rem 0.4rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
}

.gallery-item-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-item-stat {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.8);
  margin-top: 0.1rem;
  font-variant-numeric: tabular-nums;
}

.gallery-footer {
  padding: 0.65rem 1.25rem;
  border-top: 1px solid var(--tile-border);
  flex-shrink: 0;
  text-align: center;
}

.btn-reset-progress {
  background: transparent;
  border: none;
  color: #6e7681;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  transition: color 120ms;
  letter-spacing: 0.02em;
  font-family: inherit;
}

.btn-reset-progress:hover { color: #e87a7a; }

/* ── Leaderboard button ── */
.btn-leaderboard {
  background: transparent;
  border: 1px solid rgba(74, 222, 128, 0.3);
  color: var(--branch);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.3rem 1rem;
  border-radius: 14px;
  letter-spacing: 0.03em;
  transition: opacity 120ms, border-color 120ms;
  font-family: inherit;
  touch-action: manipulation;
}

.btn-leaderboard.hidden { display: none; }
.btn-leaderboard:hover { opacity: 0.85; }
.btn-leaderboard:active { opacity: 0.65; }

/* ── Leaderboard bottom sheet ── */
.leaderboard-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  z-index: 80;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: fade-in 180ms ease;
}

.leaderboard-sheet.hidden {
  display: none;
}

.leaderboard-sheet-content {
  background: #1c2128;
  border: 1px solid var(--tile-border);
  border-top: none;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: min(80dvh, var(--tg-viewport-stable-height, 80dvh));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
  animation: slide-up 220ms cubic-bezier(0.34, 1.2, 0.64, 1);
}

@keyframes slide-up {
  from { transform: translateY(60%); }
  to   { transform: translateY(0); }
}

.leaderboard-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--tile-border);
  flex-shrink: 0;
}

.leaderboard-sheet-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.btn-leaderboard-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  line-height: 1;
  transition: color 120ms;
  font-family: inherit;
}

.btn-leaderboard-close:hover { color: var(--text); }

.leaderboard-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.leaderboard-entry {
  display: grid;
  grid-template-columns: 1.4rem 1fr auto auto;
  gap: 0.35rem;
  padding: 0.3rem 0.75rem;
  align-items: center;
  font-size: 0.78rem;
  border-bottom: 1px solid rgba(48, 54, 61, 0.4);
}

.leaderboard-entry:last-child {
  border-bottom: none;
}

.leaderboard-entry--me {
  background: rgba(74, 222, 128, 0.07);
}

.leaderboard-rank {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.leaderboard-name {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.leaderboard-entry--me .leaderboard-name {
  color: var(--branch);
  font-weight: 600;
}

.leaderboard-moves,
.leaderboard-time {
  color: var(--text-muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.leaderboard-separator {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 0.4rem;
  letter-spacing: 0.1em;
  border-bottom: 1px solid rgba(48, 54, 61, 0.4);
}

.leaderboard-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 2rem 1rem;
}

/* ── Gallery fullscreen image viewer ── */
.gallery-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in 180ms ease;
}

.gallery-fullscreen.hidden {
  display: none;
}

.gallery-fullscreen-img {
  position: absolute;
  inset: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  pointer-events: none;
}

.gallery-fullscreen-close {
  position: absolute;
  bottom: max(2rem, calc(env(safe-area-inset-bottom) + 1.25rem));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 24px;
  padding: 0.65rem 2.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  letter-spacing: 0.02em;
  font-family: inherit;
  white-space: nowrap;
  touch-action: manipulation;
  transition: opacity 120ms;
}

.gallery-fullscreen-close:hover { opacity: 0.85; }
.gallery-fullscreen-close:active { opacity: 0.65; }

/* ── Telegram WebView hardening ── */

/* Prevent iOS rubber-band bounce in WebView */
html {
  overscroll-behavior: none;
}

/* Body background adapts to Telegram theme if provided; game palette stays intact. */
body.is-telegram {
  background: var(--tg-bg, var(--bg));
  overscroll-behavior: none;
}

/* Expand game padding to respect device safe-area insets (notch / home indicator). */
.is-telegram .game {
  padding:
    max(0.75rem, env(safe-area-inset-top))
    max(0.75rem, env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom))
    max(0.75rem, env(safe-area-inset-left));
}

