/* La Casa: page + HUD (DESIGN.md §7.7). Soft white translucent rounded Wii-style controls. */
:root {
  --cream: #fbf6ec;
  --plaster: #f6eede;
  --ink: #3b3444;
  --ink-soft: #7a7282;
  --accent: #3fa9de;        /* Wii-ish soft blue */
  --accent-soft: #bfe3f5;
  --pill: rgba(255, 255, 255, 0.82);
  --pill-strong: rgba(255, 255, 255, 0.94);
  --ring: rgba(120, 170, 200, 0.45);
  --shadow: 0 10px 28px -12px rgba(40, 30, 60, 0.45), 0 2px 6px -2px rgba(40, 30, 60, 0.18);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --gap: 12px;
  --ui-font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --hand-font: 'Caveat', 'Comic Sans MS', cursive;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--plaster);
  color: var(--ink);
  font-family: var(--ui-font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
  outline: none;
  cursor: grab;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}
/* Containers never take pointers; only .hud-btn does, and only while visible (see mode rules). */
.caption, .actions, .toasts, .toast, .status, .bursts, .burst, .hints { pointer-events: none; }

.hud-btn {
  pointer-events: auto;
  appearance: none;
  border: 0;
  margin: 0;
  font: inherit;
  color: var(--ink);
  background: var(--pill);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow), inset 0 0 0 2px var(--ring);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.18s cubic-bezier(.2, 1.4, .4, 1), opacity 0.3s ease, background 0.2s ease, visibility 0.3s;
}
.hud-btn:hover { background: var(--pill-strong); }
.hud-btn:active { transform: scale(0.92); }
.hud-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.hud-btn svg { width: 26px; height: 26px; display: block; }

/* Arrows: vertically centred on the screen edges (one-handed in portrait). */
.arrow {
  position: absolute;
  top: 50%;
  width: 54px;
  height: 54px;
  margin-top: -27px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--accent);
}
.arrow-left { left: calc(var(--safe-l) + 10px); }
.arrow-right { right: calc(var(--safe-r) + 10px); }
.arrow-right svg { transform: scaleX(-1); }
.arrow:active { transform: scale(0.88); }

/* Back: top-left, below the notch. */
.back {
  position: absolute;
  top: calc(var(--safe-t) + var(--gap));
  left: calc(var(--safe-l) + var(--gap));
  height: 52px;
  min-width: 52px;
  padding: 0 16px 0 10px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
}
.back-lbl { display: flex; flex-direction: column; line-height: 1.05; text-align: left; color: var(--ink); }
.back-lbl b { font-weight: 800; font-size: 0.98rem; }
.back-lbl small { font-size: 0.7rem; color: var(--ink-soft); font-weight: 600; }

/* Caption: top-centre while focused. */
.caption {
  position: absolute;
  top: calc(var(--safe-t) + var(--gap) + 4px);
  left: 50%;
  max-width: calc(100% - 2 * (var(--gap) + 150px));
  min-width: 0;
  transform: translate(-50%, -8px);
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--pill);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
  text-align: center;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
}
.caption b { font-weight: 800; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.caption small { font-size: 0.74rem; color: var(--ink-soft); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) {
  .caption { left: auto; right: calc(var(--safe-r) + var(--gap)); max-width: calc(100% - var(--safe-l) - var(--safe-r) - 3 * var(--gap) - 130px); transform: translateY(-8px); }
}
.is-focus .caption.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition: opacity 0.35s ease 0.25s, transform 0.4s cubic-bezier(.2, 1.4, .4, 1) 0.25s, visibility 0s linear 0s; }
@media (max-width: 520px) {
  .is-focus .caption.show { transform: translateY(0); }
}

