/* =========================================================
   Casa Mágica — cômodo explorável e tela da casa
   O bloco do cômodo (.room) também é usado pela prévia do painel
   administrativo, que não carrega os tokens do jogo: por isso toda
   variável aqui tem um valor de reserva.
   ========================================================= */

.room {
  position: absolute;
  inset: 0;
  overflow: hidden;
  container-type: size;
  /* As camadas internas (objetos, pet, fala) não vazam para a página. */
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  --pet-x-n: 45;
  --pet-y-n: 72;
  --pet-size-n: 34;
  font-family: var(--font-display, 'Fredoka', system-ui, sans-serif);
}

.room__bg { position: absolute; inset: 0; }
.room__bg--image { background-size: cover; background-position: center; }

/* Cenário desenhado: parede com estrelinhas, rodapé e piso de tábuas. */
.room-scenery { position: absolute; inset: 0; --floor-line: 61%; }
.room-scenery > div { position: absolute; left: 0; right: 0; }
.room-scenery__wall {
  top: 0;
  bottom: calc(100% - var(--floor-line));
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='46' height='46'%3E%3Cpath d='M23 19.8 L24 22 L26.4 22.3 L24.6 23.9 L25.1 26.3 L23 25.1 L20.9 26.3 L21.4 23.9 L19.6 22.3 L22 22 Z' fill='white' fill-opacity='0.06'/%3E%3C/svg%3E"),
    linear-gradient(rgba(255, 255, 255, var(--daylight)), rgba(255, 255, 255, var(--daylight))),
    linear-gradient(180deg, var(--wall-top), var(--wall-bottom));
}
.room-scenery__floor {
  top: var(--floor-line);
  bottom: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 58px, rgba(0, 0, 0, 0.18) 58px 61px),
    linear-gradient(180deg, var(--floor-top), var(--floor-bottom));
}
.room-scenery__trim {
  top: calc(var(--floor-line) - 8px);
  height: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12) 0 2px, var(--trim) 2px);
}
.room-scenery__glow {
  inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 50% 58%, var(--glow), transparent 70%),
    linear-gradient(rgba(4, 12, 20, var(--shade)), rgba(4, 12, 20, var(--shade)));
}
.room__objects { position: absolute; inset: 0; }

/* ---------- objetos ---------- */
.room__obj {
  position: absolute;
  padding: 0;
  margin: 0;
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  border-radius: 14px;
  transform: translateX(var(--drag-x, 0px));
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), filter 0.4s linear;
  -webkit-tap-highlight-color: transparent;
}
.room__obj:focus-visible { outline: 3px solid #3ddc97; outline-offset: 3px; }
.room__obj.is-dragging { transition: none; }
/*
 * O toque vale só onde o objeto está desenhado: a caixa de cada objeto tem
 * áreas transparentes (acima do colchão, em volta das folhas) que, se
 * recebessem o toque, esconderiam o objeto vizinho atrás. Imagens enviadas
 * pelo painel continuam tocáveis na caixa inteira.
 */
.room__obj { pointer-events: none; }
.room__obj-art { position: absolute; inset: 0; display: block; pointer-events: none; transform-origin: 50% 100%; }
.room__obj-art > svg :is(path, rect, circle, ellipse, polygon, text) { pointer-events: visiblePainted; }
.room__obj-art > svg .art-glow { pointer-events: none; }
.room__obj-art > img { pointer-events: auto; }
.room--editable .room__obj { pointer-events: auto; }
.room__obj-art > svg, .room__obj-art > img { width: 100%; height: 100%; display: block; overflow: visible; object-fit: contain; object-position: 50% 100%; }
.room__obj.is-flipped .room__obj-art { transform: scaleX(-1); }

/* Estados que ficam: luminária acesa, almofada afastada. */
.room__obj--lamp.is-on { filter: drop-shadow(0 0 16px rgba(253, 224, 71, 0.65)); }
.room__obj--chest.is-on { filter: drop-shadow(0 0 14px rgba(253, 230, 138, 0.55)); }
.room__obj .art-slide { transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1); }
.room__obj.is-on .art-slide { transform: translateX(46px); }
.room__obj .art-under { opacity: 0; transition: opacity 0.4s linear 0.15s; }
.room__obj.is-on .art-under { opacity: 1; }
.room__obj .art-leaves { transform-box: view-box; }

