/* ========== Theme ========== */
:root {
  --board: #0f2a26; /* dark teal board */
  --sun: #ffc928; /* yellow accents */
  --lav: #9b7bff; /* score pill */
  --peach: #ffa75e; /* ai tile */
  --mint: #52f0cf; /* ay tile */

  --card: #ffffff;
  --ink: #0b0b0b;
  --shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  overflow: hidden; /* no scrollbars */
  background: var(--board);
  color: var(--ink);
  font-family: Poppins, system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* App grid: header | stage | counter | buckets */
.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: clamp(8px, 1.4vh, 18px);
  padding: max(10px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
}

/* Header */
.bar {
  display: grid;
  align-items: center;
  grid-template-columns: 1fr auto 1fr;
}
.title {
  color: #111;
  background: var(--sun);
  padding: 10px 18px;
  border-radius: 18px;
  display: inline-block;
  justify-self: center;
  box-shadow: var(--shadow), inset 0 1.5px 0 rgba(255, 255, 255, 0.6);
  font-weight: 900;
  letter-spacing: 0.2px;
}
.score {
  justify-self: start;
  background: color-mix(in srgb, var(--lav) 92%, white 8%);
  color: #fff;
  font-weight: 900;
  padding: 8px 10px;
  border-radius: 999px;
  font-size: medium;

  box-shadow: var(--shadow);
}
.btn {
  justify-self: end;
  background: var(--sun);
  color: #111;
  font-weight: 900;
  padding: 10px 14px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow), inset 0 1.5px 0 rgba(255, 255, 255, 0.6);
}

/* Stage + Card */
.stage {
  display: grid;
  place-items: center;
  padding-top: 6px;
}
.card {
  position: relative;
  width: min(68dvw, 520px);
  height: min(42dvh, 360px);
  background: var(--card);
  border-radius: 24px;
  outline: 8px solid var(--sun);
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
}
.img-wrap {
  align-self: stretch;
  justify-self: stretch;
  min-width: 0;
  min-height: 0; /* allow shrinking inside grid */
  height: 100%;
  width: 100%;
}
.img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  -webkit-user-drag: none;
  user-select: none;
}

/* Sticker-style speaker button */
.speak {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(12px, 12px) rotate(-6deg);
  width: 58px;
  height: 46px;
  border: 0;
  cursor: pointer;
  background: #ffe69a;
  border-radius: 14px;
  outline: 3px solid #222;
  outline-offset: -2px;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
}
.speak svg {
  width: 26px;
  height: 26px;
  color: #222;
}

