:root {
  --bg: #f7f6f2;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-solid: #ffffff;
  --border: rgba(180, 131, 39, 0.28);
  --border-subtle: rgba(15, 23, 42, 0.1);
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #b88628;
  --accent-bright: #d4a038;
  --accent-soft: rgba(184, 134, 40, 0.13);
  --accent-ink: #7c5812;
  --radius: 12px;
  --font-sans: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, -apple-system, sans-serif;
}

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

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

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

.hidden {
  display: none !important;
}

/* ===== 全体ステージ（横画面デフォルト：全画面地図＋字幕オーバーレイ） ===== */
.stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.map-pane {
  position: relative;
  width: 100%;
  height: 100%;
}

.map-canvas {
  width: 100%;
  height: 100%;
}

.maplibregl-ctrl-bottom-right {
  bottom: 8px;
  right: 8px;
}

.maplibregl-ctrl-attrib {
  background: rgba(255, 255, 255, 0.78) !important;
  color: #475569 !important;
  font-size: 10px !important;
  border-radius: 6px !important;
  border: 1px solid var(--border-subtle) !important;
}

.maplibregl-ctrl-attrib a {
  color: #334155 !important;
}

/* ===== 最小限のフローティングHUD ===== */
.hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-top-left {
  left: max(12px, env(safe-area-inset-left));
}

.hud-top-right {
  right: max(12px, env(safe-area-inset-right));
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.hud-pill:hover,
.hud-icon-btn:hover {
  background: #ffffff;
  border-color: var(--accent);
}

.hud-sep {
  color: var(--text-muted);
  font-weight: 400;
}

.hud-step-count {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.icon-chevron {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hud-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.hud-icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hud-icon-btn.is-active,
.hud-pill-sm.is-active {
  border-color: var(--accent);
  background: #fffbeb;
  color: var(--accent-ink);
}

.hud-pill-sm {
  height: 36px;
  padding: 0 11px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ===== ポップオーバー（レイヤー / ステップ一覧 / 調整用） ===== */
.popover {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 44px);
  z-index: 30;
  width: 256px;
  max-height: calc(100% - 70px);
  overflow-y: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
}

.popover-left {
  left: max(12px, env(safe-area-inset-left));
  width: 296px;
}

.popover-right {
  right: max(12px, env(safe-area-inset-right));
}

.popover-wide {
  width: 320px;
}

.popover-header {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent-ink);
  margin-bottom: 8px;
}

.popover-header.mt {
  margin-top: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 3px;
  border-radius: 8px;
  background: #f1f5f9;
}

.segmented-4 {
  grid-template-columns: repeat(2, 1fr);
}

.seg-btn {
  padding: 6px 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--accent);
  color: #ffffff;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 2px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
}

.toggle-row:last-child {
  border-bottom: 0;
}

.toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.step-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.step-list-btn {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.35;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.step-list-btn:hover {
  background: #f1f5f9;
}

.step-list-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.step-list-scale {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--accent-ink);
}

.step-list-section {
  font-size: 11px;
  font-weight: 800;
  color: var(--accent-ink);
  padding: 8px 4px 3px;
  border-bottom: 1px solid var(--border);
  margin-top: 4px;
}

.step-list-section:first-child {
  margin-top: 0;
  padding-top: 2px;
}

/* ===== 断面・模式解説図パネル ===== */
.diagram-card {
  position: absolute;
  top: calc(max(12px, env(safe-area-inset-top)) + 46px);
  left: max(12px, env(safe-area-inset-left));
  z-index: 25;
  width: min(360px, calc(100vw - 24px));
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
}

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

.diagram-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-ink);
}

.diagram-close {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.diagram-close:hover {
  color: var(--text);
}

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

/* 白地図時の地名ラベルコントラスト */
.stage.is-blank-map .gaz-marker .map-marker-text {
  color: #0f172a;
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.95), 0 0 2px rgba(255, 255, 255, 0.95);
}

.stage.is-blank-map .gaz-marker.type-terrain .map-marker-text {
  color: #92400e;
}

.stage.is-blank-map .gaz-marker.type-mountain .map-marker-text {
  color: #166534;
}

.stage.is-blank-map .gaz-marker.type-water .map-marker-text {
  color: #0369a1;
}

/* 調整用インスペクタ */
.cam-readout {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
  padding: 8px;
  border-radius: 8px;
  background: #f1f5f9;
  color: #0f172a;
  border: 1px solid var(--border-subtle);
  white-space: pre-wrap;
}

.inspector-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.btn-sm {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  background: #f8fafc;
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn-sm.btn-accent {
  background: var(--accent);
  color: #ffffff;
  border-color: transparent;
}

.edit-textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}

