:root {
  --sky: #8ed9ff;
  --sun: #ffd84d;
  --grass: #73d564;
  --orange: #ff9c42;
  --berry: #ff6b8f;
  --navy: #1f487e;
  --cream: #fffaf1;
  --card: rgba(255, 255, 255, 0.92);
  --shadow: 0 18px 40px rgba(31, 72, 126, 0.16);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;
  --tap-size: 78px;
  font-family: "Trebuchet MS", "Segoe UI", "Arial Rounded MT Bold", Arial, sans-serif;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.8), transparent 32%),
    radial-gradient(circle at top right, rgba(255, 216, 77, 0.35), transparent 24%),
    linear-gradient(180deg, #8ed9ff 0%, #b8ecff 45%, #e7f8ff 100%);
  color: var(--navy);
}

body {
  padding: 16px;
}

button,
a {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  border: 0;
  cursor: pointer;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  min-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.screen {
  display: block;
  animation: rise 220ms ease;
}

.panel {
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  border: 3px solid rgba(255, 255, 255, 0.75);
  overflow: hidden;
}

.hero {
  position: relative;
  padding: 30px 24px 26px;
  background:
    radial-gradient(circle at 15% 15%, rgba(255, 255, 255, 0.85), transparent 24%),
    radial-gradient(circle at 85% 18%, rgba(255, 216, 77, 0.65), transparent 20%),
    linear-gradient(135deg, #5bc9ff 0%, #89e17b 100%);
  color: #113761;
}

.hero h1,
.game-header h2 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1;
  letter-spacing: 0.02em;
}

.hero p,
.mini-text {
  margin: 10px 0 0;
  font-size: clamp(1rem, 2.2vw, 1.15rem);
  line-height: 1.5;
  max-width: 38rem;
}

.sun {
  position: absolute;
  pointer-events: none;
  top: 22px;
  right: 26px;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff7a8 0%, var(--sun) 60%, #ffbf1c 100%);
  box-shadow: 0 0 0 10px rgba(255, 216, 77, 0.12);
}

.content {
  padding: 22px;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.game-card {
  position: relative;
  overflow: hidden;
  padding: 20px;
  min-height: 250px;
  border-radius: var(--radius-lg);
  text-align: left;
  box-shadow: 0 16px 30px rgba(31, 72, 126, 0.14);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  isolation: isolate;
}

.game-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  opacity: 0.72;
  z-index: -2;
}

.game-card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.5));
}

