/* Fuente y colores sacados del proyecto de Unity (Assets/Fonts, materiales y prefabs de UI). */
@font-face {
  font-family: "Comfortaa";
  src: url("fonts/Comfortaa-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Comfortaa";
  src: url("fonts/Comfortaa-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}

:root {
  /* Gradient.shadergraph del fondo del menú principal */
  --sky-top: #c0dff3;
  --sky-bottom: #f8dbdd;
  /* Contorno marrón de los sprites de UI (9slice2, botones) */
  --outline: #5a341d;
  /* UIPanel_LoadingScreen */
  --loading-bg: #231f1a;
  --loading-title: #f9ffc8;
  --tip-title: #33cc80;
  --bar-bg: rgba(51, 51, 51, .8);
  --bar-fill: #8acd69;
  /* LabCardItem / paneles del laboratorio */
  --lab-subtitle: #99cce6;
  --lab-desc: #d9e6f2;
  --lab-bio: #86efac;
  --lab-gen: #c084fc;
  /* Hierba al pie de MainMenu_BG: la página continúa el paisaje del menú */
  --grass: #cad97a;
  --ink: #231f1a;
  --muted: #5b4a3e;
  --font: "Comfortaa", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--grass);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- Botones: imágenes renderizadas de los botones del menú del juego ---------- */
.img-btn {
  display: inline-block; padding: 0; border: 0; background: none; cursor: pointer; line-height: 0;
  transition: transform .12s ease, filter .12s ease;
}
.img-btn img { height: 64px; width: auto; }
.img-btn:hover { transform: translateY(-2px) scale(1.03); filter: brightness(1.06); }
.img-btn:active { transform: translateY(2px) scale(.98); }
.img-btn:focus-visible { outline: 3px solid var(--bar-fill); outline-offset: 4px; border-radius: 16px; }
.img-btn-small img { height: 44px; }

/* ---------- Panel del juego (sprite 9slice2_0, bordes 44/44/72/44 a 1/4 como en los prefabs) ---------- */
.panel {
  border-style: solid;
  border-width: 14px 14px 23px 14px;
  border-image: url("img/panel_card.png") 44 44 72 44 fill / 14px 14px 23px 14px stretch;
  background: none;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 8px clamp(16px, 4vw, 40px);
  background: rgba(35, 31, 26, .92);
  backdrop-filter: blur(8px);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 1rem; }
.brand b { color: var(--bar-fill); }
.nav { display: flex; gap: 22px; margin-left: auto; font-weight: 700; font-size: .9rem; }
.nav a { text-decoration: none; color: rgba(255, 255, 255, .85); padding: 6px 2px; border-bottom: 2px solid transparent; }
.nav a:hover { color: #fff; border-bottom-color: var(--bar-fill); }
.nav a:focus-visible { outline: 3px solid var(--bar-fill); outline-offset: 3px; }

/* ---------- Hero: el cielo y las montañas del menú principal ---------- */
.hero {
  position: relative; overflow: hidden;
  padding: clamp(20px, 3vw, 36px) 16px 0;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 100%);
  text-align: center;
}
.hero-copy { position: relative; z-index: 1; max-width: 980px; margin: 0 auto 22px; }
.logo { margin: 0 auto 12px; }
.logo img { width: min(460px, 86vw); height: auto; margin: 0 auto; filter: drop-shadow(0 8px 14px rgba(90, 52, 29, .25)); }
.lead { margin: 0 auto 16px; max-width: 640px; font-size: clamp(1rem, 1.6vw, 1.1rem); color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 0; padding: 0; list-style: none; }
.chips li {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .82rem; font-weight: 700; color: var(--outline);
  background: rgba(255, 255, 255, .7); border: 2px solid rgba(90, 52, 29, .25);
  padding: .4em .9em; border-radius: 999px;
}
.chips img { height: 20px; width: auto; }

.hero-land {
  position: relative; z-index: 0;
  width: calc(100% + 32px); max-width: none; height: clamp(150px, 22vw, 300px); object-fit: cover; object-position: center bottom;
  margin: -110px -16px 0;
}

/* ---------- Marco del juego: siempre 16:9 (el arte del juego está pensado para 1920x1080) ---------- */
.game-shell {
  position: relative; z-index: 2;
  /* El marco se ajusta al 16:9 que cabe en la ventana; +28px = padding + borde. */
  width: min(1220px, 100%, calc((100vh - 190px) * 16 / 9 + 28px));
  width: min(1220px, 100%, calc((100svh - 190px) * 16 / 9 + 28px));
  min-width: min(100%, 340px);
  margin: 0 auto;
  padding: 10px 10px 6px;
  background: var(--loading-bg);
  border: 4px solid var(--outline);
  border-radius: 26px;
  box-shadow: 0 6px 0 var(--outline), 0 18px 40px rgba(35, 31, 26, .3);
}
.game-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  background: var(--loading-bg);
}
#unity-canvas { display: block; width: 100%; height: 100%; background: var(--loading-bg); outline: none; }

.poster {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 12px;
  padding-bottom: 6%;
  background: url("img/story_booster.webp") center / cover no-repeat;
}
.play-button img { height: clamp(64px, 11vw, 104px); }
.play-button { animation: bob 2.6s ease-in-out infinite; }
.play-button:hover { animation-play-state: paused; }
@keyframes bob { 50% { transform: translateY(-5px); } }
.poster-note {
  margin: 0; font-size: .82rem; font-weight: 700; color: #fff;
  background: rgba(35, 31, 26, .7); padding: .4em .9em; border-radius: 999px;
}

/* Pantalla de carga: misma composición que UIPanel_LoadingScreen. */
.loader {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(14px, 3vw, 34px);
  padding: 5%; color: #fff; background: var(--loading-bg);
}
.loader-title { margin: 0; font-size: clamp(1.1rem, 2.6vw, 2rem); font-weight: 700; font-style: italic; color: var(--loading-title); }
.tip-card {
  width: min(560px, 90%); min-height: 28%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 6px 18px 12px; text-align: center;
  border-style: solid; border-width: 14px 14px 23px 14px;
  border-image: url("img/panel_tip.png") 44 44 72 44 fill / 14px 14px 23px 14px stretch;
}
.tip-title { margin: 0; font-weight: 700; color: var(--tip-title); font-size: clamp(.85rem, 1.6vw, 1.1rem); }
.tip-body { margin: 0; font-weight: 700; font-size: clamp(.78rem, 1.3vw, .95rem); }
.bar {
  position: relative; width: min(380px, 70%); height: 26px; border-radius: 13px; overflow: hidden;
  background: var(--bar-bg);
}
.bar-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--bar-fill); border-radius: 13px; transition: width .25s ease; }
.bar-label, .bar-pct { position: relative; font-size: .78rem; font-weight: 700; line-height: 26px; }
.bar-label { display: block; text-align: center; }
.bar-pct { position: absolute; right: 12px; top: 0; }