/* ===== 横画面：字幕・動画風プレイヤー（白背景＋金アクセント） ===== */
.caption-pane {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  padding: 0 16px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  background: linear-gradient(to top, rgba(247, 246, 242, 0.72) 0%, rgba(247, 246, 242, 0.25) 65%, transparent 100%);
}

.dialogue-row {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 14px;
  width: min(1140px, 100%);
  pointer-events: none;
}

.yukkuri-slot {
  position: relative;
  flex: 0 0 clamp(132px, 13.5vw, 184px);
  width: clamp(132px, 13.5vw, 184px);
  height: clamp(110px, 11.2vw, 152px);
  pointer-events: none;
  opacity: 0.72;
  transform: scale(0.92);
  transform-origin: bottom center;
  transition: opacity 0.2s ease, transform 0.2s ease;
  filter: drop-shadow(0 6px 14px rgba(15, 23, 42, 0.24));
}

.yukkuri-slot.is-speaking {
  opacity: 1;
  transform: scale(1.02);
  animation: yukkuri-bob 0.65s ease-in-out infinite alternate;
}

@keyframes yukkuri-bob {
  0% { transform: scale(1.02) translateY(0px); }
  100% { transform: scale(1.02) translateY(-3px); }
}

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

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

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

.speaker-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  color: #ffffff;
}

.speaker-reimu {
  background: #be185d;
}

.speaker-marisa {
  background: #92400e;
}

.caption-card {
  pointer-events: auto;
  cursor: pointer;
  flex: 1 1 auto;
  max-width: 780px;
  padding: 14px 20px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
}

.caption-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.section-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.role-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  background: #e2e8f0;
  color: #334155;
}

.role-badge.role-question {
  background: #e0f2fe;
  color: #0369a1;
}

.role-badge.role-conclusion {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid rgba(184, 134, 40, 0.4);
}

