:root {
  --ink: rgba(255, 255, 255, 0.94);
  --soft: rgba(255, 255, 255, 0.66);
  --shade: 0 1px 14px rgba(4, 14, 34, 0.55), 0 0 2px rgba(4, 14, 34, 0.5);
  --shade-strong: 0 0 2px rgba(3, 10, 26, 0.95), 0 1px 4px rgba(3, 10, 26, 0.85), 0 2px 18px rgba(3, 10, 26, 0.7);
  --mincho: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Hiragino Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0a1326;
  color: var(--ink);
  font: 13px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#view:active { cursor: grabbing; }

#title, #caption, #hud, #labels, #progress, #home { transition: opacity 0.6s ease; }
body:not(.ready) :is(#title, #caption, #hud, #labels, #progress, #home),
body.bare :is(#title, #caption, #hud, #labels, #progress, #home) { opacity: 0; pointer-events: none; }

/* soft scrims so the type stays legible over snow and bright sky */
body::before, body::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  z-index: 1;               /* above the canvas, below every piece of type */
  pointer-events: none;
  transition: opacity 0.6s ease;
}
#labels { z-index: 2; }
#title, #caption, #hud, #progress, #home { z-index: 3; }
#intro { z-index: 4; }

#home {
  position: fixed;
  top: 34px;
  right: 34px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink);
  text-shadow: var(--shade-strong);
}
#home:hover, #home:focus-visible { text-decoration: underline; text-underline-offset: 4px; }
body::before { top: 0; height: 190px; background: linear-gradient(rgba(6, 16, 38, 0.34), rgba(6, 16, 38, 0)); }
body::after {
  bottom: 0;
  height: 340px;
  background: linear-gradient(rgba(4, 12, 30, 0), rgba(4, 12, 30, 0.30) 35%, rgba(4, 12, 30, 0.58) 70%, rgba(4, 12, 30, 0.76));
}
body.bare::before, body.bare::after, body:not(.ready)::before, body:not(.ready)::after { opacity: 0; }

/* ---- title */
#title {
  position: fixed;
  top: 30px;
  left: 34px;
  text-shadow: var(--shade);
  pointer-events: none;
}
#title h1 {
  margin: 0;
  font: 500 34px/1 var(--mincho);
  letter-spacing: 0.22em;
}
#title .en {
  margin: 12px 0 0;
  font-size: 12px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
}
#title .meta {
  margin: 5px 0 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--soft);
  font-variant-numeric: tabular-nums;
}

/* ---- chapter caption */
#caption {
  position: fixed;
  left: 34px;
  bottom: 112px;
  max-width: min(640px, calc(100vw - 68px));
  text-shadow: var(--shade-strong);
  pointer-events: none;
}
#caption p { margin: 0; opacity: 0; transform: translateY(6px); transition: opacity 0.45s ease, transform 0.45s ease; }
#caption.in p { opacity: 1; transform: none; }
#caption.in .note { transition-delay: 0.12s; }
#caption .name { font-size: 30px; font-weight: 600; line-height: 1.2; letter-spacing: 0.005em; color: #fff; }
#caption #cap-jp { margin-left: 14px; font: 500 22px/1 var(--mincho); letter-spacing: 0.12em; color: rgba(255, 255, 255, 0.9); }
#caption .note { margin-top: 5px; font-size: 16px; color: rgba(255, 255, 255, 0.92); }

/* ---- telemetry and help */
#hud {
  position: fixed;
  left: 34px;
  right: 34px;
  bottom: 24px;
  display: flex;
  align-items: flex-end;
  gap: 28px;
  text-shadow: var(--shade-strong);
  pointer-events: none;
}
#hud dl { display: flex; gap: 28px; margin: 0; }
#hud dt { font-size: 11px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(255, 255, 255, 0.82); }
#hud dd { margin: 2px 0 0; font-size: 20px; font-weight: 500; color: #fff; font-variant-numeric: tabular-nums; min-width: 4.4em; }
#hud .keys, #hud .credit { margin: 0; color: rgba(255, 255, 255, 0.88); }
#hud .keys { margin-left: auto; max-width: 470px; text-align: right; font-size: 12.5px; line-height: 1.75; }
#hud .keys span { white-space: nowrap; }
#hud .credit { max-width: 290px; text-align: right; font-size: 11px; line-height: 1.45; color: rgba(255, 255, 255, 0.78); }
kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 4px;
  margin: 0 1px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: 3px;
  background: rgba(4, 12, 30, 0.35);
  font: inherit;
  font-size: 11px;
  text-align: center;
}

