/* =========================================================
   Duckle - "Can you find all 10 Ducks?"
   Modern Web Game Stylesheet
   ========================================================= */

:root {
  --primary-color: #fbc02d;
  --accent-color: #ff5722;
  --bg-overlay: rgba(15, 23, 42, 0.75);
  --card-bg: rgba(255, 255, 255, 0.95);
  --glass-bg: rgba(255, 255, 255, 0.82);
  --glass-border: rgba(255, 255, 255, 0.4);
  --text-dark: #111827;
  --text-muted: #64748b;
  --success-color: #10b981;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0f172a;
  color: #fff;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* Ambient blurred desktop backdrop */
.desktop-backdrop {
  position: fixed;
  inset: -20px;
  background-image: url('background.jpg');
  background-size: cover;
  background-position: center;
  filter: blur(28px) brightness(0.35);
  z-index: 0;
  transform: scale(1.05);
}

/* Main Portrait Game Container */
.game-viewport {
  position: relative;
  z-index: 10;
  width: 100%;
  /* Never wider than 9:16, so the artwork is only ever cropped at the sides */
  max-width: min(450px, calc(100dvh * 9 / 16));
  height: 100vh;
  height: 100dvh;
  max-height: 900px;
  aspect-ratio: 9 / 16;
  background: #000;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.8),
              0 0 0 1px rgba(255, 255, 255, 0.15);
  border-radius: 28px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  touch-action: manipulation;
}

@media (max-width: 480px) {
  .game-viewport {
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    box-shadow: none;
  }
}

/* Game Scene Layer (zoom / pan target) */
.scene-container {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  transform-origin: center center;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

.scene-container.is-dragging {
  transition: none;
}

.scene-container.zoomed {
  cursor: grab;
}

.scene-container.zoomed:active {
  cursor: grabbing;
}

/* Stage (Holds both Background & Ducks - Locked Together, scaled as one by game.js) */
.scene-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

/* Ducks stay hidden until the stage has been fitted to the artwork */
.scene-stage.is-loading .duck-entity {
  visibility: hidden;
}

/* Top UI Banner Header (Matching Screenshot) */
.header-banner {
  position: absolute;
  /* Clear the notch / status bar when installed full-screen */
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 16px;
  right: 16px;
  z-index: 50;
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

/* The exact banner from the screenshot */
.screenshot-badge {
  background: #ffffff;
  color: #050505;
  padding: 8px 16px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.15);
  font-family: system-ui, -apple-system, "Arial Black", Impact, sans-serif;
  font-weight: 900;
  font-style: italic;
  font-size: 21px;
  line-height: 1.1;
  letter-spacing: -0.5px;
  display: inline-block;
  align-self: flex-start;
  max-width: 75%;
  animation: badge-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes badge-pop {
  0% { transform: scale(0.9) translateY(-10px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.screenshot-badge span {
  display: block;
}

/* Minimalist Clean Count Badge */
.count-badge {
  background: #ffffff;
  color: #050505;
  padding: 8px 14px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.15);
  font-family: system-ui, -apple-system, "Arial Black", Impact, sans-serif;
  font-weight: 900;
  font-style: italic;
  font-size: 19px;
  line-height: 1.1;
  letter-spacing: -0.5px;
  white-space: nowrap;
  animation: badge-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), background-color 0.2s ease;
}

.count-badge.bump {
  transform: scale(1.22);
  background: #fef08a;
}

.header-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.timer-badge {
  background: rgba(15, 23, 42, 0.72);
  color: #ffffff;
  padding: 4px 10px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.timer-badge.penalised {
  animation: timer-penalty 0.7s ease-out;
}

@keyframes timer-penalty {
  0% { background: #dc2626; transform: scale(1.18); }
  100% { background: rgba(15, 23, 42, 0.72); transform: scale(1); }
}

/* =========================================================
   Duck Entities
   ========================================================= */
/* No pointer cursor and no hover glow: sweeping the mouse must not give ducks away */
.duck-entity {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.duck-sprite-box {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center bottom;
  /* Hidden ducks hold still, with a brief fidget every so often as a clue for the patient */
  animation: duck-fidget var(--fidget-dur, 12s) var(--fidget-delay, 0s) infinite ease-in-out;
  pointer-events: none;
}

/* Perched or floating ducks cast no ground shadow */
.duck-entity.is-airborne .duck-shadow {
  display: none;
}

/* ?test_spots=1 placement labels */
.spot-label {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #ffffff;
  font-size: 7px;
  font-weight: 700;
  line-height: 1.2;
  padding: 0 2px;
  white-space: nowrap;
  pointer-events: none;
}

.scene-stage.is-debug .duck-sprite-box {
  animation: none;
}

/* Direction flipping (on the artwork only, so the found badge and toast stay readable) */
.duck-entity.is-flipped .duck-svg {
  transform: scaleX(-1);
}

/* Slope & branch perched angles */
.duck-entity.tilt-left .duck-svg {
  transform: rotate(-12deg);
}
.duck-entity.tilt-right .duck-svg {
  transform: rotate(12deg);
}
.duck-entity.is-flipped.tilt-left .duck-svg {
  transform: scaleX(-1) rotate(12deg);
}
.duck-entity.is-flipped.tilt-right .duck-svg {
  transform: scaleX(-1) rotate(-12deg);
}

/* WebP Shuba Duck Image */
.duck-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
}

/* SVG Duck */
.duck-svg {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Duck colours: the same white duck everywhere */
.duck-svg .duck-body-fill {
  fill: #ffffff;
  stroke: #111111;
}

.duck-svg .duck-beak-fill {
  fill: #fbc02d;
  stroke: #111111;
}

.duck-svg .duck-leg-fill {
  fill: #ff5722;
  stroke: #d84315;
}

.duck-svg .duck-eye {
  fill: #111111;
}

.duck-svg .duck-shadow {
  fill: rgba(0, 0, 0, 0.25);
}

/* Brief, rare fidget while hidden */
@keyframes duck-fidget {
  0%, 91%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  94% {
    transform: translateY(-1.5px) rotate(-4deg);
  }
  97% {
    transform: translateY(0) rotate(3deg);
  }
}

/* Full celebratory dancing animation (triggered only after being found!) */
@keyframes duck-dance-celebrate {
  0% {
    transform: translateY(0px) rotate(-6deg) scaleX(1);
  }
  25% {
    transform: translateY(-6px) rotate(0deg) scaleX(1.03);
  }
  50% {
    transform: translateY(0px) rotate(6deg) scaleX(1);
  }
  75% {
    transform: translateY(-6px) rotate(0deg) scaleX(1.03);
  }
  100% {
    transform: translateY(0px) rotate(-6deg) scaleX(1);
  }
}

/* Duck Legs: energetic celebration steps once found! */
.duck-entity.found .leg-left {
  animation: leg-step-celebrate-left 1.2s infinite ease-in-out;
  transform-origin: 48px 116px;
}

.duck-entity.found .leg-right {
  animation: leg-step-celebrate-right 1.2s infinite ease-in-out;
  transform-origin: 72px 116px;
}

@keyframes leg-step-celebrate-left {
  0%, 100% { transform: translateY(0) rotate(-10deg); }
  50% { transform: translateY(-8px) rotate(14deg); }
}

@keyframes leg-step-celebrate-right {
  0%, 100% { transform: translateY(-8px) rotate(14deg); }
  50% { transform: translateY(0) rotate(-10deg); }
}

/* Duck Found State */
.duck-entity.found {
  pointer-events: none;
  z-index: 25;
}

.duck-entity.found .duck-sprite-box {
  animation: duck-found-celebrate 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards,
             duck-dance-celebrate 1.2s 0.6s infinite ease-in-out;
  filter: drop-shadow(0 2px 8px rgba(251, 192, 45, 0.85)) drop-shadow(0 0 3px rgba(255, 255, 255, 0.95)) !important;
  opacity: 1 !important;
  transform-origin: center bottom;
}

@keyframes duck-found-celebrate {
  0% { transform: scale(1) translateY(0); }
  40% { transform: scale(1.4) translateY(-18px) rotate(-12deg); }
  70% { transform: scale(1.25) translateY(-10px) rotate(12deg); }
  100% { transform: scale(1) translateY(0); }
}

/* Found Badge / Golden Halo */
.found-ring {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 26px;
  height: 26px;
  background: linear-gradient(135deg, #fbc02d, #ff8f00);
  border: 2px solid #ffffff;
  border-radius: 50%;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(251, 192, 45, 0.6);
  animation: ring-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes ring-pop {
  0% { transform: scale(0) rotate(-90deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* Floating Quack Feedback Label */
.quack-toast {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85);
  color: #ffeb3b;
  font-weight: 800;
  font-size: 14px;
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
  pointer-events: none;
  animation: toast-float 1.1s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  z-index: 100;
}

@keyframes toast-float {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.7); }
  25% { opacity: 1; transform: translate(-50%, -8px) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -36px) scale(0.9); }
}

/* Miss Click Ripple */
.miss-ripple {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 0%, transparent 70%);
  transform: translate(-50%, -50%) scale(0.2);
  pointer-events: none;
  animation: ripple-spread 0.6s ease-out forwards;
  z-index: 15;
}

@keyframes ripple-spread {
  0% { transform: translate(-50%, -50%) scale(0.2); opacity: 0.9; }
  100% { transform: translate(-50%, -50%) scale(2.4); opacity: 0; }
}

/* Miss time-penalty label */
.miss-penalty {
  position: absolute;
  transform: translate(-50%, -50%);
  color: #fecaca;
  font-size: 13px;
  font-weight: 900;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  animation: penalty-float 0.9s ease-out forwards;
  z-index: 16;
}

@keyframes penalty-float {
  0% { transform: translate(-50%, -50%); opacity: 1; }
  100% { transform: translate(-50%, -34px); opacity: 0; }
}

/* Hint Radar: a search zone that holds its size, with the duck somewhere inside */
.hint-radar {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: 3px solid #ffeb3b;
  box-shadow: 0 0 25px #ffeb3b, inset 0 0 15px rgba(255, 235, 59, 0.5);
  pointer-events: none;
  animation: radar-ping 1.6s ease-in-out infinite;
  z-index: 2000;
}

@keyframes radar-ping {
  0%, 100% { transform: translate(-50%, -50%) scale(0.94); opacity: 0.95; }
  50% { transform: translate(-50%, -50%) scale(1.04); opacity: 0.55; }
}

/* =========================================================
   Bottom Floating Control Dock
   ========================================================= */
.bottom-dock {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 6px 10px;
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  max-width: 92%;
}

.dock-btn {
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.6);
  color: #1e293b;
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  touch-action: manipulation;
}

/* Keep all five controls on screen on narrow phones */
@media (max-width: 400px) {
  .bottom-dock {
    gap: 4px;
    padding: 6px;
  }

  .dock-btn {
    padding: 6px 7px;
    font-size: 11px;
    gap: 2px;
  }
}

.dock-btn:hover {
  background: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dock-btn:active {
  transform: translateY(0);
}

.dock-btn.active {
  background: #fbc02d;
  color: #0f172a;
  border-color: #f59e0b;
}

/* =========================================================
   Victory Dialog / Modal
   ========================================================= */
.victory-modal {
  border: none;
  padding: 0;
  border-radius: 28px;
  background: transparent;
  max-width: 90%;
  width: 380px;
  margin: auto;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
}

.victory-modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.victory-card {
  background: #ffffff;
  color: #0f172a;
  border-radius: 28px;
  padding: 30px 24px;
  text-align: center;
  position: relative;
  overflow: hidden;
  animation: modal-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modal-pop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.victory-badge {
  font-size: 54px;
  margin-bottom: 6px;
  animation: trophy-wobble 1.5s infinite ease-in-out;
}

@keyframes trophy-wobble {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(6deg); }
}

.victory-title {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 26px;
  font-weight: 900;
  color: #1e293b;
  margin-bottom: 6px;
}

.victory-subtitle {
  font-size: 15px;
  color: #64748b;
  margin-bottom: 20px;
}

.stars-row {
  font-size: 32px;
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.star {
  filter: drop-shadow(0 2px 4px rgba(251, 192, 45, 0.4));
  animation: star-pop 0.5s backwards;
}

.star:nth-child(1) { animation-delay: 0.1s; }
.star:nth-child(2) { animation-delay: 0.25s; }
.star:nth-child(3) { animation-delay: 0.4s; }

@keyframes star-pop {
  0% { transform: scale(0) rotate(-45deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-item {
  background: #f8fafc;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-val {
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
  margin-top: 2px;
}

.victory-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-primary {
  background: linear-gradient(135deg, #fbc02d, #f59e0b);
  color: #0f172a;
  border: none;
  padding: 14px 20px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
  transition: all 0.2s;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(245, 158, 11, 0.5);
}

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

/* =========================================================
   Levels Selector Modal
   ========================================================= */
.levels-modal {
  border: none;
  padding: 0;
  border-radius: 28px;
  background: transparent;
  max-width: 90%;
  width: 400px;
  max-height: 85vh;
  margin: auto;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
}

.levels-modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.levels-card {
  background: #ffffff;
  color: #0f172a;
  border-radius: 28px;
  padding: 24px 20px;
  max-height: 82vh;
  overflow-y: auto;
  animation: modal-pop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.levels-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.levels-title {
  font-size: 20px;
  font-weight: 900;
  color: #0f172a;
}

.modal-close-btn {
  background: #f1f5f9;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 800;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.modal-close-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.levels-subtitle {
  font-size: 13px;
  color: #64748b;
  margin-bottom: 16px;
}

.levels-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.level-card {
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 16px;
  padding: 12px 10px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
  touch-action: manipulation;
}

.level-card:hover {
  transform: translateY(-2px);
  border-color: #fbc02d;
  box-shadow: 0 4px 12px rgba(251, 192, 45, 0.25);
}

.level-card.current {
  border-color: #f59e0b;
  background: #fffbeb;
  box-shadow: 0 0 0 1px #f59e0b;
}

.level-card.locked {
  opacity: 0.55;
  cursor: not-allowed;
  filter: grayscale(0.8);
  border-style: dashed;
}

.level-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.level-card-num {
  font-size: 12px;
  font-weight: 800;
  color: #f59e0b;
  text-transform: uppercase;
}

.level-card-name {
  font-size: 14px;
  font-weight: 800;
  color: #1e293b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.level-card-stars {
  font-size: 13px;
  margin-top: 2px;
}

.level-card-time {
  font-size: 11px;
  color: #64748b;
  font-weight: 600;
}