/* Animações de cada interação (classe `is-playing` dura ~0,9 s). */
.room__obj.is-playing.anim-bounce .room__obj-art { animation: obj-bounce 0.8s cubic-bezier(0.22, 1, 0.36, 1); }
.room__obj.is-playing.anim-wiggle .room__obj-art { animation: obj-wiggle 0.7s ease-in-out; }
.room__obj.is-playing.anim-spin .room__obj-art { animation: obj-spin 0.8s ease-in-out; transform-origin: 50% 50%; }
.room__obj.is-playing.anim-sway .art-leaves { animation: obj-sway 0.9s ease-in-out; }
.room__obj.is-playing.anim-sway .room__obj-art > img { animation: obj-wiggle 0.9s ease-in-out; }
.room__obj.is-playing.anim-light .room__obj-art,
.room__obj.is-playing.anim-window .room__obj-art { animation: obj-flash 0.7s ease-out; }
.room__obj.is-playing.anim-open .room__obj-art { animation: obj-pop 0.6s cubic-bezier(0.22, 1, 0.36, 1); }
.room__obj.is-playing.anim-swap .room__obj-art { animation: obj-swap 0.6s ease-in-out; }
.room__obj.is-playing.anim-slide .room__obj-art { animation: obj-pop 0.5s ease-out; }

