/* Portrait web template. All art lives in TemplateData/images/; every
   image is optional and the page falls back to the colours below. */

@font-face {
  font-family: "Mouse Memoirs";
  src: url("fonts/MouseMemoirs-Regular.ttf") format("truetype");
  font-display: block;
}

:root {
  --sky-top: #ffe9a8;
  --sky-bottom: #ffc15e;
  --wood-dark: #5c3412;
  --wood: #8b5a2b;
  --wood-light: #c98a4b;
  --leaf: #5bd13b;
  --leaf-dark: #2f9a1f;
  --cream: #fff8e7;
  --ink: #4a2a0f;
  --danger: #e2553f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--wood-dark);
  font-family: "Mouse Memoirs", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
}

[hidden] { display: none !important; }

/* ---------- Layout ---------- */

/* Wide screens: blurred art around the portrait frame. */
#backdrop {
  position: fixed;
  inset: -40px;
  background:
    url("images/bg.png") center / cover no-repeat,
    linear-gradient(var(--sky-top), var(--sky-bottom));
  filter: blur(24px) brightness(0.7);
}

#frame {
  position: relative;
  height: 100%;
  max-width: 100%;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.45);
}

#unity-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  outline: none;
}

/* ---------- Loading screen ---------- */

#loader {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  /* Vertical padding follows the height (a % would follow the width and
     balloon in landscape), so the bottom row always stays on screen. */
  padding: calc(4dvh + var(--safe-top)) 8% calc(5dvh + var(--safe-bottom));
  background:
    url("images/bg.png") center / cover no-repeat,
    radial-gradient(circle at 50% 35%, #fff4cc 0%, transparent 60%),
    linear-gradient(var(--sky-top), var(--sky-bottom));
  transition: opacity 0.45s ease;
}

#loader.done { opacity: 0; pointer-events: none; }

.loader-top { width: 100%; display: flex; justify-content: center; }

/* Art is capped by height as well as width, so a short landscape screen
   shrinks it instead of pushing the progress bar and Play button off. */
#loader-logo {
  width: auto;
  height: auto;
  max-width: min(88%, 520px);
  max-height: 24dvh;
  animation: logo-in 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both,
             float 3s ease-in-out 0.7s infinite;
}

#loader-title {
  margin: 0;
  font-size: clamp(48px, 13vmin, 96px);
  font-weight: normal;
  letter-spacing: 1px;
  color: var(--cream);
  -webkit-text-stroke: 3px var(--wood-dark);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--wood-dark);
  animation: logo-in 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.loader-middle { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; width: 100%; }

.mascot-wrap { position: relative; width: min(62%, 380px); }

#loader-mascot {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 36dvh;
  margin: 0 auto;
  transform-origin: 50% 100%;
  animation: hop 1.1s ease-in-out infinite;
}

.mascot-shadow {
  width: 55%;
  height: 14px;
  margin: -6px auto 0;
  border-radius: 50%;
  background: rgba(74, 42, 15, 0.25);
  animation: shadow 1.1s ease-in-out infinite;
}

.loader-bottom { width: 100%; max-width: 440px; text-align: center; }

/* Soft backing so the status and tip stay readable over busy art. */
.loader-bottom p {
  width: fit-content;
  max-width: 100%;
  margin-left: auto !important;
  margin-right: auto !important;
  padding: 3px 14px;
  border-radius: 14px;
  background: rgba(255, 248, 231, 0.72);
}

#progress {
  position: relative;
  height: 38px;
  padding: 5px;
  border-radius: 20px;
  background: var(--wood);
  border: 3px solid var(--wood-dark);
  box-shadow: inset 0 3px 0 var(--wood-light), 0 5px 0 var(--wood-dark);
}

#progress-fill {
  width: 0%;
  height: 100%;
  border-radius: 14px;
  background:
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.22) 0 10px, transparent 10px 20px),
    linear-gradient(#8ef06a, var(--leaf) 55%, var(--leaf-dark));
  background-size: 28px 28px, 100% 100%;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
  transition: width 0.3s ease-out;
  animation: stripes 0.8s linear infinite;
}

