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

:root {
  --wood-dark: #3a1610;
  --wood-darker: #2a0f0b;
  --wood-mid: #c07830;
  --wood-light: #e0983c;
  --panel: #c07830;
  --panel-dark: #a8641f;
  --gold: #f5c542;
  --gold-dark: #c89000;
  --hex-empty: #1a0a08;
  --hex-empty-line: #4a1f16;
  --hex1: #e0483c;
  --hex2: #7fc94b;
  --hex3: #c14fd6;
  --hex4: #f0a94e;
  --hex5: #4ecdc4;
  --hex6: #3a3a3a;
  --shadow: rgba(0, 0, 0, 0.5);
  --font: 'Fredoka One', cursive;
}

body {
  background: var(--wood-darker);
  font-family: var(--font);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center
}

#preloader {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, #5a2f1a 0%, var(--wood-darker) 75%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px
}

.pre-logo {
  font-size: 56px;
  color: var(--gold);
  letter-spacing: -1px;
  text-shadow: 0 4px 0 var(--gold-dark), 0 0 40px rgba(245, 197, 66, 0.5);
  animation: logoPop 0.8s cubic-bezier(0.34, 1.56, 0.64, 1)
}

.pre-sub {
  font-family: 'Nunito', sans-serif;
  color: #f0c896;
  font-size: 16px;
  font-weight: 700;
  opacity: 0;
  animation: fadeIn 0.5s 0.6s forwards
}

.pre-bar-wrap {
  width: 260px;
  height: 10px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 99px;
  overflow: hidden;
  border: 2px solid var(--wood-mid)
}

.pre-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--hex1), var(--gold));
  border-radius: 99px;
  transition: width 0.08s linear
}

.pre-shapes {
  display: flex;
  gap: 14px;
  margin-top: 4px
}

.ps {
  width: 26px;
  height: 26px;
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  animation: spinBounce 1.2s ease-in-out infinite
}

.ps:nth-child(1) {
  background: var(--hex1);
  animation-delay: 0s
}

.ps:nth-child(2) {
  background: var(--hex2);
  animation-delay: 0.15s
}

.ps:nth-child(3) {
  background: var(--hex3);
  animation-delay: 0.3s
}

.ps:nth-child(4) {
  background: var(--hex4);
  animation-delay: 0.45s
}

@keyframes spinBounce {

  0%,
  100% {
    transform: translateY(0) rotate(0deg)
  }

  50% {
    transform: translateY(-14px) rotate(60deg)
  }
}

@keyframes logoPop {
  0% {
    transform: scale(0) rotate(-20deg);
    opacity: 0
  }

  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1
  }
}

@keyframes fadeIn {
  to {
    opacity: 1
  }
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px
}

.screen.active {
  display: flex
}

#home {
  background: radial-gradient(ellipse at 50% 0%, #5a2f1a 0%, var(--wood-darker) 70%)
}

.home-logo {
  font-size: 60px;
  color: var(--gold);
  letter-spacing: -1px;
  text-shadow: 0 4px 0 var(--gold-dark), 0 6px 20px rgba(0, 0, 0, 0.5);
  animation: float 3s ease-in-out infinite
}

.home-sub {
  font-family: 'Nunito', sans-serif;
  color: #f0c896;
  font-size: 15px;
  margin-top: -6px;
  margin-bottom: 28px
}

.home-shapes-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0
}

.float-shape {
  position: absolute;
  opacity: 0.12;
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  animation: floatRnd 6s ease-in-out infinite
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0px)
  }

  50% {
    transform: translateY(-12px)
  }
}

@keyframes floatRnd {

  0%,
  100% {
    transform: translateY(0) rotate(0deg)
  }

  50% {
    transform: translateY(-20px) rotate(15deg)
  }
}

