:root {
  --bg: #080f2b;
  --panel: rgba(12, 24, 68, 0.94);
  --panel2: rgba(17, 35, 92, 0.96);
  --line: rgba(255, 255, 255, 0.16);
  --text: #ffffff;
  --muted: #b8c6ff;
  --yellow: #ffd43b;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #38bdf8;
  --purple: #a855f7;
  --orange: #f97316;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at 20% 10%, rgba(56, 189, 248, 0.35), transparent 28%),
    radial-gradient(circle at 80% 12%, rgba(168, 85, 247, 0.28), transparent 30%),
    linear-gradient(160deg, #05102f 0%, #081331 45%, #030712 100%);
  color: var(--text);
  overflow-x: hidden;
}

button {
  font-family: inherit;
}

.game-page {
  min-height: 100vh;
  padding: 14px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.phone {
  width: min(100%, 520px);
  min-height: 760px;
  border-radius: 34px;
  overflow: hidden;
  position: relative;
  background:
    linear-gradient(180deg, rgba(33, 59, 157, 0.92), rgba(11, 18, 48, 0.98)),
    url("data:image/svg+xml,%3Csvg width='320' height='320' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.05'%3E%3Cpath d='M20 80 C90 20 160 140 250 60'/%3E%3Cpath d='M40 230 C130 160 200 280 310 190'/%3E%3Ccircle cx='70' cy='70' r='38'/%3E%3Ccircle cx='240' cy='220' r='60'/%3E%3C/g%3E%3C/svg%3E");
  border: 2px solid rgba(125, 211, 252, 0.45);
  box-shadow: var(--shadow), inset 0 0 36px rgba(56, 189, 248, 0.18);
}

.screen {
  display: none;
  min-height: 760px;
  padding: 14px;
  position: relative;
}

.screen.active {
  display: block;
}

.top-title {
  text-align: center;
  margin: 0 auto 12px;
  padding: 12px 14px;
  border-radius: 22px;
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
  border: 3px solid rgba(147, 197, 253, 0.7);
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.22), 0 0 28px rgba(59, 130, 246, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 26px;
  line-height: 1.05;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.top-title small {
  display: block;
  margin-top: 5px;
  font-size: 15px;
  color: var(--yellow);
}

.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1.35fr;
  gap: 8px;
  margin-bottom: 12px;
}

.hud-card {
  background: linear-gradient(180deg, rgba(20, 48, 135, 0.98), rgba(12, 24, 78, 0.98));
  border: 2px solid rgba(147, 197, 253, 0.45);
  border-radius: 16px;
  padding: 9px 8px;
  text-align: center;
  box-shadow: inset 0 2px 8px rgba(255, 255, 255, 0.08), 0 8px 16px rgba(0, 0, 0, 0.25);
}

.hud-label {
  font-size: 11px;
  font-weight: 900;
  color: #dbeafe;
  text-transform: uppercase;
}

.hud-value {
  font-size: 28px;
  line-height: 1;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.target-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  margin-top: 5px;
}

.target-item {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  font-weight: 900;
}

.main-area {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  width: 100%;
}

.boosters {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 36px;
}

.booster {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid rgba(125, 211, 252, 0.7);
  background: radial-gradient(circle at 35% 25%, #ffffff, #38bdf8 22%, #1d4ed8 58%, #172554);
  display: grid;
  place-items: center;
  font-size: 24px;
  position: relative;
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.35), inset 0 0 12px rgba(255, 255, 255, 0.35);
  cursor: pointer;
}

.booster span {
  position: absolute;
  right: -4px;
  bottom: -5px;
  min-width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--red);
  border: 2px solid #fff;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.board-wrap {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  position: relative;
}

.hero-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  min-width: 0;
}

