:root {
  --inst-ink: #0b0a10;
  --inst-paper: #f4f0e8;
  --inst-violet: #8f7df0;
  --inst-acid: #d7ff45;
  --inst-muted: rgba(244, 240, 232, .52);
  --inst-line: rgba(244, 240, 232, .16);
  /* 2026-09-02 吉田さま決定: 端末風の等幅をやめ、HUD の文字は MODO 本体と同じゴシック体に揃える */
  --inst-ui: Inter, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --inst-mono: var(--inst-ui);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--inst-ink);
  color: var(--inst-paper);
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
}

body { overflow-x: hidden; overflow-y: auto; }
body.fallback-mode { overflow: auto; }

.world { position: fixed; inset: 0; }
.world canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.institute-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 8px; pointer-events: auto; }
.institute-home-link { display: inline-flex; align-items: center; min-height: 44px; color: var(--inst-paper); font: 800 13px var(--inst-ui); text-decoration: none; }
.institute-home-link:focus-visible { outline: 2px solid var(--inst-acid); outline-offset: 2px; }
.institute-controls .modo-locale-switcher { position: static; margin: 0; padding: 0; border: 0; background: transparent; box-shadow: none; color: var(--inst-paper); font: 12px var(--inst-ui); }
.institute-controls .modo-locale-switcher > span { display: none; }
.institute-controls .modo-locale-switcher select { min-height: 44px; padding: 0 8px; border: 0; background: var(--inst-ink); color: var(--inst-paper); font: inherit; color-scheme: dark; }

.grain {
  position: absolute;
  inset: -60px;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='7'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
}

/* ---- 意味の層: 主題文・関門ラベル・ランナーラベル ---- */

.intro-thesis {
  position: fixed;
  z-index: 4;
  left: 24px;
  right: 24px;
  top: 44%;
  margin: 0;
  text-align: center;
  font-size: clamp(1rem, 2.4vw, 1.5rem);
  font-weight: 900;
  letter-spacing: .06em;
  color: var(--inst-paper);
  opacity: 0;
  transition: opacity .9s ease;
  pointer-events: none;
  word-break: auto-phrase;
  text-wrap: balance;
}
.intro-thesis.show { opacity: .95; }
.intro-thesis { text-shadow: 0 2px 26px rgb(0 0 0 / .85); transition-duration: .6s; }

body:not(.intro-done) .gate-labels, body:not(.intro-done) .ember-labels { opacity: 0; }
.gate-labels, .ember-labels { transition: opacity .8s ease; }

.gate-labels span.gate-label {
  position: fixed;
  z-index: 2;
  transform: translate(-50%, 0);
  font-family: var(--inst-ui);
  font-size: .76rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--inst-muted);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .7s ease, color .3s ease;
  pointer-events: none;
  text-shadow: 0 1px 6px rgb(0 0 0 / .9), 0 0 14px rgb(0 0 0 / .7);
}
.gate-labels span.gate-label.is-born { opacity: .75; }
/* 輪からラベルへ落ちる短い目印線。ラベルが世界の輪に「付いている」ことを示す */
.gate-labels span.gate-label::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -13px;
  width: 1px;
  height: 9px;
  background: currentColor;
  opacity: .55;
}
.gate-labels span.gate-label.is-active { color: var(--inst-acid); opacity: 1; text-shadow: 0 0 12px rgba(215, 255, 69, .55); }
.gate-labels span.gate-label.is-focused { color: var(--inst-paper); opacity: 1; text-shadow: 0 0 12px rgba(244, 240, 232, .45); }

.ember-labels span.ember-label {
  position: fixed;
  z-index: 2;
  transform: translate(-50%, 0);
  font-family: var(--inst-ui);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--inst-paper);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .35s ease, color .3s ease;
  pointer-events: none;
  text-shadow: 0 1px 6px rgb(0 0 0 / .9), 0 0 14px rgb(0 0 0 / .7);
}
.ember-labels span.ember-label.is-primary.is-born { opacity: .56; color: var(--inst-muted); }
.ember-labels span.ember-label.is-born.is-hovered,
.ember-labels span.ember-label.is-born.is-focused { opacity: 1; color: var(--inst-paper); }
.ember-labels.has-emphasis span.ember-label.is-primary:not(.is-hovered):not(.is-focused) { opacity: 0; }

