:root {
  --bg: #0f0f0f;
  --fg: #ffffff;
  --muted: rgba(255, 255, 255, 0.72);
  --card: rgba(15, 15, 15, 0.78);
  --line: rgba(255, 255, 255, 0.16);
  --accent: #c8102e; /* vermell legionari */
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#cam {
  position: fixed; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: none; background: #000;
}
body.camera-mode #cam { display: block; }

button {
  font: inherit; font-weight: 600; color: var(--fg);
  background: rgba(255, 255, 255, 0.12); border: 1px solid var(--line);
  border-radius: 999px; padding: 12px 18px; cursor: pointer;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
a.btn {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  font-weight: 600; color: var(--fg); background: rgba(255, 255, 255, 0.12); border: 1px solid var(--line);
  border-radius: 999px; padding: 15px 18px; flex: 1 1 100%;
}
.caption .video-link { display: inline-block; margin-top: 10px; font-size: 14px; font-weight: 600; color: var(--fg); text-decoration: none; }
button.primary { background: var(--fg); color: #111; border-color: var(--fg); }
button:active { transform: scale(0.97); }

.panel {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 24px 20px calc(28px + env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(15,15,15,0.15) 0%, rgba(15,15,15,0.85) 55%, #0f0f0f 100%);
}
.panel h1 { font-size: clamp(28px, 7vw, 44px); line-height: 1.05; margin: 6px 0 12px; letter-spacing: -0.02em; max-width: 14ch; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; font-size: 12px; color: var(--muted); margin: 0; }
.lead { color: var(--muted); font-size: 17px; line-height: 1.45; margin: 0 0 22px; max-width: 34ch; }
.buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.buttons button { flex: 1 1 140px; padding: 15px 18px; }
.note { font-size: 12px; color: var(--muted); margin: 18px 0 0; }
.note a { color: var(--fg); }

#overlay { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#overlay > * { pointer-events: auto; }
.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}
.topbar .right { margin-left: auto; display: flex; gap: 8px; }
.topbar button { padding: 9px 14px; font-size: 14px; }
#btn-exit { width: 40px; height: 40px; padding: 0; }
#hint {
  font-size: 13px; color: var(--fg); text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  pointer-events: none; max-width: 46vw;
}

.caption {
  position: absolute; left: 16px; right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 520px; margin: 0 auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px 16px 16px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transition: opacity 0.4s;
}
.caption .step { margin: 0; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.caption h2 { margin: 4px 0 6px; font-size: 19px; }
.caption p { margin: 0; font-size: 14.5px; line-height: 1.45; color: var(--muted); }
.caption .step::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); margin-right: 8px; vertical-align: 1px;
}

/* ?sim: simula el carrer sense càmera (proves i presentacions) */
body.sim.camera-mode #cam { display: none; }
body.sim.camera-mode {
  background:
    linear-gradient(180deg, #9fb4c7 0%, #c9c2b3 46%, #8d8577 47%, #6f6a61 100%);
}

/* ── Mapa RA ── */
body.map-mode #caption, body.map-mode #btn-scale, body.map-mode #btn-works { display: none; }
.mp { position: fixed; inset: 0; z-index: 15; pointer-events: none; }
.mp > * { pointer-events: auto; }
.mp-layer { position: absolute; inset: 0; touch-action: none; }
.mp-bubble {
  position: absolute; left: 0; top: 0; padding: 0; border: 0; background: none; backdrop-filter: none;
  display: flex; flex-direction: column; align-items: center; transform-origin: 50% 100%;
}
.mp-pill {
  font-size: 13px; font-weight: 700; color: #111; background: rgba(255,255,255,0.92);
  border-radius: 999px; padding: 5px 12px; margin-bottom: 8px; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}
.mp-pill em { font-style: normal; }
.mp-chip-id { display: none; }
.mp-bubble.far .mp-chip-id { display: inline; }
.mp-bubble.far .mp-disc, .mp-bubble.far .mp-stem { display: none; }
.mp-bubble.far .mp-pill { margin-bottom: 0; background: rgba(17,17,17,0.82); color: #fff; border: 2px solid #fff; }
.mp-disc {
  width: 66px; height: 66px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(17,17,17,0.82); border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(255,255,255,0.28), 0 4px 14px rgba(0,0,0,0.35);
  color: #fff; font-size: 20px;
}
.mp-disc.sm { width: 46px; height: 46px; font-size: 15px; box-shadow: none; flex: none; }
.mp-stem { width: 3px; height: 70px; background: linear-gradient(#fff, rgba(255,255,255,0.2)); }
.mp-name {
  position: absolute; top: 100%; margin-top: -60px; left: calc(100% - 4px); white-space: nowrap;
  font-size: 12px; font-weight: 600; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.8); display: none;
}
.mp-bubble:hover .mp-name { display: block; }
.mp-nearest {
  position: absolute; left: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: calc(100% - 200px); text-align: left; border-radius: 14px; padding: 10px 14px;
  font-size: 13px; font-weight: 500; line-height: 1.35; background: rgba(15,15,15,0.72);
}
.mp-mini {
  position: absolute; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; border-radius: 14px; overflow: hidden; background: #fff; box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.mp-mini canvas { width: 150px; height: 150px; display: block; }
.mp-radius { display: flex; flex-direction: column; gap: 6px; padding: 8px 6px; color: #111; font-size: 11px; align-items: center; }
.mp-radius > span { font-weight: 700; }
.mp-r { background: none; border: 0; padding: 0; color: #111; display: flex; flex-direction: column; align-items: center; backdrop-filter: none; }
.mp-r i { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #bbb; display: block; }
.mp-r.on i { border-color: #1e78ff; background: radial-gradient(#1e78ff 0 38%, transparent 40%); }
.mp-r b { font-size: 9px; font-weight: 600; margin-top: 1px; }
.mp-sheet {
  position: absolute; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom));
  max-width: 520px; margin: 0 auto; z-index: 50; background: rgba(15,15,15,0.92); border: 1px solid var(--line);
  border-radius: 20px; padding: 16px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.mp-sheet-head { display: flex; gap: 12px; align-items: center; }
.mp-sheet-head h2 { margin: 0; font-size: 18px; }
.mp-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.mp-close { margin-left: auto; width: 36px; height: 36px; padding: 0; flex: none; }
.mp-sheet > p { color: var(--muted); font-size: 14.5px; line-height: 1.5; margin: 12px 0 14px; }
.mp-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.mp-actions > * { flex: 1 1 140px; }
.mp-actions a.btn { padding: 12px 16px; }
@media (max-width: 520px) { .mp-nearest { max-width: calc(100% - 32px); bottom: calc(190px + env(safe-area-inset-bottom)); } }

/* ── Narració i foto ── */
#btn-audio { width: 40px; height: 40px; padding: 0; }
#btn-audio.on { background: var(--fg); color: #111; }
.photo-btn {
  position: absolute; right: 20px; bottom: calc(150px + env(safe-area-inset-bottom));
  width: 64px; height: 64px; padding: 0; border-radius: 50%;
  background: rgba(255,255,255,0.25); border: 4px solid #fff;
}
.photo-btn::after { content: ""; display: block; width: 44px; height: 44px; margin: auto; border-radius: 50%; background: #fff; }
.photo-view {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.photo-view img { max-width: 100%; max-height: 72vh; border-radius: 14px; }
.photo-view .buttons { width: 100%; max-width: 520px; }
.photo-view .buttons > * { flex: 1 1 120px; }
.mp-org { font-size: 12px; color: var(--muted); margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--line); }
.mp-org a { color: var(--fg); }
