:root {
  --void: #06021a; --deep: #0d0430; --plum: #2a0a5e;
  --magenta: #ff5cd0; --violet: #b388ff; --gold: #ffe6a3; --rose: #ffb1e2;
  --ivory: #f8efff; --muted: #a99ccc;
  --line: rgba(255, 230, 163, 0.18);
  --panel: rgba(9, 13, 24, 0.94);
  --clippy-blue: #9ad7ff; --clippy-green: #b8f28b;
  --ui-serif: "Cinzel", Georgia, serif;
  --ui-italic: "Cormorant Garamond", Georgia, serif;
  --ui-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--void);
  touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--ui-sans); color: var(--ivory);
}
#app { position: fixed; inset: 0; }
#app canvas { display: block; }

/* floating name labels above peers */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.peer-label {
  position: absolute; top: 0; left: 0;
  font: 600 13px/1 var(--ui-sans);
  color: var(--ivory);
  padding: 4px 9px; border-radius: 999px;
  background: rgba(13, 4, 48, 0.7);
  border: 1px solid var(--line);
  box-shadow: 0 6px 20px -8px rgba(0,0,0,0.8);
  white-space: nowrap; backdrop-filter: blur(4px);
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}

/* controls hint */
.hint {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(14px);
  z-index: 5; padding: 9px 16px; border-radius: 999px;
  font-size: 13px; letter-spacing: 0.01em; color: var(--ivory);
  background: rgba(13, 4, 48, 0.66); border: 1px solid var(--line);
  backdrop-filter: blur(8px); opacity: 0;
  transition: opacity 0.6s ease, transform 0.6s ease; pointer-events: none;
  max-width: calc(100vw - 32px); text-align: center;
}
.hint.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.hint strong { color: var(--gold); font-weight: 700; }

/* door prompt */
.prompt {
  position: fixed; left: 50%; top: 16%; transform: translateX(-50%) scale(0.9);
  z-index: 5; padding: 12px 22px; border-radius: 14px;
  font: 700 16px/1 var(--ui-sans); letter-spacing: 0.02em; color: var(--void);
  background: linear-gradient(135deg, var(--gold), var(--rose));
  box-shadow: 0 16px 50px -16px rgba(255, 230, 163, 0.8);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.prompt.is-visible { opacity: 1; transform: translateX(-50%) scale(1); pointer-events: auto; cursor: pointer; }

/* mobile joystick */
.joystick {
  position: fixed; left: 26px; bottom: 26px; width: 132px; height: 132px;
  border-radius: 50%; z-index: 6; display: none;
  background: radial-gradient(circle, rgba(179,136,255,0.16), rgba(13,4,48,0.4));
  border: 1px solid var(--line); touch-action: none;
}
.joystick.is-visible { display: block; }
.stick {
  position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--violet), var(--plum));
  border: 1px solid rgba(255,255,255,0.3);
  box-shadow: 0 8px 24px -8px rgba(255,92,208,0.8);
}

