* { -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: "Inter", sans-serif;
  overscroll-behavior: none;
  background: #0b1017;
  overflow: hidden;
}
*{ font-family: "Tinos", serif;}
.screen-game,
.screen-levels,
.screen-loading {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.perf-low .level-btn {
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.06), inset 0 -2px 4px rgba(0, 0, 0, 0.4);
}

.perf-low .grid-cell-empty {
  box-shadow: none;
}

.perf-low .grid-cell-filled {
  box-shadow: none;
}

.screen-game {
  background-image: linear-gradient(145deg, hsla(220 30% 12% / 0.55), hsla(240 25% 10% / 0.6), hsla(260 20% 12% / 0.6)),
    url("images/bg.png");
}

.screen-levels {
  background-image: linear-gradient(145deg, hsla(220 30% 14% / 0.55), hsla(240 25% 12% / 0.6)),
    url("images/level%20selection%20bg.png");
}

.screen-loading {
  background-image: linear-gradient(145deg, hsla(220 30% 14% / 0.55), hsla(240 25% 12% / 0.6)),
    url("images/loading%20bg.png");
}

@media (max-width: 768px) {
  .screen-game {
    background-image: linear-gradient(145deg, hsla(220 30% 12% / 0.55), hsla(240 25% 10% / 0.6), hsla(260 20% 12% / 0.6)),
      url("images/bgPhone.png");
  }

  .screen-loading {
    background-image: linear-gradient(145deg, hsla(220 30% 14% / 0.55), hsla(240 25% 12% / 0.6)),
      url("images/loading%20phone%20bg.png");
  }
}

@media (max-width: 639px) {
  .screen-levels {
    background-image: linear-gradient(145deg, hsla(220 30% 14% / 0.55), hsla(240 25% 12% / 0.6)),
      url("images/level%20selection%20phone%20bg.png");
  }
}

/* Position loading blocks + progress a bit lower to sit under title in bg image */
.screen-loading .relative.z-10 {
  margin-top: 520px;
}

@media (max-width: 768px) {
  .screen-loading .relative.z-10 {
    margin-top: 260px;
  }
}

/* Level select panel positioning to match bg panel area */
.levels-panel {
  max-width: 560px;
  margin-top: 60px;
}

@media (max-width: 639px) {
  .levels-panel {
    max-width: 320px;
    margin-top: 10px;
  }

  .level-btn {
    border-radius: 12px;
    padding-top: 6px;
    padding-bottom: 6px;
    gap: 4px;
  }

  .level-num {
    font-size: 16px;
  }

  .level-stars {
    gap: 3px;
  }

  .level-best {
    position: absolute;
    bottom: 4px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 8px;
    letter-spacing: 0.2px;
  }

  .level-stars {
    margin-bottom: 6px;
  }

  .level-btn img {
    width: 12px;
    height: 12px;
  }
}

@media (max-width: 768px) {
  .levels-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}

