/* jfeelgood.com walkable gallery — loader, HUD, cards.
   Palette mirrors the classic site: near-black + gold accent. */

:root {
  --bg: #050509;
  --bg-alt: #0b0b12;
  --accent: #f5b642;
  --accent-soft: #f5e1b8;
  --text: #f7f7f7;
  --text-muted: #b1b1c7;
  --border: #262637;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'DM Sans', system-ui, sans-serif;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
}

canvas.gallery-canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  /* drag-to-look owns the canvas on touch; no scrolling or pinch-zoom */
  touch-action: none;
}

/* ---------- no-JS / no-WebGL ---------- */

.noscript-card, .nogl-card {
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: radial-gradient(ellipse at 50% 30%, #14101f 0%, var(--bg) 65%);
  z-index: 60;
  padding: 24px;
}
.noscript-card { display: flex; } /* only in the DOM when JS is off */
.nogl-card { display: none; }
/* id+attr specificity beats the base .nogl-card rule when JS clears hidden */
#nogl:not([hidden]) { display: flex; }
.noscript-card h1, .nogl-title {
  font-family: var(--serif);
  font-weight: 300;
  letter-spacing: 0.35em;
  color: var(--accent-soft);
}
.nogl-title { font-size: 34px; margin-bottom: 18px; }
.noscript-card p, .nogl-card p { color: var(--text-muted); max-width: 480px; line-height: 1.6; }
.noscript-card a, .nogl-btn { color: var(--accent); text-decoration: none; }
.nogl-btn {
  display: inline-block;
  margin-top: 18px;
  padding: 12px 26px;
  border: 1px solid var(--accent);
  letter-spacing: 0.12em;
  font-size: 13px;
  text-transform: uppercase;
}
.nogl-btn:hover { background: rgba(245, 182, 66, 0.12); }

/* ---------- loader ---------- */

.loader {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 25%, #191324 0%, var(--bg) 70%);
  z-index: 50;
  transition: opacity 0.9s ease;
}
.loader.fading { opacity: 0; pointer-events: none; }
.loader-inner { text-align: center; max-width: 560px; padding: 24px; }
.loader-kicker {
  font-size: 12px;
  letter-spacing: 0.5em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.loader-title {
  font-family: var(--serif);
  font-weight: 300;
  font-size: clamp(42px, 7vw, 72px);
  letter-spacing: 0.32em;
  margin-left: 0.32em; /* optically recenter the tracked-out text */
  color: var(--accent-soft);
  text-shadow: 0 0 60px rgba(245, 182, 66, 0.25);
}
.loader-sub {
  font-family: var(--serif);
  font-style: italic;
  font-size: 19px;
  color: var(--text-muted);
  margin: 10px 0 34px;
}
.loader-bar {
  width: min(360px, 70vw);
  height: 2px;
  margin: 0 auto;
  background: var(--border);
  overflow: hidden;
}
.loader-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-soft));
  transition: width 0.25s ease;
}
.loader-status {
  margin-top: 12px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
  min-height: 16px;
}
.enter-btn {
  margin-top: 26px;
  padding: 14px 42px;
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: 0.22em;
  color: var(--bg);
  background: linear-gradient(90deg, var(--accent), #e8c06a);
  border: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.enter-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 30px rgba(245, 182, 66, 0.35);
}
.enter-btn[hidden] { display: none; }
.loader-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 22px;
  margin-top: 26px;
  font-size: 12px;
  color: var(--text-muted);
}
.loader-controls[hidden] { display: none; }
.loader-controls b { color: var(--accent-soft); font-weight: 500; }
.loader-classic {
  display: inline-block;
  margin-top: 30px;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  text-decoration: none;
}
.loader-classic:hover { color: var(--accent); }

/* ---------- title screen: two doors ---------- */

/* #loader carries .stage-choice first, then .stage-loading once the visitor
   picks the world. Nothing heavy runs until then. */
.title-choices {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 32px;
}
.title-btn {
  display: inline-block;
  box-sizing: border-box;
  min-width: 236px;
  min-height: 50px;
  padding: 15px 34px;
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: 0.22em;
  text-align: center;
  text-decoration: none;
  color: var(--bg);
  background: linear-gradient(90deg, var(--accent), #e8c06a);
  border: 1px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.title-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 30px rgba(245, 182, 66, 0.35); }
.title-btn.ghost {
  color: var(--accent-soft);
  background: none;
  border-color: var(--border);
}
.title-btn.ghost:hover { border-color: var(--accent); box-shadow: none; }
.title-note {
  display: grid;
  gap: 6px;
  margin-top: 22px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-muted);
}

/* stage switching — plain display rules, no [hidden] traps */
.loader.stage-choice .loader-bar,
.loader.stage-choice .loader-status,
.loader.stage-choice .enter-btn,
.loader.stage-choice .loader-controls { display: none; }
.loader.stage-loading .title-choices,
.loader.stage-loading .title-note { display: none; }

