/* historia — 3D戦況ビューア スタイル */

.b3d-root {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line, #e0d6c2);
  border-radius: var(--radius, 14px);
  background: var(--surface, #fffdf7);
  color: var(--ink, #262119);
  overflow: hidden;
  max-width: 100%;
  box-shadow: var(--shadow, 0 4px 20px rgba(60, 44, 20, 0.08));
  font-family: var(--sans, system-ui, sans-serif);
}

.b3d-root.b3d-fullscreen,
.b3d-root:fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  border-radius: 0;
  border: 0;
  width: 100vw;
  height: 100vh;
  max-width: none;
}

.b3d-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  flex-wrap: wrap;
  padding: 9px 12px;
  background: var(--surface-2, #fbf6ea);
  border-bottom: 1px solid var(--line, #e0d6c2);
}

.b3d-factions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
  min-width: 0;
}

.b3d-faction {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  line-height: 1.3;
  max-width: 100%;
}

.b3d-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

.b3d-fac-name {
  font-weight: 700;
  color: var(--ink, #262119);
}

.b3d-fac-meta {
  color: var(--ink-soft, #4b4438);
  font-size: 11.5px;
}

.b3d-fac-str {
  color: var(--muted, #776e5f);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface, #fffdf7);
  border: 1px solid var(--line, #e0d6c2);
}

.b3d-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}

.b3d-cam-group {
  display: inline-flex;
  border: 1px solid var(--line-strong, #c9bda5);
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface, #fffdf7);
}

.b3d-cam-group .b3d-btn {
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--line, #e0d6c2);
}

.b3d-cam-group .b3d-btn:last-child {
  border-right: 0;
}

.b3d-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 10px;
  min-height: 30px;
  font-family: var(--sans, system-ui, sans-serif);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink-soft, #4b4438);
  background: var(--surface, #fffdf7);
  border: 1px solid var(--line-strong, #c9bda5);
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.b3d-btn:hover {
  border-color: var(--ink, #262119);
  color: var(--ink, #262119);
}

.b3d-btn.active {
  background: var(--ink, #262119);
  color: var(--paper, #f7f2e7);
  border-color: var(--ink, #262119);
}

.b3d-detail-link {
  color: var(--link, #1d5563);
  border-color: var(--link, #1d5563);
}

.b3d-detail-link:hover {
  background: var(--link-soft, #e4efee);
  color: var(--link, #1d5563);
}

/* ── 3Dキャンバス領域 ── */

.b3d-stage-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.b3d-fullscreen .b3d-stage-wrap,
.b3d-root:fullscreen .b3d-stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
}

.b3d-stage {
  position: relative;
  width: 100%;
  height: clamp(320px, 52vw, 540px);
  background: #cfdbe3;
  overflow: hidden;
  user-select: none;
}

.b3d-compact .b3d-stage {
  height: clamp(270px, 46vw, 410px);
}

.b3d-fullscreen .b3d-stage,
.b3d-root:fullscreen .b3d-stage {
  flex: 1 1 auto;
  height: auto;
  min-height: 260px;
}

.b3d-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

.b3d-canvas:active {
  cursor: grabbing;
}

.b3d-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.b3d-leaders {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

@keyframes b3d-anchor-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.95; }
}

.b3d-anchor-halo {
  fill: rgba(230, 180, 60, 0.22);
  stroke: rgba(244, 200, 74, 0.72);
  stroke-width: 1.5;
  animation: b3d-anchor-pulse 2.2s ease-in-out infinite;
}

.b3d-anchor-halo.active {
  fill: rgba(244, 200, 74, 0.34);
  stroke: #f4c84a;
  stroke-width: 2;
}

.b3d-tags-layer,
.b3d-callouts-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.b3d-unit-tag {
  position: absolute;
  transform: translate(-50%, -100%);
  background: rgba(25, 22, 18, 0.78);
  color: #f8f5ee;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  padding: 2px 6px 3px;
  font-size: 11px;
  line-height: 1.25;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
  transition: opacity 0.16s ease;
}

.b3d-unit-tag.dimmed {
  opacity: 0.42;
  transform: translate(-50%, -100%) scale(0.9);
}

.b3d-unit-tag.selected {
  background: rgba(34, 28, 16, 0.92);
  border-color: #f4c84a;
  box-shadow: 0 0 0 1px rgba(244, 200, 74, 0.55);
}

.b3d-tag-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}

.b3d-tag-row .b3d-dot {
  width: 7px;
  height: 7px;
  border-color: rgba(255, 255, 255, 0.5);
}

.b3d-hp {
  height: 3px;
  margin-top: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.b3d-hp span {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.b3d-landmark {
  position: absolute;
  transform: translate(-50%, -100%);
  background: rgba(255, 253, 247, 0.88);
  color: #2b2419;
  border: 1px solid rgba(110, 94, 68, 0.45);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.16);
}

.b3d-landmark.dimmed {
  opacity: 0.48;
}

.b3d-landmark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 1px;
  height: 6px;
  background: rgba(43, 36, 25, 0.55);
}

/* ── 画面内ステップヘッダーバナー ── */

.b3d-step-banner {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 4;
  max-width: min(430px, calc(100% - 20px));
  background: rgba(255, 253, 247, 0.93);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line-strong, #c9bda5);
  border-radius: 10px;
  padding: 7px 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  color: var(--ink, #262119);
  pointer-events: auto;
}

.b3d-sb-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 7px;
}

.b3d-sb-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent, #8d2f33);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.b3d-sb-time {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent, #8d2f33);
  background: var(--accent-soft, #f4e3df);
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

.b3d-sb-title {
  font-size: 13px;
  font-family: var(--serif, serif);
  line-height: 1.3;
  color: var(--ink, #262119);
}

.b3d-sb-toggle {
  margin-left: auto;
  border: 1px solid var(--line-strong, #c9bda5);
  background: var(--surface-2, #fbf6ea);
  color: var(--ink-soft, #4b4438);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
}

.b3d-sb-desc {
  margin-top: 4px;
  font-size: 11.8px;
  line-height: 1.5;
  color: var(--ink-soft, #4b4438);
}

.b3d-step-banner.is-compact {
  padding: 5px 8px;
  max-width: calc(100% - 16px);
  left: 8px;
  top: 8px;
}

.b3d-step-banner.is-compact .b3d-sb-title {
  font-size: 12px;
}

.b3d-step-banner.is-collapsed .b3d-sb-desc {
  display: none;
}

/* ── 3D空間コールアウトカード（デスクトップ） ── */

.b3d-callout-card {
  position: absolute;
  pointer-events: auto;
  z-index: 3;
  width: clamp(178px, 23vw, 232px);
  text-align: left;
  font-family: var(--sans, system-ui, sans-serif);
  background: rgba(23, 20, 16, 0.88);
  backdrop-filter: blur(6px);
  color: #f8f4ea;
  border: 1.5px solid rgba(230, 180, 60, 0.56);
  border-radius: 9px;
  padding: 7px 9px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.34);
  cursor: pointer;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.b3d-callout-card:hover,
.b3d-callout-card.hovered,
.b3d-callout-card.active {
  border-color: #f4c84a;
  background: rgba(30, 25, 17, 0.95);
  box-shadow: 0 0 0 1px rgba(244, 200, 74, 0.45), 0 8px 22px rgba(0, 0, 0, 0.44);
  z-index: 4;
}

.b3d-cc-head {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 3px;
}

.b3d-cc-num {
  color: #f4c84a;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.b3d-cc-label {
  display: inline-block;
  background: rgba(230, 180, 60, 0.2);
  color: #f7d66b;
  border: 1px solid rgba(230, 180, 60, 0.45);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.25;
}

.b3d-cc-title {
  display: block;
  font-size: 12.2px;
  font-weight: 700;
  line-height: 1.32;
  color: #fffdf7;
  margin-bottom: 2px;
}

.b3d-cc-text {
  font-size: 11px;
  line-height: 1.45;
  color: #e4dccd;
}

.b3d-cc-text a.term-link {
  color: #a6e9f2;
  background: rgba(158, 217, 223, 0.16);
  border-bottom-color: rgba(166, 233, 242, 0.55);
  text-decoration-color: rgba(166, 233, 242, 0.55);
}

.b3d-cc-text a.term-link:hover {
  color: #ffffff;
  background: rgba(158, 217, 223, 0.3);
}

/* ── 3D空間コールアウトピン & フォーカスバー（モバイル / コンパクト） ── */

.b3d-callout-pin {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: auto;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-family: var(--sans, system-ui, sans-serif);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  background: rgba(22, 20, 16, 0.9);
  color: #fffaf0;
  border: 1.5px solid rgba(230, 180, 60, 0.8);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.34);
  cursor: pointer;
}

.b3d-cp-num {
  color: #f4c84a;
}

.b3d-callout-pin.active {
  background: #e6b43c;
  color: #1e1910;
  border-color: #fff3c4;
  z-index: 4;
}

.b3d-callout-pin.active .b3d-cp-num {
  color: #1e1910;
}

.b3d-mobile-focus {
  background: var(--surface-2, #fbf6ea);
  border-top: 1px solid var(--line, #e0d6c2);
  padding: 8px 10px;
}

.b3d-mobile-focus[hidden] {
  display: none;
}

.b3d-mf-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 5px;
}

.b3d-mf-pills {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.b3d-mf-pill {
  border: 1px solid var(--line-strong, #c9bda5);
  background: var(--surface, #fffdf7);
  color: var(--ink-soft, #4b4438);
  border-radius: 999px;
  padding: 3px 8px;
  font-family: var(--sans, system-ui, sans-serif);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
}

.b3d-mf-pill.active {
  background: #e6b43c;
  border-color: #c28e19;
  color: #1f190e;
}

.b3d-mf-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.b3d-mf-btn {
  min-height: 26px;
  padding: 3px 8px;
  font-size: 11px;
}

.b3d-mf-next {
  background: var(--accent, #8d2f33);
  border-color: var(--accent, #8d2f33);
  color: #fff;
}

.b3d-mf-next:hover {
  background: #732327;
  border-color: #732327;
  color: #fff;
}

.b3d-mf-title {
  display: block;
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--ink, #262119);
}

.b3d-mf-text {
  margin: 2px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-soft, #4b4438);
}

/* ── ユニット詳細インスペクター ── */

.b3d-inspector {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 3;
  width: min(260px, calc(100% - 20px));
  background: color-mix(in srgb, var(--surface, #fffdf7) 94%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line-strong, #c9bda5);
  border-radius: 10px;
  padding: 9px 11px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
  font-size: 12px;
}

.b3d-inspector[hidden] {
  display: none;
}

.b3d-insp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.b3d-insp-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.b3d-insp-close {
  border: 0;
  background: transparent;
  color: var(--muted, #776e5f);
  font-size: 17px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
}

.b3d-insp-body {
  display: grid;
  gap: 3px;
  font-size: 11.5px;
}

.b3d-insp-body > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.b3d-insp-body span {
  color: var(--muted, #776e5f);
  flex-shrink: 0;
}

.b3d-insp-body b {
  font-weight: 600;
  text-align: right;
  color: var(--ink, #262119);
}

.b3d-insp-bar {
  margin-top: 6px;
  height: 4px;
  border-radius: 999px;
  background: var(--line, #e0d6c2);
  overflow: hidden;
}

.b3d-insp-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
}

/* ── ステップ操作パネル ── */

.b3d-panel {
  padding: 10px 14px 11px;
  background: var(--surface, #fffdf7);
  border-top: 1px solid var(--line, #e0d6c2);
}

.b3d-step-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 8px;
}

.b3d-step-primary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.b3d-step-secondary {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.b3d-pills {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.b3d-pill {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line-strong, #c9bda5);
  background: var(--surface-2, #fbf6ea);
  color: var(--ink-soft, #4b4438);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.b3d-pill:hover {
  border-color: var(--ink, #262119);
}

.b3d-pill.active {
  background: var(--accent, #8d2f33);
  border-color: var(--accent, #8d2f33);
  color: #fff;
}

.b3d-prev-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.b3d-next-primary {
  background: var(--accent, #8d2f33);
  border-color: var(--accent, #8d2f33);
  color: #fff;
  padding: 6px 13px;
  font-weight: 700;
}

.b3d-next-primary:hover {
  background: #732327;
  border-color: #732327;
  color: #fff;
}

.b3d-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.b3d-scrubber {
  flex: 1 1 80px;
  min-width: 60px;
  accent-color: var(--accent, #8d2f33);
  cursor: pointer;
  height: 22px;
}

.b3d-speed {
  border: 1px solid var(--line-strong, #c9bda5);
  background: var(--surface-2, #fbf6ea);
  color: var(--ink, #262119);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  min-height: 28px;
  cursor: pointer;
}

@media (max-width: 720px), (max-width: 1100px) and (orientation: portrait) {
  .b3d-topbar {
    padding: 8px 10px;
  }
  .b3d-tools {
    width: 100%;
    margin-left: 0;
  }
  .b3d-btn {
    padding: 5px 8px;
    font-size: 11.5px;
  }
  .b3d-fac-str {
    display: none;
  }
  .b3d-panel {
    padding: 9px 10px 10px;
  }
  .b3d-step-primary {
    width: 100%;
    justify-content: space-between;
    gap: 5px;
  }
  .b3d-pill {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  .b3d-next-primary {
    padding: 5px 10px;
    font-size: 11.5px;
  }
  .b3d-controls {
    gap: 6px;
  }
}