#progress-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--cream);
  -webkit-text-stroke: 2px var(--wood-dark);
  paint-order: stroke fill;
}

#status {
  margin: 14px 0 6px;
  font-size: clamp(22px, 5.5vmin, 30px);
  color: var(--cream);
  -webkit-text-stroke: 2px var(--wood-dark);
  paint-order: stroke fill;
}

#tip {
  margin: 0;
  padding: 0 4px;
  font-size: clamp(17px, 4.2vmin, 22px);
  line-height: 1.25;
  color: var(--ink);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#tip.show { opacity: 0.85; transform: none; }

/* ---------- Error screen ---------- */

#error {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8%;
  background:
    url("images/bg.png") center / cover no-repeat,
    linear-gradient(var(--sky-top), var(--sky-bottom));
}

.error-card {
  width: 100%;
  max-width: 400px;
  padding: 26px 22px 24px;
  text-align: center;
  border-radius: 24px;
  background: var(--cream);
  border: 4px solid var(--wood-dark);
  box-shadow: 0 8px 0 var(--wood-dark);
}

#error-art { width: 55%; height: auto; margin-bottom: 8px; }

.error-card h2 { margin: 0 0 8px; font-size: 32px; font-weight: normal; }

.error-card p { margin: 0 0 20px; font-family: "Trebuchet MS", system-ui, sans-serif; font-size: 15px; line-height: 1.4; opacity: 0.8; }

#retry,
#play {
  font: inherit;
  font-size: 28px;
  padding: 10px 34px;
  border: 3px solid var(--wood-dark);
  border-radius: 18px;
  color: var(--cream);
  background: linear-gradient(#8ef06a, var(--leaf-dark));
  box-shadow: 0 5px 0 var(--wood-dark);
  -webkit-text-stroke: 1.5px var(--wood-dark);
  paint-order: stroke fill;
  cursor: pointer;
}

#retry:active,
#play:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--wood-dark); }

/* after loading, tap anywhere works. button pulses so user knows to tap */
#play {
  font-size: clamp(28px, 7vmin, 38px);
  padding: 12px 44px;
  animation: play-pulse 1.1s ease-in-out infinite;
}
#play:active { animation: none; }

@keyframes play-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

/* ---------- Unity warnings ---------- */

#unity-warning {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: 12px;
  right: 12px;
  z-index: 30;
  pointer-events: none;
}

#unity-warning .banner {
  margin-bottom: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  font-family: "Trebuchet MS", system-ui, sans-serif;
  font-size: 14px;
  color: var(--cream);
  background: rgba(74, 42, 15, 0.9);
}

#unity-warning .banner.warning { color: var(--ink); background: #ffd54a; }

#diagnostics-icon, #profiler-button {
  position: absolute;
  right: 8px;
  bottom: calc(8px + var(--safe-bottom));
  z-index: 30;
}

/* ---------- Rotate hint (phones held sideways) ---------- */

#rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--wood-dark);
  color: var(--cream);
  font-size: 28px;
  text-align: center;
}

.rotate-phone {
  width: 54px;
  height: 90px;
  border: 5px solid var(--cream);
  border-radius: 12px;
  animation: rotate 1.8s ease-in-out infinite;
}

@media (orientation: landscape) and (pointer: coarse) and (max-height: 500px) {
  #rotate-hint { display: flex; }
}

/* ---------- Motion ---------- */

@keyframes logo-in { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes hop {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  15% { transform: translateY(0) scale(1.06, 0.94); }
  45% { transform: translateY(-14%) scale(0.97, 1.03); }
  75% { transform: translateY(0) scale(1.04, 0.96); }
}
@keyframes shadow { 0%, 100% { transform: scale(1); opacity: 1; } 45% { transform: scale(0.7); opacity: 0.6; } }
@keyframes stripes { to { background-position: 28px 0, 0 0; } }
@keyframes rotate { 0%, 20% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(0deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  #tip { opacity: 0.85; transform: none; }
}
