/* ============================================================
   RESET + BASE
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Avenir Next", sans-serif;
  background: linear-gradient(160deg, #fff4e0 0%, #ffe7d1 35%, #d8e8ff 100%);
  color: #2a2138;
  font-size: 18px;
  line-height: 1.4;
  min-height: 100vh;
}

/* ============================================================
   SCREEN SYSTEM
   ============================================================ */
#game { width: 100%; min-height: 100vh; }
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 24px 18px 48px;
  text-align: center;
  min-height: 100vh;
}
.screen.active { display: flex; }

h1 {
  font-size: clamp(2rem, 6vw, 3rem);
  margin: 0 0 8px;
  color: #4a2470;
  text-shadow: 0 2px 0 rgba(255,255,255,0.6);
  letter-spacing: -0.5px;
}
h1 .amp { color: #c34a4a; font-weight: 800; }
.lead {
  font-size: clamp(1.1rem, 3vw, 1.35rem);
  color: #4d3d5e;
  margin: 0 0 20px;
  max-width: 560px;
  font-weight: 600;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn-primary {
  font-family: inherit;
  font-size: clamp(1.25rem, 3.5vw, 1.6rem);
  font-weight: 800;
  padding: 22px 40px;
  min-width: 240px;
  min-height: 80px;
  border: none;
  border-radius: 22px;
  cursor: pointer;
  color: white;
  background: linear-gradient(180deg, #ff9b6a 0%, #e85a3a 100%);
  box-shadow: 0 6px 0 #a52d18, 0 10px 24px rgba(0,0,0,0.18);
  transition: transform 0.08s, box-shadow 0.08s;
  margin: 14px 8px 8px;
  letter-spacing: 0.2px;
}
.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #a52d18, 0 6px 14px rgba(0,0,0,0.18);
}
.btn-secondary {
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 16px 28px;
  min-height: 64px;
  border: 2px solid rgba(74, 36, 112, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: #4a2470;
  cursor: pointer;
  margin-top: 14px;
  transition: transform 0.1s, background 0.15s;
}
.btn-secondary:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 1);
}
.btn-tertiary {
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 16px 28px;
  min-height: 64px;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  color: #4a2470;
  background: linear-gradient(180deg, #f0e6ff 0%, #d8c8f0 100%);
  box-shadow: 0 4px 0 #8868b0;
  margin: 8px;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn-tertiary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #8868b0;
}

/* ============================================================
   INTRO
   ============================================================ */
.intro-art {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 12px 0 20px;
  flex-wrap: nowrap;
}
.intro-cat, .intro-dog {
  width: clamp(140px, 38vw, 220px);
  height: clamp(140px, 38vw, 220px);
  filter: drop-shadow(0 8px 18px rgba(0,0,0,0.18));
}
.intro-cat svg, .intro-dog svg { width: 100%; height: 100%; display: block; }
.vs {
  font-size: clamp(1.5rem, 5vw, 2.4rem);
  font-weight: 900;
  color: #c34a4a;
  background: white;
  border-radius: 999px;
  padding: 8px 18px;
  box-shadow: 0 4px 0 #8b2c2c, 0 6px 14px rgba(0,0,0,0.18);
  transform: rotate(-6deg);
}

/* ============================================================
   CHOOSE GRID — big tappable cards
   ============================================================ */
.choose-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  width: 100%;
  max-width: 720px;
  margin: 8px 0 32px;
}
@media (min-width: 700px) {
  .choose-grid { grid-template-columns: 1fr 1fr 1fr; gap: 22px; }
}
.choose-card {
  background: white;
  border: 4px solid transparent;
  border-radius: 24px;
  padding: 14px 10px 16px;
  cursor: pointer;
  box-shadow: 0 8px 0 rgba(0,0,0,0.10), 0 14px 28px rgba(0,0,0,0.10);
  transition: transform 0.1s, box-shadow 0.1s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 220px;
  font-family: inherit;
}
.choose-card:active {
  transform: translateY(4px);
  box-shadow: 0 4px 0 rgba(0,0,0,0.10), 0 6px 14px rgba(0,0,0,0.10);
}
.choose-card.selected {
  border-color: #e85a3a;
  background: #fff5ef;
}
.choose-card .card-art {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.choose-card .card-art svg { width: 100%; height: 100%; display: block; }
.choose-card .card-label {
  margin-top: 6px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #4a2470;
}

/* ============================================================
   CUSTOMIZE LAYOUT
   ============================================================ */
.customize-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 780px;
  align-items: stretch;
}
@media (min-width: 760px) {
  .customize-layout { flex-direction: row; align-items: flex-start; }
  .preview-card { flex: 0 0 360px; }
  .controls { flex: 1; }
}
.preview-card {
  background: white;
  border-radius: 26px;
  padding: 16px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.08), 0 14px 28px rgba(0,0,0,0.10);
}
.preview-stage {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-stage svg { width: 100%; height: 100%; display: block; }
.controls {
  background: white;
  border-radius: 26px;
  padding: 18px 16px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.08), 0 14px 28px rgba(0,0,0,0.10);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.control-group { display: flex; flex-direction: column; gap: 8px; }
.control-label {
  font-size: 1.1rem;
  font-weight: 800;
  color: #4a2470;
  text-align: left;
  padding-left: 4px;
}
.opts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.opt-btn {
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 14px 20px;
  min-width: 92px;
  min-height: 64px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: linear-gradient(180deg, #f4ecff 0%, #e3d4f4 100%);
  color: #4a2470;
  cursor: pointer;
  box-shadow: 0 4px 0 #b89ad8;
  transition: transform 0.08s, box-shadow 0.08s, border-color 0.15s, background 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.opt-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #b89ad8; }
.opt-btn.active {
  border-color: #e85a3a;
  background: linear-gradient(180deg, #ffe6d8 0%, #ffc7a4 100%);
  box-shadow: 0 4px 0 #b85b30;
}
.opt-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.25);
  display: inline-block;
  box-shadow: inset 0 -3px 4px rgba(0,0,0,0.15);
}
.opt-swatch.none {
  background: repeating-linear-gradient(45deg, #fff, #fff 4px, #ddd 4px, #ddd 8px);
}

/* ============================================================
   TEAM
   ============================================================ */
.team-stage {
  display: flex;
  gap: 18px;
  width: 100%;
  max-width: 780px;
  margin: 12px 0 20px;
  justify-content: center;
  flex-wrap: wrap;
}
.team-slot {
  flex: 1 1 280px;
  max-width: 360px;
  background: white;
  border-radius: 26px;
  padding: 14px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.08), 0 14px 28px rgba(0,0,0,0.10);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.team-art {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.team-art svg { width: 100%; height: 100%; display: block; }
.team-tag {
  margin-top: 6px;
  font-size: 1.2rem;
  font-weight: 800;
  color: #4a2470;
}
.team-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
#team-edit.hidden, #team-restart.hidden, #team-save.hidden { display: none; }

/* ============================================================
   NAV BAR (STANDARDS §8)
   ============================================================ */
.nav-bar {
  position: fixed;
  top: env(safe-area-inset-top, 12px);
  right: 12px;
  display: none;
  gap: 12px;
  z-index: 50;
  padding-top: 12px;
}
.nav-bar.visible { display: flex; }
.nav-btn {
  width: 64px;
  height: 64px;
  background: rgba(255, 255, 255, 0.96);
  border: none;
  border-radius: 50%;
  font-size: 28px;
  color: #4a2470;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-family: inherit;
}
.nav-btn:active { transform: scale(0.92); }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(120%);
  background: rgba(40, 25, 60, 0.95);
  color: white;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 14px 22px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  transition: transform 0.35s ease-out;
  z-index: 200;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ============================================================
   IDLE ANIMATIONS (gentle)
   ============================================================ */
.tail-wag { transform-box: fill-box; transform-origin: center; animation: tailWag 3.2s ease-in-out infinite; }
@keyframes tailWag {
  0%, 100% { transform: rotate(-3deg); }
  50%      { transform: rotate(3deg); }
}
.blink { animation: blink 5s linear infinite; }
@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  94%, 98%      { transform: scaleY(0.08); }
}

/* ============================================================
   PICK-PLAYER SCREEN — "Who do you want to be?"
   ============================================================ */
.pick-player-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  width: 100%;
  max-width: 720px;
  margin: 8px 0 12px;
}
@media (min-width: 640px) {
  .pick-player-grid { grid-template-columns: 1fr 1fr; gap: 24px; }
}
.pick-player-card {
  font-family: inherit;
  background: white;
  border: 5px solid transparent;
  border-radius: 28px;
  padding: 18px 14px 20px;
  cursor: pointer;
  box-shadow: 0 10px 0 rgba(0,0,0,0.10), 0 18px 36px rgba(0,0,0,0.12);
  transition: transform 0.1s, box-shadow 0.1s, border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 280px;
}
.pick-player-card:active {
  transform: translateY(5px);
  box-shadow: 0 5px 0 rgba(0,0,0,0.10), 0 8px 14px rgba(0,0,0,0.12);
  border-color: #e85a3a;
  background: #fff5ef;
}
.pick-player-art {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pick-player-art svg { width: 100%; height: 100%; display: block; }
.pick-player-label {
  margin-top: 10px;
  font-size: 1.5rem;
  font-weight: 800;
  color: #4a2470;
  letter-spacing: 0.2px;
}
.pick-player-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 4px;
}

/* ============================================================
   PLAY SCREEN — fullscreen play area
   ============================================================ */
#screen-play {
  padding: 0;
  width: 100vw;
  min-height: 100vh;
  align-items: stretch;
  justify-content: stretch;
  overflow: hidden;
}
#screen-play.active { display: flex; }

.play-area {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.play-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Actor wrapper: outer handles positioning (translate), inner handles facing flip + bump animation */
.actor {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  will-change: transform;
  /* width/height set inline by JS based on play-area dimensions */
}
.actor-inner {
  width: 100%;
  height: 100%;
  transform-origin: center center;
  /* facing flip is set inline via CSS variable --flip */
  transform: scaleX(var(--flip, 1));
  display: flex;
  align-items: center;
  justify-content: center;
}
.actor-inner svg { width: 100%; height: 100%; display: block; }

/* play-fight: animate the inner element only, preserving flip */
.actor-inner.bumping {
  animation: bump-wiggle 0.22s ease-in-out infinite alternate;
}
@keyframes bump-wiggle {
  0%   { transform: scaleX(var(--flip, 1)) rotate(-14deg) translateY(-3px); }
  100% { transform: scaleX(var(--flip, 1)) rotate(14deg)  translateY(3px); }
}

/* DUST PUFF overlay */
.dust-puff {
  position: absolute;
  left: 0;
  top: 0;
  width: 160px;
  height: 160px;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.3);
  will-change: transform, opacity;
}
.dust-puff.active {
  animation: puff-burst 1.4s ease-out;
}
@keyframes puff-burst {
  0%   { opacity: 0; transform: var(--puff-pos, translate(0,0)) scale(0.25); }
  18%  { opacity: 1; transform: var(--puff-pos, translate(0,0)) scale(1.0); }
  60%  { opacity: 0.7; transform: var(--puff-pos, translate(0,0)) scale(1.4); }
  100% { opacity: 0; transform: var(--puff-pos, translate(0,0)) scale(1.9); }
}
.dust-puff svg { width: 100%; height: 100%; display: block; }
.puff-a, .puff-b, .puff-c, .puff-d, .puff-e {
  transform-origin: center center;
  transform-box: fill-box;
}
.dust-puff.active .puff-a { animation: puff-a 1.4s ease-out; }
.dust-puff.active .puff-b { animation: puff-b 1.4s ease-out; }
.dust-puff.active .puff-c { animation: puff-c 1.4s ease-out; }
.dust-puff.active .puff-d { animation: puff-d 1.4s ease-out; }
.dust-puff.active .puff-e { animation: puff-e 1.4s ease-out; }
.dust-puff.active .puff-sparkles { animation: puff-sparkle 1.4s ease-out; }
@keyframes puff-a { 0% { transform: scale(0); } 30% { transform: scale(1.2); } 100% { transform: scale(1.8); opacity: 0; } }
@keyframes puff-b { 0% { transform: translate(0,0) scale(0); } 35% { transform: translate(-6px,-6px) scale(1); } 100% { transform: translate(-30px,-20px) scale(1.4); opacity: 0; } }
@keyframes puff-c { 0% { transform: translate(0,0) scale(0); } 35% { transform: translate(6px,-6px) scale(1); }  100% { transform: translate(30px,-20px) scale(1.4); opacity: 0; } }
@keyframes puff-d { 0% { transform: translate(0,0) scale(0); } 35% { transform: translate(-4px,4px) scale(1); }  100% { transform: translate(-26px,28px) scale(1.4); opacity: 0; } }
@keyframes puff-e { 0% { transform: translate(0,0) scale(0); } 35% { transform: translate(4px,4px) scale(1); }   100% { transform: translate(26px,28px) scale(1.4); opacity: 0; } }
@keyframes puff-sparkle { 0% { opacity: 0; } 20% { opacity: 1; } 100% { opacity: 0; } }

/* On-screen hint that fades out after a few seconds */
.play-hint {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: rgba(40, 25, 60, 0.75);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.play-hint.show { opacity: 1; }
