/* ——— The East Wing (js/wing.js) ———
   Everything here starts with ew- (js/castle-wing.js draws the wing on the
   palace map, js/wing-decor.js the rooms' features; the wallpapers and floors
   are made from their drawings by ensureDecorCSS). */

/* ——— Room features: a drawing over the whole room ——— */

.feature.ew-feat { inset: 0; width: 100%; height: 100%; overflow: visible; }
.ew-fire { transform-box: fill-box; transform-origin: 50% 100%; animation: ew-flicker 0.7s ease-in-out infinite alternate; }
.room.mini .ew-fire { animation: none; }
@keyframes ew-flicker { from { transform: scale(1, 1); } to { transform: scale(1.06, 0.9); } }

/* ——— The wing on the palace map ——— */

.ew-wing { position: relative; z-index: 1; max-width: 980px; margin: 0 auto; }
.pl-imm .ew-wing { width: min(100%, 980px, max(600px, 90dvh)); }
.ew-roof { position: relative; display: block; width: 100%; height: auto; margin-bottom: -4px; overflow: visible; }
/* The castle's lawn carries on down to the wing (behind its roof), path and all. */
.ew-grounds { position: absolute; top: 0; left: -12px; width: calc(100% + 24px); height: auto; aspect-ratio: 1000 / 190; }
.lp-night .ew-grounds { filter: brightness(0.78) saturate(0.85); }
.ew-body {
  background:
    repeating-linear-gradient(0deg, transparent 0 26px, rgba(150, 120, 210, 0.14) 26px 28px),
    repeating-linear-gradient(90deg, transparent 0 54px, rgba(150, 120, 210, 0.1) 54px 56px),
    linear-gradient(#f3ecff, #e4d8fb);
  box-shadow: 0 10px 0 #d3c3f2, var(--shadow);
}
.castle-body.ew-body::before { display: none; }
.ew-lawn { display: block; width: calc(100% + 24px); height: clamp(36px, 7vw, 72px); margin: 10px -12px 0; }
.lp-night .ew-lawn { filter: brightness(0.78) saturate(0.85); }
.ew-pond, .ew-spire, .ew-lights, .ew-dome { transform-box: fill-box; }

/* An empty spot: more rooms are coming. */
.ew-soon { opacity: 0.85; }
.ew-soon-door {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  border: 3px dashed #cdb8f5;
  border-radius: 14px;
  background:
    radial-gradient(circle at 30% 30%, #fff 0 4%, transparent 5%),
    radial-gradient(circle at 72% 64%, #fff 0 3%, transparent 4%),
    linear-gradient(135deg, #f6f0ff, #e6f7ff);
}
.ew-soon-door span { font-size: clamp(22px, 4vw, 38px); animation: lp-twinkle 1.6s ease-in-out infinite alternate; }

/* A wing room's lock: its key (10 ⭐ in a world) and its gems. */
.ew-keybadge {
  position: absolute;
  top: -8px;
  right: -8px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6c4, #ffc53d 70%);
  box-shadow: 0 3px 0 var(--gold-deep), 0 0 12px rgba(255, 200, 60, 0.7);
  font-size: 17px;
  pointer-events: none;
}
.ew-keybadge.ew-fresh { animation: ew-key-pop 1.2s var(--bounce) 0.9s both, ew-key-glow 1.4s ease-in-out 2.1s 3 alternate; }
@keyframes ew-key-pop { 0% { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.35) rotate(10deg); } 100% { transform: none; } }
@keyframes ew-key-glow { to { box-shadow: 0 3px 0 var(--gold-deep), 0 0 26px #ffd54d; } }

.ew-needs { display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.ew-need {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px 6px;
  padding: 3px 8px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #f2e9f0;
  color: #7a5f78;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}
.ew-need b { padding: 0 6px; border-radius: 999px; background: #fff; color: var(--ink); }
.ew-need.done { background: linear-gradient(180deg, #fff3c2, #ffe08a); color: #6b4300; }
.ew-keyed.next .lock-overlay { background: rgba(250, 244, 255, 0.5); }

/* ——— Sky: shooting stars (a blimp in Speedy Town) ——— */

.ew-sky { position: absolute; inset: 0 0 auto; height: 40%; z-index: 0; pointer-events: none; }
.ew-shoot { position: absolute; width: clamp(50px, 9vw, 100px); opacity: 0; animation: ew-shoot 6s ease-in infinite; }
.ew-shoot svg, .ew-blimp svg { display: block; width: 100%; height: auto; }
@keyframes ew-shoot {
  0% { opacity: 0; transform: translate(0, 0); }
  8% { opacity: 1; }
  30% { opacity: 0; transform: translate(-120px, 40px); }
  100% { opacity: 0; transform: translate(-120px, 40px); }
}
.ew-blimp { position: absolute; left: 62%; top: 9%; width: clamp(70px, 12vw, 130px); animation: ew-blimp 14s ease-in-out infinite alternate; }
@keyframes ew-blimp { from { transform: translateX(0); } to { transform: translateX(-24vw); } }

/* ——— The wing rooms' own treasures (js/art-wing.js): tap reactions ———
   bubbles, sway, shimmer, mail, and slide (REACTIONS in js/living.js). */

.ew-bub { transform-box: fill-box; transform-origin: 50% 50%; }
.lp-rx-bubbles .ew-bub { animation: ew-bubble 2s ease-out both; }
.ew-sway { transform-box: fill-box; transform-origin: 50% 0; }
.lp-rx-sway .ew-sway { animation: ew-sway 0.42s ease-in-out 4 alternate; }
.lp-rx-shimmer .ew-beam { animation: lp-lights 2.4s ease-in-out both; }
.ew-glint { transform-box: fill-box; transform-origin: 50% 50%; }
.lp-rx-shimmer .ew-glint { animation: ew-glint 1.1s ease-in-out 2 both; }
.ew-aurora { transform-box: fill-box; transform-origin: 50% 50%; }
.lp-rx-shimmer .ew-aurora { animation: ew-aurora 2.4s ease-in-out; }
.room-items .room-item.lp-rx-shimmer > span { animation: ew-shine 2.4s ease-in-out; }
.ew-flag { transform-box: view-box; }
.lp-rx-mail .ew-flag { animation: ew-flagup 1.9s var(--bounce) both; }
.ew-letter { transform-box: fill-box; transform-origin: 50% 100%; }
.lp-rx-mail .ew-letter { animation: ew-letter 1.9s ease-out both; }
.room-items .room-item.lp-rx-slide > span { animation: ew-slide 1.4s ease-in-out; }
@keyframes ew-bubble { 0% { opacity: 0; transform: translateY(0) scale(0.4); } 20%, 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-360%) scale(1.15); } }
@keyframes ew-sway { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
@keyframes ew-glint { 0%, 100% { opacity: 0; transform: scale(0.2); } 50% { opacity: 1; transform: scale(1.2) rotate(45deg); } }
@keyframes ew-aurora { 0%, 100% { transform: none; opacity: 1; } 30% { transform: translateX(-4%) skewX(-6deg); opacity: 0.6; } 65% { transform: translateX(4%) skewX(6deg); } }
@keyframes ew-shine { 0%, 100% { filter: none; } 40% { filter: brightness(1.12) drop-shadow(0 0 1.2cqw #fff6c4); } }
@keyframes ew-flagup { 0%, 100% { transform: rotate(90deg); } 25%, 75% { transform: rotate(0deg); } }
@keyframes ew-letter { 0% { opacity: 0; transform: translateY(40%) scale(0.6); } 30%, 75% { opacity: 1; transform: translateY(-30%) scale(1); } 100% { opacity: 0; transform: translateY(-60%); } }
@keyframes ew-slide { 0%, 100% { transform: none; } 30% { transform: translateX(8%); } 60% { transform: translateX(-5%); } 80% { transform: translateX(2%); } }

/* ——— The shop: a room's shelf before the room is open (js/screens/shop.js) ——— */

.tab.ew-locktab:not(.active) { background: repeating-linear-gradient(135deg, #fff 0 10px, #f6f0ff 10px 20px); color: var(--ink-soft); }
.ew-shelflock {
  grid-column: 1 / -1;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 22px 18px 24px;
  border: 3px dashed #cdb8f5;
  border-radius: 22px;
  background: linear-gradient(180deg, #fbf8ff, #eef7ff);
  text-align: center;
}
.ew-shelflock-title { margin: 0; font-size: clamp(18px, 2.6vw, 24px); font-weight: 700; color: var(--ink); }
.ew-shelflock-text { margin: 0; font-size: 16px; color: var(--ink-soft); }
.ew-peek { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 6px 0; }
.ew-peek-item {
  display: grid;
  place-items: center;
  width: clamp(72px, 14vw, 110px);
  aspect-ratio: 1;
  padding: 8px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 4px 0 #e6dcf7;
  filter: saturate(0.55) opacity(0.75);
}
.ew-peek-item.legend { background: radial-gradient(circle at 50% 40%, #fff 0 38%, #ffe7a3 100%); }
.ew-peek-item .t-icon, .ew-peek-item svg { display: block; width: 100%; height: 100%; }

@media (max-width: 640px) {
  .ew-grounds { left: -6px; width: calc(100% + 12px); }
  .ew-need { padding: 2px 5px; font-size: 10px; gap: 1px 4px; }
  .ew-need b { padding: 0 4px; }
  .ew-keybadge { width: 26px; height: 26px; font-size: 13px; top: -6px; right: -6px; }
}

@media (prefers-reduced-motion: reduce) {
  .ew-fire, .ew-shoot, .ew-blimp, .ew-soon-door span, .ew-keybadge.ew-fresh { animation: none; }
  .lp-rx-sway .ew-sway, .lp-rx-shimmer .ew-aurora, .room-items .room-item.lp-rx-slide > span { animation: none; }
  .ew-shoot { opacity: 1; }
}

/* ——— Drawn Legendary treasures in a room ———
   The Flower Garden's key is a .legend too (css/styles.css, later than
   .room-item), which shrinks a Legendary treasure in a room to 17px. A drawn
   one (the East Side's centerpieces) gets the room's own size back. The emoji
   Legendaries are left as they are, so rooms already decorated don't change. */
.room-item.legend.drawn { display: block; gap: 0; margin: 0; font-size: calc(8cqw * var(--s, 1)); }
