@font-face {
  font-family: "MyCustomFont";
  src: url("Quicksand-SemiBold.ttf") format("truetype");
}

:root{
  --shadow: 0 18px 40px rgba(0,0,0,.18);
  --r: 22px;

  --blueBorder: #63b3ff;
  --blueText: #1d4ed8;

  --badge1:#c4b5fd;
  --badge2:#8b5cf6;

  --slotBorder: #fbbf24;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family:"MyCustomFont","Baloo 2", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  overflow:hidden;
}

/* Background video */
.bg-video{ position:fixed; inset:0; width:100%; height:100%; object-fit:cover; z-index:-3; }
.bg-overlay{ position:fixed; inset:0; background: rgba(255,255,255,.25); z-index:-2; }

.screen{ position:absolute; inset:0; display:none; padding:16px; }
.screen.active{ display:block; }

.logo{ height:52px; object-fit:contain; }

/* Start/Intro cards */
.card{ background:#fff; border-radius:var(--r); box-shadow:var(--shadow); }
.hero{
  width:min(520px, 92vw);
  margin:70px auto 0;
  padding:26px 22px;
  text-align:center;
}
.hero h1{ margin:0; font-size: clamp(30px, 6vw, 44px); color:#1f2a66; }
.sub{ margin:10px 0 18px; color:#6b7280; font-size:18px; }
.pill{ display:inline-block; padding:2px 12px; border-radius:999px; background:#d1fae5; color:#065f46; }

.btn{
  border:none; border-radius:999px;
  padding:14px 22px; font-size:18px; font-weight:800;
  cursor:pointer; box-shadow: 0 14px 28px rgba(0,0,0,.16);
}
.btn:active{ transform:scale(.96); }
.btn.primary{ background: linear-gradient(180deg, #a7f3d0, #6ee7b7); color:#064e3b; }

.introWrap{ width:100%; max-width:520px; margin:40px auto 0; display:flex; flex-direction:column; gap:22px; align-items:center; }
.introCard{ width:100%; background:rgba(255,255,255,.95); border-radius:var(--r); box-shadow:var(--shadow); padding:16px; display:flex; justify-content:center; position:relative; }
.introImg{ width:min(460px,80%); max-height:50vh; object-fit:contain; }
.circleText{ position:absolute; left:52%; top:61%; transform:translate(-50%,-50%); font-size: clamp(64px, 9vw, 80px); font-weight:900; color:#6b21a8; }
.introText{ width:100%; background:rgba(255,255,255,.95); border-radius:var(--r); box-shadow:var(--shadow); padding:22px; text-align:center; }

.pop-in{ animation: popIn .55s ease both; }
.slide-up{ animation: slideUp .55s ease .1s both; }
@keyframes popIn{ from{ transform:scale(.92); opacity:0 } to{ transform:scale(1); opacity:1 } }
@keyframes slideUp{ from{ transform:translateY(16px); opacity:0 } to{ transform:translateY(0); opacity:1 } }

/* Topbar + timer */
.topbar{
  width:100%;
  display:grid;
  grid-template-columns: 170px 1fr 260px;
  align-items:center;
  gap: 14px;
  padding: 10px 14px 0;
}
.timerWrap{
  background: rgba(255,255,255,.85);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: 0 10px 22px rgba(0,0,0,.12);
  display:flex;
  flex-direction:column;
  gap:6px;
  min-width: 240px;
}
.timerBar{ height: 10px; border-radius: 999px; background: #e5e7eb; overflow:hidden; }
.timerBar i{
  display:block; height:100%; width:100%;
  background: linear-gradient(90deg, #86efac, #22c55e);
  transform-origin:left;
  transform: scaleX(1);
}
.timerText{ display:flex; justify-content:flex-end; gap:10px; font-weight:900; }
.timerText .sep{ opacity:.35; }

.banner{
  width: min(460px, 92vw);
  margin: 0px auto 6px;
  padding: 12px 18px;
  border-radius: 18px;
  background: rgba(255,255,255,.90);
  box-shadow: var(--shadow);
  border: 2px solid #bfdbfe;
  text-align:center;
  font-weight: 900;
  color: var(--blueText);
  font-size: 26px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s ease, transform .25s ease;
}
.banner.show{ opacity:1; transform: translateY(0); }

/* Outer frame */
.frame{
  width: min(980px, 88vw);
  margin: 12px auto 0;
  padding: 16px;
  border-radius: 22px;
  border: 4px solid var(--blueBorder);
  background: rgba(255,255,255,.30);
  box-shadow: 0 16px 36px rgba(0,0,0,.10);

  display:grid;
  grid-template-columns: 170px 1fr 280px;
  gap: 14px;
  align-items: start;
}

/* Left letter box */
.leftPanel{
  display:flex;
  justify-content:center;
  align-items:flex-start;
  padding-top: 12px;
}
.letterBox{
  width: 130px;
  height: 130px;
  border-radius: 24px;
  background: linear-gradient(180deg, var(--badge1), var(--badge2));
  box-shadow: 0 18px 36px rgba(139,92,246,.35);
  display:flex;
  align-items:center;
  justify-content:center;
}
.letterBox span{ font-size: 78px; font-weight: 900; color:#fff; }

/* Center box */
.centerPanel{ display:flex; justify-content:center; }
.bigBox{
  position: relative;
  width: min(400px, 60vw);
  aspect-ratio: 1 / 1;
  border-radius: 26px;
  background: rgba(255,255,255,.95);
  box-shadow: var(--shadow);
  padding: 14px;
}
.bigBox::before{
  content:"";
  position:absolute;
  inset:14px;
  border-radius: 22px;
  border: 3px solid #bfdbfe;
  background: #ffffff;
  pointer-events:none;
  z-index: 2;              /* ✅ cover layer above shadow */
}
.shadowImg{ z-index: 1; opacity:.10; }
.fullImg{ z-index: 1; opacity:.08; }

/* Smooth round transition */
.bigBox.fadeOut{
  opacity: 0;
  transform: scale(0.98);
  transition: opacity .18s ease, transform .18s ease;
}
.bigBox{
  transition: opacity .18s ease, transform .18s ease;
}
/* shadow + full */
.shadowImg, .fullImg{
  position:absolute;
  inset: 28px;
  width: calc(100% - 56px);
  height: calc(100% - 56px);
  object-fit: contain;
  border-radius: 18px;
  pointer-events:none;
}

.shadowImg{ opacity:.20; z-index:1; }
.fullImg{ z-index:2;
  opacity: .12;               /* ✅ very light */
  filter: grayscale(.1); 
}
.hidden{ display:none !important; }
.fullImg.complete{
  opacity: 1;
  filter: none;
}
/* Slots visible */
.slot{
  position:absolute;
  top: 28px;
  bottom: 28px;
  width: calc((100% - 56px) / 2);
  z-index: 3;
  border: 3px dashed var(--slotBorder);
  border-radius: 18px;
  opacity: .55;
  pointer-events:none;
}
.slotLeft{ left: 28px; }
.slotRight{ right: 28px; }

/* Badge */
.bigBadge{
  position:absolute;
  left:50%;
  top:52%;
  transform: translate(-50%, -50%);
  width: 220px;
  height: 220px;
  border-radius: 34px;
  background: linear-gradient(180deg, var(--badge1), var(--badge2));
  box-shadow: 0 18px 36px rgba(139,92,246,.35);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 120px;
  font-weight: 900;
  color:#fff;
  opacity:0;
  z-index: 10;
  pointer-events:none;
}
.bigBadge.show{ animation: badgePop .25s ease forwards; }
@keyframes badgePop{
  from{ opacity:0; transform: translate(-50%, -50%) scale(.88); }
  to{ opacity:1; transform: translate(-50%, -50%) scale(1); }
}

/* Right tray panel */
.rightPanel{
  display:flex;
  flex-direction:column;
  gap: 16px;
  background: rgba(255,255,255,.70);
  border: 4px solid rgba(59,130,246,.35);
  border-radius: 22px;
  padding: 12px;
  box-shadow: 0 10px 22px rgba(0,0,0,.12);
  height: auto;
  align-self: start;
}
.trayBox{
  height: 190px;
  border-radius: 22px;
  background: rgba(255,255,255,.9);
  border: 3px dashed rgba(59,130,246,.35);
  box-shadow: 0 10px 22px rgba(0,0,0,.12);
  position: relative;
  overflow: hidden;
  padding: 0;
  flex: 0 0 auto;
}

.trayBox .piece{
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  box-shadow: none;
  border-radius: inherit;
  background: transparent;
  position: relative;
}
.piece {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  touch-action: none;
  overflow: hidden;              /* clip inside slot */
  background: transparent;
}
.trayBox .piece img{
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.piece img{
  width: 100%;
  height: 100%;
  object-fit: cover;             /* fill slot */
  object-position: center;       /* keep centered */
  display: block;
  transform: scale(1); 
}
.piece{
  overflow: hidden;       /* ✅ clips exactly to slot border */
}

.piece.lock{
  cursor: default;
  border-color: #22c55e;
  box-shadow: 0 0 0 6px rgba(34,197,94,.18);
  pointer-events: none; /* ✅ critical: locked pieces can't be selected/dragged */
}
.piece.wrong{
  border-color:#ef4444;
  box-shadow: 0 0 0 6px rgba(239,68,68,.16);
}

/* Drag visibility */
.piece.dragging {
  position: fixed !important;
  margin: 0 !important;
  z-index: 99999 !important;
  pointer-events: none;
  cursor: grabbing;
}
.piece.lock img{
  transform: scale(1); 
  transform-origin: center;       /* adjust 1.15–1.40 as needed */
}
/* smooth fade for full image */
.fullImg{
  transition: opacity .25s ease;
}
/* time up */
.timeUp{
  position:absolute;
  inset:0;
  z-index: 50;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(255,255,255,.55);
  backdrop-filter: blur(1px);
}
.timeUpCard{
  background:#fff;
  border-radius: 18px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
  border: 2px solid #fde68a;
  text-align:center;
}
.timeUpTitle{ font-weight:900; color:#b45309; font-size: 20px; }
.timeUpSub{ color: #6b7280; font-weight:800; margin-top:4px; }

/* fullscreen */
#fullscreenBtn{
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 9999;
  background: #6ee7b7;
  color: #064e3b;
  border: none;
  padding: 10px 16px;
  border-radius: 20px;
  font-weight: 800;
  cursor: pointer;
}

#screenStart .hero .logo{
  width: 280px;
  margin-bottom: 26px;
  height: 120px;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,.15));
}

/* small screens */
@media (max-width: 980px){
  .frame{
    grid-template-columns: 170px 1fr;
  }
  .rightPanel{
    grid-column: 1 / span 2;
    min-height: 260px;
  }
}
@media (max-width: 900px){

  /* Prevent side overflow */
  html, body{ overflow-x: hidden; }
  .screen{ padding: 10px; }

  /* Topbar becomes stacked and centered */
  .topbar{
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 8px;
    padding: 6px 6px 0;
  }

  /* Logo smaller so it doesn't push */
  .topbar .logo{
    height: 42px;
    justify-self: center;
  }

  /* Banner always inside screen */
  .banner{
    width: min(94vw, 520px);
    margin: 0 auto;
    font-size: clamp(16px, 4.6vw, 22px);
    padding: 10px 12px;
    text-align: center;
  }

  /* Timer always inside screen */
  .timerWrap{
    width: min(94vw, 520px);
    min-width: 0;
    margin: 0 auto;
  }
  .timerText{
    justify-content: center;
    width: 100%;
    font-size: 14px;
  }

  /* Frame centered, no overflow */
  .frame{
    width: min(94vw, 520px);
    margin: 10px auto 0;
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    gap: 10px;
    height: min(78dvh, 720px);
    overflow: hidden;
  }

  /* Hide left letter panel on mobile (optional) */
  .leftPanel{ display:none; }

  /* Puzzle box centered */
  .centerPanel{ justify-content: center; }
  .bigBox{
    width: min(86vw, 320px);
    margin: 0 auto;
  }

  /* Pieces align as 2 equal boxes */
  .rightPanel{
    width: 100%;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    height: 100%;
    align-items: stretch;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
  }

  .trayBox{
    height: 100%;
    min-height: 0;
  }
}
.popup{
  position: fixed;
  inset: 0;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(0,0,0,.35);
  z-index: 99999;
}

.popupCard{
  width: min(520px, 92vw);
  background: #fff;
  border-radius: 26px;
  padding: 22px 20px;
  box-shadow: 0 22px 50px rgba(0,0,0,.25);
  text-align:center;
}

.popupBtns{
  display:flex;
  gap: 12px;
  justify-content:center;
  margin-top: 16px;
  flex-wrap: wrap;
}

.btn.secondary{
  background: linear-gradient(180deg, #bfdbfe, #60a5fa);
  color:#0b3b8c;
}

.confettiLayer{
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99998;
  overflow: hidden;
}

.confetti{
  position: absolute;
  top: -12px;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  background: currentColor;
  color: hsl(calc(360 * var(--h, 0.5)), 80%, 60%);
  animation: fall 1.6s ease-in forwards;
}

/* random colors by nth-child trick */
.confettiLayer .confetti:nth-child(4n+1){ color:#22c55e; }
.confettiLayer .confetti:nth-child(4n+2){ color:#3b82f6; }
.confettiLayer .confetti:nth-child(4n+3){ color:#f59e0b; }
.confettiLayer .confetti:nth-child(4n){ color:#ec4899; }

@keyframes fall{
  to{
    transform: translateY(110vh) rotate(720deg);
    opacity: 0.9;
  }
}