/* Counter (chip + bar using --progress 0..1) */
.counter {
  justify-self: center;
  position: relative;
  min-height: 38px;
  padding: 0;
  background: transparent;
  box-shadow: none;
}
.counter .chip {
  display: inline-block;
  background: var(--sun);
  color: #111;
  font-weight: 900;
  padding: 6px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow), inset 0 1.5px 0 rgba(255, 255, 255, 0.6);
}
.counter::after {
  /* track */
  content: "";
  position: absolute;
  left: calc(50% - 180px);
  right: calc(50% - 180px);
  bottom: -16px;
  height: 14px;
  border-radius: 999px;
  background: #f7dcbc;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
.counter::before {
  /* fill */
  content: "";
  position: absolute;
  left: calc(50% - 180px);
  bottom: -16px;
  height: 14px;
  width: calc(360px * var(--progress, 0));
  border-radius: 999px;
  background: #ef7a19;
  transition: width 0.35s ease;
}

/* Buckets row: compact, centered tiles */
.buckets {
  --bucketW: clamp(210px, 34dvw, 280px);
  display: grid;
  grid-auto-flow: column;
  grid-template-columns: repeat(2, minmax(auto, var(--bucketW)));
  justify-content: center;
  align-items: end;
  gap: clamp(18px, 3vw, 28px);
  padding-inline: clamp(8px, 2vw, 24px);
}
.bucket {
  width: var(--bucketW);
  min-height: clamp(150px, 22dvh, 220px);
  background: var(--card);
  border-radius: 22px;
  box-shadow: var(--shadow), inset 0 1.5px 0 rgba(255, 255, 255, 0.7);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.bucket.ai {
  background: var(--peach);
}
.bucket.ay {
  background: var(--mint);
}
.bucket .label {
  position: static;
  text-align: center;
  color: #000;
  line-height: 1.05;
}
.bucket .label .big {
  display: block;
  font-size: clamp(42px, 6.2vw, 54px);
  font-weight: 900;
}
.bucket .label small {
  display: block;
  font-size: clamp(22px, 3.6vw, 26px);
  font-weight: 900;
  opacity: 1;
}

/* Drag proxy */
.dragging {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

/* Small screens tweaks */
@media (max-width: 720px) {
  .card {
    width: min(88dvw, 520px);
    height: min(36dvh, 320px);
  }
  .buckets {
    --bucketW: clamp(170px, 44vw, 260px);
  }
}

/* ---------- Balanced vertical layout ---------- */
/* Desktop/tablet: add a flexible spacer above the stage */
@media (min-width: 721px) {
  .app {
    /* rows: header | SPACER | stage | counter | buckets  */
    grid-template-rows: auto minmax(0, 0.35fr) auto auto 1fr;
  }
  .bar {
    grid-row: 1;
  } /* header */
  .stage {
    grid-row: 3;
    align-self: start;
  } /* picture card sits lower */
  .counter {
    grid-row: 4;
    margin-top: 6px;
  }
  .buckets {
    grid-row: 5;
    margin-top: clamp(12px, 3vh, 28px);
  }
}

/* Phones: keep it compact (no spacer) */
@media (max-width: 720px) {
  .app {
    grid-template-rows: auto auto auto 1fr; /* header | stage | counter | buckets */
  }
  .stage {
    align-self: center;
  }
}

/* Optional: make the progress bar a bit wider on desktop since we moved it down */
@media (min-width: 1024px) {
  .counter::after {
    left: calc(50% - 220px);
    right: calc(50% - 220px);
  }
  .counter::before {
    left: calc(50% - 220px);
    width: calc(440px * var(--progress, 0));
  }
}

/* Mobile layout: remove the stretchy 1fr row and pull buckets up */
@media (max-width: 720px) {
  .app {
    /* header | stage | counter | buckets (all content-sized) */
    grid-template-rows: auto auto auto auto;
    gap: clamp(6px, 1vh, 12px);
  }

  .stage {
    align-self: start; /* keep the card near the top cluster */
  }

  .card {
    width: min(92dvw, 520px);
    height: min(34dvh, 300px); /* a bit shorter so everything fits */
  }

  .counter {
    margin-top: 2px;
  }

  .buckets {
    --bucketW: clamp(160px, 44vw, 260px);
    align-items: center; /* no “stick to bottom of a tall row” */
    justify-content: center;
    padding-inline: 8px;
  }

  .bucket {
    min-height: clamp(120px, 18dvh, 180px); /* slightly tighter tiles */
  }

  /* progress bar a touch narrower on small screens */
  .counter::after {
    left: calc(50% - 140px);
    right: calc(50% - 140px);
  }
  .counter::before {
    left: calc(50% - 140px);
    width: calc(280px * var(--progress, 0));
  }
}
/* tighter chip + bar stack */
.counter {
  --ctr-gap: 6px; /* distance from chip to bar */
  min-height: 32px;
  padding-bottom: calc(10px + var(--ctr-gap)); /* reserve space for bar */
}

.counter .chip {
  padding: 4px 12px; /* smaller pill */
  line-height: 1; /* kill extra vertical padding */
}

/* put the bar closer and a bit slimmer */
.counter::after,
.counter::before {
  bottom: calc(-1 * var(--ctr-gap));
  height: 10px;
  border-radius: 999px;
}

/* === Image reveal animation === */
:root {
  --ease-out: cubic-bezier(0.17, 0.84, 0.44, 1); /* snappy but soft */
}

/* start state */
.img-anim {
  opacity: 0;
  transform: translateY(6px) scale(0.96);
}

/* enter animation */
.img-anim.in {
  animation: img-pop-in 0.38s var(--ease-out) forwards;
}

@keyframes img-pop-in {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* optional: brief rim glow on the card when a new image lands */
.card.flash {
  animation: card-glow 0.6s ease-out;
}
@keyframes card-glow {
  0% {
    box-shadow: 0 0 0 rgba(0, 0, 0, 0), inset 0 0 0 rgba(255, 255, 255, 0);
  }
  40% {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  }
  60% {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35),
      0 0 0 6px rgba(255, 201, 40, 0.35);
  }
  100% {
    box-shadow: var(--shadow);
  }
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .img-anim,
  .img-anim.in,
  .card.flash {
    animation: none !important;
    transform: none !important;
    opacity: 1 !important;
  }
}
/* ==== Finish modal ==== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  z-index: 60;
}
.modal-backdrop.show {
  display: flex;
}
.modal {
  width: min(90vw, 520px);
  padding: 22px 18px;
  text-align: center;
  background: #fff;
  border-radius: 28px;
  box-shadow: var(--shadow);
}
.modal .stars {
  font-size: 28px;
  margin-bottom: 8px;
}
.modal h2 {
  margin: 6px 0 6px;
  font-weight: 900;
}
.modal p {
  margin: 0 0 14px;
  font-weight: 800;
}
.modal .modal-btn {
  display: inline-block;
  margin-top: 6px;
}

/* (Optional) wrong-drop shake used by JS */
.shake {
  animation: shake 0.35s ease;
}
@keyframes shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  80% {
    transform: translateX(3px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-5px);
  }
  40%,
  60% {
    transform: translateX(5px);
  }
}
.bucket.drop-hl {
  outline: 4px dashed rgba(0, 0, 0, 0.25);
  outline-offset: -6px;
}