/* Action bar: bottom-centre above the safe area, big round buttons. */
.actions {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 18px);
  transform: translate(-50%, 16px);
  display: flex;
  gap: 18px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
}
.is-focus .actions.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition: opacity 0.35s ease 0.35s, transform 0.45s cubic-bezier(.2, 1.4, .4, 1) 0.35s, visibility 0s linear 0s; }
.action {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0;
}
.action .ico { font-size: 1.9rem; line-height: 1; }
.action .lbl { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.01em; max-width: 70px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.action:disabled { opacity: 0.45; cursor: default; filter: grayscale(0.5); }
.action:disabled:active { transform: none; }
.action.pop { animation: pop 0.35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 0% { transform: scale(0.86); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }

/* Toasts: top, Italian bold + English small. */
.toasts {
  position: absolute;
  top: calc(var(--safe-t) + var(--gap));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px - var(--safe-l) - var(--safe-r));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: top 0.3s ease;
}
.is-focus .toasts { top: calc(var(--safe-t) + var(--gap) + 66px); }
@media (max-width: 520px) {
  .is-focus .toasts { top: calc(var(--safe-t) + var(--gap) + 60px); }
}
.toast {
  background: var(--pill-strong);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: 22px;
  padding: 9px 18px 10px;
  box-shadow: var(--shadow), inset 0 0 0 1.5px var(--ring);
  text-align: center;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  max-width: 100%;
  opacity: 0;
  transform: translateY(-14px) scale(0.96);
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(.2, 1.4, .4, 1);
}
.toast.show { opacity: 1; transform: none; }
.toast.swap { animation: toast-swap 0.32s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes toast-swap { 0% { opacity: 0.35; transform: scale(0.92); } 100% { opacity: 1; transform: none; } }
.toast .it { font-weight: 800; font-size: 1rem; color: var(--ink); }
.toast .en { font-weight: 600; font-size: 0.78rem; color: var(--ink-soft); margin-top: 1px; }

/* Status pill: bottom-left at home. */
.status {
  position: absolute;
  left: calc(var(--safe-l) + var(--gap));
  bottom: calc(var(--safe-b) + var(--gap));
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 11px;
  border-radius: 999px;
  background: var(--pill);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0s linear 0.4s;
}
.status .who { color: var(--ink-soft); font-weight: 700; }
.status .ico { font-size: 1rem; line-height: 1; }
.status .temp { color: var(--ink); font-weight: 800; }
.status.show { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }

/* Sound toggle: bottom-right in both modes, clear of the centred action bar, the status pill
   (bottom-left) and the mid-height arrows. 40 px circle, 52 px hit area via ::before. */
.sound {
  position: absolute;
  right: calc(var(--safe-r) + var(--gap));
  bottom: calc(var(--safe-b) + var(--gap));
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--accent);
}
.sound::before { content: ''; position: absolute; inset: -6px; border-radius: 50%; }
.hud-btn.sound svg { width: 22px; height: 22px; pointer-events: none; }
.sound.off { color: var(--ink-soft); }

/* Mode visibility: arrows/status at home, back in focus. */
.back { opacity: 0; visibility: hidden; transform: translateX(-10px); pointer-events: none; }
.is-focus .back { opacity: 1; visibility: visible; transform: none; pointer-events: auto; transition-delay: 0.2s; }
.is-focus .arrow { opacity: 0; visibility: hidden; pointer-events: none; }
.is-focus .status.show { opacity: 0; visibility: hidden; }

/* Emoji bursts */
.bursts { position: absolute; inset: 0; overflow: hidden; }
.burst {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 26px;
  line-height: 1;
  margin: -13px 0 0 -13px;
  opacity: 0;
  will-change: transform, opacity;
  animation: burst-up 1.2s cubic-bezier(.2, .7, .3, 1) forwards;
}
@keyframes burst-up {
  0% { opacity: 0; transform: translate(0, 0) scale(calc(var(--s, 1) * 0.3)) rotate(0deg); }
  15% { opacity: 1; transform: translate(calc(var(--dx, 0px) * 0.2), calc(var(--dy, -100px) * 0.2)) scale(var(--s, 1)) rotate(calc(var(--rot, 0deg) * 0.3)); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx, 0px), var(--dy, -100px)) scale(calc(var(--s, 1) * 0.9)) rotate(var(--rot, 0deg)); }
}

