:root {
  --fg: rgba(240, 244, 255, 0.92);
  --dim: rgba(220, 228, 250, 0.55);
  --faint: rgba(220, 228, 250, 0.22);
  --accent: #ffd9a0;
  --glass: rgba(14, 18, 30, 0.42);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  --num: "Avenir Next", "Helvetica Neue", var(--font);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--fg); font-family: var(--font); overflow: hidden; -webkit-font-smoothing: antialiased; }
canvas#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.55) 100%); }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#hud { position: fixed; inset: 0; pointer-events: none; transition: opacity 1.2s ease; }
#hud.hidden { opacity: 0; }
#hud > * { pointer-events: auto; }

#brand { position: absolute; top: 26px; left: 30px; display: flex; gap: 12px; align-items: baseline; pointer-events: none; }
#brand .en { font-family: var(--num); letter-spacing: 0.38em; font-size: 11px; color: var(--fg); opacity: 0.75; }
#brand .ja { font-size: 13px; letter-spacing: 0.3em; color: var(--fg); font-weight: 300; }

#scale { position: absolute; left: 30px; bottom: 34px; pointer-events: none; }
#pow { font-family: var(--num); font-weight: 200; font-size: 64px; line-height: 1; letter-spacing: -0.01em; color: #fff; }
#pow sup { font-size: 0.42em; font-weight: 300; vertical-align: 1.2em; margin-left: 2px; display: inline-block; min-width: 1.6em; }
#pow .unit { font-size: 0.32em; color: var(--dim); margin-left: 6px; font-weight: 300; }
#human { margin-top: 10px; font-size: 14px; color: var(--fg); font-weight: 300; letter-spacing: 0.04em; }
#bar { margin-top: 14px; display: flex; align-items: center; gap: 10px; }
#barline { height: 7px; border: 1px solid rgba(255,255,255,0.7); border-top: 0; width: 100px; transition: width 0.15s; }
#barlabel { font-size: 12px; color: var(--dim); font-family: var(--num); }

#ruler { position: absolute; right: 26px; top: 70px; bottom: 120px; width: 150px; cursor: ns-resize; }
#ruler-track { position: absolute; right: 0; top: 0; bottom: 0; width: 100%; }
.tick { position: absolute; right: 0; height: 1px; background: var(--faint); width: 8px; }
.tick.major { width: 14px; background: rgba(220,228,250,0.4); }
.tick-label { position: absolute; right: 20px; transform: translateY(-50%); font-family: var(--num); font-size: 10px; color: var(--dim); white-space: nowrap; }
.stop-dot { position: absolute; right: 4px; width: 5px; height: 5px; border-radius: 50%; background: rgba(255,217,160,0.55); transform: translate(50%, -50%); }
.stop-name { position: absolute; right: 22px; transform: translateY(-50%); font-size: 12px; color: var(--dim); white-space: nowrap; opacity: 0; transition: opacity 0.4s; pointer-events: none; }
#ruler:hover .stop-name { opacity: 0.85; }
.stop-name.near { opacity: 1 !important; color: var(--accent); }
#ruler-now { position: absolute; right: 0; width: 34px; height: 0; border-top: 1.5px solid var(--accent); }
#ruler-now span { position: absolute; right: -4px; top: -4px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

#card { position: absolute; left: 30px; top: 50%; transform: translateY(-50%) translateX(-12px); width: min(380px, calc(100vw - 260px)); padding: 26px 28px 22px; background: var(--glass); backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); border: 1px solid rgba(255,255,255,0.08); border-radius: 18px; opacity: 0; transition: opacity 0.7s ease, transform 0.9s cubic-bezier(.2,.8,.2,1); pointer-events: none; }
#card.show { opacity: 1; transform: translateY(-50%) translateX(0); }
#card-en { font-family: var(--num); font-size: 10.5px; letter-spacing: 0.32em; text-transform: uppercase; color: var(--accent); opacity: 0.85; }
#card-title { margin: 8px 0 14px; font-size: 26px; font-weight: 300; letter-spacing: 0.08em; }
#card-text { margin: 0; font-size: 14px; line-height: 2; color: rgba(236,240,252,0.86); font-weight: 300; }
#card-facts { margin: 18px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 12.5px; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 14px; }
#card-facts dt { color: var(--dim); }
#card-facts dd { margin: 0; color: var(--fg); }

