:root {
  --bg: #bcd0ee;
  --panel: rgba(12, 18, 34, 0.78);
  --panel-border: rgba(120, 170, 255, 0.22);
  --ink: #e8eefc;
  --ink-dim: #9fb0d4;
  --sakura: #ff9ec7;
  --sakura-deep: #ff5fa2;
  --cyan: #4fe3ff;
  --green: #5ef2a8;
  --amber: #ffcf6b;
  --danger: #ff5a6a;
  --glow: 0 0 24px rgba(79, 227, 255, 0.25);
  --font: "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  --mono: "SFMono-Regular", "Menlo", "Consolas", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: radial-gradient(ellipse at 50% 0%, #f0f6ff 0%, #cddef6 42%, #a9c1e6 76%, #93acda 100%);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }

/* ---------- 共通HUDパネル ---------- */
.hud {
  position: fixed;
  z-index: 5;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

/* ---------- ヘッダー ---------- */
.hud-top {
  top: 16px; left: 16px; right: 16px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; transition: opacity .2s ease; }
a.brand:hover { opacity: 0.8; }
.brand .sakura { font-size: 26px; filter: drop-shadow(0 0 8px var(--sakura)); animation: spin 14s linear infinite; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 18px; letter-spacing: 0.06em; }
.round { font-size: 12px; color: var(--ink-dim); letter-spacing: 0.14em; }
.round em { color: var(--sakura); font-style: normal; }

.progress { display: flex; align-items: center; gap: 12px; min-width: 230px; }
.progress-track { flex: 1; height: 6px; border-radius: 99px; background: rgba(255,255,255,0.08); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; border-radius: 99px;
  background: linear-gradient(90deg, var(--sakura), var(--cyan));
  box-shadow: 0 0 12px var(--cyan); transition: width 0.6s cubic-bezier(.4,0,.2,1); }
.progress-label { font: 600 12px/1 var(--mono); color: var(--ink-dim); white-space: nowrap; }

/* ---------- タイムライン ---------- */
.timeline {
  top: 92px; left: 16px; width: 220px;
  padding: 12px; display: flex; flex-direction: column; gap: 6px;
}
.tl-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; transition: all .25s ease;
}
.tl-item:hover { background: rgba(255,255,255,0.05); }
.tl-item.active { background: rgba(79,227,255,0.10); border-color: rgba(79,227,255,0.35); }
.tl-item.done .tl-num { background: var(--green); color: #04140c; border-color: var(--green); }
.tl-num {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font: 700 12px/1 var(--mono);
  border: 1px solid var(--panel-border); color: var(--ink-dim);
}
.tl-item.active .tl-num { background: var(--cyan); color: #041018; border-color: var(--cyan); box-shadow: var(--glow); }
.tl-body { display: flex; flex-direction: column; gap: 2px; }
.tl-label { font-size: 13px; font-weight: 600; }
.tl-sub { font-size: 11px; color: var(--ink-dim); }

/* ---------- ターミナル ---------- */
.terminal {
  right: 16px; bottom: 150px; width: 380px; max-width: 44vw;
  overflow: hidden; opacity: 0; transform: translateY(8px);
  transition: opacity .4s ease, transform .4s ease;
}
.terminal.show { opacity: 1; transform: translateY(0); }
.term-bar {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px; background: rgba(0,0,0,0.35);
  border-bottom: 1px solid var(--panel-border);
}
.dot { width: 11px; height: 11px; border-radius: 50%; }
.dot.red { background: #ff5f57; } .dot.yellow { background: #febc2e; } .dot.green { background: #28c840; }
.term-title { margin-left: 8px; font: 600 12px/1 var(--mono); color: var(--ink-dim); }
.term-body {
  padding: 14px 16px; min-height: 120px; max-height: 210px; overflow-y: auto;
  font: 13px/1.6 var(--mono); color: var(--green);
  white-space: pre-wrap; word-break: break-word;
}
.term-body .cmd { color: var(--cyan); }
.term-body .out { color: var(--ink-dim); }
.term-body .warn { color: var(--amber); }
.term-body .bad { color: var(--danger); }
.term-body .cursor { display: inline-block; width: 8px; height: 15px; background: var(--green);
  vertical-align: text-bottom; animation: blink 1s steps(1) infinite; }

/* ---------- ナレーション ---------- */
.narration {
  bottom: 90px; left: 50%; transform: translateX(-50%);
  width: min(680px, 92vw); padding: 16px 26px; text-align: center;
  border-color: rgba(255,158,199,0.3);
}
.narr-title { font-size: 17px; letter-spacing: 0.04em; margin-bottom: 6px;
  background: linear-gradient(90deg, var(--sakura), var(--cyan)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.narr-text { font-size: 14px; line-height: 1.7; color: var(--ink); }

/* ---------- 操作パネル ---------- */
.controls {
  bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; padding: 10px 14px;
}
.ctrl {
  font: 600 13px/1 var(--font); color: var(--ink);
  background: rgba(255,255,255,0.06); border: 1px solid var(--panel-border);
  padding: 11px 18px; border-radius: 10px; cursor: pointer; transition: all .2s ease;
}
.ctrl:hover { background: rgba(255,255,255,0.13); transform: translateY(-1px); }
.ctrl:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.ctrl-primary { background: linear-gradient(90deg, var(--sakura-deep), var(--cyan)); color: #06101c; border: none; box-shadow: var(--glow); }
.ctrl-ghost { background: transparent; }

/* ---------- 開始オーバーレイ ---------- */
.intro-overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center;
  background: radial-gradient(ellipse at center, rgba(8,14,28,0.7), rgba(3,6,14,0.96));
  backdrop-filter: blur(4px); transition: opacity .8s ease;
}
.intro-overlay.hide { opacity: 0; pointer-events: none; }
.intro-card { text-align: center; padding: 40px; max-width: 620px; }
.intro-sakura { font-size: 64px; filter: drop-shadow(0 0 20px var(--sakura)); animation: float 4s ease-in-out infinite; }
.intro-card h1 { font-size: 44px; letter-spacing: 0.08em; margin: 12px 0 4px; }
.intro-card h1 span { background: linear-gradient(90deg, var(--sakura), var(--cyan)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.intro-sub { font: 600 15px/1 var(--mono); letter-spacing: 0.3em; color: var(--sakura); text-transform: uppercase; margin-bottom: 22px; }
.intro-desc { font-size: 14px; line-height: 2; color: var(--ink-dim); margin-bottom: 30px; }
.intro-start {
  font: 700 16px/1 var(--font); color: #06101c; cursor: pointer;
  background: linear-gradient(90deg, var(--sakura-deep), var(--cyan));
  border: none; padding: 16px 40px; border-radius: 12px; box-shadow: var(--glow);
  transition: transform .2s ease; }
.intro-start:hover { transform: scale(1.05); }
.intro-hint { margin-top: 18px; font-size: 12px; color: var(--ink-dim); }

/* ---------- ローディング ---------- */
.loading {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; background: var(--bg);
  color: var(--ink-dim); font-size: 14px; transition: opacity .5s ease;
}
.loading.hide { opacity: 0; pointer-events: none; }
.loader-sakura { font-size: 46px; animation: spin 2s linear infinite; }

/* ---------- アニメーション ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }

/* ---------- 終了（エンディング）オーバーレイ ---------- */
.end-overlay {
  position: fixed; inset: 0; z-index: 25; display: grid; place-items: center;
  background: radial-gradient(ellipse at center, rgba(8,14,28,0.72), rgba(3,6,14,0.95));
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none; transition: opacity .8s ease;
}
.end-overlay.show { opacity: 1; pointer-events: auto; }
.end-card { text-align: center; padding: 40px; max-width: 620px; animation: endPop .7s cubic-bezier(.34,1.4,.5,1); }
.end-sakura { font-size: 60px; filter: drop-shadow(0 0 20px var(--sakura)); animation: float 4s ease-in-out infinite; }
.end-title { font-size: clamp(22px, 4vw, 34px); letter-spacing: 0.04em; margin: 14px 0 10px;
  background: linear-gradient(90deg, var(--sakura-deep), var(--cyan)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.end-text { font-size: 15px; line-height: 1.9; color: var(--ink-dim); margin-bottom: 30px; }
.end-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.end-btn {
  font: 700 15px/1 var(--font); color: var(--ink); cursor: pointer; text-decoration: none;
  background: rgba(255,255,255,0.08); border: 1px solid var(--panel-border);
  padding: 14px 26px; border-radius: 12px; transition: all .2s ease;
}
.end-btn:hover { background: rgba(255,255,255,0.16); transform: translateY(-2px); }
.end-btn-primary { background: linear-gradient(90deg, var(--sakura-deep), var(--cyan)); color: #06101c; border: none; box-shadow: var(--glow); }
@keyframes endPop { from { opacity: 0; transform: scale(.92) translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- レイアウト調整（コントローラをヘッダーへ / タイムライン圧縮） ---------- */
.hud-top { flex-wrap: wrap; row-gap: 8px; }
.top-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.controls-inline { display: flex; gap: 6px; flex-wrap: wrap; }
.hud-top .ctrl { padding: 8px 12px; font-size: 12.5px; border-radius: 9px; }
.progress { min-width: 150px; }
.timeline { top: 86px; width: 198px; padding: 8px; gap: 3px; }
.tl-item { padding: 6px 9px; gap: 8px; }
.tl-num { width: 20px; height: 20px; font-size: 11px; }
.tl-label { font-size: 12px; }
.tl-sub { font-size: 10px; }
.narration { bottom: 24px; }

/* ---------- レスポンシブ ---------- */
@media (max-width: 820px) {
  .timeline { display: none; }
  .terminal { width: 92vw; max-width: none; right: 4vw; bottom: 220px; }
  .narration { bottom: 150px; }
  .intro-card h1 { font-size: 32px; }
}