@keyframes obj-bounce {
  0% { transform: scale(1, 1); }
  25% { transform: scale(1.12, 0.86); }
  55% { transform: translateY(-14%) scale(0.94, 1.08); }
  80% { transform: scale(1.04, 0.96); }
  100% { transform: none; }
}
@keyframes obj-wiggle { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-6deg); } 45% { transform: rotate(5deg); } 70% { transform: rotate(-3deg); } }
@keyframes obj-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes obj-sway { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-9deg); } 55% { transform: rotate(7deg); } 80% { transform: rotate(-3deg); } }
@keyframes obj-flash { 0% { filter: brightness(1); } 30% { filter: brightness(1.6) saturate(1.3); } 100% { filter: brightness(1); } }
@keyframes obj-pop { 0% { transform: scale(1); } 40% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes obj-swap { 0% { transform: scaleX(1); } 50% { transform: scaleX(0.05); } 100% { transform: scaleX(1); } }

/* Dica: um brilho pulsando em volta de algo que ainda esconde um segredo. */
.room__obj.is-hinting::after {
  content: '';
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  border: 3px solid rgba(250, 204, 21, 0.85);
  box-shadow: 0 0 22px rgba(250, 204, 21, 0.55);
  animation: obj-hint 1.3s ease-in-out infinite;
  pointer-events: none;
}
@keyframes obj-hint { 0%, 100% { opacity: 0.25; transform: scale(0.92); } 50% { opacity: 1; transform: scale(1.04); } }

/* Selinho do segredo já encontrado. */
.room__badge {
  position: absolute;
  top: -10px;
  right: -4px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-size: 16px;
  border-radius: 50%;
  background: rgba(10, 40, 48, 0.88);
  border: 2px solid #3ddc97;
  box-shadow: 0 0 12px rgba(61, 220, 151, 0.55);
  pointer-events: none;
}
.room__badge[hidden] { display: none; }
.room__badge.is-new { animation: badge-pop 0.6s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes badge-pop { 0% { transform: scale(0); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* ---------- pet ---------- */
.room__pet {
  position: absolute;
  z-index: 55;
  width: calc(var(--pet-size-n) * 1cqw);
  aspect-ratio: 344 / 412;
  left: calc(var(--pet-x-n) * 1cqw - var(--pet-size-n) * 0.5cqw);
  bottom: calc((100 - var(--pet-y-n)) * 1cqh);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform-origin: 50% 100%;
  transition: left 0.75s cubic-bezier(0.22, 1, 0.36, 1);
  -webkit-tap-highlight-color: transparent;
  pointer-events: none;
}
.room__pet-hit { position: absolute; left: 22%; right: 22%; top: 42%; bottom: 8%; border-radius: 45%; pointer-events: auto; }
.room__pet:focus-visible { outline: 3px solid #3ddc97; outline-offset: 2px; border-radius: 24px; }
.room__pet-art { width: 100%; height: 100%; transform-origin: 50% 90%; animation: room-breathe 4.2s ease-in-out infinite; pointer-events: none; }
.room__pet-art > svg { width: 100%; height: 100%; display: block; overflow: visible; transition: transform 0.3s linear; }
.room__pet.is-facing-left .room__pet-art > svg { transform: scaleX(-1); }
.room__pet.is-asleep .room__pet-art { animation: room-sleep 5s ease-in-out infinite; }

@keyframes room-breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.025, 0.975); } }
@keyframes room-sleep { 0%, 100% { transform: scale(1.02, 0.96); } 50% { transform: scale(1.05, 0.93); } }

.room__pet.react-happy { animation: pet-react-happy 0.9s ease-in-out; }
.room__pet.react-jump { animation: pet-react-jump 0.9s cubic-bezier(0.22, 1, 0.36, 1); }
.room__pet.react-play { animation: pet-react-play 1s ease-in-out; }
.room__pet.react-spin { animation: pet-react-spin 0.9s ease-in-out; }
.room__pet.react-look { animation: pet-react-look 1s ease-in-out; }
.room__pet.react-sleep { animation: pet-react-sleep 2s ease-in-out; }

@keyframes pet-react-happy { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-7deg) scale(1.04); } 45% { transform: rotate(6deg) scale(1.04); } 70% { transform: rotate(-3deg); } }
@keyframes pet-react-jump { 0%, 100% { transform: none; } 20% { transform: scale(1.1, 0.88); } 50% { transform: translateY(-22%) scale(0.95, 1.06); } 80% { transform: scale(1.05, 0.95); } }
@keyframes pet-react-play { 0%, 100% { transform: none; } 25% { transform: translateY(-10%) rotate(-10deg); } 50% { transform: rotate(10deg); } 75% { transform: translateY(-8%) rotate(-6deg); } }
@keyframes pet-react-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes pet-react-look { 0%, 100% { transform: none; } 30%, 70% { transform: rotate(-8deg) translateY(-3%); } }
@keyframes pet-react-sleep { 0%, 100% { transform: none; } 25%, 75% { transform: scale(1.05, 0.9); } }

/* ---------- fala ---------- */
.room__speech {
  position: absolute;
  z-index: 300;
  left: clamp(3cqw, calc(var(--pet-x-n) * 1cqw + var(--pet-size-n) * 0.18cqw), 54cqw);
  bottom: calc((100 - var(--pet-y-n)) * 1cqh + var(--pet-size-n) * 1.08cqw);
  max-width: 44cqw;
  padding: 9px 14px;
  border-radius: 18px 18px 18px 6px;
  background: rgba(14, 44, 54, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #f4f6ff;
  font-size: clamp(0.8rem, 3.6cqw, 1.05rem);
  line-height: 1.25;
  box-shadow: 0 12px 26px -12px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transform: translateY(6px) scale(0.92);
  transform-origin: 10% 100%;
  transition: opacity 0.25s linear, transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}
.room__speech.is-visible { opacity: 1; transform: none; }

/* ---------- bolha "Novo!" ---------- */
.room__reveal {
  position: absolute;
  z-index: 310;
  display: grid;
  justify-items: center;
  gap: 4px;
  transform: translate(-50%, -100%);
  animation: reveal-in 0.55s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  transition: opacity 0.45s linear, transform 0.45s ease-in;
}
.room__reveal.is-leaving { opacity: 0; transform: translate(-50%, -80%) scale(0.5); }
.room__reveal-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  font-size: 32px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(61, 220, 151, 0.4), rgba(10, 40, 48, 0.92));
  border: 3px solid #3ddc97;
  box-shadow: 0 0 26px rgba(61, 220, 151, 0.7);
}
.room__reveal-tag {
  position: absolute;
  top: -8px;
  right: -34px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #d9fbe8;
  color: #0b3b2b;
  font-size: 0.8rem;
  font-weight: 700;
}
.room__reveal-reward {
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(10, 40, 48, 0.92);
  border: 1px solid rgba(250, 204, 21, 0.7);
  color: #fef3c7;
  font-size: 0.78rem;
  white-space: nowrap;
}
@keyframes reveal-in { 0% { opacity: 0; transform: translate(-50%, -40%) scale(0.4); } 100% { opacity: 1; transform: translate(-50%, -100%) scale(1); } }

