:root {
  --ink: #0b0d16;
  --ink-2: #141827;
  --paper: #f4ede1;
  --muted: rgba(244, 237, 225, 0.62);
  --line: rgba(244, 237, 225, 0.16);
  --glass: rgba(11, 13, 22, 0.58);
  --vermilion: #e1452d;
  --lantern: #f4c46a;
  --frame-ratio: 1.75; /* 1344 / 768, overwritten from world config */
  --ease-cine: cubic-bezier(0.65, 0, 0.2, 1);
  --serif: "Shippori Mincho B1", "Hiragino Mincho ProN", serif;
  --sans: "Zen Kaku Gothic New", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--paper); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ── Stage ─────────────────────────────────────────────── */
#world { position: fixed; inset: 0; overflow: hidden; background: #000; }
#stage {
  position: absolute; left: 50%; top: 50%;
  width: max(100vw, calc(100vh * var(--frame-ratio)));
  height: max(100vh, calc(100vw / var(--frame-ratio)));
  transform: translate(-50%, -50%);
}
#scene-layers, .scene-layer, .scene-layer > *, #journey { position: absolute; inset: 0; width: 100%; height: 100%; }
.scene-layer { overflow: hidden; will-change: transform, opacity, filter; }
.scene-layer img, .scene-layer video { object-fit: cover; display: block; }
.scene-layer video { opacity: 0; transition: opacity 0.8s ease; }
.scene-layer video.ready { opacity: 1; }

/* Placeholder scene: a lantern-lit gradient that gently "breathes" until the
   real still and loop exist. */
.placeholder {
  background:
    radial-gradient(60% 50% at 30% 70%, hsla(var(--h), 90%, 60%, 0.55), transparent 70%),
    radial-gradient(40% 40% at 75% 35%, hsla(calc(var(--h) + 30), 90%, 70%, 0.35), transparent 70%),
    linear-gradient(180deg, hsl(calc(var(--h) + 220), 45%, 9%) 0%, hsl(var(--h), 55%, 18%) 70%, hsl(var(--h), 60%, 8%) 100%);
  display: grid; place-items: center;
  animation: breathe 16s ease-in-out infinite alternate;
}
.placeholder span { font-family: var(--serif); font-weight: 800; font-size: 22vmin; color: rgba(255, 255, 255, 0.07); letter-spacing: 0.08em; writing-mode: vertical-rl; }
@keyframes breathe { from { transform: scale(1); } to { transform: scale(1.06) translate(-1%, -0.5%); } }

#journey { object-fit: cover; opacity: 0; pointer-events: none; z-index: 2; }
#journey.playing { opacity: 1; }

#vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(120% 90% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.55)), linear-gradient(180deg, rgba(0,0,0,0.45), transparent 18%, transparent 78%, rgba(0,0,0,0.55)); }

/* ── Hotspots ──────────────────────────────────────────── */
#hotspots { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; }
#hotspots .spot { fill: rgba(244, 196, 106, 0); stroke: var(--lantern); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-dasharray: 6 6; cursor: pointer; transition: fill 0.3s, opacity 0.4s; animation: march 1.2s linear infinite; }
#hotspots .spot:hover, #hotspots .spot:focus { fill: rgba(244, 196, 106, 0.16); outline: none; stroke-dasharray: none; }
#hotspots .spot.taken { stroke: rgba(244, 237, 225, 0.7); }
@keyframes march { to { stroke-dashoffset: -12; } }
#hotspot-labels { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.spot-label {
  position: absolute; transform: translate(-50%, -50%); pointer-events: auto;
  padding: 0.55em 1em; border-radius: 999px; border: 1px solid var(--line);
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: clamp(12px, 1.1vw, 15px); white-space: nowrap; transition: transform 0.25s, background 0.25s, opacity 0.4s;
}
.spot-label:hover { background: rgba(225, 69, 45, 0.85); transform: translate(-50%, -50%) scale(1.05); }
.spot-label .new { margin-left: 0.5em; color: var(--lantern); font-size: 0.8em; font-weight: 700; letter-spacing: 0.08em; }
body.labels-hidden #hotspots, body.labels-hidden #hotspot-labels { opacity: 0; pointer-events: none; }
body.travelling #hotspots, body.travelling #hotspot-labels, body.travelling .hint, body.travelling .info-card { opacity: 0; pointer-events: none; transition: opacity 0.3s; }