.runner-label {
  position: fixed;
  z-index: 2;
  transform: translate(14px, -50%);
  font-family: var(--inst-ui);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: rgba(244, 240, 232, .85);
  white-space: nowrap;
  pointer-events: none;
}

body.fallback-mode .intro-thesis, body.fallback-mode .gate-labels, body.fallback-mode .ember-labels, body.fallback-mode .runner-label { display: none; }

/* ---- 設備点検（DRILL）: 研究の値と同じ配列に混ぜない独立パネル ---- */

.drill-panel {
  position: fixed;
  z-index: 3;
  right: 22px;
  top: 96px;
  max-width: 268px;
  padding: 12px 14px 12px 18px;
  border: 0;
  background: rgba(11, 10, 16, .35);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-family: var(--inst-ui);
  opacity: 0;
  transition: opacity .8s ease;
  pointer-events: none;
}
/* 箱の枠線ではなく、すみれ色の光の縦線で「別系統の記録」を示す */
.drill-panel::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 2px;
  background: linear-gradient(180deg, var(--inst-violet), rgba(143, 125, 240, 0));
  box-shadow: 0 0 10px rgba(143, 125, 240, .45);
}
body.intro-done .drill-panel { opacity: 1; }
body.in-sea .drill-panel { opacity: 0; pointer-events: none; }
body.in-sea .gate-labels { opacity: 0; pointer-events: none; }
body.in-sea .ember-labels { opacity: 0; pointer-events: none; }
.drill-panel p { margin: 0; }
.drill-kicker { font-size: .7rem; font-weight: 700; letter-spacing: .04em; color: var(--inst-muted); }
.drill-line { margin-top: 8px !important; font-size: .74rem; font-weight: 500; line-height: 1.7; color: rgba(244, 240, 232, .86); }
.drill-line b { color: var(--inst-acid); font-weight: 700; }
.drill-line b[data-outcome="failed"] { color: #ff8a7a; }
.drill-notice { margin-top: 8px !important; font-size: .66rem; font-weight: 500; line-height: 1.6; color: var(--inst-muted); }

body.fallback-mode .drill-panel { display: none; }

@media (max-width: 720px) {
  .drill-panel { display: none; }
}

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

.hud { position: fixed; z-index: 3; }

/* Page identity belongs to the scene; there is no global navigation strip. */
.institute-heading {
  position: relative;
  z-index: 3;
  max-width: min(480px, calc(100% - 44px));
  margin: 20px 22px;
  pointer-events: none;
}
/* 導入（黒にナレーション 4 拍）の間は上帯（見出し・戻る・言語）も消して世界だけを見せる
   （2026-09-12 吉田さま「最初の説明のときヘッダーが残って世界観に没入できない」）。
   下帯と同じく intro-done で 8px 浮上しながら現れる。WebGL 失敗の fallback では最初から見せる。 */
.institute-heading { transition: opacity .9s ease, transform .9s ease; }
body:not(.intro-done):not(.fallback-mode) .institute-heading { opacity: 0; transform: translateY(-8px); }
body:not(.intro-done):not(.fallback-mode) .institute-controls { pointer-events: none; }
.institute-heading h1 { margin: 0; font-size: 1.1rem; font-weight: 900; }
.institute-heading p { margin: 8px 0 0; color: var(--inst-muted); font-size: .75rem; line-height: 1.7; }

.hud-hint {
  /* 左の読み出し列（最大 520px）と重ならないよう右寄せ。読み出しが短い（現在の候補が無い）状態で kicker 行と同じ高さに来ても交差しない */
  left: auto;
  right: 22px;
  max-width: min(40vw, 520px);
  bottom: max(148px, calc(env(safe-area-inset-bottom, 0px) + 148px));
  margin: 0;
  text-align: right;
  line-height: 1.5;
  font-family: var(--inst-ui);
  font-size: .78rem;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--inst-muted);
  opacity: 0;
  transition: opacity 1.2s ease;
  pointer-events: none;
}
body.scene-ready.intro-done .hud-hint { opacity: .8; }
body.hint-dismissed .hud-hint { opacity: 0 !important; }
body.in-sea .hud-hint { opacity: 0 !important; pointer-events: none; }
/* 下帯は読み込み中から導入が終わるまで出さない（scene-ready を待つと、読み込み中に一度見えてから消える） */
body:not(.intro-done):not(.fallback-mode) .hud-bottom { opacity: 0; }

