/* ==========================================================================
   JungleRun — Web UI Stylesheet
   All sizes derived from actual PNG pixel dimensions and reference storyboard
   
   Asset dimensions:
   - BG.png:              1080 x 1920  (9:16)
   - Logo:                 827 x 377
   - Instruction box:      937 x 810   (safe text area ~72% x ~72% inner)
   - Message.png:          501 x 268
   - Button.png:           346 x 123
   - Pizza Glow:           383 x 384
   - Sound icons:           98 x 100 / 100 x 103
   - hand.png:             200 x 200
   - pizza box mockup:    2250 x 1500
   ========================================================================== */

@font-face {
  font-family: 'LCScript';
  src: url('../assets/fonts/LCScriptTT-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'MrEaves';
  src: url('../assets/fonts/MrEavesXLSanNarR.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'MrEaves';
  src: url('../assets/fonts/MrEavesXLSanNarU.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-display: 'LCScript', Georgia, serif;
  --font-ui: 'MrEaves', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --text-light: #fefce8;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: var(--font-ui);
  color: var(--text-light);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

/* ==========================================================================
   STAGE — a 9:16 phone-shaped box. Fills the screen on phones, and is
   centred (letterboxed) on desktop/tablet. Every UI size below is in
   cqw / cqh (% of the stage), so layout is identical on every device.
   ========================================================================== */
#stage {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 100vh;
  height: 100dvh;
  width: min(100vw, calc(100vh * 9 / 16));
  width: min(100vw, calc(100dvh * 9 / 16));
  container-type: size;
  overflow: visible;
  background: transparent;
  z-index: 10;
  pointer-events: none;
}

#unity-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 1;
}
#unity-canvas { width: 100%; height: 100%; display: block; background: #070e0b; outline: none; }

/* ---------- Screens ---------- */
.ui-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(4.5cqh + var(--safe-t)) 6cqw calc(4cqh + var(--safe-b));
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .3s ease, visibility .3s ease;
}
.ui-screen.active { opacity: 1; visibility: visible; pointer-events: auto; }

/* Make backdrop & loading BG span full screen width even on iPad 3:4 */
.ui-backdrop-clear::before,
.ui-backdrop-blur::before,
#screen-loading::before {
  content: "";
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  height: 100dvh;
  z-index: -1;
  pointer-events: none;
}

.ui-backdrop-clear { background: none; }
.ui-backdrop-clear::before {
  background: linear-gradient(180deg, rgba(0,0,0,.28) 0%, transparent 28%, transparent 68%, rgba(0,0,0,.4) 100%);
}

.ui-backdrop-blur { background: none; backdrop-filter: none; -webkit-backdrop-filter: none; }
.ui-backdrop-blur::before {
  background: linear-gradient(180deg, rgba(0,0,0,.26) 0%, rgba(0,0,0,.08) 50%, rgba(0,0,0,.36) 100%);
  backdrop-filter: blur(1.2px);
  -webkit-backdrop-filter: blur(1.2px);
}

/* ---------- Logo (827x377, includes "SOLO EN CINES") ---------- */
.game-logo-img {
  width: 72cqw;
  height: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 .8cqw 1.8cqw rgba(0,0,0,.75));
}

/* ---------- Card + pizza stack ---------- */
.center-stack {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  padding: 1cqh 0;
}

.jungle-card {
  --cw: min(86cqw, 42cqh);   /* scales proportionally with screen height & width */
  width: var(--cw);
  aspect-ratio: 937 / 810;
  flex-shrink: 0;
  pointer-events: none;
  /* frame art on top; dark translucent panel under it, exactly in the frame's opening */
  background:
    url('../assets/images/instruction-box.webp') 0 0 / 100% 100% no-repeat,
    linear-gradient(rgb(18 20 18 / 10%), rgb(18 20 18 / 34%)) 34.09% 45.16% / 56% 69% no-repeat;
  /* frame opening = x 15-71%, y 14-83% of the PNG (art is 937x810 -> height = .864 * width) */
  padding: calc(var(--cw) * .147) calc(var(--cw) * .315) calc(var(--cw) * .173) calc(var(--cw) * .175);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  filter: drop-shadow(0 1.5cqw 3cqw rgba(0,0,0,.6));
  position: relative;
  left: calc(var(--cw) * .07);
  transform: translateY(1.5cqw) scale(.97);
  transition: transform .3s cubic-bezier(.22,1,.36,1);
}
#screen-intro .jungle-card { --cw: min(84cqw, 42cqh); }
.ui-screen.active .jungle-card { transform: none; }