.snake-card {
  background: linear-gradient(180deg, #c7f68f 0%, #8fe178 100%);
}

.snake-card::before {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 500'%3E%3Cdefs%3E%3ClinearGradient id='bg' x1='0' y1='0' x2='0' y2='1'%3E%3Cstop offset='0%25' stop-color='%2397e2ff'/%3E%3Cstop offset='100%25' stop-color='%2379d86c'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='800' height='500' fill='url(%23bg)'/%3E%3Ccircle cx='676' cy='92' r='54' fill='%23ffe16b'/%3E%3Cpath d='M0 372 C109 319 194 348 277 324 C366 298 438 336 530 308 C619 279 697 315 800 274 L800 500 L0 500 Z' fill='%235bbd59'/%3E%3Cpath d='M0 407 C114 363 187 380 276 352 C360 325 471 367 567 338 C665 309 727 330 800 307 L800 500 L0 500 Z' fill='%2347a947'/%3E%3Crect x='552' y='186' width='34' height='34' rx='10' fill='%23ff5f7e'/%3E%3Cpath d='M568 188 C570 177 580 172 587 178' fill='none' stroke='%2328893c' stroke-width='5' stroke-linecap='round'/%3E%3Cpath d='M188 278 C230 230 303 227 352 259 C401 292 412 362 368 402 C325 441 244 437 198 401 C151 363 147 314 188 278 Z' fill='none' stroke='%2320a44c' stroke-width='32' stroke-linecap='round' stroke-linejoin='round'/%3E%3Ccircle cx='335' cy='286' r='7' fill='%23133a61'/%3E%3Ccircle cx='359' cy='286' r='7' fill='%23133a61'/%3E%3C/svg%3E");
}

.puzzle-card {
  background: linear-gradient(180deg, #ffe77d 0%, #ffb65f 100%);
}

.puzzle-card::before {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 500'%3E%3Cdefs%3E%3ClinearGradient id='bg' x1='0' y1='0' x2='1' y2='1'%3E%3Cstop offset='0%25' stop-color='%23fff1a8'/%3E%3Cstop offset='100%25' stop-color='%23ffb05f'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect width='800' height='500' fill='url(%23bg)'/%3E%3Ccircle cx='128' cy='84' r='34' fill='%23ffffff' fill-opacity='0.55'/%3E%3Ccircle cx='705' cy='99' r='24' fill='%23ffffff' fill-opacity='0.45'/%3E%3Cg transform='translate(415 84)'%3E%3Crect x='0' y='0' width='102' height='102' rx='20' fill='%238ed9ff'/%3E%3Crect x='115' y='0' width='102' height='102' rx='20' fill='%2373d564'/%3E%3Crect x='230' y='0' width='102' height='102' rx='20' fill='%23ff9c42'/%3E%3Crect x='0' y='115' width='102' height='102' rx='20' fill='%23ffb4d0'/%3E%3Crect x='115' y='115' width='102' height='102' rx='20' fill='%23a5b8ff'/%3E%3Crect x='230' y='115' width='102' height='102' rx='20' fill='%239af0d2'/%3E%3Crect x='0' y='230' width='102' height='102' rx='20' fill='%23ffd84d'/%3E%3Crect x='115' y='230' width='102' height='102' rx='20' fill='%23ffa9a0'/%3E%3Crect x='230' y='230' width='102' height='102' rx='20' fill='%23fff7df' stroke='%23f0c56a' stroke-dasharray='12 10' stroke-width='6'/%3E%3Cg fill='%23133a61' font-family='Trebuchet MS, Arial, sans-serif' font-size='42' font-weight='700' text-anchor='middle'%3E%3Ctext x='51' y='63'%3E1%3C/text%3E%3Ctext x='166' y='63'%3E2%3C/text%3E%3Ctext x='281' y='63'%3E3%3C/text%3E%3Ctext x='51' y='178'%3E4%3C/text%3E%3Ctext x='166' y='178'%3E5%3C/text%3E%3Ctext x='281' y='178'%3E6%3C/text%3E%3Ctext x='51' y='293'%3E7%3C/text%3E%3Ctext x='166' y='293'%3E8%3C/text%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.truck-card {
  background: linear-gradient(180deg, #ffc86b 0%, #ff8f4d 100%);
}

.truck-card::before {
  background-image: url("../images/monstertruck-puzzle.png");
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 96px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  font-weight: 700;
  font-size: 0.95rem;
}

.card-title {
  margin: 18px 0 10px;
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  line-height: 1;
}

.card-text {
  max-width: 18rem;
  font-size: 1rem;
  line-height: 1.4;
}

.play-btn,
.back-btn,
.shuffle-btn,
.restart-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 58px;
  padding: 14px 22px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 1.06rem;
  color: #113761;
  background: #fff;
  box-shadow: 0 10px 18px rgba(17, 55, 97, 0.15);
}

.play-btn {
  background: #fff8d3;
  margin-top: 18px;
}

.page-shell {
  display: grid;
  gap: 18px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.back-btn {
  min-width: 168px;
  background: #fff;
}

.game-header {
  flex: 1;
  padding: 18px 22px;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(255, 248, 211, 0.94));
  box-shadow: var(--shadow);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.stats-row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.stat-pill {
  flex: 1;
  min-width: 140px;
  padding: 14px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(31, 72, 126, 0.1);
}

.canvas-wrap,
.side-card,
.puzzle-board-card {
  padding: 18px;
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

#snakeCanvas {
  display: block;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(143, 225, 120, 0.25), rgba(115, 213, 100, 0.35)),
    linear-gradient(90deg, rgba(255, 255, 255, 0.25) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.25) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
  border: 4px solid #fff;
  box-shadow: inset 0 8px 20px rgba(31, 72, 126, 0.08);
  touch-action: none;
}

.snake-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
  touch-action: manipulation;
}

.control-btn {
  min-height: var(--tap-size);
  border-radius: 24px;
  background: linear-gradient(180deg, #ffd84d 0%, #ffb62a 100%);
  color: #113761;
  font-size: 1.8rem;
  font-weight: 900;
  box-shadow: 0 10px 18px rgba(255, 182, 42, 0.35);
  user-select: none;
  touch-action: manipulation;
}

.control-btn.blank {
  background: transparent;
  box-shadow: none;
  cursor: default;
}

.control-btn:active,
.shuffle-btn:active,
.restart-btn:active,
.back-btn:active,
.play-btn:active {
  transform: translateY(2px) scale(0.99);
}

.side-card h3,
.puzzle-board-card h3 {
  margin: 0 0 10px;
  font-size: 1.45rem;
}

.side-card p,
.puzzle-board-card p {
  margin: 0;
  line-height: 1.5;
}

.status-message {
  min-height: 30px;
  margin-top: 14px;
  font-weight: 800;
  color: #d8446d;
}

.puzzle-area {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(290px, 0.8fr);
}

.art-puzzle-area {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(220px, 0.62fr) minmax(0, 1.38fr);
}

.art-puzzle-top {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.piece-tray,
.board-grid {
  position: relative;
  display: block;
  width: 100%;
}

.art-piece {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 18px rgba(31, 72, 126, 0.14);
  background-repeat: no-repeat;
  background-size: 600% 400%;
  overflow: hidden;
  touch-action: manipulation;
}

.jigsaw-piece,
.jigsaw-slot {
  position: absolute;
  display: block;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
}

.jigsaw-piece {
  cursor: grab;
  touch-action: none;
  user-select: none;
  filter: drop-shadow(0 12px 18px rgba(31, 72, 126, 0.16));
}

.jigsaw-piece.dragging {
  z-index: 1000;
  pointer-events: none;
  filter: drop-shadow(0 16px 28px rgba(31, 72, 126, 0.28));
}

.jigsaw-piece.drag-origin {
  opacity: 0.2;
}

.jigsaw-piece.placed {
  cursor: default;
  filter: none;
}

.jigsaw-slot {
  pointer-events: none;
}

.jigsaw-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.art-piece::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 13px;
  border: 2px dashed rgba(255, 255, 255, 0.32);
  pointer-events: none;
}

.art-piece.selected {
  outline: 5px solid rgba(255, 216, 77, 0.95);
  transform: scale(1.03);
}

.art-piece:active {
  transform: scale(0.98);
}

.board-slot {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  border: 3px dashed rgba(31, 72, 126, 0.28);
  background: rgba(142, 217, 255, 0.16);
  overflow: hidden;
  touch-action: manipulation;
}

.board-slot.hint::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 10px;
  border: 2px dashed rgba(31, 72, 126, 0.16);
}

.board-slot.filled {
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.92);
  background-repeat: no-repeat;
}

