:root {
  /* Agora/XTEC-inspired palette + friendly WebGL tone */
  --bg-page: #f4f5f6;
  --card-bg: rgba(255, 255, 255, 0.92);
  --card-border: #e3e6ea;

  --text-main: #1f2937;
  --text-muted: #6b7280;

  --olive: #7a8f18;
  --olive-hover: #8aa51e;

  --purple: #6b3b86;
  --purple-hover: #5a2f72;

  --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.08);
  --shadow-softer: 0 6px 16px rgba(0, 0, 0, 0.06);

  --radius-lg: 18px;
  --radius: 14px;
  --maxw: 980px;

  /* iOS real viewport helper (set by app.js) */
  --vh: 1vh;

  /* Safe areas */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  touch-action: none;
}

body {
  margin: 0;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Helvetica,
    Arial,
    "Apple Color Emoji",
    "Segoe UI Emoji";
  color: var(--text-main);

  background:
    radial-gradient(
      1000px 620px at 16% 12%,
      rgba(122, 143, 24, 0.18),
      transparent 60%
    ),
    radial-gradient(
      980px 620px at 84% 16%,
      rgba(107, 59, 134, 0.18),
      transparent 64%
    ),
    radial-gradient(
      900px 620px at 55% 88%,
      rgba(122, 143, 24, 0.1),
      transparent 66%
    ),
    radial-gradient(
      900px 620px at 48% 72%,
      rgba(107, 59, 134, 0.08),
      transparent 70%
    ),
    var(--bg-page);

  overflow: hidden; /* single source of truth */
}

/* Subtle grain (still light) */
body:before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='.10'/%3E%3C/svg%3E");
  opacity: 0.12;
  pointer-events: none;
  mix-blend-mode: multiply;
}

/* =========================================================
   Unity full-viewport (safe-area applied ONCE in container)
   ========================================================= */
#unity-container {
  position: fixed;
  inset: 0;
  display: none;
  background: #000;

  /* Safe area applied here ONCE */
  padding: var(--sat) var(--sar) var(--sab) var(--sal);

  /* Use real iOS height from --vh */
  height: calc(var(--vh) * 100);
  width: 100vw;
}

/* Canvas fills the padded container (NO extra safe-area here) */
#unity-canvas {
  position: absolute;
  inset: 0;

  width: 100% !important;
  height: 100% !important;

  display: block;
  background: #000;
  outline: none;
  touch-action: none;
}

#unity-loading-bar {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
}

#unity-warning {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  z-index: 4;
  display: none;
}

#unity-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0; /* safe-area already handled by container padding */
  z-index: 2;
  pointer-events: auto;
}

/* =========================
   Start Overlay (centered)
   - allows internal scroll to avoid cutting on iPhone
   ========================= */
#startOverlay {
  position: fixed;
  inset: 0;
  z-index: 9999;

  /* En iOS: que sea un scroller real */
  display: block;
  height: calc(var(--vh) * 100);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;

  /* evita “rebotes” raros y permite gesto */
  overscroll-behavior: contain;
  touch-action: pan-y;

  padding: calc(clamp(16px, 4vw, 44px) + var(--sat))
    calc(clamp(16px, 4vw, 44px) + var(--sar))
    calc(clamp(16px, 4vw, 44px) + var(--sab))
    calc(clamp(16px, 4vw, 44px) + var(--sal));
}

.shell {
  width: min(var(--maxw), 100%);
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: clamp(14px, 2.8vw, 22px);
  align-items: stretch;
}

/* El contenido se centra si cabe; si no, se puede scrollear desde arriba */
#startOverlay .shell {
  margin: 0 auto;
  min-height: calc(
    var(--vh) * 100 - (clamp(16px, 4vw, 44px) * 2) - var(--sat) - var(--sab)
  );
  align-content: center; /* centra el grid “si hay espacio” */
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }
}

