:root {
  --bg-space: #070b14;
  --glass-bg: rgba(11, 17, 30, 0.84);
  --glass-border: rgba(148, 163, 184, 0.25);
  --reimu-color: #e05260;
  --marisa-color: #f0c040;
  --accent-blue: #38bdf8;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-sans: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-space);
  color: var(--text-main);
  font-family: var(--font-sans);
  user-select: none;
  -webkit-user-select: none;
}

.stage-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 45%, #0f172a 0%, #050811 100%);
}

/* 3D Earth ステージ */
.earth-host {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  transition: filter 0.45s ease, opacity 0.45s ease;
}

.stage-root[data-mode="diagram"] .earth-host,
.stage-root[data-mode="photo"] .earth-host {
  filter: blur(6px) brightness(0.28);
}

.stage-root[data-mode="diagram"] .map-beacon-layer,
.stage-root[data-mode="photo"] .map-beacon-layer {
  opacity: 0;
  pointer-events: none;
}

.stage-root[data-mode="earth+diagram"] .earth-host {
  filter: brightness(0.92);
}

/* 地図上の解説対象・ゆっくり点滅ビーコン */
.map-beacon-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}

.stage-root[data-mode="diagram"] .map-beacon-layer {
  opacity: 0.25;
}

.map-beacon {
  position: absolute;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}

.map-beacon-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2.5px solid var(--beacon-color, #38bdf8);
  background: transparent;
  box-shadow: inset 0 0 12px var(--beacon-color, #38bdf8);
  transform: translate(-50%, -50%) scale(0.75);
  animation: beacon-pulse 2.2s ease-in-out infinite;
}

.map-beacon-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--beacon-color, #facc15);
  box-shadow: 0 0 14px var(--beacon-color, #facc15);
  transform: translate(-50%, -50%);
  animation: beacon-core-blink 2.2s ease-in-out infinite;
}

@keyframes beacon-pulse {
  0%, 100% {
    transform: translate(-50%, -50%) scale(0.7);
    opacity: 0.95;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.65);
    opacity: 0.15;
  }
}

@keyframes beacon-core-blink {
  0%, 100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: 0.45;
    transform: translate(-50%, -50%) scale(0.82);
  }
}

