:root {
  --bg: #0e0f13;
  --fg: #e8e9ee;
  --muted: #9aa0ab;
  --accent: #6080ff;
  --panel: rgba(14, 15, 19, 0.72);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
/* the hidden attribute must always win over later display rules */
[hidden] { display: none !important; }
html, body { background: var(--bg); color: var(--fg);
  font-family: system-ui, -apple-system, sans-serif; }

/* iOS Safari: kill the grey tap-flash and the 300 ms tap delay on every button */
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

#stage { position: relative; width: 100%; height: 82vh; overflow: hidden;
  /* prevent pull-to-refresh / page-scroll bleed when the user drags inside the canvas */
  overscroll-behavior: contain; }
#canvas-host { position: absolute; inset: 0; }
#canvas-host canvas { width: 100%; height: 100%; display: block;
  /* let JS own all touch gestures on the WebGL canvas — no browser pinch/pan/dbl-tap-zoom */
  touch-action: none; }

#hero-overlay { position: absolute; left: 5vw; bottom: 8vh; max-width: 30rem;
  background: var(--panel); padding: 1.5rem; border-radius: 10px;
  backdrop-filter: blur(8px); }
#hero-overlay h1 { font-size: 1.9rem; line-height: 1.15; }
#hero-overlay p { color: var(--muted); margin: 0.6rem 0 1rem; }

.cta-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
button, .btn-secondary { font: inherit; padding: 0.6rem 1rem; border-radius: 7px;
  border: 1px solid var(--accent); cursor: pointer; text-decoration: none; }
button { background: var(--accent); color: #fff; }
.btn-secondary { background: transparent; color: var(--fg); }

#stage-controls { position: absolute; left: 50%; bottom: 1.5rem;
  transform: translateX(-50%); display: flex; gap: 0.6rem; z-index: 5; }
#stage-controls button { background: var(--panel); color: var(--fg);
  border: 1px solid rgba(255,255,255,0.25); font-size: 1rem; font-weight: 500;
  padding: 0.7rem 1.3rem; border-radius: 999px; backdrop-filter: blur(8px); }
#stage-controls button:hover { border-color: var(--accent); }

/* fullscreen: hide the intro overlay — pure splat */
#stage:fullscreen #hero-overlay { display: none; }
#stage:-webkit-full-screen #hero-overlay { display: none; }

/* iOS Safari iPhone has no Fullscreen API for non-<video>: CSS pseudo-fullscreen */
body.fs-fallback { overflow: hidden; }
body.fs-fallback #stage {
  position: fixed; inset: 0; width: 100vw; height: 100dvh;
  z-index: 9999;
}
body.fs-fallback #hero-overlay { display: none; }

#drop-hint { position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center; font-size: 1.4rem;
  background: rgba(96,128,255,0.25); border: 3px dashed var(--accent); }
#viewer-error { position: absolute; left: 50%; top: 1rem;
  transform: translateX(-50%); background: #5a1f1f; color: #ffd9d9;
  padding: 0.6rem 1rem; border-radius: 7px; }
#viewer-spinner { position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%); background: var(--panel);
  padding: 0.6rem 1.2rem; border-radius: 7px; color: var(--fg); }

#about { max-width: 48rem; margin: 0 auto; padding: 4rem 1.5rem; }
#about h2 { font-size: 1.5rem; margin-bottom: 0.8rem; }
#about p { color: var(--muted); line-height: 1.6; margin-bottom: 1rem; }
#pipeline-flow { list-style: none; display: flex; flex-wrap: wrap; gap: 0.5rem;
  margin: 1.2rem 0; }
#pipeline-flow li { background: #1a1c24; padding: 0.4rem 0.8rem;
  border-radius: 6px; font-size: 0.85rem; }
#pipeline-flow li + li::before { content: "→"; color: var(--accent);
  margin-right: 0.5rem; margin-left: -0.3rem; }
#about a { color: var(--accent); }

footer { display: flex; gap: 0.6rem; justify-content: center;
  padding: 2rem 1rem; color: var(--muted); font-size: 0.85rem;
  border-top: 1px solid #1a1c24; }
footer a { color: var(--muted); }

@media (max-width: 600px) {
  /* dvh follows the dynamic viewport (URL bar collapse on iOS); falls back to vh */
  #stage { height: 70vh; height: 70dvh; }
  #hero-overlay { left: 3vw; right: 3vw; max-width: none;
    bottom: calc(8vh + env(safe-area-inset-bottom)); }
  /* push controls below the iPhone notch / status bar */
  #stage-controls { bottom: auto; top: calc(1rem + env(safe-area-inset-top)); }
}

/* ---------- Walking-mode CTA (entry button) ---------- */

#cta-walk {
  position: absolute; left: 50%; top: 38%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, var(--accent) 0%, #4a6ae8 100%);
  color: #fff; font-weight: 600; font-size: 1.1rem;
  padding: 0.95rem 1.6rem; border-radius: 999px; border: none;
  box-shadow: 0 8px 28px rgba(96, 128, 255, 0.45),
              0 0 0 1px rgba(255, 255, 255, 0.12) inset;
  cursor: pointer; z-index: 10;
  opacity: 0; transition: opacity 0.5s ease, transform 0.5s ease;
  letter-spacing: 0.01em;
}
#cta-walk.is-visible { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#cta-walk:hover { transform: translate(-50%, -50%) scale(1.03); }
#cta-walk:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

/* ---------- Walking-mode HUD overlay ---------- */