.art-puzzle-preview {
  width: 100%;
  aspect-ratio: 3 / 2;
  border-radius: 22px;
  border: 4px solid #fff;
  box-shadow: inset 0 8px 18px rgba(31, 72, 126, 0.08);
  background-size: cover;
  background-position: center;
}

.preview-truck {
  background-image: url("../images/monstertruck-puzzle.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-color: rgba(255, 255, 255, 0.88);
  max-width: 230px;
  justify-self: start;
}

.art-win-banner {
  margin-top: 16px;
}

.truck-board-card,
.loose-pieces-card {
  display: grid;
  gap: 16px;
  align-content: start;
}

.piece-tray {
  min-height: 520px;
}

.board-grid {
  min-height: 520px;
}

.puzzle-top {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.shuffle-btn,
.restart-btn {
  background: linear-gradient(180deg, #73d564 0%, #49c158 100%);
  color: #fff;
  min-width: 156px;
}

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  touch-action: manipulation;
}

.tile,
.tile-empty {
  aspect-ratio: 1 / 1;
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.6rem, 3vw, 2.3rem);
  font-weight: 900;
}

.tile {
  color: #113761;
  box-shadow: 0 12px 18px rgba(31, 72, 126, 0.14);
  transition: transform 140ms ease;
  touch-action: manipulation;
}

.tile:active {
  transform: scale(0.97);
}

.tile-empty {
  border: 3px dashed rgba(31, 72, 126, 0.16);
  background: rgba(143, 217, 255, 0.18);
}

.tile-1 { background: #8ed9ff; }
.tile-2 { background: #ffd84d; }
.tile-3 { background: #ff9c42; }
.tile-4 { background: #73d564; }
.tile-5 { background: #ffb4d0; }
.tile-6 { background: #a5b8ff; }
.tile-7 { background: #ffa9a0; }
.tile-8 { background: #9af0d2; }

.win-banner {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 20px;
  background: linear-gradient(135deg, #fff8d3, #ffffff);
  font-size: 1.2rem;
  font-weight: 900;
  color: #d27800;
  box-shadow: 0 12px 22px rgba(255, 216, 77, 0.28);
}

.sparkles {
  display: inline-flex;
  gap: 6px;
  margin-left: 6px;
  vertical-align: middle;
}

.sparkles span {
  animation: twinkle 900ms ease-in-out infinite alternate;
}

.sparkles span:nth-child(2) {
  animation-delay: 200ms;
}

.sparkles span:nth-child(3) {
  animation-delay: 400ms;
}

.footer-note {
  text-align: center;
  padding: 4px 8px 18px;
  font-weight: 700;
  color: rgba(17, 55, 97, 0.72);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes twinkle {
  from {
    transform: translateY(0) scale(0.9);
    opacity: 0.75;
  }
  to {
    transform: translateY(-3px) scale(1.08);
    opacity: 1;
  }
}

@media (max-width: 860px) {
  .menu-grid,
  .game-layout,
  .puzzle-area,
  .art-puzzle-area {
    grid-template-columns: 1fr;
  }

  .game-card {
    min-height: 0;
  }
}

@media (max-width: 560px) {
  body {
    padding: 10px;
  }

  .app {
    min-height: calc(100vh - 20px);
  }

  .hero,
  .content,
  .canvas-wrap,
  .side-card,
  .puzzle-board-card,
  .game-header {
    padding: 16px;
  }

  .sun {
    width: 68px;
    height: 68px;
    top: 20px;
    right: 16px;
  }

  .top-bar {
    align-items: stretch;
  }

  .back-btn {
    width: 100%;
  }

  .stat-pill {
    min-width: 100%;
  }

  .control-btn {
    min-height: 72px;
    border-radius: 20px;
  }

  .piece-tray {
    min-height: 620px;
  }
}