.btn {
  font-family: var(--font);
  font-size: 22px;
  color: #3a1610;
  background: var(--gold);
  border: none;
  border-radius: 16px;
  padding: 14px 48px;
  cursor: pointer;
  letter-spacing: 0.5px;
  box-shadow: 0 6px 0 var(--gold-dark), 0 8px 20px rgba(0, 0, 0, 0.35);
  transition: all 0.1s;
  position: relative;
  z-index: 1;margin-top: 5px;
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--gold-dark), 0 4px 10px rgba(0, 0, 0, 0.25)
}

.btn-secondary {
  background: var(--hex1);
  box-shadow: 0 6px 0 #a02c22, 0 8px 20px rgba(224, 72, 60, 0.3);
  color: #fff;
  font-size: 18px;
  padding: 12px 32px
}

.btn-secondary:active {
  box-shadow: 0 2px 0 #a02c22
}

.stars-row {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  align-items: center
}

.star-ico {
  font-size: 26px;
  filter: drop-shadow(0 0 6px rgba(245, 197, 66, 0.6))
}

.level-select {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  max-width: 360px;
  width: 100%;
  margin-top: 16px;
  position: relative;
  z-index: 1
}

.lvl-btn {
  font-family: var(--font);
  font-size: 20px;
  background: var(--panel-dark);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 12px 0;
  color: #fff;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  /* 3D Shadow */
  box-shadow:
    0 4px 0 rgba(0, 0, 0, 0.45),
    0 7px 12px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.lvl-btn:hover {
  background: var(--wood-mid);
  border-color: var(--gold)
}

.lvl-btn.locked {
  opacity: 0.4;
  cursor: not-allowed
}

.lvl-btn .lstar {
  position: absolute;
  top: -6px;
  right: -4px;
  font-size: 11px
}

#game {
  background: var(--wood-darker);
  justify-content: flex-start;
  padding: 0;
  gap: 0;
  position: relative;
  overflow-y: auto
}

.game-area {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  max-width: 420px;
  flex: 1
}

.board-panel {
  background: radial-gradient(ellipse at 50% 15%, #5a2a17 0%, #3a1610 55%, #2a0f0b 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 10px;
  position: relative;
  z-index: 2;
}

.tray-panel {
  background: linear-gradient(180deg, #e0a052 0%, #c9822f 55%, #b56f24 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 12px 10px;
  position: relative;
  z-index: 1;
}

.level-banner {
  width: 100%;
  display: flex;
  justify-content: center;
  padding-top: 10px;
  position: relative;
  z-index: 3
}

.level-banner-inner {
  position: relative;
  background: linear-gradient(180deg, #fbe08a 0%, #f0b93e 45%, #c9821a 100%);
  color: #5a2a0a;
  font-size: 21px;
  padding: 9px 30px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  border: 2px solid #8a5416;
}

.level-banner-inner::before,
.level-banner-inner::after {
  content: '';
  position: absolute;
  top: 1px;
  width: 0;
  height: 0;
  border-style: solid;
  filter: brightness(0.85)
}

.level-banner-inner::before {
  left: -17px;
  border-width: 18px 17px 18px 0;
  border-color: transparent #a8631a transparent transparent
}

.level-banner-inner::after {
  right: -17px;
  border-width: 18px 0 18px 17px;
  border-color: transparent transparent transparent #a8631a
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 22px;
  position: relative;
  z-index: 3
}

.hud-stars,
.hud-coins {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  color: var(--gold);
  font-family: var(--font);
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.5)
}

.hud-coins {
  color: #ffd54f
}

.level-title {
  margin-top: 2px;
  font-size: 13px;
  color: #f0c896;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase
}

#grid-container {
  position: relative;
  padding: 14px;
  border-radius: 16px;
  background: radial-gradient(ellipse at 50% 35%, #241209 0%, #160b06 100%);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.55)
}

#puzzle-grid {
  position: relative
}

.hex-cell {
  position: absolute;
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
  transition: transform 0.1s
}

.hex-cell.empty {
  background: radial-gradient(circle at 35% 25%, #4f403c 0%, #160b06 70%);
  box-shadow: inset 0 0 0 1px #6b4423, inset 0 0 8px rgba(0, 0, 0, 0.6)
}

.hex-cell.locked {
  background: linear-gradient(160deg, #c4c4cc, #6a6a76);
  box-shadow: inset 0 0 0 2px #3a3a42, 0 2px 4px rgba(0, 0, 0, 0.4)
}

.hex-cell .lock-ico {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 52%;
  height: 52%;
  pointer-events: none
}

.hex-cell.filled {
  cursor: default
}

.hex-cell.highlight {
  filter: brightness(1.15)
}

.hex-cell.valid-drop {
  background: #3a8a4a !important;
  animation: pulse 0.5s ease-in-out infinite alternate
}

.hex-cell.invalid-drop {
  background: #8b1a1a !important
}

@keyframes pulse {
  from {
    opacity: 0.7
  }

  to {
    opacity: 1
  }
}

.hex-cell.placed {
  animation: cellPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1)
}

@keyframes cellPop {
  0% {
    transform: scale(0.7)
  }

  100% {
    transform: scale(1)
  }
}

.pieces-tray {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%
}

.tray-label {
  font-size: 11px;
  color: #5a2e0e;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  opacity: 0.75
}

.pieces-shelf {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  padding: 14px 10px;
  min-height: 90px;
  width: 100%
}

.piece-wrapper {
  position: relative;
  cursor: grab;
  user-select: none;
  transition: transform 0.15s;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, 0.35))
}