.card-title {
  font-family: var(--font-ui);
  font-size: calc(var(--cw) * .075);
  font-weight: 700;
  line-height: 1.05;
  color: #fff;
  margin-bottom: calc(var(--cw) * .022);
  text-shadow: 0 .4cqw 1.2cqw rgba(0,0,0,.9);
}
.card-desc {
  font-family: var(--font-ui);
  font-size: calc(var(--cw) * .043);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-light);
  text-shadow: 0 .3cqw .9cqw rgba(0,0,0,.95);
}
.card-desc-lg {
  font-family: var(--font-ui);
  font-size: calc(var(--cw) * .058);
  font-weight: 700;
  line-height: 1.22;
  color: #fff;
  text-shadow: 0 .4cqw 1.2cqw rgba(0,0,0,.95);
}

.pizza-glow-img {
  width: min(44cqw, 24cqh);
  height: min(44cqw, 24cqh);
  flex-shrink: 1;
  min-height: 0;
  object-fit: contain;
  pointer-events: none;
  margin-top: 0;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 1.2cqw 2.4cqw rgba(0,0,0,.65));
  animation: floatSlow 3s ease-in-out infinite;
}

/* ---------- Buttons ---------- */
.action-group {
  margin-top: auto;
  width: 100%;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2cqw;
}

.btn-wood {
  width: 44cqw;
  aspect-ratio: 501 / 268;
  background: url('../assets/images/message-box.webp') center / 100% 100% no-repeat;
  border: none;
  font-family: var(--font-display);
  font-size: 7.4cqw;
  letter-spacing: .02em;
  color: #fff;
  text-shadow: 0 .5cqw 1.2cqw rgba(0,0,0,.8);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  /* nudge: optically centre the label on the plank body (measured from the PNG) */
  padding: 1.7cqw 1.9cqw 0 0;
  filter: drop-shadow(0 1.4cqw 2.4cqw rgba(0,0,0,.55));
  transition: transform .12s ease, filter .15s ease;
}
.btn-wood.btn-pill {
  width: 44cqw;
  aspect-ratio: 346 / 123;
  background-image: url('../assets/images/button.webp');
  font-size: 6.6cqw;
  padding: 1.4cqw .9cqw 0 0;
}
.btn-wood:hover { filter: brightness(1.08) drop-shadow(0 1.4cqw 2.4cqw rgba(0,0,0,.55)); }
.btn-wood:active { transform: scale(.95); }

.btn-link {
  background: none;
  border: none;
  color: #fff;
  font-family: var(--font-display);
  font-size: 3.9cqw;
  text-decoration: underline;
  text-underline-offset: .7cqw;
  text-shadow: 0 .4cqw .9cqw rgba(0,0,0,.9);
  cursor: pointer;
  padding: .5cqw 2cqw;
}
.privacy-link {
  font-family: var(--font-ui);
  font-size: 2.4cqw;
  color: rgba(255,255,255,.85);
  text-decoration: underline;
  text-underline-offset: .5cqw;
  text-shadow: 0 .2cqw .8cqw rgba(0,0,0,.9);
}

/* ---------- 1. Loading ---------- */
#screen-loading {
  justify-content: center;
  gap: 11cqh;
  padding-top: 0;
  background: transparent;
  z-index: 50;
}
#screen-loading::before {
  background: url('../assets/images/loading-bg.webp') center / cover no-repeat, #070e0b;
}
#screen-loading .game-logo-img { width: 72cqw; margin-top: -6cqh; }
.loading-box {
  width: 68cqw;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2.4cqw;
}
.loading-label {
  font-family: var(--font-display);
  font-size: 4.4cqw;
  letter-spacing: .06em;
  color: #f59e0b;
  text-shadow: 0 .4cqw 1.2cqw rgba(0,0,0,.9);
}
#unity-loading-bar {
  width: 100%;
  height: 6.4cqw;
  background: rgba(0,0,0,.4);
  border: .45cqw solid #b45309;
  border-radius: 99px;
  padding: .7cqw;
  overflow: hidden;
  box-shadow: inset 0 .5cqw 1cqw rgba(0,0,0,.7);
}
#unity-loading-bar-inner {
  width: 12%;
  min-width: 5cqw;
  height: 100%;
  background: linear-gradient(90deg, #d97706 0%, #f59e0b 60%, #d97706 100%);
  border-radius: 9999px;
}