#progress {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 10px;
  cursor: pointer;
}
#progress::before, #bar {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: rgba(255, 255, 255, 0.18);
}
#bar { background: rgba(255, 255, 255, 0.85); transform-origin: left; transform: scaleX(0); }

/* ---- landmark labels */
#labels { position: fixed; inset: 0; overflow: hidden; pointer-events: none; }
.label {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  white-space: nowrap;
  font-size: 10.5px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  text-shadow: 0 0 3px rgba(4, 14, 34, 0.95), 0 0 9px rgba(4, 14, 34, 0.7), 0 1px 1px rgba(4, 14, 34, 0.6);
  will-change: transform, opacity;
}
.label i {
  position: absolute;
  left: 0;
  top: -30px;
  width: 1px;
  height: 30px;
  background: linear-gradient(rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0));
}
.label span { position: absolute; left: 7px; top: -37px; }
.label.flip span { left: auto; right: 7px; }
.label small {
  margin-left: 7px;
  font: 400 11px/1 var(--mincho);
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.85);
  text-transform: none;
}

/* ---- opening screen: a still, a short description and the Start button */
#intro {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px 24px;
  overflow: auto;
  background:
    linear-gradient(rgba(6, 14, 32, 0.34), rgba(6, 14, 32, 0.66)),
    #0a1326 url(poster.webp) center / cover no-repeat;
  transition: opacity 0.9s ease, visibility 0.9s;
}
body.ready #intro { opacity: 0; visibility: hidden; }
#intro .card { max-width: 580px; text-align: center; text-shadow: var(--shade-strong); }
#intro .jp { margin: 0; font: 500 54px/1 var(--mincho); letter-spacing: 0.3em; text-indent: 0.3em; }
#intro h2 { margin: 20px 0 0; font-size: 15px; font-weight: 600; letter-spacing: 0.34em; text-indent: 0.34em; text-transform: uppercase; }
#intro .blurb { margin: 22px 0 0; font-size: 16.5px; line-height: 1.6; color: rgba(255, 255, 255, 0.94); }
#start {
  margin-top: 30px;
  padding: 15px 34px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: #0a1326;
  font: 600 15px/1 var(--sans);
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 6px 26px rgba(3, 10, 26, 0.45);
  transition: transform 0.15s ease, background 0.15s ease;
}
#start:hover { background: #eaf1ff; transform: translateY(-1px); }
#start:focus-visible { outline: 2px solid #fff; outline-offset: 4px; }
#start:disabled { opacity: 0.5; cursor: default; transform: none; }
#intro .fine { margin: 16px 0 0; font-size: 13px; color: rgba(255, 255, 255, 0.84); }
body.loading :is(#start, #intro .fine) { display: none; }
#intro-status {
  min-height: 1.5em;
  margin: 22px 0 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.92);
}
body.failed #intro-status { font-size: 14px; font-weight: 500; letter-spacing: 0.01em; text-indent: 0; text-transform: none; color: #ffc4ba; }
#intro .sources { margin: 36px 0 0; font-size: 11px; line-height: 1.55; color: rgba(255, 255, 255, 0.7); }
#intro a { color: #fff; text-underline-offset: 3px; }

/* touch screens: swap the keyboard hints for touch ones */
#hud .keys.touch { display: none; }
@media (pointer: coarse) {
  #hud .keys { display: none; }
  #hud .keys.touch { display: block; }
}

@media (max-width: 860px) {
  #hud .keys, #hud .keys.touch, #hud .credit { display: none; }
  #title { top: 20px; left: 20px; }
  #home { top: 22px; right: 20px; font-size: 10px; }
  #caption { left: 20px; bottom: 92px; }
  #caption .name { font-size: 23px; }
  #caption #cap-jp { display: block; margin: 6px 0 0; font-size: 17px; }
  #caption .note { font-size: 14px; }
  #hud { left: 20px; right: 20px; }
  #hud dl { gap: 16px; }
  #hud dt { font-size: 9px; letter-spacing: 0.1em; }
  #hud dd { font-size: 16px; min-width: 0; }
  .label small { display: none; }       /* narrow screens: English names only */
  #intro .jp { font-size: 42px; }
  #intro .blurb { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  #caption p, #intro, #start { transition: none; }
}
