/* ─── Lumi Pet — base styles ─────────────────────────────── */

:root {
  /* Palette — same family as lumichat stickers */
  --mint: #a8e2d5;
  --mint-light: #cbefe4;
  --mint-dark: #6db4a4;
  --coral: #e85c48;
  --coral-light: #ff8070;
  --gold: #ffc947;
  --gold-light: #ffe58a;
  --gold-dark: #d89520;
  --lavender: #b4a6e8;
  --lavender-light: #c7b8f0;
  --sky: #b0cbee;
  --ink: #2b2530;
  --ink-soft: #6a6472;
  --paper: #ffffff;

  /* Bar colors */
  --bar-hunger: #ff8a5b;
  --bar-fun: #6cc5ff;
  --bar-clean: #7fdcc8;
  --bar-empty: rgba(255, 255, 255, 0.35);

  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display",
               "Onest", system-ui, sans-serif;
  color: var(--ink);
}

body {
  /* Default backdrop — meadow vibe; the .world layer below paints over it once a bg image loads. */
  background:
    radial-gradient(ellipse at top, var(--lavender-light) 0%, transparent 60%),
    linear-gradient(180deg, var(--lavender) 0%, var(--sky) 65%, var(--mint-light) 100%);
  background-attachment: fixed;
  position: relative;
  overflow: hidden;
}

/* ─── Living world: bg image + ambient particles ──────────── */

.world {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-size: cover;
  background-position: center bottom;
  background-repeat: no-repeat;
  transition: background-image 800ms ease, opacity 800ms ease;
}

.world.has-bg { opacity: 1; }

.ambient {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.ambient__particle {
  position: absolute;
  font-size: 22px;
  opacity: 0;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.15));
  will-change: transform, opacity;
}

/* Happy particles drift up-and-across */
.ambient__particle.is-happy {
  animation: drift var(--dur, 14s) linear var(--delay, 0s) infinite;
}

@keyframes drift {
  0%   { transform: translate(0, 110vh) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.85; }
  90%  { opacity: 0.85; }
  100% { transform: translate(40px, -10vh) rotate(20deg); opacity: 0; }
}

/* Sad particles fall straight down (rain) */
.ambient__particle.is-sad {
  animation: fall var(--dur, 2.4s) linear var(--delay, 0s) infinite;
}

@keyframes fall {
  0%   { transform: translateY(-40px); opacity: 0; }
  20%  { opacity: 0.7; }
  100% { transform: translateY(110vh); opacity: 0; }
}

/* Sleepy particles twinkle in place */
.ambient__particle.is-sleepy {
  animation: twinkle var(--dur, 3s) ease-in-out var(--delay, 0s) infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50%      { opacity: 0.95; transform: scale(1.1); }
}

/* ─── Layout ──────────────────────────────────────────────── */

.scene {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
  gap: 8px;
  max-width: 540px;
  margin: 0 auto;
}

/* ─── Meters ──────────────────────────────────────────────── */

.meters {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 12px rgba(80, 60, 140, 0.08);
}

.meter {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-md);
}

.meter__icon {
  font-size: 22px;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.1));
}

.meter__bar {
  flex: 1;
  height: 12px;
  background: var(--bar-empty);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
}

.meter__fill {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  transition: width 600ms cubic-bezier(.2,.7,.3,1),
              background-color 400ms ease;
}

.meter[data-meter="hunger"] .meter__fill { background: var(--bar-hunger); }
.meter[data-meter="fun"] .meter__fill { background: var(--bar-fun); }
.meter[data-meter="clean"] .meter__fill { background: var(--bar-clean); }

.meter.is-low .meter__fill {
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ─── Stage / Lumi ────────────────────────────────────────── */

.stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: var(--radius-lg);
}

.lumi {
  position: relative;
  width: min(70vw, 320px);
  aspect-ratio: 1;
  cursor: pointer;
  animation: breathe 3.6s ease-in-out infinite;
  transition: transform 200ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lumi:active { transform: scale(0.96); }

.lumi__sprite {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
  filter: drop-shadow(0 12px 24px rgba(80, 60, 140, 0.25));
}

.lumi__sprite.is-loaded { display: block; }

.lumi__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(120px, 32vw, 200px);
  filter: drop-shadow(0 8px 16px rgba(80, 60, 140, 0.25));
  animation: float 4s ease-in-out infinite;
}

.lumi__sprite.is-loaded ~ .lumi__placeholder { display: none; }