/* ── HUD ───────────────────────────────────────────────── */
.hud { position: fixed; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 14px max(16px, env(safe-area-inset-left)); pointer-events: none; }
.hud-bottom { bottom: 0; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
.hud-top { top: 0; }
.hud-cluster { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--paper); text-decoration: none; font-weight: 700; letter-spacing: 0.18em; font-size: 13px; padding: 6px 14px 6px 6px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); }
.brand em { font-style: normal; font-weight: 400; color: var(--muted); }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--vermilion); font-family: var(--serif); letter-spacing: 0; }
.chip, .pill, .icon-btn, .now-playing, .volume { background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius: 999px; }
.chip { padding: 8px 14px; font-family: var(--serif); font-weight: 700; font-size: 14px; }
.pill { padding: 10px 16px; font-size: 13px; transition: background 0.2s, transform 0.2s; }
.pill:hover { background: rgba(244, 237, 225, 0.14); }
.pill[aria-pressed="true"] { background: var(--paper); color: var(--ink); }
.pill b { margin-left: 6px; color: var(--lantern); }
.pill-accent { background: var(--vermilion); border-color: transparent; }
.pill-accent:hover { background: #f05a41; transform: translateY(-1px); }
.pill-lg { padding: 16px 28px; font-size: 16px; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; font-size: 15px; padding: 0; }
.icon-btn:hover { background: rgba(244, 237, 225, 0.14); }
.now-playing { display: flex; align-items: center; gap: 10px; padding: 6px 14px 6px 10px; font-size: 12px; line-height: 1.2; }
.now-playing small { display: block; color: var(--muted); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }
.now-playing small + b + small { text-transform: none; letter-spacing: 0; }
.eq { display: flex; align-items: flex-end; gap: 2px; height: 14px; }
.eq i { width: 3px; background: var(--lantern); animation: eq 0.9s ease-in-out infinite alternate; }
.eq i:nth-child(2) { animation-delay: -0.3s; } .eq i:nth-child(3) { animation-delay: -0.6s; }
body.muted .eq i { animation-play-state: paused; height: 3px; }
@keyframes eq { from { height: 3px; } to { height: 14px; } }
.volume { display: flex; align-items: center; gap: 4px; padding-right: 12px; }
.volume .icon-btn { border: 0; background: none; backdrop-filter: none; }
.volume input { width: 80px; accent-color: var(--lantern); }

.hint { position: fixed; z-index: 9; top: 70px; left: max(16px, env(safe-area-inset-left)); padding: 10px 14px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); font-size: 12px; display: grid; gap: 3px; transition: opacity 0.3s; }
.hint span:last-child { color: var(--muted); }

.info-card { position: fixed; z-index: 9; right: max(16px, env(safe-area-inset-right)); top: 70px; width: min(320px, calc(100vw - 32px)); padding: 18px 20px; border-radius: 16px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transition: opacity 0.3s; }
.info-card small { color: var(--lantern); letter-spacing: 0.14em; text-transform: uppercase; font-size: 11px; }
.info-card h2 { font-family: var(--serif); margin: 4px 0 8px; font-size: 24px; }
.info-card p { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.info-card dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.info-card dt { color: var(--muted); }
.info-card dd { margin: 0; }

/* ── Map ───────────────────────────────────────────────── */
#map { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; padding: 24px; border: 1px solid var(--line); border-radius: 20px; background: rgba(14, 16, 27, 0.92); color: var(--paper); backdrop-filter: blur(18px); }
#map::backdrop { background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(4px); }
.map-head { display: flex; justify-content: space-between; align-items: flex-start; }
.map-head small, .map-stats small { color: var(--muted); font-size: 12px; }
.map-head h2 { font-family: var(--serif); margin: 4px 0 16px; font-size: 28px; }
.map-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.map-stats div { padding: 12px 14px; border-radius: 12px; background: rgba(244, 237, 225, 0.06); }
.map-stats b { display: block; font-family: var(--serif); font-size: 22px; margin-top: 2px; }
#map-svg { width: 100%; display: block; border-radius: 14px; background: radial-gradient(80% 80% at 60% 50%, #1b2236, #0d101b); }
#map-svg .route { stroke: rgba(244, 237, 225, 0.35); stroke-width: 0.004; stroke-dasharray: 0.01 0.01; fill: none; }
#map-svg .route.taken { stroke: var(--lantern); stroke-dasharray: none; }
#map-svg .place circle { fill: #3a4058; stroke: var(--paper); stroke-width: 0.003; }
#map-svg .place.visited circle { fill: var(--vermilion); }
#map-svg .place.here circle { fill: var(--lantern); }
#map-svg .place { cursor: pointer; }
#map-svg .place.locked { cursor: default; opacity: 0.55; }
#map-svg text { fill: var(--paper); font-size: 0.022px; font-family: var(--sans); }
.map-legend { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lg { display: inline-block; width: 18px; height: 0; border-top: 2px dashed rgba(244,237,225,0.5); margin-left: 8px; }
.lg.taken { border-top: 2px solid var(--lantern); margin-left: 0; }
.lg.here { width: 10px; height: 10px; border: 0; border-radius: 50%; background: var(--lantern); }
.text-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 12px; padding: 4px 0; }

/* ── Intro & rotate ────────────────────────────────────── */
.intro, .rotate { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; text-align: center; padding: 24px; }
.intro { background: radial-gradient(70% 60% at 50% 60%, rgba(225, 69, 45, 0.22), transparent 70%), rgba(6, 7, 12, 0.72); backdrop-filter: blur(6px); transition: opacity 1.2s var(--ease-cine), visibility 1.2s; }
.intro.gone { opacity: 0; visibility: hidden; }
.intro h1 { font-family: var(--serif); font-weight: 800; font-size: clamp(48px, 10vw, 128px); margin: 0.1em 0; letter-spacing: 0.02em; }
.intro h1 em { font-style: normal; color: var(--lantern); }
.intro-kicker { letter-spacing: 0.3em; text-transform: uppercase; font-size: 12px; color: var(--muted); }
.intro-tagline { max-width: 32em; margin: 0 auto 32px; color: var(--muted); line-height: 1.7; }
.rotate { z-index: 30; background: var(--ink); }
.rotate h2 { font-family: var(--serif); }
.rotate-icon { font-size: 48px; margin: 0; animation: tilt 2s ease-in-out infinite; }
@keyframes tilt { 50% { transform: rotate(-90deg); } }

@media (max-width: 760px) {
  .now-playing, .volume input, .hint span:first-child { display: none; }
  .hud-top .chip { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .info-card { top: auto; bottom: 70px; }
  #ride-btn { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .placeholder, #hotspots .spot, .eq i, .rotate-icon { animation: none; }
}