.next-section-wrap {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.btn-next-section {
  padding: 5px 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-next-section:hover {
  background: var(--accent-bright);
}

.scale-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.step-title {
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
}

.subtitle-text {
  font-size: clamp(16px, 1.4vw, 18.5px);
  font-weight: 600;
  line-height: 1.68;
  color: #0f172a;
}

.fact-list {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin-top: 8px;
}

.fact-list li {
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 6px;
  background: #f1f5f9;
  border: 1px solid var(--border-subtle);
}

/* 動画風プレイヤーバー */
.player-bar {
  pointer-events: auto;
  width: min(780px, 100%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.1);
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.ctrl-btn:hover {
  background: #f1f5f9;
}

.ctrl-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.ctrl-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

.ctrl-play {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #ffffff;
}

.ctrl-play:hover {
  background: var(--accent-bright);
}

.tts-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.ctrl-tts.is-on {
  color: #7c5812;
  background: rgba(184, 134, 40, 0.14);
}

.ctrl-tts.is-on:hover {
  background: rgba(184, 134, 40, 0.24);
}

.ctrl-rate-btn {
  height: 24px;
  min-width: 38px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.ctrl-rate-btn:hover {
  background: #f1f5f9;
}

.tts-controls.hidden {
  display: none;
}

.timeline {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}

.timeline-seg {
  position: relative;
  flex: 1;
  height: 5px;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.12);
  cursor: pointer;
  overflow: hidden;
  transition: height 0.12s ease, background 0.12s ease;
}

.timeline-seg:hover {
  height: 8px;
}

.timeline-seg.is-done {
  background: rgba(184, 134, 40, 0.55);
}

.timeline-seg.is-active {
  background: rgba(184, 134, 40, 0.22);
}

.timeline-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: var(--accent);
}

.player-hint {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: right;
}

/* ===== 縦画面（Portrait）: 上半分が地図、下半分に解説＆操作 ===== */
@media (orientation: portrait) {
  .stage {
    display: flex;
    flex-direction: column;
  }

  .map-pane {
    flex: 0 0 53dvh;
    height: 53dvh;
  }

  .caption-pane {
    position: static;
    flex: 1 1 auto;
    height: 47dvh;
    padding: 12px 14px max(14px, env(safe-area-inset-bottom));
    background: var(--surface-solid);
    border-top: 2px solid var(--accent);
    justify-content: space-between;
    pointer-events: auto;
    overflow-y: auto;
  }

  .dialogue-row {
    align-items: center;
    gap: 6px;
  }

  .yukkuri-slot {
    flex: 0 0 84px;
    width: 84px;
    height: 70px;
  }

  .caption-card {
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 2px;
  }

  .step-title {
    font-size: 15px;
  }

  .subtitle-text {
    font-size: 15.5px;
    line-height: 1.7;
  }

  .fact-list {
    display: flex;
    margin-top: 10px;
  }

  .player-bar {
    width: 100%;
    margin-top: 8px;
    background: #f8fafc;
    box-shadow: none;
  }
}

/* ===== 字幕内の用語リンク（用語別カラー同期） ===== */
.term-link,
.term-concept {
  display: inline;
  padding: 0 3px;
  border: 0;
  border-bottom: 2px solid var(--term-color, var(--accent));
  background: color-mix(in srgb, var(--term-color, var(--accent)) 13%, transparent);
  border-radius: 3px;
  color: var(--term-color, var(--accent-ink));
  font: inherit;
  font-weight: 700;
  transition: background 0.15s ease, color 0.15s ease;
}

.term-link {
  cursor: pointer;
}

.term-link:hover,
.term-link.is-selected {
  background: var(--term-color, var(--accent));
  color: #ffffff;
}

.term-note-bar {
  margin-top: 6px;
  padding: 5px 10px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--term-color, var(--accent)) 10%, #ffffff);
  border: 1px solid color-mix(in srgb, var(--term-color, var(--accent)) 30%, transparent);
  border-left: 3.5px solid var(--term-color, var(--accent));
  font-size: 11.5px;
  line-height: 1.42;
  color: #1e293b;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.term-note-item strong {
  color: #7c5812;
}

/* ===== iPad mini 等タブレット横画面（1024x768 / 1133x744） ===== */
@media (orientation: landscape) and (max-width: 1180px) and (min-height: 501px) {
  .hud-top-left { left: max(12px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); }
  .hud-top-right { right: max(12px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); }
  .maplibregl-ctrl-bottom-right {
    bottom: auto;
    top: calc(max(10px, env(safe-area-inset-top)) + 44px);
    right: max(12px, env(safe-area-inset-right));
  }
  .caption-pane {
    padding: 0 max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    gap: 8px;
  }
  .yukkuri-slot {
    flex: 0 0 118px;
    width: 118px;
    height: 98px;
  }
  .caption-card {
    padding: 11px 16px;
  }
  .subtitle-text {
    font-size: 15.5px;
    line-height: 1.58;
  }
}

/* ===== nubia S2R 等スマホ横画面（高さ500px以下） ===== */
@media (orientation: landscape) and (max-height: 500px) {
  .hud-top-left { left: max(8px, env(safe-area-inset-left)); top: max(6px, env(safe-area-inset-top)); }
  .hud-top-right { right: max(8px, env(safe-area-inset-right)); top: max(6px, env(safe-area-inset-top)); gap: 5px; }
  .hud-pill { padding: 5px 10px; font-size: 12px; }
  .hud-icon-btn { width: 32px; height: 32px; }
  .hud-icon-btn svg { width: 15px; height: 15px; }
  .popover {
    top: calc(max(6px, env(safe-area-inset-top)) + 38px);
    max-height: calc(100dvh - 150px);
  }
  .maplibregl-ctrl-bottom-right {
    bottom: auto;
    top: calc(max(6px, env(safe-area-inset-top)) + 38px);
    right: max(8px, env(safe-area-inset-right));
  }
  .diagram-card {
    top: 44px;
    right: max(8px, env(safe-area-inset-right));
    width: 220px;
  }
  .caption-pane {
    padding: 0 max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    gap: 5px;
  }
  .dialogue-row { gap: 8px; }
  .yukkuri-slot {
    flex: 0 0 92px;
    width: 92px;
    height: 76px;
  }
  .caption-card {
    padding: 7px 12px;
    max-width: calc(100% - 208px);
  }
  .caption-meta { gap: 5px; margin-bottom: 2px; }
  .speaker-tag { padding: 1px 8px; font-size: 10.5px; }
  .section-badge, .role-badge, .scale-badge { font-size: 9.5px; padding: 1px 6px; }
  .step-title { font-size: 11.5px; }
  .subtitle-text { font-size: 13.5px; line-height: 1.44; }
  .term-note-bar { margin-top: 4px; padding: 4px 8px; font-size: 11px; }
  .next-section-wrap { margin-top: 4px; }
  .btn-next-section { padding: 3px 10px; font-size: 11px; }
  .player-bar { padding: 4px 10px; gap: 8px; width: min(680px, 100%); }
  .ctrl-btn { width: 28px; height: 28px; }
  .ctrl-btn svg { width: 13px; height: 13px; }
  .player-hint { font-size: 10px; min-width: 36px; }
}