.hero {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.hero-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  flex: 0 0 auto;
  position: relative;
  background:
    radial-gradient(circle at 52% 36%, #ffd7aa 0 22%, transparent 23%),
    radial-gradient(circle at 44% 42%, #111827 0 3%, transparent 4%),
    radial-gradient(circle at 61% 42%, #111827 0 3%, transparent 4%),
    radial-gradient(circle at 52% 55%, #ef4444 0 5%, transparent 6%),
    linear-gradient(180deg, #f97316 0 22%, #7c2d12 23% 42%, #dc2626 43% 100%);
  border: 3px solid #facc15;
  box-shadow: 0 0 18px rgba(250, 204, 21, 0.55);
}

.hero-avatar::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 4px;
  width: 33px;
  height: 18px;
  border-radius: 50% 50% 40% 40%;
  background: #7c2d12;
  transform: rotate(-8deg);
}

.hero-name {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.15;
  min-width: 0;
}

.hero-name strong {
  display: block;
  font-size: 16px;
  color: #fff;
}

.score-pill {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 13px;
  font-weight: 900;
  color: #fde68a;
  white-space: nowrap;
  max-width: 126px;
  overflow: hidden;
}

.board {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1;
  padding: 7px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(30, 64, 175, 0.95), rgba(15, 23, 42, 0.95));
  border: 3px solid rgba(125, 211, 252, 0.55);
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  gap: 4px;
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.55), 0 16px 28px rgba(0, 0, 0, 0.35);
  touch-action: none;
  user-select: none;
  overflow: hidden;
}

.cell {
  border-radius: 9px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: grid;
  place-items: center;
  position: relative;
  overflow: visible;
  min-width: 0;
  min-height: 0;
}

.gem {
  width: 92%;
  height: 92%;
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
  font-size: clamp(17px, 4.8vw, 28px);
  line-height: 1;
  transform-origin: center;
  filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.35));
  transition: transform 0.12s ease, filter 0.12s ease, opacity 0.18s ease;
}

.gem.selected {
  transform: scale(1.15);
  filter: drop-shadow(0 0 12px #fff) drop-shadow(0 0 18px #facc15);
}

.gem.matching {
  animation: popGem 0.28s ease forwards;
}

.gem.drop {
  animation: dropGem 0.22s ease;
}

.cell.flash::after {
  content: "";
  position: absolute;
  inset: -30%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.95), rgba(250, 204, 21, 0.45), transparent 60%);
  animation: flash 0.32s ease forwards;
  pointer-events: none;
}

.progress {
  margin-top: 12px;
  border-radius: 18px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 10px;
}

.stars {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 27px;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}

.bar {
  height: 12px;
  border-radius: 999px;
  margin-top: 8px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #22c55e, #facc15, #f97316);
  box-shadow: 0 0 16px rgba(250, 204, 21, 0.8);
  transition: width 0.25s ease;
}

.bottom-actions,
.bonus-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.btn {
  border: 0;
  min-height: 48px;
  border-radius: 18px;
  font-size: 15px;
  font-weight: 900;
  color: #fff;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.28), 0 14px 18px rgba(0, 0, 0, 0.28);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.28), 0 8px 12px rgba(0, 0, 0, 0.22);
}