/* ---------- 2. HUD (pass-through: swipes reach the Unity canvas) ---------- */
#screen-hud {
  z-index: 15;
  pointer-events: none !important;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  padding: calc(2.6cqh + var(--safe-t)) 4cqw calc(5cqh + var(--safe-b));
}
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; }
.hud-lives { display: flex; align-items: center; gap: .4cqw; padding-top: .4cqw; }
.life-icon {
  width: 16cqw;
  height: 16cqw;
  object-fit: contain;
  filter: drop-shadow(0 .5cqw 1.2cqw rgba(0,0,0,.8));
  transition: transform .25s ease, opacity .25s ease, filter .25s ease;
}
.life-icon.lost { opacity: .22; filter: grayscale(1); transform: scale(.8); }

.hud-score-badge {
  width: 31cqw;
  aspect-ratio: 346 / 123;
  background: url('../assets/images/button.webp') center / 100% 100% no-repeat;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1.2cqw;
  font-family: var(--font-display);
  font-size: 3.9cqw;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: #fff;
  padding: 1.4cqw .8cqw 0 0;
  text-shadow: 0 .4cqw .9cqw rgba(0,0,0,.85);
  filter: drop-shadow(0 1cqw 1.8cqw rgba(0,0,0,.5));
}

#global-sound-btn {
  position: absolute;
  top: calc(2.6cqh + var(--safe-t) + 14cqw);
  right: 7cqw;
  z-index: 45;
  width: 8.6cqw;
  height: 8.6cqw;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  display: none;
  filter: drop-shadow(0 .7cqw 1.6cqw rgba(0,0,0,.6));
  transition: transform .15s ease;
}
#global-sound-btn.visible { display: block; }
#global-sound-btn:active { transform: scale(.9); }
#global-sound-btn img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; display: block; }

.hud-tutorial {
  align-self: center;
  width: 68cqw;
  aspect-ratio: 501 / 268;
  background: url('../assets/images/message-box.webp') center / 100% 100% no-repeat;
  padding: 5.4cqw 7.2cqw 3.8cqw 7.2cqw;
  display: flex;
  align-items: center;
  gap: 2.4cqw;
  font-family: var(--font-ui);
  font-size: 3.35cqw;
  font-weight: 700;
  line-height: 1.18;
  color: #fff;
  text-shadow: 0 .3cqw .9cqw rgba(0,0,0,.95);
  filter: drop-shadow(0 1.4cqw 2.8cqw rgba(0,0,0,.7));
  opacity: 0;
  transform: translateY(2.5cqw);
  transition: opacity .35s ease, transform .35s ease;
}
.hud-tutorial.visible { opacity: 1; transform: none; }
.hud-tutorial-icon { flex-shrink: 0; width: 10cqw; height: 10cqw; object-fit: contain; }
.hud-tutorial-text { flex: 1; min-width: 0; }

/* ---------- Desktop Notice ("Play on mobile for the best experience") ---------- */
#desktop-notice {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px;
  background: url('../assets/images/loading-bg.webp') center / cover no-repeat, #070e0b;
  text-align: center;
}

@media (hover: hover) and (pointer: fine) and (min-width: 769px) {
  #desktop-notice:not(.dismissed) {
    display: flex;
  }
}

.desktop-logo {
  width: min(300px, 70vw);
  height: auto;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,.8));
}

.desktop-instruction {
  max-width: 420px;
  font-family: var(--font-ui);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.4;
  color: #fefce8;
  text-shadow: 0 2px 8px rgba(0,0,0,.9);
}

/* ---------- Debug bar (?debug=ui) — outside the stage ---------- */
#debug-ui-bar {
  position: fixed;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: none;
  gap: 4px;
  background: rgba(0,0,0,.88);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 99px;
  padding: 5px 10px;
}
#debug-ui-bar.enabled { display: flex; }
#debug-ui-bar button {
  background: #1f2937; color: #f9fafb; border: 1px solid #374151;
  border-radius: 99px; padding: 4px 9px; font-size: 11px; font-weight: 600; cursor: pointer;
}
#debug-ui-bar button:hover { background: #374151; }

@keyframes floatSlow { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-.8cqw); } }