/* keyboard legend on desktop, on-screen legend on touch */
.loader-controls.touch-controls { display: none; }
html.touch .loader .loader-controls:not(.touch-controls) { display: none; }
html.touch .loader.stage-loading .loader-controls.touch-controls { display: flex; }

/* ---------- HUD ---------- */

#hud[hidden] { display: none; }

.compass {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(5, 5, 9, 0.55), transparent);
  z-index: 20;
}
.compass .tick {
  position: absolute;
  top: 12px;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-soft);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}
.compass .tick::after {
  content: '';
  display: block;
  width: 1px;
  height: 7px;
  margin: 4px auto 0;
  background: var(--accent);
}
.compass .tick.dim { color: var(--text-muted); opacity: 0.6; }

.prompt {
  position: fixed;
  left: 50%;
  bottom: 12vh;
  transform: translateX(-50%);
  padding: 10px 22px;
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent-soft);
  background: rgba(5, 5, 9, 0.72);
  border: 1px solid rgba(245, 182, 66, 0.5);
  border-radius: 2px;
  z-index: 20;
  pointer-events: none;
}
.prompt b { color: var(--accent); font-weight: 500; }
.prompt[hidden] { display: none; }

.hint {
  position: fixed;
  left: 50%;
  top: 56px;
  transform: translateX(-50%);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  z-index: 20;
  pointer-events: none;
  transition: opacity 1s ease;
}
.hint[hidden] { display: none; }

.footer-links {
  position: fixed;
  right: 14px;
  bottom: 12px;
  display: flex;
  gap: 16px;
  z-index: 20;
  font-size: 11px;
  letter-spacing: 0.14em;
}
.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
}
.footer-links a:hover { color: var(--accent); }

/* crosshair dot while pointer-locked */
#hud.locked::after {
  content: '';
  position: fixed;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: rgba(245, 225, 184, 0.8);
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
  z-index: 20;
}

/* ---------- info card overlay ---------- */

.card-overlay, .viewer-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 3, 6, 0.78);
  backdrop-filter: blur(3px);
  z-index: 40;
}
.card-overlay[hidden], .viewer-overlay[hidden] { display: none; }

.card-box {
  position: relative; /* .card-close anchors here, not to the viewport */
  display: flex;
  gap: 28px;
  max-width: min(920px, 92vw);
  max-height: 86vh;
  padding: 28px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
}
.card-box img {
  max-width: 44vw;
  max-height: 76vh;
  width: auto;
  height: auto;
  object-fit: contain;
  align-self: center;
}
.card-text {
  overflow-y: auto;
  min-width: 240px;
  max-width: 380px;
  padding-right: 6px;
}
.card-kicker {
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
.card-title {
  font-family: var(--serif);
  font-weight: 300;
  font-size: 32px;
  color: var(--accent-soft);
  margin: 0 0 6px;
}
.card-meta {
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.card-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}
.card-body p { margin: 0 0 12px; }
.card-actions { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 12px; }
.card-btn {
  padding: 10px 22px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--bg);
  background: linear-gradient(90deg, var(--accent), #e8c06a);
}
.card-btn.ghost {
  color: var(--accent-soft);
  background: transparent;
  border: 1px solid var(--border);
}
.card-btn:hover { filter: brightness(1.08); }
.card-close {
  position: absolute;
  top: 18px;
  right: 22px;
  font-size: 26px;
  line-height: 1;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
}
.card-close:hover { color: var(--accent); }
.card-stock { font-size: 12px; color: var(--accent); margin-top: 10px; letter-spacing: 0.1em; }

/* ---------- citizen dialogue tree ---------- */

.card-box.dialogue { min-width: min(420px, 88vw); }
.dlg-say {
  min-height: 3.4em;
  font-style: italic;
  color: var(--accent-soft);
}
.dlg-say p { margin: 0; }
.dlg-choices {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.dlg-choice {
  text-align: left;
  padding: 11px 15px;
  font-size: 13px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  color: var(--text);
  background: rgba(245, 182, 66, 0.06);
  border: 1px solid var(--border);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.dlg-choice::before { content: "› "; color: var(--accent); }
.dlg-choice:hover {
  color: var(--accent-soft);
  background: rgba(245, 182, 66, 0.14);
  border-color: var(--accent);
}
.dlg-choice.ghost {
  color: var(--text-muted);
  background: transparent;
  margin-top: 4px;
}
.dlg-choice.ghost::before { content: ""; }

/* ---------- archive full-res viewer ---------- */

.viewer-box { position: relative; text-align: center; max-width: 94vw; }
.viewer-box img {
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.8);
}
.viewer-caption {
  margin-top: 14px;
  font-family: var(--serif);
  font-size: 20px;
  color: var(--accent-soft);
}
.viewer-sub { font-size: 12px; color: var(--text-muted); letter-spacing: 0.14em; margin-top: 4px; }
.viewer-sub a { color: var(--accent); text-decoration: none; }

/* fade-to-black used for gallery enter/exit */
#fade {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 30;
}
#fade.on { opacity: 1; }

/* ---------- on-screen controls (touch devices) ---------- */

/* Built by gallery/js/touch.js and appended to #hud, so it inherits
   #hud[hidden] and appears exactly when the world is entered. The layer itself
   never swallows events — only the stick and the buttons do — which leaves the
   canvas free to receive drag-to-look everywhere else. */
#touch {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* reading a card shouldn't happen behind a thumbstick */
html.overlay-open #touch { display: none; }

.touch-stick {
  position: fixed;
  left: calc(20px + env(safe-area-inset-left));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 136px;
  height: 136px;
  border-radius: 50%;
  border: 1px solid rgba(245, 182, 66, 0.28);
  background: rgba(5, 5, 9, 0.3);
  display: grid;
  place-items: center;
  pointer-events: auto;
  touch-action: none;
}
.touch-knob {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(245, 225, 184, 0.26);
  border: 1px solid rgba(245, 182, 66, 0.6);
  pointer-events: none;
}

.touch-buttons {
  position: fixed;
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}
.touch-row { display: flex; gap: 12px; }
.touch-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--accent-soft);
  background: rgba(5, 5, 9, 0.5);
  border: 1px solid rgba(245, 182, 66, 0.42);
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.touch-btn.on { background: rgba(245, 182, 66, 0.42); color: var(--bg); }
/* ACT stays dim until something is actually in range */
.touch-btn.touch-act {
  align-self: flex-end;
  width: 78px;
  height: 78px;
  opacity: 0.38;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}