.hud-bottom {
  left: 0;
  right: 0;
  bottom: 0;
  transition: opacity .9s ease;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 0 22px calc(env(safe-area-inset-bottom, 0px) + 16px);
  pointer-events: none;
}

.stage-readout {
  position: relative;
  max-width: min(520px, 72vw);
  padding-left: 16px;
  font-family: var(--inst-ui);
  transition: opacity .9s ease, transform .9s ease;
}
/* 読み出しの左に、芯線の続きのような酸性色の光の縦線。箱の代わりに「ここが計器」だと示す */
.stage-readout::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 2px;
  border-radius: 1px;
  background: linear-gradient(180deg, var(--inst-acid), rgba(215, 255, 69, .35) 45%, rgba(215, 255, 69, 0));
  box-shadow: 0 0 12px rgba(215, 255, 69, .4);
  opacity: calc(.6 + .4 * var(--inst-pulse, .8));
}
body.scene-ready:not(.intro-done) .stage-readout { transform: translateY(8px); }
body.scene-ready:not(.intro-done) .stage-rail { transform: translateY(8px); }
.stage-rail { transition: opacity .9s ease, transform .9s ease .15s; }
.stage-readout p { margin: 0; }
.readout-kicker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  /* 行が折り返したとき、下のリンクの当たり判定（上下 9px ずつ広げる）が上の行と重ならない間隔 */
  column-gap: 12px;
  row-gap: 18px;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--inst-muted);
}
.readout-state { color: var(--inst-acid); }
.readout-state[data-tone="violet"] { color: var(--inst-violet); }
/* 状態語の前に、その色で発光する小さな点（関門の輪の光と同じ語彙） */
.readout-state:not(:empty)::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
  vertical-align: 1px;
  opacity: calc(.55 + .45 * var(--inst-pulse, .8));
}
.readout-place-link {
  /* 文字は1行のまま、タップ領域だけ上下へ広げる（負のマージンで行送りを増やさない） */
  display: inline-flex;
  align-items: center;
  padding-block: 9px;
  margin-block: -9px;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--inst-acid);
  /* 下線は文字に付ける（当たり判定の箱の底に線を引くと、下の見出しに食い込む） */
  text-decoration: underline;
  text-decoration-color: rgba(215, 255, 69, .55);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  text-shadow: 0 0 10px rgba(215, 255, 69, .35);
  pointer-events: auto;
  transition: text-decoration-color .2s ease, text-shadow .2s ease;
}
.readout-place-link:hover { text-decoration-color: var(--inst-acid); text-shadow: 0 0 14px rgba(215, 255, 69, .7); }
.readout-notes-link { margin-left: auto; }
.readout-place-link:focus-visible { outline: 2px solid var(--inst-acid); outline-offset: 2px; }
.readout-label {
  margin-top: 4px !important;
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  font-size: clamp(1.05rem, 2.4vw, 1.45rem);
  font-weight: 900;
  letter-spacing: .02em;
}
.readout-desc {
  margin-top: 6px !important;
  font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  font-size: .8rem;
  line-height: 1.62;
  font-weight: 600;
  color: rgba(244, 240, 232, .78);
  word-break: auto-phrase;
}
.readout-facts {
  margin-top: 6px !important;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .01em;
  line-height: 1.65;
  color: var(--inst-muted);
  white-space: pre-line;
}
/* 光の数字: 値は紙色で太く、見出しは淡く。区切りの「・」はそのまま淡い */
.readout-facts .fact-value { color: var(--inst-paper); font-weight: 800; font-size: .82rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.readout-facts .fact-label { color: var(--inst-muted); }

/* 番号レール: 箱ではなく、細い線の上に並ぶ7つの光の点。現在の関門は関門の輪と同じ酸性色の輪 */
.stage-rail {
  position: relative;
  display: flex;
  gap: 2px;
  pointer-events: auto;
}
.stage-rail::before {
  content: "";
  position: absolute;
  left: 22px;
  right: 22px;
  top: 15px;
  height: 1px;
  background: linear-gradient(90deg, rgba(244, 240, 232, 0), rgba(244, 240, 232, .28) 18%, rgba(244, 240, 232, .28) 82%, rgba(244, 240, 232, 0));
  pointer-events: none;
}
.stage-rail button {
  position: relative;
  display: grid;
  grid-template-rows: 30px auto;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 0 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--inst-muted);
  font-family: var(--inst-ui);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1;
  cursor: pointer;
  transition: color .2s ease;
}
.stage-rail button::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(244, 240, 232, .34);
  box-shadow: 0 0 6px rgba(244, 240, 232, .2);
  transition: transform .2s ease, background .2s ease, box-shadow .2s ease;
}
.stage-rail button[data-passed="true"]::before { background: var(--inst-violet); box-shadow: 0 0 8px rgba(143, 125, 240, .55); }
.stage-rail button[data-current="true"] { color: var(--inst-acid); }
.stage-rail button[data-current="true"]::before {
  width: 12px;
  height: 12px;
  background: transparent;
  border: 2px solid var(--inst-acid);
  box-shadow: 0 0 12px rgba(215, 255, 69, .6), inset 0 0 6px rgba(215, 255, 69, .35);
  opacity: calc(.6 + .4 * var(--inst-pulse, .8));
}
.stage-rail button:hover { color: var(--inst-paper); }
.stage-rail button:hover::before { transform: scale(1.3); background: rgba(244, 240, 232, .7); }
.stage-rail button[data-current="true"]:hover::before { background: transparent; }
.stage-rail button:focus-visible { outline: 2px solid var(--inst-acid); outline-offset: 2px; }
.stage-rail button[data-focused="true"] { color: var(--inst-paper); }
.stage-rail button[data-focused="true"]::before { background: var(--inst-paper); box-shadow: 0 0 10px rgba(244, 240, 232, .7); }
.stage-rail button[data-focused="true"][data-current="true"]::before { background: transparent; }