/* 精密図解レイヤー */
.diagram-layer {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.35s ease, transform 0.35s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-root[data-mode="diagram"] .diagram-layer {
  inset: 52px 32px 190px 32px;
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* 歴史資料写真レイヤー（全画面排他表示） */
.photo-layer {
  position: absolute;
  inset: 52px 32px 190px 32px;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.35s ease, transform 0.35s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-root[data-mode="photo"] .photo-layer {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.photo-card {
  width: 100%;
  height: 100%;
  max-width: 960px;
  max-height: 100%;
  background: rgba(11, 18, 32, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 16px;
  padding: 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
}

.photo-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.photo-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #f8fafc;
}

.photo-frame {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, 0.55);
  border-radius: 10px;
  padding: 8px;
  overflow: hidden;
}

.photo-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  display: block;
}

.photo-caption {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.45;
  color: #cbd5e1;
  flex-shrink: 0;
  text-align: center;
}

.stage-root[data-mode="earth+diagram"] .diagram-layer {
  top: 56px;
  right: 28px;
  bottom: 200px;
  width: min(46vw, 620px);
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.diagram-card {
  width: 100%;
  height: 100%;
  max-width: 1080px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: rgba(10, 16, 29, 0.88);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  padding: 14px 18px;
  overflow: hidden;
}

.diagram-header {
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
  padding-bottom: 8px;
}

.diagram-title {
  font-size: clamp(15px, 1.5vw, 20px);
  font-weight: 700;
  color: #f8fafc;
}

.diagram-subtitle {
  font-size: clamp(11px, 1vw, 13px);
  color: #cbd5e1;
  margin-top: 2px;
}

.diagram-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.diag-svg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.diag-node {
  transition: opacity 0.35s ease, filter 0.35s ease;
}

.diag-node.is-dim {
  opacity: 0.45;
}

.diag-node.is-focus {
  opacity: 1;
  animation: diag-focus-pulse 2.4s ease-in-out infinite;
}

@keyframes diag-focus-pulse {
  0%, 100% {
    filter: drop-shadow(0 0 10px rgba(250, 204, 21, 0.48));
    opacity: 1;
  }
  50% {
    filter: drop-shadow(0 0 3px rgba(250, 204, 21, 0.15));
    opacity: 0.78;
  }
}

/* 最小限のフローティングHUD */
.hud-top-left {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(44vw, 520px);
  padding: 6px 14px;
  background: rgba(10, 16, 29, 0.68);
  backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.hud-chapter {
  color: var(--marisa-color);
  font-weight: 700;
  flex-shrink: 0;
}

.hud-sep {
  color: var(--text-muted);
  flex-shrink: 0;
}

.hud-step-title {
  color: var(--text-main);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-top-right {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.3s ease;
}

.hud-btn {
  appearance: none;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(8px);
  color: var(--text-main);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
}

.hud-btn:hover {
  background: rgba(30, 41, 59, 0.92);
  border-color: rgba(248, 250, 252, 0.45);
}

.hud-btn.is-active {
  background: rgba(12, 74, 110, 0.90);
  border-color: var(--accent-blue);
  color: #e0f2fe;
}

.hud-btn-icon {
  padding: 6px 11px;
  font-size: 15px;
}

.hud-btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.map-explore-hint {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid var(--accent-blue);
  border-radius: 999px;
  font-size: 12.5px;
  color: #e0f2fe;
}

.map-explore-hint[hidden] {
  display: none;
}

/* ゆっくり立ち絵＋字幕エリア */
.yukkuri-stage {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 34px;
  z-index: 15;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 16px;
  padding: 0 24px;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.stage-root.is-map-explore .yukkuri-stage {
  opacity: 0.18;
  transform: translateY(20px);
}

.yukkuri-char {
  width: clamp(160px, 18vw, 240px);
  aspect-ratio: 400 / 320;
  flex-shrink: 0;
  transition: transform 0.22s ease, filter 0.22s ease, opacity 0.22s ease;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.7));
}

.yukkuri-left .yukkuri-layers {
  transform: scaleX(-1);
}

.yukkuri-layers {
  position: relative;
  width: 100%;
  height: 100%;
}

.yukkuri-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.yukkuri-char.is-speaking {
  transform: translateY(-8px) scale(1.05);
  opacity: 1;
}

.yukkuri-char.is-listening {
  transform: translateY(4px) scale(0.95);
  opacity: 0.78;
}

.yukkuri-char.is-bounce {
  animation: yukkuri-bob 0.36s ease-in-out infinite alternate;
}

@keyframes yukkuri-bob {
  from { transform: translateY(-8px) scale(1.05); }
  to { transform: translateY(-13px) scale(1.06); }
}

.yukkuri-svg {
  width: 100%;
  height: auto;
  display: block;
}

/* 字幕ボックス */
.dialogue-box {
  pointer-events: auto;
  flex: 1;
  max-width: 820px;
  min-height: 122px;
  background: var(--glass-bg);
  backdrop-filter: blur(14px);
  border-radius: 16px;
  border: 2.5px solid var(--marisa-color);
  padding: 12px 20px 14px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.65);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color 0.25s ease;
}

.dialogue-box[data-speaker="reimu"] {
  border-color: var(--reimu-color);
}

.dialogue-box[data-speaker="marisa"] {
  border-color: var(--marisa-color);
}

.dialogue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.speaker-badge {
  font-size: 13px;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 6px;
  letter-spacing: 0.04em;
}

.dialogue-box[data-speaker="reimu"] .speaker-badge {
  background: rgba(224, 82, 96, 0.22);
  color: #ff9aa4;
  border: 1px solid rgba(224, 82, 96, 0.5);
}

.dialogue-box[data-speaker="marisa"] .speaker-badge {
  background: rgba(240, 192, 64, 0.2);
  color: #fde047;
  border: 1px solid rgba(240, 192, 64, 0.5);
}

.step-counter {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.dialogue-text {
  font-size: clamp(15px, 1.45vw, 18.5px);
  line-height: 2.25;
  min-height: 4.5em;
  color: #f8fafc;
  user-select: none;
  -webkit-user-select: none;
}

.dialogue-glossary {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(253, 224, 71, 0.22);
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 76px;
  overflow-y: auto;
}

.dialogue-glossary[hidden] {
  display: none;
}

.glossary-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  line-height: 1.45;
  color: #cbd5e1;
}

.glossary-term {
  color: #fde047;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.glossary-desc {
  color: #e2e8f0;
}

.stage-root.is-ruby-off .dialogue-text {
  line-height: 1.75;
}

.dialogue-text ruby {
  ruby-position: over;
}

.dialogue-text rt {
  font-size: 0.54em;
  color: #cbd5e1;
  font-weight: 500;
  letter-spacing: 0.02em;
  transform: translateY(-3px);
}

.dialogue-hint {
  text-align: right;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* 本文中の用語リンク（金色は地図外の歴史用語専用） */
.inline-emphasis {
  color: var(--marisa-color);
  font-weight: 700;
  border-bottom: 1.5px solid rgba(253, 224, 71, 0.78);
  padding-bottom: 1px;
}

.inline-term {
  color: #fde047;
  border-bottom: 1px dashed rgba(250, 204, 21, 0.75);
  cursor: help;
  font-weight: 600;
  padding: 0 2px;
  border-radius: 3px;
  transition: background 0.15s ease;
}

.inline-term:hover {
  background: rgba(250, 204, 21, 0.18);
}

.inline-term.is-geo {
  color: var(--term-color, #38bdf8);
  border-bottom: 1.5px solid var(--term-color, #38bdf8);
  cursor: pointer;
}

.inline-term.is-geo::after {
  content: " 📍";
  font-size: 0.78em;
  opacity: 0.85;
}

.inline-term.is-geo:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* 用語ポップアップ */
.term-popover {
  position: fixed;
  z-index: 50;
  max-width: 320px;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--accent-blue);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.65);
  pointer-events: none;
}

.term-popover-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #7dd3fc;
  margin-bottom: 4px;
}

.term-popover-body {
  font-size: 12.5px;
  line-height: 1.55;
  color: #e2e8f0;
}

/* 極細プレイヤーバー */
.player-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 30px;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  background: linear-gradient(to top, rgba(5, 8, 17, 0.92), rgba(5, 8, 17, 0.55));
}

.player-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: #cbd5e1;
  font-size: 12px;
  padding: 3px 7px;
  cursor: pointer;
  border-radius: 4px;
}

.player-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.player-btn.is-playing {
  color: var(--marisa-color);
}

.progress-track {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 1px;
  height: 16px;
}

.progress-seg {
  flex: 1;
  height: 5px;
  border-radius: 99px;
  background: rgba(148, 163, 184, 0.28);
  cursor: pointer;
  transition: height 0.15s ease, background 0.15s ease;
}

.progress-seg:hover {
  height: 8px;
  background: rgba(248, 250, 252, 0.55);
}

.progress-seg.is-done {
  background: rgba(56, 189, 248, 0.65);
}

.progress-seg.is-current {
  height: 8px;
  background: var(--marisa-color);
}

/* チャプター一覧オーバーレイ */
.chapter-drawer {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(3, 6, 14, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.chapter-drawer[hidden] {
  display: none;
}

.chapter-drawer-panel {
  width: min(680px, 100%);
  max-height: 82vh;
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75);
}

.chapter-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.chapter-drawer-head h2 {
  font-size: 16px;
  font-weight: 700;
}

.chapter-list {
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chapter-only-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  background: rgba(30, 41, 59, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 12px;
  padding: 13px 16px;
  color: #f1f5f9;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}

.chapter-only-btn:hover {
  background: rgba(51, 65, 85, 0.92);
  border-color: var(--accent-blue);
  transform: translateX(2px);
}

.chapter-only-btn.is-current {
  background: rgba(240, 192, 64, 0.16);
  border-color: var(--marisa-color);
  color: #fef08a;
  font-weight: 700;
}

.chapter-only-meta {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.chapter-only-btn.is-current .chapter-only-meta {
  color: #fde047;
}

/* ゲーム風 単元ステージセレクトメニュー */
.unit-drawer-panel {
  width: min(1040px, 100%);
  max-height: 86vh;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98) 0%, rgba(9, 14, 28, 0.99) 100%);
  border: 1px solid rgba(56, 189, 248, 0.32);
}

.unit-head-title-wrap {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.unit-head-summary {
  font-size: 12px;
  font-weight: 600;
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 999px;
  padding: 2px 10px;
}

.unit-era-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(15, 23, 42, 0.55);
}

.unit-era-tab {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(30, 41, 59, 0.65);
  color: #cbd5e1;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.unit-era-tab:hover {
  background: rgba(51, 65, 85, 0.85);
  border-color: rgba(148, 163, 184, 0.5);
  color: #f8fafc;
}

.unit-era-tab.is-active {
  background: rgba(56, 189, 248, 0.22);
  border-color: #38bdf8;
  color: #e0f2fe;
}

.unit-era-count {
  font-size: 11px;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}

.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 12px;
  padding: 16px 20px 20px;
}

.unit-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  padding: 12px 14px 10px;
  border-radius: 12px;
  background: linear-gradient(160deg, rgba(30, 41, 59, 0.82) 0%, rgba(15, 23, 42, 0.92) 100%);
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-top: 3px solid var(--era-accent, #38bdf8);
  color: #f8fafc;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.unit-card[data-era="ancient"] { --era-accent: #4ade80; }
.unit-card[data-era="medieval"] { --era-accent: #fb7185; }
.unit-card[data-era="early_modern"] { --era-accent: #c084fc; }
.unit-card[data-era="modern"] { --era-accent: #38bdf8; }

.unit-card:hover {
  transform: translateY(-2px);
  background: linear-gradient(160deg, rgba(38, 53, 77, 0.94) 0%, rgba(20, 30, 50, 0.96) 100%);
  border-color: var(--era-accent, #38bdf8);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}

.unit-card.is-current {
  border-color: var(--marisa-color);
  border-top-color: var(--marisa-color);
  background: linear-gradient(160deg, rgba(240, 192, 64, 0.18) 0%, rgba(23, 30, 48, 0.95) 100%);
  box-shadow: 0 0 0 1px rgba(240, 192, 64, 0.4), 0 10px 24px rgba(0, 0, 0, 0.5);
}

.unit-card-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.unit-stage-badge {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #0f172a;
  background: var(--era-accent, #38bdf8);
  border-radius: 5px;
  padding: 2px 6px;
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.unit-card.is-current .unit-stage-badge {
  background: var(--marisa-color);
}

.unit-period-pill {
  font-size: 10.5px;
  font-weight: 600;
  color: #cbd5e1;
  background: rgba(148, 163, 184, 0.14);
  border-radius: 5px;
  padding: 2px 6px;
  white-space: nowrap;
}

.unit-status-pill {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #94a3b8;
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.unit-status-pill.is-playing {
  color: #fde047;
}

.unit-status-pill.is-clear {
  color: #4ade80;
}

.unit-status-pill.is-started {
  color: #7dd3fc;
}

.unit-card-title {
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.4;
  color: #f8fafc;
  min-height: 38px;
}

.unit-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}

.unit-card-progress {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  overflow: hidden;
}

.unit-card-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--era-accent, #38bdf8);
  transition: width 0.25s ease;
}

.unit-card.is-current .unit-card-progress-fill {
  background: var(--marisa-color);
}

@media (max-width: 1180px) {
  .hud-top-left {
    max-width: min(36vw, 380px);
    font-size: 12px;
    padding: 5px 11px;
  }
  .hud-btn {
    padding: 5px 10px;
    font-size: 11.5px;
  }
  .hud-btn-icon {
    padding: 5px 9px;
    font-size: 13.5px;
  }
  .yukkuri-char {
    width: clamp(120px, 15vw, 185px);
  }
}

@media (max-width: 960px) {
  .hud-top-left {
    max-width: 30vw;
    font-size: 11.5px;
    padding: 4px 10px;
  }
  .hud-top-right {
    gap: 4px;
  }
  .hud-btn {
    padding: 4px 8px;
    font-size: 11px;
  }
  .hud-btn-icon {
    padding: 4px 8px;
    font-size: 12.5px;
  }
}

@media (max-width: 860px) {
  .yukkuri-char {
    width: 96px;
  }
  .stage-root[data-mode="earth+diagram"] .diagram-layer {
    inset: 48px 16px 156px 16px;
    width: auto;
  }
}

/* スマートフォン横画面（nubia S2R 等：高さ 360〜450px）向け最適化 */
@media (max-height: 520px) {
  .hud-top-left {
    top: max(6px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    max-width: min(32vw, 290px);
    padding: 4px 10px;
    font-size: 11px;
  }
  .hud-top-right {
    top: max(6px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    gap: 4px;
  }
  .hud-btn {
    padding: 4px 8px;
    font-size: 10.5px;
  }
  .hud-btn-icon {
    padding: 4px 7px;
    font-size: 12px;
  }
  .yukkuri-stage {
    bottom: calc(24px + env(safe-area-inset-bottom));
    gap: 10px;
    padding: 0 max(12px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-right));
  }
  .yukkuri-char {
    width: 92px;
  }
  .dialogue-box {
    min-height: 74px;
    max-width: 680px;
    padding: 6px 14px 7px;
    border-radius: 12px;
    border-width: 2px;
  }
  .dialogue-header {
    margin-bottom: 2px;
  }
  .speaker-badge {
    font-size: 11px;
    padding: 1px 8px;
  }
  .step-counter {
    font-size: 11px;
  }
  .dialogue-text {
    font-size: 13.5px;
    line-height: 1.95;
  }
  .dialogue-glossary {
    margin-top: 3px;
    padding-top: 3px;
    max-height: 40px;
    gap: 2px;
  }
  .glossary-item {
    font-size: 10.5px;
    line-height: 1.3;
    gap: 6px;
  }
  .stage-root.is-ruby-off .dialogue-text {
    line-height: 1.5;
  }
  .dialogue-hint {
    display: none;
  }
  .stage-root[data-mode="diagram"] .diagram-layer {
    inset: 34px 12px 104px 12px;
  }
  .stage-root[data-mode="earth+diagram"] .diagram-layer {
    top: 34px;
    right: 12px;
    bottom: 104px;
    left: auto;
    width: min(50vw, 460px);
  }
  .diagram-card {
    padding: 6px 10px;
    border-radius: 10px;
  }
  .diagram-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 3px;
    padding-bottom: 3px;
  }
  .diagram-title {
    font-size: 13px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .diagram-subtitle {
    font-size: 10.5px;
    margin-top: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .player-bar {
    height: 24px;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .chapter-drawer-panel {
    max-height: 90vh;
  }
  .chapter-drawer-head {
    padding: 10px 14px;
  }
  .chapter-list {
    padding: 10px 14px;
    gap: 7px;
  }
  .chapter-only-btn {
    padding: 9px 12px;
    font-size: 13px;
  }
  .unit-era-tabs {
    padding: 6px 12px;
    gap: 6px;
  }
  .unit-era-tab {
    padding: 4px 10px;
    font-size: 11px;
  }
  .unit-grid {
    grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
    gap: 8px;
    padding: 10px 12px 12px;
  }
  .unit-card {
    padding: 8px 10px;
    gap: 5px;
  }
  .unit-card-title {
    font-size: 12px;
    min-height: 32px;
  }
}
