:root {
  --bg: #050304;
  --cream: #ecdfc6;
  --cream-dim: rgba(236, 223, 198, 0.62);
  --line: rgba(236, 223, 198, 0.18);
  --red: #b8192b;
  --red-deep: #7e0d18;
  --glass: rgba(10, 6, 7, 0.55);
  --f-black: 'UnifrakturMaguntia', serif;
  --f-caps: 'Cinzel', serif;
  --f-body: 'Cormorant Garamond', Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--cream);
  font-family: var(--f-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

button { font: inherit; color: inherit; }

/* ───────── chargement ───────── */
#loader {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 22px;
  background: radial-gradient(ellipse at 50% 45%, #1a0a0d 0%, var(--bg) 70%);
  transition: opacity 1.2s ease, visibility 1.2s;
}
.ready #loader { opacity: 0; visibility: hidden; }
.loader-title {
  font-family: var(--f-black);
  font-size: clamp(44px, 9vw, 84px);
  color: var(--cream);
  text-shadow: 0 0 28px rgba(184, 25, 43, 0.55);
}
#loader .bar {
  width: min(240px, 60vw);
  height: 1px;
  background: var(--line);
  overflow: hidden;
}
#loader .bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--red);
  box-shadow: 0 0 12px var(--red);
  transition: width 0.4s ease;
}
#loader .label {
  font-style: italic;
  font-size: 18px;
  color: var(--cream-dim);
}

/* ───────── intro ───────── */
#intro {
  position: fixed;
  left: 50%;
  bottom: max(34px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: none;
  border: 0;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.9s ease 0.6s;
}
.ready #intro { opacity: 1; pointer-events: auto; }
#intro.hidden { opacity: 0 !important; pointer-events: none !important; transition-delay: 0s; }
.intro-line {
  width: 1px;
  height: 38px;
  background: linear-gradient(to bottom, transparent, var(--red));
  animation: drip 2.4s ease-in-out infinite;
}
.intro-text {
  font-family: var(--f-caps);
  font-size: 12px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--cream-dim);
  animation: breathe 2.4s ease-in-out infinite;
}
@keyframes drip { 0%, 100% { transform: scaleY(0.4); transform-origin: top; } 50% { transform: scaleY(1); } }
@keyframes breathe { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* ───────── HUD ───────── */
.hud {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1s ease, transform 1s ease;
}
.is-open .hud { opacity: 1; }
.hud > * { pointer-events: auto; }
.hud-top {
  top: 0;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top)) 20px 0;
  transform: translateY(-8px);
}
.hud-bottom {
  bottom: 0;
  justify-content: center;
  gap: 18px;
  padding: 0 16px max(18px, env(safe-area-inset-bottom));
  transform: translateY(8px);
}
.is-open .hud-top, .is-open .hud-bottom { transform: none; }

.brand {
  display: grid;
  justify-items: start;
  gap: 2px;
  background: none;
  border: 0;
  padding: 4px;
  cursor: pointer;
  text-align: left;
}
.brand-name {
  font-family: var(--f-black);
  font-size: 26px;
  line-height: 1;
  text-shadow: 0 0 18px rgba(184, 25, 43, 0.45);
}
.brand-sub {
  font-family: var(--f-caps);
  font-size: 10px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--cream-dim);
}
.hud-actions { display: flex; align-items: center; gap: 10px; }

.join-btn {
  display: grid;
  justify-items: center;
  gap: 1px;
  height: 44px;
  padding: 0 18px;
  align-content: center;
  border-radius: 999px;
  border: 1px solid rgba(184, 25, 43, 0.75);
  background: linear-gradient(180deg, rgba(126, 13, 24, 0.85), rgba(70, 6, 14, 0.85));
  color: var(--cream);
  text-decoration: none;
  box-shadow: 0 0 18px rgba(184, 25, 43, 0.35);
  transition: box-shadow 0.25s, transform 0.25s;
}
.join-btn:hover, .join-btn:focus-visible {
  box-shadow: 0 0 26px rgba(184, 25, 43, 0.7);
  transform: translateY(-1px);
  outline: none;
}
.join-label {
  font-family: var(--f-caps);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.join-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-style: italic;
  color: var(--cream-dim);
}
.join-meta i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3bb35c;
  box-shadow: 0 0 8px #3bb35c;
}

.icon-btn, .nav-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  transition: border-color 0.25s, box-shadow 0.25s, color 0.25s, opacity 0.25s;
}
.icon-btn svg, .nav-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn:hover, .nav-btn:hover:not(:disabled), .icon-btn:focus-visible, .nav-btn:focus-visible {
  border-color: var(--red);
  color: #fff;
  box-shadow: 0 0 18px rgba(184, 25, 43, 0.45), inset 0 0 12px rgba(184, 25, 43, 0.25);
  outline: none;
}
.nav-btn:disabled { opacity: 0.25; cursor: default; }
#sound-btn .off { display: none; }
#sound-btn.off .on { display: none; }
#sound-btn.off .off { display: block; }

.where {
  display: grid;
  justify-items: center;
  min-width: 170px;
  gap: 3px;
}
#section {
  font-family: var(--f-caps);
  font-size: 12px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}
#pages {
  font-style: italic;
  font-size: 15px;
  color: var(--cream-dim);
  min-height: 1em;
}

.hint {
  position: fixed;
  left: 50%;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 64px);
  transform: translateX(-50%);
  margin: 0;
  z-index: 5;
  font-style: italic;
  font-size: 15px;
  color: var(--cream-dim);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.is-open .hint { animation: hint 6s ease 0.6s forwards; }
.hint-touch { display: none; }
@media (hover: none) {
  .hint-mouse { display: none; }
  .hint-touch { display: inline; }
}
@keyframes hint { 0% { opacity: 0; } 15%, 75% { opacity: 1; } 100% { opacity: 0; } }

#toast {
  position: fixed;
  left: 50%;
  top: 76px;
  transform: translate(-50%, -8px);
  z-index: 10;
  padding: 10px 18px;
  border: 1px solid rgba(184, 25, 43, 0.5);
  border-radius: 999px;
  background: rgba(14, 6, 8, 0.85);
  font-size: 16px;
  font-style: italic;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.noscript {
  position: fixed;
  inset: auto 0 40% 0;
  text-align: center;
  font-size: 20px;
}

@media (max-width: 600px) {
  .brand-name { font-size: 22px; }
  .join-long { display: none; }
  .brand-sub { font-size: 9px; letter-spacing: 0.2em; white-space: nowrap; }
  .join-btn { padding: 0 14px; }
  .hud-actions { gap: 8px; }
  .hud-top { padding-left: 16px; padding-right: 16px; }
  .where { min-width: 130px; }
  .hint { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .intro-line, .intro-text { animation: none; }
}