/* name gate */
.gate {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: 24px; pointer-events: auto;
  background:
    radial-gradient(ellipse at 20% 15%, rgba(255,92,208,0.2), transparent 55%),
    radial-gradient(ellipse at 85% 85%, rgba(99,60,255,0.26), transparent 55%),
    linear-gradient(160deg, #06021a 0%, #0a0322 45%, #110540 100%);
  transition: opacity 0.6s ease;
}
.gate.is-gone { opacity: 0; pointer-events: none; }
.gate-card {
  max-width: 520px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.gate-mark {
  font-family: var(--ui-serif); font-weight: 500; letter-spacing: 0.32em; text-transform: uppercase;
  font-size: 0.74rem; color: var(--gold); opacity: 0.85;
}
.gate-title {
  font-family: var(--ui-serif); font-weight: 700; font-size: clamp(2.4rem, 7vw, 3.6rem); margin: 0; line-height: 1.05;
  background: linear-gradient(120deg, #fff8e0 0%, #ffe6a3 35%, #ffb1e2 70%, #b388ff 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.gate-sub {
  font-family: var(--ui-italic); font-style: italic; font-size: clamp(1.05rem, 2.4vw, 1.32rem);
  color: var(--rose); margin: 0; max-width: 44ch; line-height: 1.45;
}
.gate-row { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }
.gate-input {
  font: 500 1rem var(--ui-sans); color: var(--ivory);
  padding: 13px 16px; border-radius: 12px; min-width: 200px;
  background: rgba(0,0,0,0.3); border: 1px solid rgba(154,215,255,0.3); outline: none;
}
.gate-input:focus { border-color: var(--clippy-green); box-shadow: 0 0 0 3px rgba(184,242,139,0.14); }
.gate-input::placeholder { color: #7f8fa3; }
.gate-btn {
  font: 700 1rem var(--ui-sans); color: var(--void); cursor: pointer;
  padding: 13px 22px; border-radius: 12px; border: none;
  background: linear-gradient(135deg, var(--gold), var(--rose));
  box-shadow: 0 16px 44px -16px rgba(255,230,163,0.8);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.gate-btn:hover { transform: translateY(-2px); box-shadow: 0 22px 56px -18px rgba(255,177,226,0.8); }
.gate-classic {
  font-family: var(--ui-italic); font-style: italic; font-size: 0.95rem; color: var(--muted);
  text-decoration: none; margin-top: 6px; transition: color 0.2s ease;
}
.gate-classic:hover { color: var(--gold); }

/* fade-to-black on entering a project */
.fade {
  position: fixed; inset: 0; z-index: 30; background: #06021a; opacity: 0; pointer-events: none;
  transition: opacity 0.6s ease;
}
.fade.is-active { opacity: 1; }

/* ───────────── loading screen (eccentric town materializer) ───────────── */
.loader {
  position: fixed; inset: 0; z-index: 28; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.55s ease;
  background:
    radial-gradient(ellipse at 22% 18%, rgba(255,92,208,0.22), transparent 55%),
    radial-gradient(ellipse at 82% 82%, rgba(99,60,255,0.28), transparent 55%),
    linear-gradient(160deg, #06021a 0%, #0a0322 45%, #110540 100%);
}
.loader.is-active { opacity: 1; pointer-events: auto; }

/* swirling acid warp behind the core */
.loader-warp {
  position: absolute; width: 170vmax; height: 170vmax; border-radius: 50%;
  background: conic-gradient(from 0deg,
    var(--magenta), var(--violet), var(--clippy-blue), var(--clippy-green),
    var(--gold), var(--rose), var(--magenta));
  filter: blur(90px) saturate(1.3); opacity: 0.22;
  animation: loaderWarp 26s linear infinite;
}
@keyframes loaderWarp { to { transform: rotate(360deg); } }

.loader-core {
  position: relative; z-index: 2; text-align: center; padding: 24px; max-width: 92vw;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}

/* portal rings + the Cloppy mascot */
.loader-portal { position: relative; width: 190px; height: 190px; margin-bottom: 4px; }
.lp-ring { position: absolute; inset: 0; border-radius: 50%; }
.lp-ring-1 { border: 2px dashed rgba(154,215,255,0.7); animation: loaderSpin 7s linear infinite; }
.lp-ring-2 {
  inset: 22px; border: 2px solid rgba(255,92,208,0.55);
  border-right-color: transparent; border-left-color: transparent;
  animation: loaderSpin 4.5s linear infinite reverse;
}
.lp-ring-3 { inset: 44px; border: 2px dashed rgba(184,242,139,0.6); animation: loaderSpin 11s linear infinite; }
.loader-portal::after {
  content: ''; position: absolute; inset: 30px; border-radius: 50%;
  background: radial-gradient(circle, rgba(179,136,255,0.4), transparent 70%); filter: blur(6px);
}
@keyframes loaderSpin { to { transform: rotate(360deg); } }

/* live 3D Cloppy (clippy.glb) rendered into this canvas; fades in over the SVG */
.loader-canvas {
  position: absolute; inset: 0; margin: auto;
  opacity: 0; transition: opacity 0.5s ease;
  filter: drop-shadow(0 0 12px rgba(154, 215, 255, 0.55));
}
.loader-portal.has-model .loader-canvas { opacity: 1; }
.loader-portal.has-model .loader-cloppy { display: none; }

.loader-cloppy {
  position: absolute; inset: 0; margin: auto; width: 116px; height: 145px; overflow: visible;
  filter: drop-shadow(0 0 10px rgba(154,215,255,0.7));
  animation: loaderBob 2.3s ease-in-out infinite;
}
@keyframes loaderBob {
  0%, 100% { transform: translateY(5px) rotate(-4deg); }
  50%      { transform: translateY(-11px) rotate(4deg); }
}
.lc-pupil { transform-box: fill-box; transform-origin: center; animation: loaderLook 3.1s ease-in-out infinite; }
@keyframes loaderLook {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(2px, -1px); }
  60% { transform: translate(-2px, 1px); }
}

.loader-word {
  font-family: var(--ui-serif); font-weight: 700; letter-spacing: 0.14em; text-transform: lowercase;
  font-size: clamp(1.3rem, 3.6vw, 1.9rem); line-height: 1.1;
  background: linear-gradient(120deg, #fff8e0, #ffe6a3 35%, #ffb1e2 70%, #b388ff 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: loaderShimmer 4s ease-in-out infinite;
}
@keyframes loaderShimmer { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }

.loader-msg {
  font-family: var(--ui-italic); font-style: italic; color: var(--rose);
  font-size: clamp(1rem, 2.6vw, 1.22rem); min-height: 1.5em; line-height: 1.4;
  transition: opacity 0.32s ease; opacity: 1;
}

.loader-track {
  position: relative; width: min(340px, 78vw); height: 6px; margin-top: 2px;
  border-radius: 999px; background: rgba(255,255,255,0.08); border: 1px solid var(--line); overflow: hidden;
}
.loader-fill {
  display: block; width: 4%; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--clippy-blue), var(--violet), var(--magenta), var(--gold));
  background-size: 300% 100%; box-shadow: 0 0 14px rgba(255,92,208,0.8);
  transition: width 0.2s ease; animation: loaderFlow 2.2s linear infinite;
}
@keyframes loaderFlow { to { background-position: 300% 50%; } }

.loader-pct { font: 600 0.82rem/1 var(--ui-sans); letter-spacing: 0.14em; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .loader-warp, .lp-ring, .loader-cloppy, .lc-pupil, .loader-word, .loader-fill { animation: none; }
}

/* ───────────── Cloppy chat (ported from the classic page) ───────────── */
.chat {
  position: fixed; right: clamp(12px, 3vw, 28px); bottom: clamp(12px, 3vw, 28px);
  z-index: 12; width: min(400px, calc(100vw - 24px));
  max-height: min(640px, calc(100dvh - 24px));
  border: 1px solid rgba(154,215,255,0.28); border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 28px 90px -24px rgba(0,0,0,0.8), 0 0 54px -32px rgba(154,215,255,0.9);
  backdrop-filter: blur(16px); overflow: hidden;
  display: none; flex-direction: column;
  font-family: var(--ui-sans);
}
.chat.is-open { display: flex; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 14px 12px;
  border-bottom: 1px solid rgba(154,215,255,0.18);
  background: linear-gradient(135deg, rgba(154,215,255,0.12), rgba(184,242,139,0.08));
}
.chat-avatar { width: 34px; height: 34px; object-fit: contain; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.35)); }
.chat-title { flex: 1; min-width: 0; }
.chat-title h2 { margin: 0; color: #f4fbff; font-size: 0.98rem; line-height: 1.2; }
.chat-title p { margin: 2px 0 0; color: #a9bdd0; font-size: 0.78rem; }
.chat-icon, .chat-send {
  border: 1px solid rgba(154,215,255,0.24); color: #f4fbff; background: rgba(255,255,255,0.06);
  cursor: pointer; transition: background 0.2s ease, border-color 0.2s ease;
}
.chat-icon { width: 34px; height: 34px; border-radius: 8px; font-size: 1.1rem; line-height: 1; }
.chat-icon:hover, .chat-send:hover { background: rgba(154,215,255,0.14); border-color: rgba(184,242,139,0.48); }
.chat-messages { flex: 1; min-height: 240px; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 12px; }
.chat-message { max-width: 88%; padding: 10px 12px; border-radius: 12px; font-size: 0.92rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-message.assistant { align-self: flex-start; color: #f4fbff; background: rgba(154,215,255,0.1); border: 1px solid rgba(154,215,255,0.18); border-top-left-radius: 4px; }
.chat-message.user { align-self: flex-end; color: #102216; background: linear-gradient(135deg, var(--clippy-green), var(--clippy-blue)); border-top-right-radius: 4px; }
.chat-message.error { align-self: stretch; max-width: none; color: #ffd6df; background: rgba(255,92,127,0.12); border: 1px solid rgba(255,92,127,0.26); }
.chat-suggestions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 14px; }
.chat-suggestions.is-hidden { display: none; }
.chat-suggestion {
  border: 1px solid rgba(184,242,139,0.24); border-radius: 999px; padding: 8px 10px;
  color: #e9fff0; background: rgba(184,242,139,0.08); cursor: pointer; font: inherit; font-size: 0.8rem; line-height: 1.2;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.chat-suggestion:hover { background: rgba(184,242,139,0.16); border-color: rgba(184,242,139,0.52); }
.chat-compose { display: flex; gap: 10px; padding: 12px; border-top: 1px solid rgba(154,215,255,0.18); background: rgba(255,255,255,0.035); }
.chat-input {
  flex: 1; min-height: 44px; max-height: 120px; resize: none;
  border: 1px solid rgba(154,215,255,0.2); border-radius: 10px; padding: 10px 12px;
  color: #f4fbff; background: rgba(0,0,0,0.22); font: inherit; line-height: 1.4; outline: none;
}
.chat-input:focus { border-color: rgba(184,242,139,0.62); box-shadow: 0 0 0 3px rgba(184,242,139,0.12); }
.chat-input::placeholder { color: #7f8fa3; }
.chat-send { width: 44px; height: 44px; border-radius: 10px; flex: 0 0 auto; font-size: 1.15rem; }
.chat-send:disabled, .chat-suggestion:disabled, .chat-input:disabled { cursor: not-allowed; opacity: 0.55; }

@media (max-width: 640px) {
  /* Bottom sheet: pinned to the bottom, capped to the *visual* viewport (dvh)
     so the header + close button are always on-screen and tappable. The message
     list takes the slack and scrolls; the compose row stays above the keyboard. */
  .chat {
    left: 8px; right: 8px; bottom: 8px; top: auto; width: auto;
    max-height: 80dvh;
    border-radius: 18px;
  }
  .chat-head { padding: 16px 14px 14px; }
  .chat-icon { width: 40px; height: 40px; font-size: 1.25rem; }
  .chat-messages { min-height: 100px; }
  .chat-message { max-width: 92%; }
  .hint { font-size: 11px; bottom: 14px; }
}