@keyframes breathe {
  0%, 100% { transform: scale(1) translateY(0); }
  50%      { transform: scale(1.025) translateY(-4px); }
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-8px) rotate(2deg); }
}

/* Tap reaction */
.lumi.is-tapped {
  animation: bounce 400ms ease;
}

@keyframes bounce {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.08) rotate(-3deg); }
  60%  { transform: scale(0.95) rotate(2deg); }
  100% { transform: scale(1); }
}

/* ─── Equipped wardrobe overlay ───────────────────────────── */

.equipped {
  position: absolute;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
  transform: translate(var(--shift-x, 0), var(--shift-y, 0));
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25));
}

.equipped.is-on { display: flex; }

.equipped img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.equipped__emoji {
  line-height: 1;
  font-size: inherit;
}

/* ─── Corner buttons (closet, school) ─────────────────────── */

.corner-btn {
  position: absolute;
  top: 8px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 3px 0 rgba(80, 60, 140, 0.18),
              0 6px 14px rgba(80, 60, 140, 0.18);
  font-size: 22px;
  cursor: pointer;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms ease;
}

.corner-btn:active { transform: scale(0.92); }
.corner-btn--right { right: 8px; }
.corner-btn--left  { left: 8px; }

.corner-btn.has-news::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 2px white;
  animation: pulse 1.4s ease-in-out infinite;
}

/* ─── Modal (used by closet, school, etc) ─────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal[hidden] { display: none !important; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(43, 37, 48, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  animation: fade 200ms ease;
}

@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal__panel {
  position: relative;
  background: white;
  border-radius: 24px;
  padding: 18px;
  max-width: 460px;
  width: 100%;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0,0,0,0.25);
  animation: pop 280ms cubic-bezier(.2,.7,.3,1.4);
}

@keyframes pop {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal__title {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}

.modal__close {
  appearance: none;
  border: none;
  background: #f3f0f8;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__actions { display: flex; gap: 8px; }

.modal__close:active { transform: scale(0.92); }

.modal__hint {
  color: var(--ink-soft);
  font-size: 13px;
  margin-bottom: 14px;
}

/* ─── Closet grid ─────────────────────────────────────────── */

.closet-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.closet-item {
  appearance: none;
  border: 2px solid transparent;
  background: #f7f5fb;
  border-radius: 16px;
  aspect-ratio: 1;
  font-size: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 120ms ease, border-color 200ms ease;
}

.closet-item:active { transform: scale(0.92); }
.closet-item.is-locked { opacity: 0.35; cursor: default; }
.closet-item.is-locked::after {
  content: "?";
  font-size: 28px;
  color: var(--ink-soft);
}
.closet-item.is-locked > * { display: none; }

.closet-item.is-equipped {
  border-color: var(--gold);
  background: #fff8e6;
  box-shadow: 0 0 0 4px rgba(255, 201, 71, 0.25);
}

.closet-item.is-equipped::before {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 12px;
  color: white;
  background: var(--gold-dark);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.closet-item img { width: 80%; height: 80%; object-fit: contain; }

/* ─── Mini-games ──────────────────────────────────────────── */

.game-visual {
  text-align: center;
  font-size: 56px;
  line-height: 1.1;
  padding: 14px 0 16px;
  letter-spacing: 0.05em;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.game-visual.is-small { font-size: 40px; }

.game-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.game-option {
  appearance: none;
  border: 3px solid var(--mint);
  background: white;
  border-radius: 18px;
  height: 90px;
  font-size: 38px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 120ms ease, border-color 200ms ease, background 200ms;
  position: relative;
  overflow: hidden;
}

.game-option:active { transform: scale(0.95); }

.game-option__swatch {
  display: block;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  box-shadow: 0 3px 0 rgba(0,0,0,0.18), inset 0 -3px 0 rgba(0,0,0,0.12);
}

.game-option.is-correct {
  border-color: var(--mint-dark);
  background: #ecfaf3;
  animation: bounceCorrect 500ms ease;
}
.game-option.is-wrong {
  border-color: #f08080;
  background: #fff0f0;
  animation: shakeWrong 360ms ease;
}

@keyframes bounceCorrect {
  0%, 100% { transform: scale(1); }
  40%      { transform: scale(1.12); }
}
@keyframes shakeWrong {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-8px); }
  75%      { transform: translateX(8px); }
}