.btn-green {
  background: linear-gradient(180deg, #34d399, #16a34a);
  border: 2px solid rgba(187, 247, 208, 0.7);
}

.btn-blue {
  background: linear-gradient(180deg, #38bdf8, #2563eb);
  border: 2px solid rgba(191, 219, 254, 0.7);
}

.btn-purple {
  background: linear-gradient(180deg, #c084fc, #7c3aed);
  border: 2px solid rgba(233, 213, 255, 0.7);
}

.message {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 50%;
  z-index: 30;
  transform: translateY(-50%) scale(0.92);
  opacity: 0;
  pointer-events: none;
  padding: 18px;
  text-align: center;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(30, 64, 175, 0.98), rgba(88, 28, 135, 0.98));
  border: 3px solid rgba(250, 204, 21, 0.75);
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.5), 0 0 36px rgba(250, 204, 21, 0.35);
  transition: all 0.2s ease;
}

.message.show {
  opacity: 1;
  transform: translateY(-50%) scale(1);
  pointer-events: auto;
}

.message h2 {
  margin: 0 0 8px;
  font-size: 25px;
  color: #fde047;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.message p {
  margin: 0 0 14px;
  color: #e0f2fe;
  font-weight: 700;
}

.bonus-screen {
  background:
    radial-gradient(circle at 80% 15%, rgba(248, 113, 113, 0.24), transparent 30%),
    radial-gradient(circle at 25% 18%, rgba(56, 189, 248, 0.22), transparent 32%),
    linear-gradient(180deg, rgba(69, 10, 10, 0.78), rgba(17, 24, 39, 0.96));
}

.bonus-title {
  background: linear-gradient(180deg, #ef4444, #b91c1c);
  border-color: rgba(254, 202, 202, 0.8);
}

.bonus-title small {
  color: #bfdbfe;
}

.bonus-hud {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.objective-text {
  font-weight: 900;
  color: #fde047;
  margin-top: 5px;
}

.bonus-stage {
  position: relative;
  height: 520px;
  border-radius: 24px;
  overflow: hidden;
  border: 3px solid rgba(250, 204, 21, 0.6);
  background:
    linear-gradient(90deg, rgba(17, 24, 39, 0.85), rgba(31, 41, 55, 0.65)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.05) 0 2px, transparent 2px 62px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0 2px, transparent 2px 62px),
    #1f2937;
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.72), 0 18px 30px rgba(0, 0, 0, 0.35);
}

.lava {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 74px;
  background:
    radial-gradient(circle at 20% 10%, #fff7ed 0 6%, transparent 7%),
    radial-gradient(circle at 65% 35%, #fde047 0 8%, transparent 9%),
    linear-gradient(180deg, #fb923c, #dc2626 50%, #7f1d1d);
  box-shadow: 0 -10px 28px rgba(239, 68, 68, 0.75);
  animation: lavaMove 1.6s infinite alternate ease-in-out;
}

.prison {
  position: absolute;
  right: 22px;
  top: 62px;
  width: 90px;
  height: 126px;
  border-radius: 44px 44px 18px 18px;
  background: linear-gradient(180deg, #111827, #030712);
  border: 4px solid #6b7280;
  box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.8), 0 0 22px rgba(250, 204, 21, 0.25);
  overflow: hidden;
}

.prison::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 15px, rgba(209, 213, 219, 0.9) 15px 20px);
  z-index: 2;
}

.princess {
  position: absolute;
  left: 15px;
  bottom: 12px;
  width: 58px;
  height: 74px;
  z-index: 1;
}

.princess::before {
  content: "👸";
  font-size: 56px;
  position: absolute;
  inset: 0;
  filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.45));
}

.rescue-hero {
  position: absolute;
  left: 92px;
  top: 238px;
  width: 74px;
  height: 96px;
  z-index: 6;
  transition: left 0.45s ease, top 0.45s ease, transform 0.45s ease;
}

.rescue-hero::before {
  content: "🧑‍🚀";
  font-size: 70px;
  position: absolute;
  inset: 0;
  filter: drop-shadow(0 7px 6px rgba(0, 0, 0, 0.5));
}

.rescue-hero.saved {
  left: 275px;
  top: 92px;
  transform: scale(0.92);
}

.rocks {
  position: absolute;
  left: 80px;
  top: 58px;
  width: 220px;
  height: 155px;
  z-index: 4;
  transition: transform 0.7s ease, opacity 0.6s ease;
}

.rocks.cleared {
  transform: translateY(260px) rotate(8deg);
  opacity: 0.2;
}

.rock {
  position: absolute;
  width: 31px;
  height: 31px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #d1d5db, #6b7280 55%, #374151);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: inset -4px -5px 6px rgba(0, 0, 0, 0.35), 0 4px 6px rgba(0, 0, 0, 0.28);
}

.pin {
  position: absolute;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fde68a, #f59e0b);
  border: 2px solid #92400e;
  box-shadow: 0 5px 8px rgba(0, 0, 0, 0.4), 0 0 16px rgba(250, 204, 21, 0.45);
  transform-origin: left center;
  z-index: 8;
  cursor: pointer;
  transition: transform 0.28s ease, opacity 0.25s ease;
}

.pin::before,
.pin::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 28px;
  height: 28px;
  margin-top: -14px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff7ed, #f59e0b 55%, #92400e);
  border: 2px solid #78350f;
}

.pin::before {
  left: -14px;
}

.pin::after {
  right: -14px;
}

.pin.pulled {
  transform: translateX(-90px) rotate(-10deg) !important;
  opacity: 0.25;
  pointer-events: none;
}