.panel {
  position: relative;
  border-radius: var(--radius-lg);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.panel:after {
  content: "";
  position: absolute;
  inset: -2px;
  background:
    radial-gradient(
      760px 260px at 18% 0%,
      rgba(122, 143, 24, 0.16),
      transparent 62%
    ),
    radial-gradient(
      760px 260px at 82% 0%,
      rgba(107, 59, 134, 0.14),
      transparent 62%
    );
  pointer-events: none;
  opacity: 0.9;
}

.left {
  padding: clamp(18px, 3.2vw, 32px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 360px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 16px;

  background-image: url("logo_Corbella.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  background-color: #fff;

  border: 1px solid rgba(0, 0, 0, 0.05);
  box-shadow: var(--shadow-softer);
  flex: 0 0 auto;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.2px;
  line-height: 1.1;
}
.brand p {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.headline {
  margin-top: 18px;
  max-width: 56ch;
}
.headline h2 {
  margin: 0 0 10px;
  font-size: clamp(24px, 3.2vw, 38px);
  line-height: 1.08;
  letter-spacing: -0.4px;
}
.headline p {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.55;
}

.ctaRow {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--card-border);
  background: #fff;
  color: var(--text-main);
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 14.5px;
  font-weight: 800;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    background 0.12s ease;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(17, 24, 39, 0.08);
}
.btn:active {
  transform: translateY(0px);
}
.btn:focus-visible {
  outline: 3px solid rgba(122, 143, 24, 0.25);
  outline-offset: 2px;
}

.btnPrimary {
  background: linear-gradient(180deg, var(--olive), #6f8315);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.05);
}
.btnPrimary:hover {
  background: linear-gradient(180deg, var(--olive-hover), #738916);
}

.btnSecondary {
  background: linear-gradient(180deg, var(--purple), #5b2f72);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.05);
}
.btnSecondary:hover {
  background: linear-gradient(180deg, var(--purple-hover), #512a66);
}

.meta {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 12.8px;
  align-items: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--olive);
  box-shadow: 0 0 0 3px rgba(122, 143, 24, 0.12);
}

.kbd {
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 12px;
  color: rgba(31, 41, 55, 0.78);
  padding: 4px 8px;
  border-radius: 10px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.9);
}

.footerNote {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  font-size: 0.85rem;
  color: rgba(31, 41, 55, 0.7);
}

.footerBlock {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.devSignature {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.devLabel {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  opacity: 0.55;
}

.devBrandRow {
  display: flex;
  align-items: center;
}

.devBrand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}

.devLogo {
  height: 20px;
  width: auto;
  opacity: 0.9;
}

.devName {
  font-weight: 600;
  color: #1f2937;
}

.devEmailLine {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--purple, #6b3b86);
  font-weight: 500;
}

.mailIcon {
  font-size: 0.9rem;
  opacity: 0.8;
}

.devEmailLine:hover {
  opacity: 0.75;
}

.right {
  padding: clamp(16px, 2.6vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: flex-start; /* keep tip visible */
}

.preview {
  position: relative;
  border-radius: var(--radius);
  border: 1px solid var(--card-border);

  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0)),
    url("preview.png") center / cover no-repeat;

  overflow: hidden;

  flex-shrink: 0;
  min-height: 160px;
}
@media (min-width: 600px) {
  .preview {
    min-height: 250px;
  }
}
@media (min-width: 1024px) {
  .preview {
    min-height: 300px;
  }
}

.previewInner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 14px;
  gap: 12px;
}

.badge {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--card-border);
  font-size: 12.8px;
  color: var(--text-muted);
  max-width: 72%;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

/* Tip below preview */
.tipBelowPreview {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;

  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.82);

  font-size: 12.8px;
  line-height: 1.45;
  color: var(--text-muted);
}
.tipBelowPreview .tipIcon {
  font-size: 18px;
  line-height: 1;
  margin-top: 1px;
}
.tipBelowPreview .tipText {
  max-width: 48ch;
}

/* Start overlay fade-out */
.fadeOut {
  animation: fadeOut 0.22s ease forwards;
}
@keyframes fadeOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
  .fadeOut {
    animation: none;
  }
  body:before {
    display: none;
  }
}

/* =========================
   Modal (smooth & premium)
   ========================= */
.modalOverlay {
  position: fixed;
  inset: 0;
  z-index: 10000;

  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 4vw, 44px);

  background: rgba(17, 24, 39, 0.28);
  backdrop-filter: blur(8px);

  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}
.modalOverlay.isOpen {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  width: min(760px, 100%);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-soft);
  overflow: hidden;

  transform: translateY(18px) scale(0.96);
  opacity: 0;

  transition:
    transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 0.32s ease;
}
.modalOverlay.isOpen .modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}
.modalOverlay.isClosing {
  opacity: 0;
}
.modalOverlay.isClosing .modal {
  transform: translateY(12px) scale(0.97);
  opacity: 0;
}