/* ---------- partículas ---------- */
.room__fx { position: absolute; inset: 0; z-index: 320; pointer-events: none; }
.fx-glyph, .fx-bubble, .fx-confetti, .fx-glow { position: absolute; pointer-events: none; }
.fx-glyph { font-size: 20px; color: #fde68a; text-shadow: 0 0 8px rgba(253, 224, 71, 0.8); animation: fx-fly 1.1s ease-out forwards; }
.fx-glyph--sparkles { color: #ecfccb; }
.fx-glyph--stars { color: #fde047; }
.fx-glyph--zzz { color: #c7d2fe; font-weight: 700; text-shadow: none; }
.fx-bubble { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(186, 230, 253, 0.9); background: rgba(186, 230, 253, 0.2); animation: fx-fly 1.2s ease-out forwards; }
.fx-confetti { width: 8px; height: 12px; border-radius: 2px; animation: fx-fly 1.1s ease-out forwards; }
.fx-glow {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid rgba(250, 250, 210, 0.9);
  box-shadow: 0 0 30px rgba(253, 224, 71, 0.7);
  transform: translate(-50%, -50%);
  animation: fx-glow 1.1s ease-out forwards;
}
@keyframes fx-fly {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, -40px))) scale(1.15) rotate(40deg); }
}
@keyframes fx-glow { 0% { opacity: 1; transform: translate(-50%, -50%) scale(0.4); } 100% { opacity: 0; transform: translate(-50%, -50%) scale(3.4); } }

/* ---------- modo de edição (painel) ---------- */
.room--editable .room__obj { outline: 1px dashed rgba(255, 255, 255, 0.45); cursor: move; touch-action: none; }
.room--editable .room__obj.is-selected { outline: 3px solid #facc15; outline-offset: 1px; }
.room--editable .room__pet { pointer-events: none; opacity: 0.85; }

@media (prefers-reduced-motion: reduce) {
  .room__pet-art, .room__pet, .room__obj-art, .room__obj.is-hinting::after, .room__reveal { animation: none !important; }
  .room__pet { transition: none; }
}

/* Cor arco-íris: o pet troca de cor devagar (desligado para quem prefere menos movimento). */
.pet-svg--rainbow { animation: pet-rainbow 6s linear infinite; }
@keyframes pet-rainbow { from { filter: hue-rotate(0deg); } to { filter: hue-rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .pet-svg--rainbow { animation: none; filter: hue-rotate(90deg); } }

/* =========================================================
   Tela da casa
   ========================================================= */
.house-shell { gap: 8px; }

/* Barra do topo: voltar · cômodo e humor · carteira, numa linha só. */
.house-bar {
  position: relative;
  z-index: 3;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 5px 8px 5px 5px;
  border-radius: var(--r-pill);
}
.house-bar__back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  padding: 0 12px 0 8px;
  border: 1px solid var(--glass-border);
  border-radius: var(--r-pill);
  background: var(--glass-surface-strong);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 0.86rem;
  cursor: pointer;
}
.house-bar__back span:first-child { font-size: 1.3rem; line-height: 1; }
.house-bar__back:focus-visible { outline: 2px solid var(--brand-mint); outline-offset: 2px; }
.house-bar__title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.house-bar__room { font-family: var(--font-display); font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.house-bar__mood { font-size: 1.05rem; line-height: 1; }
.house-bar__wallet { display: flex; gap: 4px; flex-shrink: 0; }
.house-bar__coin {
  padding: 4px 9px;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--text-primary) 7%, transparent);
  border: 1px solid var(--glass-border);
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}
.house-bar__coin--common { color: var(--coin-common); }
.house-bar__coin--premium { color: var(--coin-premium); }