.pin-1 {
  left: 76px;
  top: 140px;
  width: 210px;
  transform: rotate(9deg);
}

.pin-2 {
  left: 68px;
  top: 325px;
  width: 205px;
  transform: rotate(0deg);
}

.pin-3 {
  left: 244px;
  top: 225px;
  width: 134px;
  transform: rotate(-18deg);
}

.spikes {
  position: absolute;
  left: 110px;
  bottom: 72px;
  width: 140px;
  height: 44px;
  z-index: 3;
  display: flex;
  align-items: end;
  gap: 4px;
}

.spikes span {
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-bottom: 44px solid #d1d5db;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.4));
}

.bonus-mini-board {
  position: absolute;
  right: 16px;
  bottom: 92px;
  width: 142px;
  height: 142px;
  padding: 5px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 3px;
  background: rgba(15, 23, 42, 0.75);
  border: 2px solid rgba(125, 211, 252, 0.45);
  border-radius: 14px;
  z-index: 5;
}

.mini-gem {
  display: grid;
  place-items: center;
  font-size: 21px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.1);
}

.floating-text {
  position: absolute;
  z-index: 40;
  font-weight: 900;
  color: #fde047;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
  animation: floatText 0.8s ease forwards;
  pointer-events: none;
}

.shake {
  animation: shake 0.25s linear;
}

@keyframes flash {
  from {
    opacity: 1;
    transform: scale(0.5);
  }

  to {
    opacity: 0;
    transform: scale(1.4);
  }
}

@keyframes popGem {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  55% {
    transform: scale(1.35) rotate(10deg);
    opacity: 1;
  }

  100% {
    transform: scale(0.1);
    opacity: 0;
  }
}

@keyframes dropGem {
  from {
    transform: translateY(-22px) scale(0.9);
    opacity: 0.65;
  }

  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes floatText {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.85);
  }

  25% {
    opacity: 1;
  }

  to {
    opacity: 0;
    transform: translateY(-36px) scale(1.08);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

@keyframes lavaMove {
  from {
    filter: brightness(1);
    transform: translateY(0);
  }

  to {
    filter: brightness(1.25);
    transform: translateY(5px);
  }
}

@media (max-width: 520px) {
  .game-page {
    padding: 8px;
  }

  .phone {
    width: 100%;
    border-radius: 24px;
  }

  .screen {
    padding: 10px;
  }

  .top-title {
    font-size: 22px;
    padding: 10px;
  }

  .top-title small {
    font-size: 13px;
  }

  .hud {
    gap: 6px;
  }

  .hud-card {
    padding: 8px 5px;
  }

  .hud-value {
    font-size: 24px;
  }

  .target-row {
    gap: 4px;
  }

  .target-item {
    font-size: 11px;
  }

  .main-area {
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 7px;
  }

  .boosters {
    padding-top: 34px;
  }

  .booster {
    width: 45px;
    height: 45px;
    font-size: 21px;
  }

  .hero-avatar {
    width: 48px;
    height: 48px;
  }

  .hero-name strong {
    font-size: 15px;
  }

  .hero-name {
    font-size: 12px;
  }

  .score-pill {
    max-width: 100px;
    font-size: 12px;
    padding: 7px 8px;
  }

  .board {
    gap: 3px;
    padding: 6px;
  }

  .cell {
    border-radius: 8px;
  }

  .gem {
    font-size: clamp(15px, 5.4vw, 25px);
  }

  .bonus-stage {
    height: 500px;
  }
}

@media (max-width: 390px) {
  .screen {
    padding: 8px;
  }

  .main-area {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 6px;
  }

  .booster {
    width: 39px;
    height: 39px;
    font-size: 18px;
  }

  .booster span {
    min-width: 19px;
    height: 19px;
    font-size: 11px;
  }

  .hero-avatar {
    width: 42px;
    height: 42px;
  }

  .hero-name {
    display: none;
  }

  .score-pill {
    max-width: 94px;
    font-size: 11px;
  }

  .board {
    gap: 3px;
    padding: 5px;
  }

  .gem {
    font-size: clamp(14px, 5.2vw, 22px);
  }
}