#walk-hud {
  position: absolute; inset: 0; z-index: 20;
  pointer-events: none;  /* let underlying canvas keep receiving events */
}
#walk-hud > * { pointer-events: auto; }
#walk-hud > #walk-crosshair { pointer-events: none; }

#walk-crosshair {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  color: #fff; opacity: 0.55; font-size: 1.6rem; line-height: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  user-select: none;
}

#walk-mode-indicator {
  position: absolute;
  left: calc(1.2rem + env(safe-area-inset-left));
  top:  calc(1.2rem + env(safe-area-inset-top));
  background: var(--panel); color: var(--fg);
  padding: 0.45rem 0.95rem; border-radius: 999px;
  font-size: 0.9rem; font-weight: 600;
  border: 1px solid rgba(255,255,255,0.18);
  backdrop-filter: blur(8px);
}
#walk-mode-indicator[data-mode="fly"] {
  background: linear-gradient(135deg, #4a6ae8 0%, #6080ff 100%);
  color: #fff; border-color: rgba(255,255,255,0.35);
}

#walk-exit {
  position: absolute;
  right: calc(1.2rem + env(safe-area-inset-right));
  top:   calc(1.2rem + env(safe-area-inset-top));
  background: rgba(170, 48, 48, 0.85); color: #fff;
  width: 2.4rem; height: 2.4rem; padding: 0;
  border-radius: 999px; border: 1px solid rgba(255,255,255,0.3);
  font-size: 1.1rem; line-height: 1; cursor: pointer;
  backdrop-filter: blur(8px);
}
#walk-exit:hover { background: rgba(190, 56, 56, 0.95); }

#walk-controls-hint {
  position: absolute; left: 50%;
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--panel); color: var(--fg);
  padding: 0.45rem 1rem; border-radius: 999px;
  font-size: 0.82rem; letter-spacing: 0.02em;
  border: 1px solid rgba(255,255,255,0.15);
  backdrop-filter: blur(8px);
  transition: opacity 0.8s ease;
}
#walk-controls-hint.is-dim { opacity: 0.25; }

#walk-eye-overlay {
  position: absolute; left: 50%; top: 58%;
  transform: translate(-50%, -50%);
  background: var(--panel); color: var(--fg);
  padding: 0.4rem 0.9rem; border-radius: 7px;
  font-size: 0.85rem; opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
#walk-eye-overlay.is-visible { opacity: 1; }

/* ---------- Walking-mode touch buttons (Jump / Fly) ---------- */

#walk-touch-buttons {
  position: absolute;
  right:  calc(1rem + env(safe-area-inset-right));
  bottom: calc(4.5rem + env(safe-area-inset-bottom));
  display: none;  /* shown on touch-capable devices only — see media-query below */
  flex-direction: column; gap: 0.6rem;
  pointer-events: auto;
}
#walk-touch-buttons button {
  width: 3.6rem; height: 3.6rem;
  border-radius: 999px; border: 1px solid rgba(255,255,255,0.3);
  background: var(--panel); color: var(--fg);
  font-size: 1.3rem; line-height: 1; cursor: pointer;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#walk-touch-buttons button:active {
  background: var(--accent); border-color: rgba(255,255,255,0.6);
}

/* Show touch buttons only on coarse-pointer devices (phones/tablets). */
@media (hover: none) and (pointer: coarse) {
  #walk-touch-buttons { display: flex; }
  /* hide the keyboard controls-hint on touch — it lists keys you don't have */
  #walk-controls-hint { display: none; }
}

/* Mobile tweaks */
@media (max-width: 600px) {
  #cta-walk { font-size: 1rem; padding: 0.85rem 1.3rem; top: 35%; }
  #walk-mode-indicator { font-size: 0.8rem; padding: 0.4rem 0.8rem; }
  #walk-controls-hint { font-size: 0.72rem; bottom: 1rem; max-width: 92vw; }
  #walk-touch-buttons button { width: 3.2rem; height: 3.2rem; font-size: 1.2rem; }
}

/* Collision editor toolbar */
#collision-toolbar {
  position: absolute;
  right: max(env(safe-area-inset-right), 1rem);
  top: 5rem;
  width: 18rem;
  max-width: calc(100vw - 2rem);
  padding: 0.8rem;
  background: rgba(14, 15, 19, 0.92);
  color: #d8dee9;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0.5rem;
  font: 0.85rem/1.4 system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  z-index: 5;
}
#collision-toolbar h3 { margin: 0 0 0.25rem; font-size: 0.95rem; }
#collision-toolbar fieldset {
  margin: 0;
  padding: 0.35rem 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0.3rem;
  display: flex; gap: 0.6rem; flex-wrap: wrap;
}
#collision-toolbar fieldset legend { padding: 0 0.3rem; }
#collision-toolbar label { display: flex; align-items: center; gap: 0.35rem; }
#collision-toolbar .coll-row { display: flex; gap: 0.5rem; }
#collision-toolbar .coll-row button { flex: 1; }
#collision-toolbar button {
  padding: 0.4rem 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0.3rem;
  cursor: pointer;
}
#collision-toolbar button:hover { background: rgba(255, 255, 255, 0.1); }
#collision-toolbar .coll-checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
}
#collision-toolbar #coll-status {
  margin: 0;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
}
@media (max-width: 600px) {
  #collision-toolbar {
    right: 0; left: 0; bottom: 0; top: auto;
    width: 100%; max-width: 100%;
    border-radius: 0.5rem 0.5rem 0 0;
    padding-bottom: max(env(safe-area-inset-bottom), 0.8rem);
  }
}
