:root {
  color-scheme: dark;
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  --papel: #f3ede2;
  --tinta: #211d19;
  --cristal: rgba(27, 25, 23, .91);
  --linea: 1px solid rgba(250, 241, 219, .22);
  --sombra: 0 3px 18px rgba(13, 11, 10, .18);
  --margen: clamp(12px, 1.6vw, 26px);
  --izquierda: max(var(--margen), env(safe-area-inset-left));
  --derecha: max(var(--margen), env(safe-area-inset-right));
  --arriba: max(var(--margen), env(safe-area-inset-top));
  --abajo: max(var(--margen), env(safe-area-inset-bottom));
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: #242321;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  color: var(--papel);
  height: 100dvh;
  position: relative;
  -webkit-text-size-adjust: 100%;
}

button, summary, select {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible, summary:focus-visible, select:focus-visible, #escena:focus-visible {
  outline: 3px solid #f7c889;
  outline-offset: 3px;
}

button:disabled { cursor: progress; opacity: .72; }
button:enabled:active, summary:active { transform: translateY(1px); }

#visita, #escena, #portada, #interfaz {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#escena {
  display: block;
  touch-action: none;
  cursor: grab;
}

#escena:active { cursor: grabbing; }
#escena:focus-visible { outline-offset: -4px; }
#visita > picture { display: contents; }
#portada { object-fit: cover; object-position: center; pointer-events: none; }

#cabecera {
  position: absolute;
  z-index: 3;
  top: var(--arriba);
  left: var(--izquierda);
  right: var(--derecha);
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  grid-template-areas: "volver marca . destino controles";
  align-items: start;
  gap: .55rem;
  pointer-events: none;
}

.marca, .selector-destino, #ayuda, #inicio, .panel-ayuda, .indicaciones, #estado, .sin-js {
  background: var(--cristal);
  border: var(--linea);
  box-shadow: var(--sombra);
}

.marca {
  grid-area: marca;
  justify-self: start;
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .35rem 1rem .35rem .35rem;
  border-radius: .78rem;
  white-space: nowrap;
}

.logotipo {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 2.45rem;
  padding: 0 .85rem .13rem;
  border-radius: .43rem;
  background: var(--papel);
  color: var(--tinta);
  font-size: .79rem;
  font-weight: 750;
  letter-spacing: .16em;
  text-indent: .16em;
}

.logotipo::after {
  content: "";
  position: absolute;
  right: .85rem;
  bottom: .42rem;
  left: .85rem;
  height: 1px;
  background: #af8b59;
}

h1, h2 {
  font-family: "Baskervville", Georgia, "Times New Roman", serif;
  font-weight: 500;
}

h1 { margin: 0; font-size: clamp(1.13rem, 1.5vw, 1.45rem); line-height: 1.12; white-space: normal; }

.selector-destino {
  grid-area: destino;
  justify-self: start;
  position: relative;
  display: flex;
  align-items: center;
  min-height: 46px;
  padding-left: .92rem;
  border-radius: 999px;
  pointer-events: auto;
}

.selector-destino > span {
  color: #dbcbb8;
  font-size: .88rem;
}

.selector-destino::after {
  content: "";
  position: absolute;
  right: .9rem;
  top: calc(50% - 4px);
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  pointer-events: none;
}

#destino {
  appearance: none;
  -webkit-appearance: none;
  min-height: 44px;
  padding: 0 2rem 0 .55rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: .96rem;
  font-weight: 600;
}

#destino option { background: #27251f; color: var(--papel); }
#destino:disabled { cursor: progress; opacity: .78; }

#controles { grid-area: controles; position: relative; pointer-events: auto; }
#ayuda, .acciones button, #cerrar-ayuda, #reintentar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  min-height: 46px;
  padding: 0 1rem;
  border-radius: 999px;
  font-size: .94rem;
  font-weight: 600;
  line-height: 1.15;
  user-select: none;
}

#ayuda { list-style: none; }
#ayuda::-webkit-details-marker { display: none; }

.icono-ayuda {
  display: inline-grid;
  place-items: center;
  width: 1.17rem;
  height: 1.17rem;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-size: .83rem;
  line-height: 1;
}

.panel-ayuda {
  position: absolute;
  top: calc(100% + .55rem);
  right: 0;
  width: min(21rem, calc(100vw - var(--izquierda) - var(--derecha)));
  max-height: calc(100dvh - var(--arriba) - var(--abajo) - 54px);
  padding: 1.18rem;
  border-radius: .85rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  color: #f1eade;
  background: #25231f;
}

.panel-ayuda h2 { margin: 0; font-size: 1.55rem; }
.panel-ayuda dl { margin: 1rem 0; }
.panel-ayuda dl > div + div { margin-top: .86rem; }
.panel-ayuda dt { margin: 0 0 .18rem; font-size: .95rem; font-weight: 650; }
.panel-ayuda dd { margin: 0; color: #ddd7cc; font-size: 1rem; line-height: 1.4; }

kbd {
  padding: 0 .22rem;
  border: 1px solid #8c8376;
  border-radius: .24rem;
  font: 600 .84em/1.1 "Inter", "Segoe UI", sans-serif;
  white-space: nowrap;
}

#cerrar-ayuda, #guia, #reintentar {
  background: var(--papel);
  color: var(--tinta);
  border: 1px solid rgba(255, 252, 243, .85);
}

#cerrar-ayuda { min-height: 42px; }
#interfaz { z-index: 2; pointer-events: none; }

