/* =============================================================
   Klara – utseende
   ============================================================= */

:root {
  --purple: #5b3fa0;
  --bg: #efe4ff;
  --panel: #ffffff;
  --font: 'Baloo 2', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font);
  color: var(--purple);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------- Mätare överst ---------- */

#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 4px solid #e2d4ff;
  z-index: 2;
}

#meters { display: flex; flex: 1; gap: 8px; min-width: 0; }

.meter {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.m-icon { font-size: 24px; line-height: 1.1; }
.m-bar {
  width: 100%;
  max-width: 120px;
  height: 12px;
  background: #ece6f7;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid #d9cdf3;
}
.m-fill { height: 100%; width: 50%; border-radius: 6px; transition: width .3s, background .3s; }
.m-word { font-size: 12px; font-weight: 800; letter-spacing: .5px; line-height: 1.3; }
.meter.low .m-icon { animation: pulse 0.9s ease-in-out infinite; }
.meter.low .m-word { color: #e0304a; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3) rotate(-8deg); }
}

#hud-right { display: flex; gap: 6px; align-items: center; }

#stars {
  border: none;
  background: #fff3b0;
  border: 3px solid #ffd43b;
  border-radius: 999px;
  padding: 2px 12px;
  font-size: 22px;
  font-weight: 800;
  white-space: nowrap;
}
#stars.bump { animation: bump .45s ease; }
@keyframes bump { 50% { transform: scale(1.35); } }

#mute {
  border: 3px solid #e2d4ff;
  background: #fff;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 20px;
  padding: 0;
}

/* ---------- Spelplanen ---------- */

#stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #efe4ff;
}
#stage-wrap[data-scene="walk"] { background: #7ccbff; }

#stage {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  touch-action: none;
}
#stage text { font-family: var(--font); }

/* ---------- Knappar längst ner ---------- */

#buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 4px solid #e2d4ff;
  z-index: 2;
}

.btn {
  flex: 1;
  max-width: 130px;
  min-width: 0;
  min-height: 70px;
  border: none;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 2px;
  color: #fff;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .22);
  transition: transform .08s, box-shadow .08s, opacity .2s;
  -webkit-user-select: none;
  user-select: none;
}
.btn .ic { font-size: 30px; line-height: 1.1; }
.btn .w { font-size: 15px; font-weight: 800; letter-spacing: .5px; text-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.btn:active, .btn.pressed { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0, 0, 0, .22); }
.btn.big { max-width: 260px; flex: 2; }
.btn.big .ic { font-size: 36px; }
.btn.big .w { font-size: 20px; }