.game-result {
  text-align: center;
  margin-top: 18px;
}

.game-result__msg {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--mint-dark);
}

.game-result.is-wrong .game-result__msg { color: #c33; }

.game-next {
  appearance: none;
  border: none;
  background: var(--gold);
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  padding: 12px 28px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--gold-dark);
}

.game-next:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--gold-dark);
}

/* ─── FX layer (hearts, sparkles, etc) ────────────────────── */

.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}

.trail {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  mix-blend-mode: screen;
  transition: opacity 100ms linear;
}

.stage {
  /* Make pointer events go to the stage so magic.js can capture strokes;
     children with pointer-events:none let the stroke pass through. */
  touch-action: none;
}

.lumi { pointer-events: none; }

.fx {
  position: absolute;
  font-size: 32px;
  opacity: 0;
  animation: rise 1400ms ease-out forwards;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.15));
}

@keyframes rise {
  0%   { opacity: 0; transform: translate(-50%, 0) scale(0.5); }
  20%  { opacity: 1; transform: translate(-50%, -20px) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -160px) scale(0.8); }
}

/* ─── Garden ──────────────────────────────────────────────── */

.garden {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 12px rgba(80, 60, 140, 0.08);
}

.plot {
  appearance: none;
  border: none;
  background: linear-gradient(180deg, #d9b58c 0%, #b08a5c 100%);
  border-radius: var(--radius-md);
  height: 70px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15),
              inset 0 2px 0 rgba(255,255,255,0.25);
  transition: transform 120ms ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.plot::before {
  /* Soil pattern dots */
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(70, 40, 10, 0.25) 1.5px, transparent 1.5px);
  background-size: 10px 10px;
  opacity: 0.6;
  pointer-events: none;
}

.plot:active { transform: scale(0.95); }

.plot__plant {
  font-size: 32px;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2));
  z-index: 1;
  transition: transform 300ms ease;
}

.plot.is-ready .plot__plant {
  animation: wiggle 0.9s ease-in-out infinite;
}

@keyframes wiggle {
  0%, 100% { transform: rotate(-6deg) scale(1); }
  50%      { transform: rotate(6deg) scale(1.06); }
}

.plot.is-ready {
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15),
              inset 0 2px 0 rgba(255,255,255,0.25),
              0 0 0 2px var(--gold),
              0 0 18px rgba(255, 201, 71, 0.55);
}

.plot__progress {
  position: absolute;
  bottom: 4px;
  left: 6px;
  right: 6px;
  height: 4px;
  background: rgba(255,255,255,0.35);
  border-radius: 999px;
  overflow: hidden;
  z-index: 1;
}

.plot__progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--mint), var(--gold));
  border-radius: 999px;
  transition: width 600ms ease;
}

.plot.is-empty .plot__progress { display: none; }
.plot.is-ready .plot__progress-fill { width: 100% !important; }

/* Sparkle pulse on ready plot */
.plot.is-ready::after {
  content: "✨";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 14px;
  animation: pulse 1.2s ease-in-out infinite;
}

/* ─── Actions ─────────────────────────────────────────────── */

.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 12px rgba(80, 60, 140, 0.08);
}

.action {
  appearance: none;
  border: none;
  background: var(--paper);
  border-radius: var(--radius-md);
  aspect-ratio: 1;
  font-size: 36px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(80, 60, 140, 0.15),
              0 6px 12px rgba(80, 60, 140, 0.12);
  transition: transform 120ms ease, box-shadow 120ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(80, 60, 140, 0.15),
              0 2px 6px rgba(80, 60, 140, 0.12);
}

.action.is-pulse {
  animation: nudge 1.2s ease-in-out infinite;
}

@keyframes nudge {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

.action__icon {
  line-height: 1;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.1));
}

.action__icon img {
  width: 64%;
  height: 64%;
  object-fit: contain;
  display: block;
}

/* ─── Mood-driven background tint (Phase 3 hook) ──────────── */

body.mood-happy { /* default */ }
body.mood-sad   {
  background:
    radial-gradient(ellipse at top, #8d99b5 0%, transparent 60%),
    linear-gradient(180deg, #6b7a99 0%, #8da3c0 65%, #b3c4dc 100%);
}
body.mood-sleepy {
  background:
    radial-gradient(ellipse at top, #2d2350 0%, transparent 60%),
    linear-gradient(180deg, #1f1a3a 0%, #463b73 65%, #7a6cab 100%);
}