/* ---- readable fallback (hidden while the scene runs) ---- */

.stage-readable {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body.fallback-mode .stage-readable {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip-path: none;
  white-space: normal;
  max-width: 620px;
  margin: 0 auto;
  padding: 96px 22px 80px;
}
body.fallback-mode .world, body.fallback-mode .hud-hint, body.fallback-mode .hud-bottom { display: none; }

.fallback-notice {
  margin: 0 0 28px;
  font-family: var(--inst-mono);
  font-size: .72rem;
  color: var(--inst-muted);
}
.stage-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 34px; }
.stage-kicker {
  margin: 0 0 8px;
  font-family: var(--inst-ui);
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--inst-acid);
}
.stage-list h2 { margin: 0 0 8px; font-size: 1.05rem; line-height: 1.7; letter-spacing: .01em; }
.stage-list p { margin: 0; font-size: .82rem; line-height: 1.8; color: rgba(244, 240, 232, .72); }
.fallback-claim { margin: 40px 0 0; font-size: .74rem; line-height: 1.9; color: var(--inst-muted); }
.not-yet {
  display: none;
  position: relative;
  z-index: 5;
  min-height: 100svh;
  margin-top: 100svh;
  padding: 96px 22px 80px;
  background: var(--inst-ink);
}
.not-yet:focus { outline: none; }
.not-yet-inner { max-width: 620px; margin: 0 auto; }
.not-yet h2 { margin: 0; font-size: clamp(1.05rem, 2.4vw, 1.45rem); line-height: 1.7; letter-spacing: .02em; }
.not-yet-lead { margin: 8px 0 0; font-size: .82rem; line-height: 1.8; color: rgba(244, 240, 232, .72); }
.not-yet-list { display: grid; gap: 28px; margin-top: 34px; }
.not-yet-list article { padding-top: 28px; border-top: 1px solid var(--inst-line); }
.not-yet-list h3 { margin: 0 0 8px; font-size: 1.05rem; line-height: 1.7; letter-spacing: .01em; overflow-wrap: anywhere; }
.not-yet-list p { margin: 0; font-size: .82rem; line-height: 1.8; color: rgba(244, 240, 232, .72); overflow-wrap: anywhere; }
.not-yet-calibration .result-threshold-note { margin-top: 16px; color: var(--inst-muted); }
.not-yet-calibration a { display: inline-block; padding-block: 13px; margin-block: -13px; color: var(--inst-acid); text-underline-offset: 3px; }
.not-yet-calibration a:focus-visible { outline: 2px solid var(--inst-acid); outline-offset: 2px; }
.fallback-notes { display: none; margin-top: 56px; padding-top: 28px; border-top: 1px solid var(--inst-line); }
body.scene-ready .not-yet { display: none; }
body.fallback-mode .not-yet { display: block; min-height: auto; margin-top: 0; }
body.fallback-mode .fallback-notes { display: block; max-width: 620px; margin: 0 auto; padding: 28px 22px 80px; }
.fallback-notes h2 { margin: 0 0 8px; font-size: 1.05rem; line-height: 1.7; }
.fallback-notes h3 { margin: 28px 0 8px; font-size: .9rem; }
.fallback-notes p:not(.stage-kicker) { margin: 0 0 8px; font-size: .82rem; line-height: 1.8; color: rgba(244, 240, 232, .72); }
.fallback-notes-rules { margin: 16px 0 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.fallback-notes-rules b { display: block; font-family: var(--inst-ui); font-size: .8rem; font-weight: 600; letter-spacing: .02em; color: var(--inst-acid); }

/* 721〜1000px では readout 本文と横幅が交差して重なるため、ヒント行は広い画面だけに出す（2026-08-22 実画面） */
@media (max-width: 1023px) {
  .hud-hint { display: none; }
}

@media (max-width: 720px) {
  .hud-bottom {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 0 16px calc(env(safe-area-inset-bottom, 0px) + 14px);
  }
  .stage-readout { max-width: none; }
  .readout-desc { font-size: .74rem; }
  .stage-rail { justify-content: space-between; gap: 4px; }
  .stage-rail button { flex: 1; min-width: 0; }
  /* モバイルはタップとレール番号で操作が自明なため、ヒント行は出さない */
  .hud-hint { display: none; }
}


/* 狭い幅（〜363px）でも7個とも 44px 幅を保つ: 下帯の左右余白 16px を点の列だけ 10px 取り戻し（7×44=308 ≤ 320−12）、隙間を 0 にする。
   720px 以下の flex:1 指定より後に置いて上書きする */
@media (max-width: 363px) {
  .stage-rail { gap: 0; margin-inline: -10px; justify-content: center; }
  .stage-rail button { flex: 0 0 44px; min-width: 44px; }
  .stage-rail::before { left: 22px; right: 22px; }
}

@media (max-height: 640px) {
  .hud-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .hud-hint, .stage-rail button, .stage-rail button::before, .ember-labels span.ember-label { transition: none; transform: none; }
  .stage-readout, .stage-rail { transition: none; transform: none !important; }
  /* 動く画面の上の blur は合成負荷が大きいので、動きを減らす設定では濃い暗幕に置き換える */
  .drill-panel { -webkit-backdrop-filter: none; backdrop-filter: none; background: rgba(11, 10, 16, .72); }
}
