/* Porchlight WebGL template: a porch at night. Only Google Fonts load from outside; every font falls back locally. */

:root {
  --night: #0d0818;
  --night-2: #1b1030;
  --plum: #2a1838;
  --plum-2: #3d2150;
  --amber: #ffb454;
  --amber-soft: #ffd48a;
  --pumpkin: #f07a1a;
  --cream: #f6ead2;
  --muted: #b3a3c8;
  --danger: #ff6b6b;
  --ink: #1a0e21;
  --script: "Caveat", "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;
  --round: "Fredoka", "Avenir Next Rounded", "Avenir Next", "Trebuchet MS", system-ui, -apple-system, sans-serif;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--night);
  color: var(--cream);
  font-family: var(--round);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

#unity-container {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--night);
}

#unity-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--night);
  outline: none;
}

.hidden { display: none !important; }

/* ---------- Loader / doorbell gate ---------- */

#porch-loader {
  --progress: 0;
  --stage: clamp(92px, min(24vw, 24vh), 190px);
  position: absolute;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  box-sizing: border-box;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 50% 34%, rgba(255, 170, 80, calc(0.06 + var(--progress) * 0.1)), transparent 70%),
    radial-gradient(ellipse 80% 45% at 78% 96%, rgba(150, 70, 190, 0.35), transparent 70%),
    linear-gradient(180deg, #07040f 0%, #120a24 38%, #2b1340 72%, #3a1a47 86%, #160c20 100%);
  transition: opacity 0.9s ease;
}
#porch-loader.is-ready { pointer-events: auto; cursor: pointer; }
#porch-loader.is-leaving { opacity: 0; pointer-events: none; }

/* Sky and street */
.pl-sky { position: absolute; inset: 0; pointer-events: none; }
.pl-stars { position: absolute; left: 0; top: 0; width: 100%; height: 72%; }
.pl-twinkle { animation: pl-twinkle 3.2s ease-in-out infinite; }
@keyframes pl-twinkle { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

.pl-moon {
  position: absolute;
  left: 7%;
  top: 8%;
  width: clamp(70px, 13vmin, 150px);
  height: auto;
  filter: drop-shadow(0 0 18px rgba(255, 240, 200, 0.35));
}

.pl-bat { position: absolute; width: clamp(30px, 5vmin, 54px); height: auto; opacity: 0.9; }
.pl-bat-a { left: 18%; top: 20%; animation: pl-bat-a 16s linear infinite, pl-flap 0.32s ease-in-out infinite alternate; }
.pl-bat-b { left: 70%; top: 14%; width: clamp(22px, 3.6vmin, 40px); animation: pl-bat-b 21s linear infinite, pl-flap 0.28s ease-in-out infinite alternate; }
@keyframes pl-bat-a { 0% { transform: translate(-30vw, 6vh); } 50% { transform: translate(40vw, -4vh); } 100% { transform: translate(110vw, 3vh); } }
@keyframes pl-bat-b { 0% { transform: translate(40vw, 0); } 50% { transform: translate(-30vw, 8vh); } 100% { transform: translate(-90vw, -2vh); } }
@keyframes pl-flap { from { scale: 1 1; } to { scale: 1 0.45; } }

.pl-fog {
  position: absolute;
  left: -30%;
  width: 160%;
  height: 34%;
  bottom: 4%;
  background: radial-gradient(ellipse 50% 50% at 50% 50%, rgba(170, 120, 210, 0.22), transparent 70%);
  filter: blur(6px);
}
.pl-fog-a { animation: pl-drift 26s ease-in-out infinite alternate; }
.pl-fog-b { bottom: -6%; opacity: 0.8; animation: pl-drift 34s ease-in-out infinite alternate-reverse; }
@keyframes pl-drift { from { transform: translateX(-6%); } to { transform: translateX(6%); } }

.pl-street { position: absolute; left: 0; bottom: 0; width: 100%; height: 30%; }
.pl-windows rect { filter: drop-shadow(0 0 6px rgba(255, 180, 84, 0.8)); animation: pl-window 7s ease-in-out infinite; }
.pl-windows rect:nth-child(3n) { animation-delay: -2.4s; }
.pl-windows rect:nth-child(3n+1) { animation-delay: -4.1s; }
@keyframes pl-window { 0%, 100% { opacity: 1; } 48% { opacity: 1; } 50% { opacity: 0.55; } 52% { opacity: 1; } }

.pl-leaves { position: absolute; inset: 0; }
.pl-leaf {
  position: absolute;
  top: -8%;
  width: clamp(14px, 2.4vmin, 24px);
  animation-name: pl-fall, pl-sway;
  animation-timing-function: linear, ease-in-out;
  animation-iteration-count: infinite, infinite;
  animation-direction: normal, alternate;
  opacity: 0.85;
}
.pl-leaf svg { display: block; width: 100%; height: auto; }
@keyframes pl-fall { from { top: -8%; } to { top: 108%; } }
@keyframes pl-sway { from { transform: translateX(-22px) rotate(-35deg); } to { transform: translateX(22px) rotate(40deg); } }

/* Centre column */
.pl-center {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 2vh, 22px);
  width: 100%;
  max-width: 1000px;
}