.piece-wrapper:active {
  cursor: grabbing
}

.piece-wrapper.selected {
  filter: drop-shadow(0 0 10px var(--gold));
  transform: scale(1.08)
}

.piece-wrapper.placed-piece {
  opacity: 0.25;
  pointer-events: none
}

.piece-hex {
  position: absolute;
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%)
}

.controls-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 6px 0 10px;
  position: relative;
  z-index: 3
}

.ctrl-btn {
  font-family: var(--font);
  font-size: 14px;
  background: linear-gradient(180deg, #5a2a12, #3a1610);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 8px 16px;
  color: #fff0dd;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35)
}

.ctrl-btn:hover {
  background: linear-gradient(180deg, #7a3a18, #4a2010);
  border-color: var(--gold)
}

.ctrl-btn svg {
  width: 16px;
  height: 16px
}

#success-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px)
}

#success-overlay.show {
  display: flex
}

.success-card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-dark) 100%);
  border-radius: 24px;
  padding: 32px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  border: 3px solid var(--gold);
  box-shadow: 0 0 60px rgba(245, 197, 66, 0.35);
  animation: cardIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1)
}

@keyframes cardIn {
  from {
    transform: scale(0.5) rotate(-5deg);
    opacity: 0
  }

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

.success-emoji {
  font-size: 64px;
  animation: bounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1)
}

@keyframes bounce {
  0% {
    transform: scale(0)
  }

  60% {
    transform: scale(1.2)
  }

  100% {
    transform: scale(1)
  }
}

.success-title {
  font-size: 36px;
  color: var(--gold);
  margin: 8px 0 4px;
  text-shadow: 0 3px 0 var(--gold-dark)
}

.success-stars {
  font-size: 32px;
  margin: 8px 0
}

.success-sub {
  font-family: 'Nunito', sans-serif;
  color: #fff0dd;
  font-size: 14px;
  margin-bottom: 20px
}

.success-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap
}

.confetti-piece {
  position: fixed;
  top: -10px;
  width: 10px;
  height: 10px;
  opacity: 1;
  pointer-events: none;
  z-index: 600;
  animation: confettiFall linear forwards
}

@keyframes confettiFall {
  to {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0
  }
}

.float-score {
  position: fixed;
  font-family: var(--font);
  font-size: 28px;
  color: var(--gold);
  pointer-events: none;
  z-index: 400;
  animation: floatUp 0.8s ease-out forwards;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5)
}

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

  100% {
    transform: translateY(-60px) scale(1.3);
    opacity: 0
  }
}

#drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 900;
  opacity: 0.85;
  transform: scale(1.15);
  display: none
}