body.has-prompt .touch-btn.touch-act { opacity: 1; border-color: var(--accent); }

/* ---------- touch HUD adjustments ---------- */

html.touch, html.touch body { overscroll-behavior: none; }

html.touch .compass {
  height: calc(44px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}
html.touch .compass .tick { top: calc(12px + env(safe-area-inset-top)); font-size: 10px; letter-spacing: 0.12em; }
/* the hint is long and transient; float it clear of the compass, the footer
   links and the thumb controls rather than letting it wrap across them */
html.touch .hint {
  top: 30%;
  max-width: 78vw;
  padding: 12px 16px;
  text-align: center;
  line-height: 1.7;
  color: var(--accent-soft);
  background: rgba(5, 5, 9, 0.66);
  border: 1px solid rgba(245, 182, 66, 0.25);
  border-radius: 2px;
}
/* clear of the thumbstick and the button cluster */
html.touch .prompt {
  bottom: calc(env(safe-area-inset-bottom) + 178px);
  max-width: 84vw;
  text-align: center;
  line-height: 1.5;
  letter-spacing: 0.14em;
}
/* the home-indicator strip is where the footer links used to sit; the top-right
   band under the compass is the only place nothing else claims */
html.touch .footer-links {
  bottom: auto;
  left: auto;
  right: calc(12px + env(safe-area-inset-right));
  top: calc(52px + env(safe-area-inset-top));
  gap: 14px;
  font-size: 10px;
}
/* pointer lock has no meaning here, so the legend loses its ESC line */
html.touch .loader-controls.touch-controls { gap: 10px 18px; }

@media (orientation: landscape) and (max-height: 540px) {
  html.touch .prompt { bottom: auto; top: calc(58px + env(safe-area-inset-top)); }
  html.touch .compass { height: calc(34px + env(safe-area-inset-top)); }
  .touch-stick { width: 112px; height: 112px; }
  .touch-knob { width: 46px; height: 46px; }
  .touch-btn { width: 56px; height: 56px; font-size: 12px; }
  .touch-btn.touch-act { width: 66px; height: 66px; }
}

/* ---------- narrow screens ---------- */

@media (max-width: 760px) {
  .title-choices { flex-direction: column; align-items: stretch; }
  .title-btn { min-width: 0; width: 100%; }
  .loader-inner { padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); }
  .loader-sub { font-size: 17px; margin-bottom: 24px; }

  /* the card is a two-column layout with a 44vw image on desktop; stack it and
     move the scroll from .card-text to the box so image and text move together */
  .card-box {
    box-sizing: border-box; /* keep the padding inside the 94vw, off the edges */
    flex-direction: column;
    gap: 16px;
    width: 94vw;
    max-width: 94vw;
    max-height: 88vh;
    max-height: 88dvh;
    padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  .card-box img { max-width: 100%; max-height: 40vh; max-height: 40dvh; align-self: center; }
  .card-text { max-width: none; min-width: 0; overflow: visible; }
  .card-title { font-size: 26px; }
  .card-box.dialogue { min-width: 0; }
  .card-actions .card-btn { flex: 1 1 auto; text-align: center; min-height: 44px; }
  .dlg-choice { min-height: 48px; }
  .card-close {
    top: 4px;
    right: 6px;
    width: 44px;
    height: 44px;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .viewer-box {
    max-width: 96vw;
    max-height: 90vh;
    max-height: 90dvh;
    padding-top: calc(env(safe-area-inset-top) + 10px);
  }
  .viewer-box img { max-width: 94vw; max-height: 62vh; max-height: 62dvh; }
}