.pl-logo-wrap { position: relative; width: min(94vw, 820px, 150vh); }
.pl-logo-glow {
  position: absolute;
  inset: -12% -8% -20%;
  background: radial-gradient(ellipse 50% 50% at 50% 50%, rgba(255, 150, 60, calc(0.16 + var(--progress) * 0.22)), transparent 70%);
  pointer-events: none;
}
.pl-logo { position: relative; display: block; width: 100%; height: auto; overflow: visible; }
.pl-letter { animation: pl-drop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
@keyframes pl-drop { from { transform: translateY(-120px); opacity: 0; } 40% { opacity: 1; } to { transform: translateY(0); opacity: 1; } }
.pl-bulb-glow { opacity: calc(0.12 + var(--progress) * 0.75); }
.pl-glass { animation: pl-flicker 5.5s steps(1) infinite; }
@keyframes pl-flicker { 0%, 100% { opacity: 1; } 91% { opacity: 1; } 92% { opacity: 0.55; } 93% { opacity: 1; } 95% { opacity: 0.7; } 96% { opacity: 1; } }

.pl-tagline {
  display: inline-block;
  position: relative;
  margin-top: clamp(-10px, -1vh, 0px);
  padding: 0.12em 1.3em 0.2em;
  font-family: var(--script);
  font-weight: 700;
  font-size: clamp(18px, min(4.2vw, 5.6vh), 34px);
  color: #ffe2a6;
  background: linear-gradient(180deg, #5a2c68, #3a1848);
  border: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  transform: rotate(-1.2deg);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}
.pl-tagline::before, .pl-tagline::after {
  content: "\2605";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--round);
  font-size: 0.6em;
  color: var(--amber);
}
.pl-tagline::before { left: 0.45em; }
.pl-tagline::after { right: 0.45em; }
.pl-tagline span { display: inline-block; }

/* Stage: the jack-o'-lantern while loading, the doorbell when ready */
.pl-stage { position: relative; width: calc(var(--stage) * 1.25); height: var(--stage); }
.pl-jack, .pl-bell {
  position: absolute;
  inset: 0;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.45s ease, transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pl-jack svg { position: relative; width: 100%; height: 100%; }
.pl-jack-glow {
  position: absolute;
  inset: -40%;
  background: radial-gradient(circle at 50% 55%, rgba(255, 170, 60, 0.55), transparent 60%);
  opacity: 0.15;
  animation: pl-candle 1.8s ease-in-out infinite alternate;
}
@keyframes pl-candle { from { filter: brightness(0.85); } to { filter: brightness(1.15); } }

.pl-bell { opacity: 0; transform: scale(0.4) rotate(-12deg); pointer-events: none; outline: none; }
.pl-bell svg { position: relative; height: 100%; width: auto; filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.5)); }
.pl-bell .pl-button { transform-box: fill-box; transform-origin: center; animation: pl-bell-glow 1.6s ease-in-out infinite; }
@keyframes pl-bell-glow { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.25) drop-shadow(0 0 8px #ffc25c); } }
.pl-ring {
  position: absolute;
  left: 50%;
  top: 50.6%;
  width: calc(var(--stage) * 0.5);
  height: calc(var(--stage) * 0.5);
  margin: calc(var(--stage) * -0.25) 0 0 calc(var(--stage) * -0.25);
  border-radius: 50%;
  border: 3px solid rgba(255, 196, 100, 0.85);
  box-shadow: 0 0 22px rgba(255, 170, 70, 0.6);
  opacity: 0;
}

#porch-loader.is-ready .pl-jack { opacity: 0; transform: scale(0.6) translateY(20%); }
#porch-loader.is-ready .pl-bell { opacity: 1; transform: none; pointer-events: auto; }
#porch-loader.is-ready .pl-ring { animation: pl-ripple 2.2s ease-out infinite; }
#porch-loader.is-ready .pl-ring-b { animation-delay: 1.1s; }
@keyframes pl-ripple { 0% { transform: scale(0.8); opacity: 0.9; } 100% { transform: scale(2.6); opacity: 0; } }
#porch-loader.is-ready .pl-bell:hover, #porch-loader.is-ready .pl-bell:focus-visible { transform: scale(1.06); }
#porch-loader.is-rung .pl-bell svg { animation: pl-press 0.35s ease-out; }
#porch-loader.is-rung .pl-ring { animation: pl-ripple 0.9s ease-out 2; }
#porch-loader::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 62%, rgba(255, 205, 130, 0.55), transparent 60%);
  opacity: 0;
}
#porch-loader.is-rung::after { animation: pl-flash 1s ease-out; }
@keyframes pl-flash { 0% { opacity: 0; } 18% { opacity: 1; } 100% { opacity: 0; } }
#porch-loader.is-rung .pl-logo-glow { background: radial-gradient(ellipse 50% 50% at 50% 50%, rgba(255, 190, 90, 0.55), transparent 70%); transition: background 0.4s; }
@keyframes pl-press { 0% { transform: scale(1); } 35% { transform: scale(0.9); } 100% { transform: scale(1); } }