#tourbar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: transparent; pointer-events: none; }
#tourfill { height: 100%; width: 0; background: linear-gradient(90deg, rgba(255,217,160,0), var(--accent)); transition: width 0.6s; }

#controls { position: absolute; left: 50%; bottom: 30px; transform: translateX(-50%); display: flex; gap: 6px; padding: 6px; border-radius: 999px; background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border: 1px solid rgba(255,255,255,0.08); }
#controls button { height: 42px; min-width: 42px; border-radius: 999px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 12px; color: var(--dim); transition: background 0.25s, color 0.25s; }
#controls button:hover { background: rgba(255,255,255,0.08); color: var(--fg); }
#controls button.on { color: var(--fg); }
#controls button.primary { color: #1a1206; background: var(--accent); padding: 0 20px 0 16px; font-size: 13.5px; letter-spacing: 0.06em; }
#controls button.primary:hover { background: #ffe6bf; color: #1a1206; }
#controls svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#btn-tour svg { fill: currentColor; stroke: none; }
#btn-tour .pause { display: none; }
#btn-tour.playing .pause { display: block; }
#btn-tour.playing .play { display: none; }
#controls .toggle:not(.on) svg { opacity: 0.45; }
#controls .toggle:not(.on)::after { content: ""; position: absolute; width: 22px; height: 1.6px; background: currentColor; transform: rotate(-45deg); }
#controls button { position: relative; }

#hint { position: absolute; left: 50%; bottom: 84px; transform: translateX(-50%); font-size: 12px; color: var(--dim); letter-spacing: 0.02em; transition: opacity 1s; pointer-events: none; }
#hint.gone { opacity: 0; }