.error {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center; color: #fff; background: rgba(209, 94, 94, .95); font-weight: 700;
}
.toast { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); display: grid; gap: 6px; z-index: 5; }
.toast div { background: var(--loading-title); color: var(--ink); padding: .5em .9em; border-radius: 10px; font-size: .85rem; }

.game-bar { display: flex; align-items: center; gap: 14px; padding: 8px 4px 2px; color: rgba(255, 255, 255, .8); font-size: .85rem; }
.game-bar-title { font-weight: 700; color: #fff; }
.game-bar-title small { opacity: .6; font-weight: 400; }
.game-bar-hint { margin-left: auto; }
.game-bar .img-btn img { height: 44px; }

/* Aviso de girar el móvil: solo en táctiles en vertical, una vez arrancado el juego. */
.rotate-hint { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  .game-shell.started .rotate-hint {
    position: absolute; inset: 0; z-index: 6;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
    color: #fff; font-weight: 700; text-align: center; background: rgba(35, 31, 26, .94);
  }
  .rotate-hint img { height: 45%; width: auto; animation: tilt 2.2s ease-in-out infinite; }
  .rotate-hint p { margin: 0; padding: 0 12px; }
}
@keyframes tilt { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }

/* ---------- Pantalla completa ---------- */
.exit-fs { display: none; }
.game-shell:fullscreen, .game-shell.pseudo-fs {
  width: 100vw; height: 100vh; height: 100dvh; max-width: none;
  margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none;
  display: flex; align-items: center; justify-content: center;
  background: #000;
}
.game-shell:-webkit-full-screen { width: 100vw; height: 100vh; margin: 0; padding: 0; border: 0; border-radius: 0; display: flex; align-items: center; justify-content: center; background: #000; }
.game-shell.pseudo-fs { position: fixed; inset: 0; z-index: 100; }
.game-shell:fullscreen .game-frame, .game-shell.pseudo-fs .game-frame {
  width: min(100vw, calc(100vh * 16 / 9));
  width: min(100vw, calc(100dvh * 16 / 9));
  border-radius: 0;
}
.game-shell:-webkit-full-screen .game-frame { width: min(100vw, calc(100vh * 16 / 9)); border-radius: 0; }
.game-shell:fullscreen .game-bar, .game-shell.pseudo-fs .game-bar, .game-shell:-webkit-full-screen .game-bar { display: none; }
.game-shell.pseudo-fs .exit-fs { display: block; position: absolute; left: 8px; bottom: 8px; z-index: 7; opacity: .85; }
.game-shell.pseudo-fs .exit-fs img { height: 36px; }
html.is-fullscreen body { overflow: hidden; }

/* ---------- Secciones ---------- */
.section { padding: clamp(48px, 7vw, 88px) clamp(16px, 4vw, 40px); max-width: 1180px; margin: 0 auto; text-align: center; }
.section-head { max-width: 680px; margin: 0 auto 32px; }
.section h2 { margin: 0 0 10px; font-size: clamp(1.6rem, 3.4vw, 2.3rem); color: var(--outline); line-height: 1.15; }
.section-head p { margin: 0; color: var(--muted); }

.story { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; text-align: left; }
.story figure { margin: 0; display: flex; flex-direction: column; }
.story img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 6px; }
.story figcaption { padding: 12px 4px 2px; font-size: .88rem; color: var(--ink); }
.story figcaption b { display: block; margin-bottom: 4px; font-size: .78rem; letter-spacing: .04em; color: var(--outline); }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.card { padding: 6px 10px 8px; text-align: left; transition: transform .2s ease; }
.card:hover { transform: translateY(-4px); }
.card img { height: 190px; width: auto; margin: 0 auto 10px; filter: drop-shadow(0 8px 10px rgba(90, 52, 29, .2)); }
.card h3 { margin: 0 0 6px; font-size: 1.12rem; color: var(--outline); }
.card p { margin: 0; color: var(--ink); font-size: .93rem; }

/* El laboratorio: fondo con el arte de lab_bg y fichas como LabCardItem. */
.section-lab { position: relative; max-width: none; overflow: hidden; background: var(--loading-bg); }
.section-lab > * { position: relative; max-width: 1100px; margin-left: auto; margin-right: auto; }
.lab-art { position: absolute !important; inset: 0; max-width: none !important; opacity: .28; }
.lab-art img { width: 100%; height: 100%; object-fit: cover; }
.section-lab h2 { color: var(--loading-title); }
.section-lab .section-head p { color: var(--lab-desc); }
.lab-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 0 auto; padding: 0; list-style: none; text-align: left; }
.lab-card {
  display: flex; gap: 14px; align-items: flex-start; padding: 4px 8px 6px;
  border-style: solid; border-width: 14px 14px 23px 14px;
  border-image: url("img/panel_lab.png") 44 44 72 44 fill / 14px 14px 23px 14px stretch;
}
.lab-card img { width: 64px; height: auto; flex: none; }
.lab-card b { display: block; color: #fff; font-size: 1.02rem; }
.lab-card small { display: block; color: var(--lab-subtitle); font-size: .78rem; margin-bottom: 6px; }
.lab-card p { margin: 0 0 4px; color: var(--lab-desc); font-size: .88rem; }
.lab-card em { font-style: normal; font-weight: 700; font-size: .86rem; }
.lab-card .bio { color: var(--lab-bio); }
.lab-card .gen { color: var(--lab-gen); }

.facts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 0 0 28px; text-align: left; }
.facts div { padding: 4px 8px 6px; }
.facts dt { font-size: .75rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--outline); margin-bottom: 4px; }
.facts dd { margin: 0; font-size: .92rem; color: var(--ink); }
#classroom .img-btn img { height: 72px; }

.footer {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 36px 16px 44px; text-align: center; color: rgba(255, 255, 255, .75); font-size: .85rem;
  background: var(--loading-bg);
}
.footer p { margin: 0; }

.diag-icon { position: absolute; right: 8px; bottom: 8px; z-index: 8; width: 32px; cursor: pointer; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .story { grid-template-columns: 1fr 1fr; }
  .lab-cards { grid-template-columns: 1fr 1fr; }
  .facts { grid-template-columns: 1fr 1fr; }
  .game-bar-hint { display: none; }
  .game-bar .img-btn { margin-left: auto; }
}
@media (max-width: 640px) {
  .nav { display: none; }
  .topbar .img-btn-small { margin-left: auto; }
  .brand span { display: none; }
  .story, .cards, .lab-cards, .facts { grid-template-columns: 1fr; }
  .game-shell { padding: 6px 6px 4px; border-radius: 18px; }
  .game-frame { border-radius: 10px; }
  .card img { height: 160px; }
  .poster-note { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