/* Tap hints: 9 px warm dot + a thin ring pulse; the 40 px button is the (invisible) hit area. */
.hints { position: absolute; inset: 0; overflow: hidden; opacity: 0; visibility: hidden; transition: opacity 0.45s ease, visibility 0s linear 0.45s; }
.hints.show { opacity: 1; visibility: visible; transition: opacity 0.9s ease, visibility 0s linear 0s; }
.hint {
  position: absolute; left: 0; top: 0; width: 40px; height: 40px; margin: -20px 0 0 -20px; padding: 0;
  border: 0; background: transparent; appearance: none; cursor: pointer; touch-action: none;
  pointer-events: auto; -webkit-tap-highlight-color: transparent; transition: opacity 0.4s ease;
}
.hint.off { opacity: 0; visibility: hidden; pointer-events: none; transition: none; }
.hint::before, .hint::after { content: ''; position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; }
.hint::before { background: #fffaf0; box-shadow: 0 0 0 1px rgba(70, 45, 30, 0.22), 0 1px 5px rgba(25, 15, 10, 0.55); }
.hint::after { border: 1.5px solid rgba(255, 255, 255, 0.9); box-sizing: border-box; opacity: 0; animation: hint-ring 2.6s ease-out var(--delay, 0s) infinite; }
.hint.calm { opacity: 0.55; }
.hint.calm::after { animation: none; }
.hint:focus-visible { outline: 2px solid var(--accent); outline-offset: -6px; border-radius: 50%; }
@keyframes hint-ring {
  0% { transform: scale(1); opacity: 0.85; }
  45%, 100% { transform: scale(2.9); opacity: 0; }
}

/* ---------- Loading ---------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--cream);
  transition: opacity 0.8s ease, visibility 0s linear 0.8s;
}
#loading.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-inner { display: flex; flex-direction: column; align-items: center; }
.loading-house { width: 84px; height: 84px; animation: hop 1.1s cubic-bezier(.3, 0, .4, 1) infinite; transform-origin: 50% 100%; }
.loading-heart { animation: beat 1.1s ease-in-out infinite; transform-origin: 26.5px 42px; transform-box: view-box; }
.loading-shadow { width: 58px; height: 9px; margin-top: 2px; border-radius: 50%; background: rgba(90, 58, 38, 0.18); animation: squash 1.1s cubic-bezier(.3, 0, .4, 1) infinite; }
.loading-msg { margin: 18px 0 0; display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 24px; }
.loading-msg .it { font-family: var(--hand-font); font-size: 2.1rem; font-weight: 700; color: #7a4e2e; }
.loading-msg .en { font-size: 0.85rem; color: var(--ink-soft); font-weight: 600; margin-top: 4px; }
#loading.fatal .loading-house, #loading.fatal .loading-shadow { animation: none; }
@keyframes hop {
  0%, 100% { transform: translateY(0) scale(1.04, 0.96); }
  15% { transform: translateY(0) scale(1, 1); }
  45% { transform: translateY(-22px) scale(0.97, 1.04); }
  75% { transform: translateY(0) scale(1, 1); }
}
@keyframes squash {
  0%, 100% { transform: scaleX(1.05); opacity: 1; }
  45% { transform: scaleX(0.6); opacity: 0.5; }
}
@keyframes beat { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.25); } }

/* ---------- Debug ---------- */
.debug {
  position: fixed;
  left: calc(var(--safe-l) + 8px);
  top: calc(var(--safe-t) + 72px);
  z-index: 40;
  margin: 0;
  padding: 6px 9px;
  border-radius: 10px;
  background: rgba(20, 16, 30, 0.72);
  color: #e8f6ff;
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  pointer-events: none;
  white-space: pre;
}

/* Landscape phones: keep things compact. */
@media (max-height: 500px) and (orientation: landscape) {
  .action { width: 64px; height: 64px; }
  .action .ico { font-size: 1.5rem; }
  .actions { bottom: calc(var(--safe-b) + 10px); }
  .back { height: 46px; }
}

/* Reduced motion: UI transitions only (the 3D scene is unaffected). */
@media (prefers-reduced-motion: reduce) {
  .hud-btn, .caption, .actions, .toasts, .toast, .status, #loading { transition-duration: 0.01s !important; transition-delay: 0s !important; }
  .hud-btn:active, .action.pop { transform: none; animation: none; }
  .toast.swap { animation: none; }
  .hint::after { animation: none; }
  .loading-house, .loading-shadow, .loading-heart { animation: none; }
  .burst { animation-name: burst-fade; }
  @keyframes burst-fade { 0% { opacity: 0; transform: translate(0, -10px); } 20%, 70% { opacity: 1; } 100% { opacity: 0; transform: translate(0, -24px); } }
}
