:root {
  --tinta: #f2f7f8;
  --tinta-suau: #b9ccd1;
  --fons-panell: rgba(8, 28, 38, 0.92);
  --vora: rgba(185, 204, 209, 0.25);
  --accent: #7fd3e0;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0b3a4a; color: var(--tinta); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
#escena { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.barra { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: max(10px, env(safe-area-inset-top)) 16px 10px; background: linear-gradient(rgba(4,20,28,.55), rgba(4,20,28,0)); pointer-events: none; }
.barra > * { pointer-events: auto; }
.marca { font-weight: 600; letter-spacing: .02em; }
.zona-nom { color: var(--tinta-suau); flex: 1; }
.idioma { background: transparent; color: var(--tinta); border: 1px solid var(--vora); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 14px; cursor: pointer; }

.capa { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(2, 12, 18, 0.45); z-index: 10; }
.capa.amagat, .debug.amagat { display: none; }
.panell { position: relative; max-width: 520px; width: 100%; max-height: calc(100% - 32px); overflow: auto; background: var(--fons-panell); border: 1px solid var(--vora); border-radius: 14px; padding: 24px 22px 20px; }
.panell h1 { font-size: 22px; margin: 0 36px 8px 0; }
.panell h2 { font-size: 22px; margin: 0 36px 2px 0; }
.panell h3 { font-size: 15px; margin: 16px 0 6px; color: var(--tinta-suau); text-transform: uppercase; letter-spacing: .04em; }
.panell p { margin: 6px 0; }
.panell ul { margin: 0; padding-left: 20px; }
.panell li { margin: 4px 0; }
.panell a { color: var(--accent); }
.ajuda { color: var(--tinta-suau); font-size: 15px; }
.cientific { font-style: italic; color: var(--tinta-suau); margin-top: 0; }
.tancar { position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--vora); background: transparent; color: var(--tinta); font-size: 24px; line-height: 1; cursor: pointer; }
.primari { margin-top: 14px; min-height: 44px; padding: 10px 18px; border: 0; border-radius: 10px; background: var(--accent); color: #062833; font: inherit; font-weight: 600; cursor: pointer; }
.tancar:focus-visible, .primari:focus-visible, .idioma:focus-visible, .so:focus-visible, .avis button:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.debug { position: fixed; right: 12px; bottom: 12px; width: min(340px, calc(100% - 24px)); max-height: 60vh; overflow: auto; background: var(--fons-panell); border: 1px solid var(--vora); border-radius: 12px; padding: 12px; font-size: 14px; z-index: 5; }
.debug label { display: grid; grid-template-columns: 1fr 64px; gap: 6px; align-items: center; margin: 6px 0; }
.debug input[type=range] { grid-column: 1 / -1; width: 100%; }
.debug textarea { width: 100%; margin-top: 8px; font: 12px/1.3 ui-monospace, monospace; background: #041a22; color: var(--tinta); border: 1px solid var(--vora); border-radius: 6px; }
.debug button { margin-top: 8px; font: inherit; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--vora); background: transparent; color: var(--tinta); cursor: pointer; }

.so { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 36px; background: transparent; color: var(--tinta); border: 1px solid var(--vora); border-radius: 8px; cursor: pointer; }
.avis { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(460px, calc(100% - 32px)); background: var(--fons-panell); border: 1px solid var(--vora); border-radius: 12px; padding: 12px 14px; z-index: 6; transition: opacity .4s; }
.avis.amagat { display: none; }
.avis-cap { font-size: 17px; }
.avis-cap em { color: var(--tinta-suau); font-size: 15px; }
.avis-text { margin: 8px 0 0; font-size: 15px; line-height: 1.45; }
.avis-botons { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.avis button { min-height: 40px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--vora); background: transparent; color: var(--tinta); font: inherit; font-size: 15px; cursor: pointer; }
.avis button#avis-escoltar { background: var(--accent); color: #062833; border-color: var(--accent); font-weight: 600; }
.so [hidden] { display: none; }
/* f3-17 (petición de Quim, 01-oct): aviso de especie translúcido para ver el fondo; sombra en el texto para leerlo sobre arena clara. */
.avis { background: rgba(8, 28, 38, 0.42); border-color: rgba(236, 246, 248, 0.28); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9); }
.avis button { background: rgba(8, 28, 38, 0.25); border-color: rgba(236, 246, 248, 0.35); }
.avis button#avis-escoltar { background: rgba(127, 211, 224, 0.82); text-shadow: none; }