#intro { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(4,6,14,0.55), rgba(0,0,0,0.92)); transition: opacity 1.4s ease; z-index: 10; }
#intro.gone { opacity: 0; pointer-events: none; }
.intro-inner { text-align: center; max-width: 560px; padding: 24px; }
.intro-en { font-family: var(--num); letter-spacing: 0.42em; font-size: 11px; color: var(--accent); margin-left: 0.42em; }
#intro h1 { font-family: var(--num); font-size: 58px; font-weight: 200; letter-spacing: 0.06em; line-height: 1.12; margin: 22px 0 22px; }
.lead { font-size: 15px; line-height: 2.1; color: rgba(236,240,252,0.8); font-weight: 300; margin: 0 0 34px; }
#loader { width: 220px; height: 1px; background: rgba(255,255,255,0.15); margin: 0 auto; overflow: hidden; }
#loadfill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
#loadtext { font-size: 12px; color: var(--dim); margin: 12px 0 28px; letter-spacing: 0.02em; min-height: 1em; }
.intro-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.intro-buttons button { padding: 14px 26px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.22); font-size: 14px; letter-spacing: 0.08em; transition: background 0.3s, opacity 0.3s, color 0.3s; }
.intro-buttons button.primary { background: var(--accent); color: #1a1206; border-color: transparent; }
.intro-buttons button:disabled { opacity: 0.3; cursor: default; }
.intro-buttons button:not(:disabled):hover { background: rgba(255,255,255,0.1); }
.intro-buttons button.primary:not(:disabled):hover { background: #ffe6bf; }
.credit { font-size: 12px; color: var(--faint); margin-top: 26px; line-height: 1.8; }
.note { font-size: 12px; color: var(--dim); margin-top: 22px; }

@media (max-width: 720px) {
  #pow { font-size: 44px; }
  #ruler { width: 70px; top: 64px; bottom: 150px; right: 14px; }
  .tick-label, .stop-name { display: none; }
  #card { left: 16px; right: 16px; width: auto; top: auto; bottom: 150px; transform: translateY(12px); padding: 18px 20px; }
  #card.show { transform: translateY(0); }
  #card-title { font-size: 21px; margin: 6px 0 8px; }
  #card-text { font-size: 13px; line-height: 1.85; }
  #card-facts { display: none; }
  #scale { left: 18px; bottom: auto; top: 58px; }
  #brand { left: 18px; top: 22px; }
  #controls { bottom: 22px; }
  #hint { display: none; }
  #intro h1 { font-size: 40px; }
}

/* ---------- opening title ---------- */
#opening { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; opacity: 0; transition: opacity 2.4s ease; z-index: 5; }
#opening.show { opacity: 1; }
.op-en { font-family: var(--num); font-size: 11px; letter-spacing: 0.42em; color: var(--accent); margin-bottom: 18px; }
.op-title { font-family: var(--num); font-weight: 200; font-size: clamp(36px, 6vw, 76px); letter-spacing: 0.06em; color: #fff; }
#opening.show .op-title { animation: op-rise 7s ease-out both; }
@keyframes op-rise { from { transform: translateY(14px); letter-spacing: 0.14em; opacity: 0; } 30% { opacity: 1; } to { transform: none; letter-spacing: 0.06em; } }

/* ---------- finale flashes ---------- */
#flash { position: fixed; left: 0; right: 0; top: 50%; transform: translateY(-50%); text-align: center; font-size: clamp(22px, 3.2vw, 38px); font-weight: 300; letter-spacing: 0.14em; color: #fff; pointer-events: none; opacity: 0; z-index: 4; }
#flash .pw { display: block; font-family: var(--num); font-size: 0.45em; letter-spacing: 0.2em; color: var(--accent); margin-bottom: 10px; }
#flash.on { animation: flash 1.3s ease-out; }
@keyframes flash { 0% { opacity: 0; transform: translateY(-50%) scale(0.96); } 18% { opacity: 1; } 100% { opacity: 0; transform: translateY(-50%) scale(1.04); } }

/* ---------- finale: the scale strip ---------- */
#finale { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(2,3,8,0.55), rgba(0,0,0,0.88)); opacity: 0; pointer-events: none; transition: opacity 2s ease; z-index: 8; }
#finale.show { opacity: 1; pointer-events: auto; }
.fin-inner { width: min(1100px, 94vw); text-align: center; }
.fin-en { font-family: var(--num); font-size: 11px; letter-spacing: 0.42em; color: var(--accent); }
#finale h2 { font-family: var(--num); font-weight: 200; font-size: clamp(30px, 4.4vw, 54px); margin: 14px 0 6px; letter-spacing: 0.02em; }
#finale h2 sup { font-size: 0.45em; }
#finale h2 .to { color: var(--dim); margin: 0 0.3em; }
.strip { width: 100%; height: auto; overflow: visible; }
.strip .axis { stroke: rgba(255,255,255,0.55); stroke-width: 1.2; stroke-dasharray: 1000; stroke-dashoffset: 1000; }
#finale.show .strip .axis { animation: draw 1.6s 0.3s ease-in-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.strip .tk { stroke: rgba(255,255,255,0.35); stroke-width: 1; opacity: 0; }
.strip .tkl { fill: rgba(220,228,250,0.55); font-size: 11px; font-family: var(--num); text-anchor: middle; opacity: 0; }
.strip .it { opacity: 0; }
.strip .it circle { fill: #fff; }
.strip .it .lead { stroke: rgba(255,255,255,0.22); stroke-width: 1; }
.strip .it text { fill: rgba(240,244,255,0.9); font-size: 13px; text-anchor: middle; font-family: var(--font); }
.strip .it.me circle { fill: var(--accent); }
.strip .it.me text { fill: var(--accent); font-size: 16px; font-weight: 600; }
.strip .me-pulse circle { fill: none; stroke: var(--accent); stroke-width: 1.5; opacity: 0; transform-box: fill-box; transform-origin: center; }
#finale.show .strip .tk, #finale.show .strip .tkl { animation: fade-in 0.5s calc(0.3s + var(--d)) forwards; }
#finale.show .strip .it { animation: pop 0.6s var(--d) cubic-bezier(.2,.8,.2,1) forwards; }
#finale.show .strip .me-pulse circle { animation: pulse 2.2s var(--d) ease-out infinite; }
@keyframes fade-in { to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0% { opacity: 0.9; transform: scale(1); } 100% { opacity: 0; transform: scale(4.5); } }
.closing { min-height: 7.5em; margin: 26px auto 0; max-width: 46em; font-size: 15px; line-height: 2.1; font-weight: 300; color: rgba(236,240,252,0.88); }
.closing span { opacity: 0; transition: opacity 1.6s ease; }
.closing span.on { opacity: 1; }
.fin-buttons { display: flex; gap: 12px; justify-content: center; margin-top: 26px; opacity: 0; pointer-events: none; transition: opacity 1.4s ease; }
#finale.done .fin-buttons { opacity: 1; pointer-events: auto; }
.fin-buttons button { padding: 13px 24px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.22); font-size: 14px; letter-spacing: 0.08em; }
.fin-buttons button.primary { background: var(--accent); color: #1a1206; border-color: transparent; }
.fin-buttons button:hover { background: rgba(255,255,255,0.1); }
.fin-buttons button.primary:hover { background: #ffe6bf; }
@media (max-width: 720px) { .strip .it text { font-size: 11px; } .strip .it.me text { font-size: 13px; } .closing { font-size: 13px; } }

body.finale-on #hud { opacity: 0; pointer-events: none; }
body.finale-on #hud > * { pointer-events: none; }
#opening::before { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse 60% 40% at center, rgba(0,0,0,0.55), rgba(0,0,0,0) 70%); z-index: -1; }

/* ---------- HTML-in-Canvas plaques (drawn into the canvas, laid out here) ---------- */
.plaque { position: absolute; left: 0; top: 0; width: 420px; padding: 26px 28px 22px; box-sizing: border-box; color: rgba(240,244,255,0.94); background: linear-gradient(160deg, rgba(20,26,44,0.78), rgba(8,10,20,0.7)); border: 1px solid rgba(255,255,255,0.14); border-radius: 18px; font-family: var(--font); }
.plaque .pq-en { font-family: var(--num); font-size: 10.5px; letter-spacing: 0.32em; text-transform: uppercase; color: var(--accent); }
.plaque h3 { margin: 8px 0 12px; font-size: 26px; font-weight: 300; letter-spacing: 0.08em; }
.plaque p { margin: 0; font-size: 14px; line-height: 2; font-weight: 300; }
.plaque dl { margin: 16px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 12.5px; border-top: 1px solid rgba(255,255,255,0.12); padding-top: 12px; }
.plaque dt { color: var(--dim); } .plaque dd { margin: 0; }
.pq-btns { display: flex; gap: 8px; margin-top: 16px; }
.pq-btns button { font: inherit; font-size: 12.5px; padding: 7px 14px; border-radius: 999px; border: 1px solid rgba(255,217,160,0.5); color: var(--accent); background: rgba(255,217,160,0.06); cursor: pointer; }
.pq-btns button:hover { background: rgba(255,217,160,0.2); }

/* digest: only the stop button stays */
body.digest-on #controls button:not(#btn-tour), body.digest-on #hint { display: none; }
body.digest-on #ruler { pointer-events: none; opacity: 0.5; }
body.finale-on.digest-on #hud { opacity: 1; }
body.finale-on.digest-on #hud > *:not(#controls) { opacity: 0; }
body.finale-on.digest-on #controls { position: fixed; z-index: 9; pointer-events: auto; }
.closing.lines span { display: block; }
#controls button[hidden] { display: none; }

/* phones: the narration carries the explanation; the card shows only when the voice is off */
@media (max-width: 720px) {
  #card { top: auto; bottom: 92px; max-height: 42vh; overflow: auto; }
  body:not(.voice-off) #card { display: none; }
}
#controls button { white-space: nowrap; }
#controls svg .fill { fill: currentColor; stroke: none; }
#btn-prev, #btn-next { min-width: 36px !important; padding: 0 8px !important; }
@media (max-width: 720px) {
  #controls { gap: 2px; padding: 4px; }
  #controls button { min-width: 38px; padding: 0 6px; }
  #controls button.primary { padding: 0 14px 0 10px; }
  #btn-hic { display: none !important; }
}