@media (min-width: 1024px) {
  .levels-panel {
    max-width: 720px;
  }

  .levels-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

.ui-panel {
  background-image: linear-gradient(145deg, hsla(230 25% 22% / 0.75), hsla(230 25% 12% / 0.85)),
    url("images/panel.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.board-surface {
  background-image: linear-gradient(145deg, hsla(220 25% 14% / 0.9), hsla(220 25% 10% / 0.95)),
    url("images/board-bg.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* Canvas board */
.board-canvas {
  width: 100%;
  height: 100%;
}

/* Level buttons - gold framed, embossed look */
.level-btn {
  border-radius: 14px;
  background: linear-gradient(180deg, #162338 0%, #0c1a2a 100%);
  border: 2px solid #d6b76a;
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.15),
    inset 0 -4px 8px rgba(0, 0, 0, 0.5),
    0 6px 14px rgba(0, 0, 0, 0.45);
  position: relative;
  overflow: hidden;
}

.level-btn::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.level-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: radial-gradient(120% 80% at 50% 0%, rgba(255, 255, 255, 0.18), transparent 60%);
  pointer-events: none;
}

.level-num {
  color: #f2d48c;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.level-best {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: rgba(230, 220, 200, 0.8);
}

.level-btn.is-locked {
  filter: saturate(0.2) brightness(0.8);
}

/* Modal sizing to match the larger reference box */
.modal-card {
  width: 420px;
  max-width: 92vw;
}

/* Game buttons styled similar to level buttons */
.game-btn {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
  border: 2px solid rgba(214, 183, 106, 0.7);
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.12),
    inset 0 -4px 8px rgba(0, 0, 0, 0.45),
    0 6px 14px rgba(0, 0, 0, 0.4);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.game-btn:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow:
    inset 0 2px 5px rgba(255, 255, 255, 0.2),
    inset 0 -4px 10px rgba(0, 0, 0, 0.5),
    0 10px 22px rgba(0, 0, 0, 0.5);
  filter: brightness(1.08);
}

.game-btn:active {
  transform: translateY(1px) scale(0.99);
}

.game-btn-primary {
  color: #f7f3e8;
  background: linear-gradient(180deg, #2f7bd4 0%, #1c4b9a 100%);
}

.game-btn-secondary {
  color: #d6d6d6;
  background: linear-gradient(180deg, #2a3340 0%, #1b212c 100%);
}

.game-btn-danger {
  color: #f7eaea;
  background: linear-gradient(180deg, #b64b4b 0%, #7f2e2e 100%);
}

.modal-status-img {
  width: 150px;
  height: auto;
  margin-top: -6px;
}

/* Score bar layout */
.scorebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.scorebar-progress {
  max-width: 100%;
}

@media (max-width: 640px) {
  .scorebar {
    grid-template-columns: 1fr auto auto;
    row-gap: 8px;
  }
  .scorebar-progress {
    grid-column: 1 / -1;
    max-width: none;
  }
}

@media (max-width: 768px) {
  .grid-cell-empty {
    box-shadow:
      inset 0 1px 2px rgba(255, 255, 255, 0.04),
      inset 0 -2px 4px rgba(0, 0, 0, 0.5);
  }

  .grid-cell-empty::after {
    display: none;
  }
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 2px solid rgba(214, 183, 106, 0.6);
  background: linear-gradient(180deg, #1f2a38 0%, #141b25 100%);
  color: #f2d48c;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, filter 0.18s ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.moves-tag {
  background: linear-gradient(145deg, #3a2b12, #22180a);
  color: #f2d48c;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.12), 0 2px 6px rgba(0, 0, 0, 0.35);
}

.score-tag {
  background: linear-gradient(145deg, #1f2a38, #141b25);
  color: #f2d48c;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.12), 0 2px 6px rgba(0, 0, 0, 0.35);
}

.scorebar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.scorebar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Slightly larger buttons/tags */
.scorebar .moves-tag,
.scorebar .score-tag,
.scorebar span.text-sm {
  padding: 8px 12px;
  font-size: 13px;
}

.icon-btn {
  width: 46px;
  height: 46px;
  font-size: 16px;
}

.drag-overlay { transition: opacity 0.2s ease; }
.cell-clear-animation { animation: popClear 0.25s cubic-bezier(0.2, 0.9, 0.4, 1.1) forwards; }

@keyframes popClear {
  0% { transform: scale(1); background-color: #a5f3fc; opacity: 1; }
  100% { transform: scale(0.9); background-color: #f0fdf4; opacity: 0; }
}

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

@keyframes starPop {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  60% { transform: scale(1.3) rotate(5deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes blockFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes blastParticle {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--bx, 30px), var(--by, -30px)) scale(0); opacity: 0; }
}

.blast-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.blast-fall {
  position: absolute;
  width: 30px;
  height: 30px;
  opacity: 0;
  animation: blastSideFall var(--d, 1.4s) ease-out forwards;
  transform: translate(0, 0) scale(var(--s, 0.6)) rotate(var(--r, 0deg));
  filter: drop-shadow(0 0 8px rgba(255, 210, 120, 0.45));
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

@keyframes blastSideFall {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(var(--s, 0.6)) rotate(var(--r, 0deg));
  }
  10% { opacity: 1; }
  100% {
    opacity: 0;
    transform: translate(var(--dx, 40px), var(--dy, 220px)) scale(0.15) rotate(calc(var(--r, 0deg) + 140deg));
  }
}
.perf-low * {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}