.c-orange { background: #ff9a3c; }
.c-blue   { background: #3fa9ff; }
.c-green  { background: #4cc764; }
.c-teal   { background: #2ec4b6; }
.c-purple { background: #9b6fe8; }
.c-pink   { background: #ff6fae; }
.c-yellow { background: #ffbf1f; }

#buttons.busy .btn { opacity: .45; pointer-events: none; }

/* ---------- Meddelande ---------- */

#toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -220%);
  opacity: 0;
  background: #fff;
  border: 4px solid #b48be8;
  border-radius: 20px;
  padding: 6px 20px;
  font-size: 24px;
  font-weight: 800;
  white-space: nowrap;
  max-width: 94%;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 6px 18px rgba(91, 63, 160, .2);
  transition: transform .35s cubic-bezier(.2, 1.4, .4, 1), opacity .25s;
  pointer-events: none;
  z-index: 5;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ---------- Välkommen ---------- */

#welcome {
  position: fixed;
  inset: 0;
  background: rgba(70, 40, 120, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 16px;
}
#welcome[hidden] { display: none; }
.w-card {
  background: #fff;
  border-radius: 28px;
  border: 5px solid #b48be8;
  padding: 16px 28px 24px;
  text-align: center;
  max-width: 420px;
  width: 100%;
  animation: popin .4s cubic-bezier(.2, 1.4, .4, 1);
}
.w-svg { width: 200px; max-width: 60%; height: auto; }
.w-card h1 { margin: 0; font-size: 36px; }
.w-card p { margin: 4px 0 16px; font-size: 24px; font-weight: 600; }
.w-card .btn { margin: 0 auto; width: 180px; }
@keyframes popin { from { transform: scale(.6); opacity: 0; } }

/* ---------- Butik ---------- */

#panel {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 12px;
  z-index: 3;
}
#panel[hidden] { display: none; }

.shop {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  flex-wrap: wrap;
}
.shop-left { display: flex; flex-direction: column; align-items: center; }
.shop-title {
  font-size: 30px;
  font-weight: 800;
  background: #fff;
  border-radius: 999px;
  padding: 0 22px;
  border: 4px solid #ff6fae;
}
.preview {
  position: relative;
  width: 240px;
  max-width: 60vw;
  background: #fff;
  border-radius: 50%;
  aspect-ratio: 1;
  border: 5px solid #e2d4ff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
}
.preview svg { width: 88%; height: auto; }
.p-hearts { position: absolute; inset: 0; pointer-events: none; }
.p-hearts span {
  position: absolute;
  top: 40%;
  font-size: 30px;
  animation: heartup 1.6s ease-out forwards;
  opacity: 0;
}
@keyframes heartup {
  0% { transform: translateY(0) scale(.5); opacity: 0; }
  15% { opacity: 1; transform: translateY(-10px) scale(1); }
  100% { transform: translateY(-120px) scale(1.1); opacity: 0; }
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 130px));
  gap: 10px;
}
.card {
  background: #fff;
  border: 4px solid #e2d4ff;
  border-radius: 20px;
  padding: 6px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 5px 0 #d9cdf3;
  transition: transform .08s;
}
.card:active { transform: translateY(4px); box-shadow: 0 1px 0 #d9cdf3; }
.c-ic { font-size: 40px; line-height: 1.2; }
.c-w { font-size: 14px; font-weight: 800; }
.c-p {
  margin-top: 4px;
  font-size: 16px;
  font-weight: 800;
  background: #fff3b0;
  border-radius: 999px;
  padding: 0 10px;
}
.card.on { border-color: #4cc764; }
.card.on .c-p { background: #4cc764; color: #fff; }
.card.off .c-p { background: #ece6f7; }
.card.cant { opacity: .55; }
.card.shake { animation: shake .4s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* =============================================================
   Animationer i bilden (SVG)
   ============================================================= */

/* Klara */
.klara .tail { animation: wag 1.6s ease-in-out infinite; }
@keyframes wag {
  0%, 100% { transform: rotate(-7deg); }
  50% { transform: rotate(10deg); }
}
.eyes { transform-box: fill-box; transform-origin: center; animation: blink 4.5s infinite; }
@keyframes blink {
  0%, 93%, 100% { transform: scaleY(1); }
  96% { transform: scaleY(.1); }
}
.klara.walking .leg.legA { animation: stepA .32s ease-in-out infinite alternate; }
.klara.walking .leg.legB { animation: stepB .32s ease-in-out infinite alternate; }
@keyframes stepA { from { transform: rotate(-24deg); } to { transform: rotate(24deg); } }
@keyframes stepB { from { transform: rotate(24deg); } to { transform: rotate(-24deg); } }

/* Adele */
.adele.walking .aleg.legA { animation: kstepA .4s ease-in-out infinite alternate; }
.adele.walking .aleg.legB { animation: kstepB .4s ease-in-out infinite alternate; }
.adele.walking .armL { animation: kstepB .4s ease-in-out infinite alternate; }
@keyframes kstepA { from { transform: rotate(-16deg); } to { transform: rotate(16deg); } }
@keyframes kstepB { from { transform: rotate(16deg); } to { transform: rotate(-16deg); } }
.kid-inner.hop { animation: hop .5s ease; }
@keyframes hop { 40% { transform: translateY(-26px); } }
.armL.wave { animation: wave 1.3s ease-in-out; }
@keyframes wave {
  0%, 100% { transform: rotate(0); }
  25%, 55% { transform: rotate(150deg); }
  40%, 70% { transform: rotate(122deg); }
}

/* Mat och vatten */
.tilt { transition: transform .45s ease; }
.tilt.pour-can { transform: rotate(120deg); }
.tilt.pour-jug { transform: rotate(60deg); }
.fall { animation: fall .7s ease-in both; }
@keyframes fall {
  from { transform: translateY(0); opacity: 1; }
  90% { opacity: 1; }
  to { transform: translateY(95px); opacity: 0; }
}
.stream {
  fill: none;
  stroke: #7cd3ff;
  stroke-width: 9;
  stroke-linecap: round;
  animation: streamin .25s ease-out;
}
@keyframes streamin { from { opacity: 0; } }

/* Natt när Klara sover */
.night { fill: #141842; opacity: 0; transition: opacity 1.2s; pointer-events: none; }
.night.on { opacity: .5; }

/* Pratbubbla */
.bubble { animation: bubblein .3s cubic-bezier(.2, 1.4, .4, 1); transform-box: fill-box; transform-origin: center bottom; }
.bubble.urgent { animation: bubblein .3s cubic-bezier(.2, 1.4, .4, 1), wiggle 1s ease-in-out .3s infinite; }
@keyframes bubblein { from { transform: scale(.3); opacity: 0; } }
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-5deg); }
  75% { transform: rotate(5deg); }
}

/* Effekter: hjärtan, stjärnor, Zzz */
.floatup { animation: floatup 1.6s ease-out forwards; }
@keyframes floatup {
  0% { transform: translate(0, 0) scale(.5); opacity: 0; }
  15% { transform: translate(0, -20px) scale(1); opacity: 1; }
  100% { transform: translate(0, -130px) scale(1.1); opacity: 0; }
}
.zzz { animation: zzz 1.7s ease-out forwards; }
@keyframes zzz {
  0% { transform: translate(0, 0) scale(.4); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(40px, -110px) scale(1.2); opacity: 0; }
}

/* Leksaksmusen */
.running .mouse-body { animation: scurry .16s linear infinite alternate; }
@keyframes scurry { from { transform: translateY(0); } to { transform: translateY(-4px); } }

/* Promenad */
.leash { fill: none; stroke: #e0457f; stroke-width: 5; stroke-linecap: round; }
.star-bob { animation: starbob 1.2s ease-in-out infinite alternate; }
@keyframes starbob { from { transform: translateY(0) rotate(-8deg); } to { transform: translateY(-12px) rotate(8deg); } }
.star-got { animation: starget .6s ease-in forwards; }
@keyframes starget { to { transform: translateY(-120px) scale(1.6); opacity: 0; } }
.fly1 { animation: fly1 9s ease-in-out infinite; }
.fly2 { animation: fly2 11s ease-in-out infinite; }
@keyframes fly1 {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-120px, -40px); }
  50% { transform: translate(-60px, 60px); }
  75% { transform: translate(90px, 10px); }
}
@keyframes fly2 {
  0%, 100% { transform: translate(0, 0); }
  30% { transform: translate(140px, 50px); }
  60% { transform: translate(60px, -50px); }
  80% { transform: translate(-60px, 20px); }
}
.wings { transform-box: fill-box; transform-origin: center; animation: flap .25s ease-in-out infinite alternate; }
@keyframes flap { from { transform: scaleX(1); } to { transform: scaleX(.3); } }

/* ---------- Små skärmar ---------- */

@media (max-width: 520px) {
  #hud { padding: 6px 8px; gap: 6px; }
  #meters { gap: 4px; }
  .m-icon { font-size: 20px; }
  .m-word { font-size: 10px; }
  #stars { font-size: 18px; padding: 2px 8px; }
  #mute { width: 38px; height: 38px; font-size: 17px; }
  #buttons { gap: 5px; padding: 6px; }
  .btn { min-height: 60px; border-radius: 16px; }
  .btn .ic { font-size: 24px; }
  .btn .w { font-size: 11px; }
  .shop-grid { grid-template-columns: repeat(3, minmax(80px, 1fr)); gap: 8px; }
  .c-ic { font-size: 32px; }
}

@media (max-height: 500px) {
  .m-icon { font-size: 18px; }
  .btn { min-height: 54px; }
  .btn .ic { font-size: 22px; }
  .preview { width: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  .klara .tail, .eyes, .star-bob, .fly1, .fly2, .wings { animation: none; }
}