/* Status */
.pl-status { min-height: 3.2em; }
.pl-status-main {
  font-family: var(--round);
  font-weight: 600;
  font-size: clamp(15px, min(3.4vw, 4.2vh), 24px);
  color: var(--cream);
  letter-spacing: 0.01em;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}
.pl-status-sub {
  font-size: clamp(11px, min(2.6vw, 3vh), 14px);
  color: var(--muted);
  margin-top: 2px;
  letter-spacing: 0.04em;
}
#porch-loader.is-ready .pl-status-main { color: #ffe2a6; font-size: clamp(17px, min(4vw, 5vh), 28px); animation: pl-invite 1.6s ease-in-out infinite; }
@keyframes pl-invite { 0%, 100% { opacity: 0.8; } 50% { opacity: 1; } }

/* Short landscape phones: tighten everything so it fits in ~360px of height. */
@media (orientation: landscape) and (max-height: 480px) {
  #porch-loader { --stage: clamp(70px, 22vh, 120px); }
  .pl-logo-wrap { width: min(74vw, 118vh); }
  .pl-center { gap: 4px; }
  .pl-status { min-height: 2.6em; }
}
/* Portrait: logo up top, a bigger stage in the middle. */
@media (orientation: portrait) {
  #porch-loader { --stage: clamp(110px, 32vw, 200px); }
  .pl-center { gap: clamp(14px, 4vh, 40px); }
  .pl-moon { left: auto; right: 8%; top: 5%; }
  .pl-tagline { white-space: normal; max-width: 86vw; }
}

@media (prefers-reduced-motion: reduce) {
  .pl-leaf, .pl-bat, .pl-fog, .pl-letter, .pl-twinkle, .pl-glass, .pl-jack-glow, .pl-ring, .pl-windows rect, .pl-status-main { animation: none !important; }
  .pl-leaf { display: none; }
}

/* ---------- Rotate card (phones in portrait, once loaded) ---------- */

#rotate-card {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 50;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background:
    radial-gradient(ellipse 70% 50% at 50% 40%, rgba(255, 180, 84, 0.14), transparent 70%),
    linear-gradient(180deg, #07040f, #2b1340);
  color: var(--cream);
  text-align: center;
  padding: 24px;
  box-sizing: border-box;
}
.rotate-phone {
  width: 54px;
  height: 92px;
  border: 4px solid var(--amber-soft);
  border-radius: 12px;
  box-shadow: 0 0 24px rgba(255, 180, 84, 0.35);
  animation: porch-rotate 2.4s ease-in-out infinite;
}
.rotate-text { font-size: 22px; font-weight: 600; color: var(--amber-soft); }
.rotate-hint { font-size: 14px; color: var(--muted); }
@keyframes porch-rotate {
  0%, 25% { transform: rotate(0deg); }
  55%, 100% { transform: rotate(-90deg); }
}
@media (orientation: portrait) {
  body.porch-mobile.porch-ready #rotate-card { display: flex; }
}

/* ---------- Error panel ---------- */

#error-panel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  background: rgba(8, 5, 14, 0.85);
  z-index: 20;
  overflow: auto;
}

.error-card {
  max-width: 640px;
  width: 100%;
  background: var(--plum);
  border: 1px solid rgba(255, 107, 107, 0.4);
  border-radius: 16px;
  padding: 22px 26px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  font-size: 14px;
  line-height: 1.5;
}

.error-card h2 { margin: 0 0 8px; color: var(--danger); font-size: 20px; }
.error-card code { background: rgba(0, 0, 0, 0.35); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.error-card pre {
  background: rgba(0, 0, 0, 0.4);
  padding: 10px 12px;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #ffd0d0;
  font-size: 12px;
  max-height: 160px;
  overflow: auto;
}
.error-card ul { padding-left: 20px; }

#error-retry {
  margin-top: 8px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--amber);
  background: transparent;
  color: var(--amber-soft);
  font-size: 14px;
  cursor: pointer;
}
#error-retry:hover { background: rgba(255, 180, 84, 0.12); }

/* ---------- Footer ---------- */

#unity-footer {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 5;
}

#unity-fullscreen-button {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(255, 212, 138, 0.25);
  background: rgba(18, 13, 28, 0.6);
  color: var(--amber-soft);
  font-size: 18px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.2s;
}
#unity-fullscreen-button:hover { opacity: 1; }

/* ---------- Mobile ---------- */

#unity-container.unity-mobile #unity-fullscreen-button { display: none; }

/* The canvas takes every touch itself (joystick, two-finger orbit, pinch). */
#unity-canvas.unity-mobile {
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
body.porch-mobile { overscroll-behavior: none; position: fixed; inset: 0; }