/* Objetivo e contador na mesma faixa. */
.house-progress {
  position: relative;
  z-index: 3;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  border-radius: var(--r-md);
}
.house-quest__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.house-quest__title { font-family: var(--font-display); font-size: 0.95rem; line-height: 1.15; }
.house-quest__text { font-size: 0.72rem; color: var(--text-secondary); line-height: 1.2; }
.house-counter { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; width: 96px; }
.house-counter__row { display: flex; align-items: center; gap: 6px; }
.house-counter__icon { font-size: 1.1rem; line-height: 1; }
.house-counter__value { font-family: var(--font-display); font-size: 1.15rem; line-height: 1; font-variant-numeric: tabular-nums; }
.house-counter__track { position: relative; width: 100%; height: 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.house-counter__fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--brand-mint), #6ee7b7); transition: width 0.6s var(--ease-liquid); box-shadow: 0 0 10px rgba(61, 220, 151, 0.7); }
.house-progress.is-complete { border-color: rgba(61, 220, 151, 0.7); box-shadow: var(--shadow-glow-green); }
.house-progress.is-complete .house-counter__icon { animation: badge-pop 0.6s ease-out; }

.house-rooms { display: flex; gap: 6px; overflow-x: auto; flex-shrink: 0; scrollbar-width: none; }
.house-rooms[hidden] { display: none; }
.house-room-tab { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--glass-border); background: var(--glass-surface); color: var(--text-secondary); font-family: var(--font-display); white-space: nowrap; cursor: pointer; }
.house-room-tab.is-active { background: var(--glass-surface-strong); color: var(--text-primary); border-color: rgba(61, 220, 151, 0.6); }
.house-room-tab__done { color: var(--brand-mint); }

.house-stage {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 220px;
  border-radius: var(--r-lg);
  overflow: hidden;
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-soft), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  background: #123b45;
}
.house-loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--text-secondary); }

.house-explore {
  position: relative;
  z-index: 3;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 56px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #86efac, #3ddc97);
  color: #07231a;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  box-shadow: 0 10px 28px -10px rgba(61, 220, 151, 0.9), inset 0 2px 0 rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease-liquid);
}
.house-explore:active { transform: scale(0.97); }
.house-explore:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.house-explore__chev { font-size: 1.6rem; line-height: 1; }

.house-rewards { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.house-reward { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; background: var(--glass-surface-strong); border: 1px solid rgba(250, 204, 21, 0.55); font-family: var(--font-display); }
.house-reward__icon { font-size: 1.3rem; }

/* Telas baixas (ex.: 320×568): o quarto mantém espaço e o botão não encosta na navegação. */
@media (max-height: 640px) {
  .house-shell { gap: 6px; }
  .house-bar { min-height: 42px; }
  .house-bar__back { min-height: 32px; }
  .house-progress { padding: 6px 12px; }
  .house-quest__text { display: none; }
  .house-stage { min-height: 170px; }
  .house-explore { min-height: 46px; font-size: 1.1rem; }
}

@media (max-width: 380px) {
  .house-bar__back span:last-child { display: none; }
  .house-bar__back { padding: 0 10px; }
}