.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--card-border);
  background:
    radial-gradient(
      520px 180px at 18% 10%,
      rgba(122, 143, 24, 0.12),
      transparent 60%
    ),
    radial-gradient(
      520px 180px at 82% 10%,
      rgba(107, 59, 134, 0.1),
      transparent 65%
    ),
    rgba(255, 255, 255, 0.92);
}
.modalHeader h3 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.1px;
}
.modalBody {
  padding: 14px 16px 4px;
}
.modalFooter {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.92);
}

/* =========================
   Error toast (Start screen)
   ========================= */
.toast {
  position: fixed;
  top: calc(18px + var(--sat));
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  z-index: 10001;

  width: min(720px, calc(100% - 32px));
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;

  padding: 12px 12px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-soft);

  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.26s ease,
    transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast.isOpen {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.toastIcon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;

  background:
    radial-gradient(
      18px 18px at 30% 30%,
      rgba(122, 143, 24, 0.14),
      transparent 60%
    ),
    radial-gradient(
      18px 18px at 70% 70%,
      rgba(107, 59, 134, 0.12),
      transparent 65%
    ),
    rgba(0, 0, 0, 0.03);
  border: 1px solid var(--card-border);
}
.toastTitle {
  font-weight: 900;
  letter-spacing: -0.1px;
  color: var(--text-main);
  margin-bottom: 2px;
  font-size: 14.5px;
}
.toastMsg {
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.35;
}
.toastClose {
  appearance: none;
  border: 1px solid var(--card-border);
  background: #fff;
  color: var(--text-muted);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}
.toastClose:hover {
  color: var(--text-main);
  box-shadow: 0 10px 18px rgba(17, 24, 39, 0.08);
  transform: translateY(-1px);
}

/* =========================
   Rotate device overlay
   ========================= */
#rotateOverlay {
  position: fixed;
  inset: 0;
  z-index: 10002;
  display: none;

  height: calc(var(--vh) * 100);

  padding: calc(16px + var(--sat)) calc(16px + var(--sar))
    calc(16px + var(--sab)) calc(16px + var(--sal));

  background:
    radial-gradient(
      800px 400px at 20% 10%,
      rgba(122, 143, 24, 0.18),
      transparent 60%
    ),
    radial-gradient(
      800px 400px at 80% 20%,
      rgba(107, 59, 134, 0.18),
      transparent 65%
    ),
    rgba(244, 245, 246, 0.96);

  align-items: center;
  justify-content: center;
  text-align: center;
}

.rotateCard {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 28px 26px;
  max-width: 320px;
}
.rotateIcon {
  font-size: 40px;
  margin-bottom: 10px;
}
.rotateCard h2 {
  margin: 0 0 6px;
  font-size: 18px;
}
.rotateCard p {
  margin: 0;
  font-size: 14px;
  color: var(--text-muted);
}

.iconBtn {
  appearance: none;
  border: 1px solid var(--card-border);
  background: #fff;
  color: var(--text-muted);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}
.iconBtn:hover {
  color: var(--text-main);
  box-shadow: 0 10px 18px rgba(17, 24, 39, 0.08);
  transform: translateY(-1px);
}