.acciones, .indicaciones {
  position: absolute;
  bottom: var(--abajo);
  margin: 0;
}

.acciones {
  left: var(--izquierda);
  display: flex;
  gap: .48rem;
  pointer-events: auto;
}

.acciones button { min-height: 48px; box-shadow: var(--sombra); }
#guia { padding-inline: 1.18rem; font-weight: 700; }

.icono-guia {
  display: inline-block;
  width: .8rem;
  height: .8rem;
  background: currentColor;
  clip-path: polygon(17% 1%, 98% 50%, 17% 99%);
}

#guia[aria-pressed="true"] .icono-guia {
  clip-path: inset(10% round 1px);
}

.icono-inicio {
  position: relative;
  width: 1.13rem;
  height: 1.13rem;
}

.icono-inicio::before, .icono-inicio::after {
  position: absolute;
  content: "";
}

.icono-inicio::before {
  top: 18%;
  left: 18%;
  width: 64%;
  height: 64%;
  transform: rotate(45deg);
  border-top: 1.6px solid currentColor;
  border-left: 1.6px solid currentColor;
}

.icono-inicio::after {
  top: 46%;
  left: 19%;
  width: 62%;
  height: 44%;
  border: 1.6px solid currentColor;
  border-top: 0;
}

.indicaciones {
  right: var(--derecha);
  padding: .65rem .92rem;
  border-radius: 999px;
  font-size: .88rem;
  line-height: 1.2;
}

.indicaciones b { font-size: .83rem; letter-spacing: .045em; }
.indicaciones span { margin: 0 .24rem; color: #d6bfa0; }

#joystick {
  display: none;
  position: absolute;
  bottom: var(--abajo);
  left: var(--izquierda);
  place-items: center;
  width: 88px;
  height: 88px;
  border: 1.5px solid rgba(255, 245, 223, .62);
  border-radius: 50%;
  background: rgba(22, 24, 24, .56);
  box-shadow: var(--sombra), inset 0 0 0 5px rgba(255, 255, 255, .06);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
}

#pomo {
  display: block;
  width: 36px;
  height: 36px;
  border: 1px solid #f5ecdb;
  border-radius: 50%;
  background: rgba(235, 225, 208, .81);
  box-shadow: 0 2px 5px rgba(0, 0, 0, .35);
  pointer-events: none;
}

#estado, .sin-js {
  position: absolute;
  z-index: 2;
  bottom: calc(var(--abajo) + 4.1rem);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .65rem;
  width: max-content;
  max-width: calc(100vw - var(--izquierda) - var(--derecha));
  margin: 0;
  padding: .62rem 1rem;
  border-radius: .7rem;
  font-size: .96rem;
  line-height: 1.35;
}

.actividad {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  border: 1.6px solid rgba(244, 235, 215, .35);
  border-top-color: var(--papel);
  border-radius: 50%;
  animation: vuelta 900ms linear infinite;
}

@keyframes vuelta { to { transform: rotate(360deg); } }
#estado:has(#reintentar:not([hidden])) .actividad { display: none; }
#reintentar { min-height: 40px; }

.sin-interfaz #cabecera,
.sin-interfaz #interfaz,
.sin-interfaz #portada,
.sin-interfaz #estado,
.sin-interfaz .sin-js { display: none !important; }
.sin-interfaz #escena { outline: none; cursor: none; }

@media (hover: hover) {
  #ayuda:hover, #inicio:enabled:hover { background: #39332b; }
  #guia:enabled:hover, #cerrar-ayuda:hover, #reintentar:hover { background: #fff9ed; }
}

.tactil #joystick { display: grid; }
.tactil .acciones { left: auto; right: var(--derecha); }
.tactil .indicaciones { display: none; }
.tactil #estado, .tactil .sin-js { bottom: calc(var(--abajo) + 100px); }

@media (max-width: 650px) {
  #cabecera {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "volver marca controles" "destino destino destino";
    row-gap: .4rem;
  }
  .marca { gap: .65rem; padding-right: .8rem; }
  .logotipo { min-height: 2.2rem; padding-inline: .65rem; }
  .selector-destino { min-height: 44px; }
  #ayuda, .acciones #inicio { min-width: 46px; padding-inline: .6rem; }
  .texto-ayuda, .texto-inicio, .texto-volver, .indicaciones { display: none; }
  #volver { min-width: 46px; padding-inline: .6rem; justify-content: center; }
  .marca { min-width: 0; }
  .titular { min-width: 0; }
  .subtitulo { white-space: normal; }
  .acciones button { min-height: 46px; }
  .acciones { gap: .35rem; }
}

@media (max-width: 330px), (max-height: 480px) {
  #joystick { width: 72px; height: 72px; }
  #pomo { width: 30px; height: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  .actividad { animation: none; }
}

/* Integración en la web de ejemplos (21/11, v2): volver a la página de la sede y subtítulo. */
#volver {
  grid-area: volver;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  min-height: 3.15rem;
  padding: 0 1rem;
  border-radius: .78rem;
  background: var(--cristal);
  border: var(--linea);
  box-shadow: var(--sombra);
  color: inherit;
  font-weight: 650;
  text-decoration: none;
}
#volver:focus-visible { outline: 2px solid #f3e6cc; outline-offset: 2px; }
.titular { display: grid; gap: .1rem; }
.subtitulo { margin: 0; font-size: .74rem; line-height: 1.2; opacity: .78; letter-spacing: .01em; }
@media (hover: hover) { #volver:hover { background: #39332b; } }