/* ---------- Mapa (T-14, HU-01/HU-02) ---------- */
.boto-barra { background: transparent; color: var(--tinta); border: 1px solid var(--vora); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 14px; cursor: pointer; }
.zona-nom-caixa { flex: 1; min-width: 0; }
.zona-nom { background: transparent; border: 0; padding: 6px 4px; color: var(--tinta-suau); font: inherit; font-size: 15px; text-decoration: underline dotted; text-underline-offset: 4px; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.boto-barra:focus-visible, .zona-nom:focus-visible, .zona-punt:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
@media (max-width: 420px) { .marca { display: none; } }
.mapa-panell { max-width: 960px; padding: 18px 16px 14px; }
.mapa-marc { width: min(100%, calc((100vh - 230px) * 4 / 3)); margin: 10px auto 0; container-type: inline-size; }
.mapa-area { position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; }
@media (max-aspect-ratio: 1/1) { .mapa-marc { width: min(100%, calc((100vh - 250px) * 3 / 4)); } .mapa-area { aspect-ratio: 3 / 4; } }
/* Pantallas bajas (móvil en horizontal): el mapa no se encoge por debajo de 480 px de ancho; el panel se desplaza. */
@media (min-aspect-ratio: 1/1) and (max-height: 560px) { .mapa-marc { width: min(100%, 480px); } .mapa-panell .ajuda { display: none; } }
/* Mapa estrecho: solo números sobre el mapa y leyenda debajo (los rótulos no caben sin solaparse; medido a 360 px). */
.mapa-llegenda { display: none; list-style: none; margin: 8px 0 0; padding: 0; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.mapa-llegenda button { display: flex; gap: 6px; align-items: center; width: 100%; min-height: 32px; background: none; border: 0; padding: 2px 0; color: var(--tinta); font: inherit; font-size: 15px; text-align: left; cursor: pointer; }
.mapa-llegenda .punt { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; font-weight: 700; background: rgba(8,28,38,.85); border: 2px solid var(--tinta-suau); }
.mapa-llegenda .completa .punt { background: var(--accent); color: #062833; border-color: #fff; }
.mapa-llegenda .completa { font-weight: 600; }
.mapa-llegenda .marcada .punt { border-style: dashed; }
@container (max-width: 559px) { .zona-punt .etiqueta { display: none; } .zona-punt { transform: translate(-50%, -50%) !important; } .mapa-llegenda { display: grid; } }
.mapa-costa { position: absolute; inset: 0; width: 100%; height: 100%; }
.mapa-poble { position: absolute; left: 50%; top: 1.5%; transform: translateX(-50%); font-size: 14px; color: #eef3e6; text-shadow: 0 1px 2px #000; }
.mapa-nord { position: absolute; right: 8px; top: 1.5%; font-size: 14px; color: #eef3e6; text-shadow: 0 1px 2px #000; }
.mapa-zones { list-style: none; margin: 0; padding: 0; position: absolute; inset: 0; }
.mapa-zones li { position: absolute; }
.zona-punt { width: max-content; display: flex; align-items: center; gap: 6px; position: absolute; left: 0; top: 0; background: none; border: 0; padding: 0; color: var(--tinta); font: inherit; font-size: 15px; line-height: 1.2; cursor: pointer; text-align: left; }
.zona-punt .punt { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; font-weight: 700; background: rgba(8,28,38,.85); border: 2px solid var(--tinta-suau); }
.zona-punt .etiqueta { white-space: nowrap; padding: 2px 7px; border-radius: 6px; background: rgba(8,28,38,.78); }
.zona-punt.completa .punt { background: var(--accent); color: #062833; border-color: #fff; }
.zona-punt.completa .etiqueta { font-weight: 600; }
.zona-punt.marcada .punt { border-style: dashed; }
.zona-punt.marcada .etiqueta { color: #dbe7ea; }
.zona-punt[data-etiqueta="dreta"] { transform: translate(-14px, -50%); }
.zona-punt[data-etiqueta="esquerra"] { flex-direction: row-reverse; text-align: right; transform: translate(calc(-100% + 14px), -50%); }
.zona-punt[data-etiqueta="sobre"] { flex-direction: column-reverse; text-align: center; transform: translate(-50%, calc(-100% + 14px)); }
.zona-punt[data-etiqueta="sota"] { flex-direction: column; text-align: center; transform: translate(-50%, -14px); }
.mapa-info { min-height: 1.45em; margin: 10px 2px 0; color: var(--tinta-suau); }
.esborrany { display: inline-block; font-size: 14px; padding: 2px 8px; border-radius: 6px; background: #5a4a12; color: #ffe9a8; }
#mapa-titol:focus { outline: none; }
.primari:disabled { opacity: .65; cursor: progress; }

/* ---------- Navegación en la escena (HU-03): saltos, giroscopio y botones ▲▼ en pantallas táctiles ---------- */
.nav-escena { position: fixed; right: 12px; bottom: max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 5; }
.boto-nav, .boto-mov { background: var(--fons-panell); color: var(--tinta); border: 1px solid var(--vora); font: inherit; cursor: pointer; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: none; }
.boto-nav { min-height: 44px; padding: 8px 14px; border-radius: 10px; font-size: 15px; }
.boto-nav[aria-pressed="true"] { background: var(--accent); color: #062833; border-color: var(--accent); font-weight: 600; }
.boto-mov { width: 56px; height: 56px; border-radius: 50%; font-size: 22px; line-height: 1; }
.boto-mov:active { background: var(--accent); color: #062833; }
/* Transparencia (petición de Quim, 01-oct): se ve el fondo marino a través; el texto lleva sombra para seguir legible.
   Al pulsar o activar recuperan el color sólido para que se note la respuesta. */
.boto-nav, .boto-mov { background: rgba(8, 28, 38, 0.28); border-color: rgba(236, 246, 248, 0.35); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85); }
/* f3-16: navegacion arriba a la derecha (bajo la barra) en un desplegable; ▲▼ abajo, aun mas transparentes. */
.nav-dalt { position: fixed; top: calc(max(10px, env(safe-area-inset-top)) + 48px); right: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 6; }
.nav-menu { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.nav-menu[hidden] { display: none; }
.boto-desplegar[aria-expanded="true"] span[aria-hidden] { display: inline-block; transform: rotate(180deg); }
.nav-mov { position: fixed; right: 12px; bottom: max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; z-index: 5; }
.boto-mov { background: rgba(8, 28, 38, 0.12); border-color: rgba(236, 246, 248, 0.22); }
/* f3-18 (petición de Quim, 01-oct): triángulos ▲▼ translúcidos en vez de blanco opaco; al pulsar recuperan el tono oscuro. */
.boto-mov { color: rgba(236, 246, 248, 0.55); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); }
.boto-mov:active { color: #062833; }
.punt-nom { top: calc(max(10px, env(safe-area-inset-top)) + 52px); }
.boto-mov { font-size: 24px; }
.boto-nav[aria-pressed="true"], .boto-mov:active { background: rgba(127, 211, 224, 0.75); color: #062833; text-shadow: none; }
.boto-nav:focus-visible, .boto-mov:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.punt-nom { position: fixed; left: 50%; top: 64px; transform: translateX(-50%); margin: 0; padding: 6px 14px; border-radius: 10px; background: var(--fons-panell); border: 1px solid var(--vora); font-size: 16px; z-index: 5; }
/* En móvil, el aviso de especie ocupa el ancho de abajo: los botones suben para no taparlo. */
@media (max-width: 600px) { .nav-mov { bottom: max(150px, calc(env(safe-area-inset-bottom) + 150px)); } .punt-nom { top: auto; bottom: max(16px, env(safe-area-inset-bottom)); } }
