/* =========================================================
 *  Global base
 * ======================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

/* メタエリア全体：等幅＋ちょい端末っぽい色味に */
#viewer-meta {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 11px;
  color: #d6ffe0;
}

/* FILE ブロック：カード化＋高さは内容に合わせる */
#meta-file {
  margin-bottom: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(0, 255, 140, 0.45);

  /* 変な min-height があっても潰す */
  min-height: 0;
}

/* File ラベルを “ゾーン名” として強調 */
#meta-file h3 {
  margin: 0 0 4px 0;
  padding-bottom: 2px;
  font-size: 18px;
  letter-spacing: 0.16em;
  text-transform: uppercase;

  color: #ffe480; /* 黄系で見出し感 */
  border-bottom: 1px solid rgba(255, 232, 128, 0.4);
}

/* 中の各行 */
#meta-file > div {
  line-height: 1.3;
}

/* MODEL パネル全体：等幅系フォントでログ感を出す */
#meta-model {
  font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
}

/* 見出し "MODEL" 自体もちょっとラベルっぽく */
#meta-model h3 {
  margin: 0 0 4px 0;
  padding-bottom: 2px;
  font-size: 18px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #ffe480;
  border-bottom: 1px solid rgba(255, 232, 128, 0.3);
}

/* ログ 1 レコード */
.model-log-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 4px;
}

.model-log-row--stacked {
  flex-direction: column;
}

/* ラベルピル */
.model-log-label {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid #3dee7b;
  font-size: 10px;
  letter-spacing: 0.08em;
}

/* ラベル種別ごとの色を変えたかったらここで微調整 */
.model-log-label--boot   { border-color: #3dee7b; }
.model-log-label--model  { border-color: #3db7ee; }
.model-log-label--camera { border-color: #ee8a3d; }
.model-log-label--layers { border-color: #eedd3d; }
.model-log-label--frame  { border-color: #d13dee; }

/* テキスト */
.model-log-text {
  line-height: 1.4;
}

/* MODEL のフルパス：横に長くなりがちなので省略記号付き */
.model-log-mono {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-log-placeholder {
  opacity: 0.5;
}

/* =========================================================
 *  Promo card（右上）
 * ======================================================= */
 #promo-ticker-bar {
   position: absolute;
   top: 4px;                    /* HUD より上に寄せる */
   left: 48%;
   transform: translateX(-50%);
   width: min(440px, 80vw);
   z-index: 40;                 /* HUD より前面＝外側 */
}

.promo-ticker-shell {
  overflow: hidden;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: linear-gradient(
    to right,
    rgba(0, 0, 0, 0.85),
    rgba(0, 40, 0, 0.85)
  );
  font-size: 11px;
  color: #f0fff0;
}

.promo-ticker-line {
  display: inline-flex;
  gap: 48px;
  padding: 4px 16px;
  white-space: nowrap;
  animation: promo-ticker-marquee 24s linear infinite;
}

@keyframes promo-ticker-marquee {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); } /* span の並べ方で調整 */
}


/* =========================================================
 *  右側メタ情報エリア（detail パネル）
 * ======================================================= */

.detail-panel {
  font-size: 12px;
  line-height: 1.2;
  color: #ddd;
}

.detail-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 4px;
  border-bottom: 1px solid #444;
  padding-bottom: 44px;
}

.detail-kind {
  font-weight: 600;
  opacity: 0.7;
}

.detail-name {
  font-weight: 600;
}

.detail-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-section {
  margin-bottom: 4px;
}

.detail-summary .detail-row {
  display: grid;
  grid-template-columns: minmax(0, 90px) minmax(0, 1fr);
  gap: 2px 6px;
  margin-bottom: 2px;
}

.detail-key {
  opacity: 0.7;
  white-space: nowrap;
}

.detail-value {
  word-break: break-all;
}

.detail-json {
  background: #050505;
  border: 1px solid #333;
  padding: 4px;
  max-height: 260px;
  overflow: auto;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 10px;
}

/* =========================================================
 *  Document caption（3D ビュー右上オーバーレイ）
 * ======================================================= */

.doc-caption-card {
  position: absolute;
  top: 1.75rem;     /* ticker のちょい下ぐらい。必要なら微調整 */
  right: 1.75rem;
  pointer-events: none;
  color: rgb(229 229 229); /* text-neutral-200 相当 */
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: right;
  max-width: 22rem;
  z-index: 35;      /* 3D より前, promo-ticker(40) より下 */
}

.doc-caption-title {
  font-size: 1.0rem;
  font-weight: 600;
  line-height: 1.3;
  padding-bottom: 0.2rem;
  margin-bottom: 0.2rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.55);
  text-shadow:
    0 0 10px rgba(0, 0, 0, 0.9),
    0 0 20px rgba(0, 0, 0, 0.7);
}

.doc-caption-body {
  display: block;
  max-width: 16em;       /* 全角 16 文字ぶんぐらいの幅を想定 */
  white-space: normal;   /* 折り返し許可 */
  word-break: break-all; /* 日本語でも途中で折って OK */
  font-size: 0.8rem;
  line-height: 1.5;
  opacity: 0.9;
  margin-left: auto;
  text-shadow:
    0 0 8px rgba(0, 0, 0, 0.8),
    0 0 18px rgba(0, 0, 0, 0.6);
}

/* 教科書チックな明朝系フォントだけ doc-caption に適用 */
#doc-caption-title,
#doc-caption-body {
  font-family:
    "Yu Mincho",
    "游明朝",
    "BIZ UDMincho Medium",
    "Hiragino Mincho ProN",
    "Noto Serif JP",
    "MS Mincho",
    serif;
  letter-spacing: 0.04em;
}

/* 使うなら隠しクラスも doc-caption に寄せる */
.doc-caption-hidden {
  display: none;
}

/* =========================================================
 *  HUD（トースト）
 * ======================================================= */

#viewer-hud {
  /* ベース背景（状態クラスで上書き可） */
  background: rgba(0, 0, 0, 0.85);
  z-index: 30;
}

#viewer-hud.hud-visible {
  opacity: 1;
  --tw-translate-y: 0; /* Tailwind transform の Y を 0 に */
}

#viewer-hud.hud-hidden {
  opacity: 0;
  --tw-translate-y: -0.5rem; /* translate-y-2 相当 */
}

/* 色だけ状態ごとに切り替え */
#viewer-hud.hud-info {
  background: rgba(0, 0, 0, 0.85);
}

#viewer-hud.hud-warn {
  background: rgba(190, 140, 32, 0.9);
}

#viewer-hud.hud-error {
  background: rgba(180, 32, 32, 0.9);
}

/* data-status="error" が付いた時の枠・文字色強調 */
#viewer-hud[data-status="error"] {
  border-color: #f66;
  color: #fdd;
}

/* =========================================================
 *  下部ツールバー（frame + viewer settings）
 * ======================================================= */

/* 全体クリック可に */
#viewer-toolbar {
  pointer-events: auto;
}

/* 「単一フレーム」のとき少しグレーアウト */
.frame-block.frame-single {
  opacity: 0.35;
}

/* filter 3 連トグル */
.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #f5f5f5;
}

/* SVG は黒なので、反転して白＋少し明るめにする */
.filter-icon-img {
  width: 20px;
  height: 20px;
  display: block !important;
  filter: none !important;
}

/* デフォルトは「on アイコンだけ表示」 */
.filter-icon-off {
  display: none;
}

.filter-toggle.filter-off .filter-icon-on {
  display: none;
}

.filter-toggle.filter-off .filter-icon-off {
  display: inline-flex;
}

/* off 状態だけ少し暗く */
.filter-toggle.filter-off {
  opacity: 0.4;
}

/* 再生ボタン内のアイコン共通 */
.frame-play-icon,
.frame-pause-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 初期状態：play だけ表示、pause は隠す */
#btn-play .frame-play-icon {
  display: inline-flex;
}
#btn-play .frame-pause-icon {
  display: none;
}

/* 再生中：.is-playing が付いたら逆転 */
#btn-play.is-playing .frame-play-icon {
  display: none;
}
#btn-play.is-playing .frame-pause-icon {
  display: inline-flex;
}

/* フレーム操作行のフェード（continuous モードだけ濃く） */
.frame-controls {
  opacity: 0.4;
  transition: opacity 0.15s ease-out;
}

.frame-controls.mode-continuous {
  opacity: 1;
}

/* =========================================
 *  Frame スライダ（長さ固定版）
 * ======================================= */

.frame-slider-wrapper {
  position: relative;
  display: inline-block;       /* ← これが肝。wrapper 幅 = slider 幅 に揃える */
  --frame-zero-frac: 0.5;      /* 0 ラベル位置（0.0〜1.0） */
  --frame-value-frac: 0;       /* 現在値ラベル位置（0.0〜1.0） */
}

.frame-slider {
  width: 195px;                /* ← バーの長さを固定 */
  --frame-track-height: 12px;

  -webkit-appearance: none;
  appearance: none;
  height: var(--frame-track-height);
  border-radius: 999px;
  background: transparent;
}

/* WebKit トラック */
.frame-slider::-webkit-slider-runnable-track {
  height: var(--frame-track-height);
  border-radius: 999px;
  background: #444;
}

/* WebKit サム（thumb）は透明にして、上からラベルをかぶせる */
.frame-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: transparent;
  border: none;
  margin-top: calc(-0.5 * var(--frame-track-height));
  box-shadow: none;
  cursor: pointer;
}

/* Firefox トラック */
.frame-slider::-moz-range-track {
  height: var(--frame-track-height);
  border-radius: 999px;
  background: #444;
}

/* Firefox サム */
.frame-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: pointer;
}

/* 現在 frameNo 丸ラベル：値と連動して左右に動く */
.frame-label-current {
  position: absolute;
  top: -2px; /* トラック中心にかぶるよう微調整 */
  left: calc(var(--frame-value-frac) * 100%);
  transform: translateX(-50%);
  min-width: 22px;
  height: 22px;
  padding: 0 4px;
  border-radius: 999px;

  display: flex;
  align-items: center;
  justify-content: center;

  font-size: 12px;
  font-weight: 900;
  background: #ffffff;
  color: #000000;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
  z-index: 1;
  pointer-events: none;
}

/* min / 0 / max ラベルと 0 縦線（バーの下） */
.frame-labels {
  position: relative;
  margin-top: 8px;
  font-size: 16px;
  line-height: 1;
}

.frame-label {
  position: absolute;
  white-space: nowrap;
}

/* min：左端 */
.frame-label-min {
  left: 0;
  transform: translateX(0);
}

/* max：右端 */
.frame-label-max {
  right: 0;
  transform: translateX(0);
}

/* 0：JS が表示制御＆位置更新（0〜1 の frac） */
.frame-label-zero {
  left: calc(var(--frame-zero-frac) * 100%);
  transform: translateX(-50%);
}

/* 0 の縦線目盛り */
#frame-zero-line {
  position: absolute;
  top: -24px;
  bottom: -2px;
  width: 2px;
  left: calc(var(--frame-zero-frac) * 100%);
  transform: translateX(-50%);
  background: #0000ff;
  opacity: 0.5;
}

/* gauge / timeline モードのトラック見た目 */
.frame-slider.frame-mode-gauge::-webkit-slider-runnable-track {
  background: #444;
}
.frame-slider.frame-mode-gauge::-moz-range-track {
  background: #444;
}

.frame-slider.frame-mode-timeline::-webkit-slider-runnable-track {
  background: linear-gradient(
    to right,
    rgba(255, 255, 255, 0.55),
    rgba(255, 255, 255, 0.12)
  );
}
.frame-slider.frame-mode-timeline::-moz-range-track {
  background: linear-gradient(
    to right,
    rgba(255, 255, 255, 0.55),
    rgba(255, 255, 255, 0.12)
  );
}


/* =========================================================
 *  共通ボタン（keycap）
 * ======================================================= */

.keycap {
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.8);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
}

.keycap:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* カメラモードの pill が active のとき */
.mode-pill-active {
  background: rgba(255, 255, 255, 0.85);
  color: #000000;
  opacity: 1;
}

/* =========================================================
 *  Gizmo 本体（右下）
 * ======================================================= */

/* HOME ボタン（左上） */
#gizmo-home {
  position: absolute;
  left: 4px;
  top: 4px;
  padding: 1px 8px;
  font-size: 9px;
  line-height: 1.4;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.8);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

#gizmo-home:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* 軸ボタン（X/Y/Z） */
.gizmo-axis {
  width: 22px;
  height: 22px;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.8);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.gizmo-axis:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* Gizmo サブキャンバス */
#gizmo-slot canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#gizmo-slot svg {
  pointer-events: none;
}

/* Gizmo 内のボタン類は pointer-events 有効に */
#gizmo-wrapper button,
#gizmo-wrapper .keycap,
#gizmo-wrapper .gizmo-axis {
  pointer-events: auto;
  position: relative;
  z-index: 30;
}

/* モード表示（右上テキスト） */
#gizmo-wrapper .gizmo-mode-indicator {
  font-size: 11px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.85);
}

#gizmo-mode-label {
  text-transform: lowercase;
  letter-spacing: 0.12em;
  font-weight: 500;
}

/* preset view トグル（右下 row 内の pill） */
#gizmo-presets-toggle {
  padding: 2px 10px;
  font-size: 10px;
  line-height: 1.4;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(0, 0, 0, 0.8);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

#gizmo-presets-toggle:hover {
  background: rgba(255, 255, 255, 0.18);
}

[data-role="gizmo-axis-row"] .gizmo-axis-btn,
[data-role="gizmo-view-row"] .gizmo-view-btn {
  /* hit area / sizing */
  min-width: 26px;
  height: 22px;
  padding: 0 8px;

  /* typography */
  font-size: 11px;
  line-height: 1;

  /* avoid layout wobble */
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* 任意：ホバー/押下の効き（keycapが既に持ってるなら不要） */
[data-role="gizmo-axis-row"] .gizmo-axis-btn:hover,
[data-role="gizmo-view-row"] .gizmo-view-btn:hover {
  filter: brightness(1.08);
}

[data-role="gizmo-axis-row"] .gizmo-axis-btn:active,
[data-role="gizmo-view-row"] .gizmo-view-btn:active {
  transform: translateY(1px);
}


/* coord. アイコン共通（world-axis） */
.coordinate-icon-img {
  width: 20px;
  height: 20px;
  display: block !important;
  filter: none !important; /* icons are authored for dark UI */
}

/* world-axis pill 自体を少し大きめに */
#world-axes-toggle {
  padding-inline: 0.5rem; /* px-2 相当 */
  padding-block: 0.25rem; /* py-1 相当 */
  font-size: 12px;
}

/* world-axis 中のアイコンだけ 1.2 倍 (20→24) */
#world-axes-toggle .coordinate-icon-img {
  width: 24px;
  height: 24px;
}

/* data-visible に応じて on/off 切り替え */
#world-axes-toggle [data-icon] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#world-axes-toggle[data-visible="true"] [data-icon="off"],
#world-axes-toggle[data-visible="false"] [data-icon="on"] {
  display: none;
}

/* =========================================================
 *  AutoOrbit（右下：CW / auto / CCW）
 * ======================================================= */

/* 本体コンテナ */
.auto-orbit-slot {
  width: 100px;
  height: 30px;
}

.auto-orbit-pill {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.7);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

/* ボタン共通 */
.auto-orbit-btn {
  border: none;
  background: transparent;
  color: #fdfdfd;
  padding: 0;
  font-size: 11px;
  cursor: pointer;
}

.auto-orbit-btn:focus {
  outline: none;
}

/* 左右の矢印ボタン */
.auto-orbit-btn-dir {
  width: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: transparent;
}

/* 回転中：選択されている向きだけ薄いピンク */
.auto-orbit-btn-dir.is-running {
  background: rgba(255, 182, 210, 0.32);
}

/* 倍速時：そのボタンだけ濃いピンク */
.auto-orbit-btn-dir.is-running.is-fast {
  background: rgba(255, 105, 180, 0.65);
}

/* AutoOrbit アイコン（SVG img 用） */
.auto-orbit-icon-img {
  width: 24px;
  height: 24px;
  display: block !important;
  filter: none !important;
}

/* 中央の autoOrbit ボタン */
.auto-orbit-center {
  flex: 0 0 auto;
  min-width: 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 6px;
  font-size: 10px;
}

.auto-orbit-text-top {
  font-size: 10px;
  line-height: 1.05;
  text-align: left;
}

.auto-orbit-text-bottom {
  font-size: 10px;
  line-height: 1.05;
  text-align: right;
}

/* =====================================================================
   SSOT: public/viewer/index.html layout baseline
   - /viewer is served from /public (NOT Astro), so no scoped [data-astro-*] CSS.
   - IDs / data-role defined in ui/domContract.js are positioned here.
   ===================================================================== */

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  color: #f5f5f5;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

/* Fullscreen canvas underlay */
#viewer-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  z-index: 0;
}

/* Toast / status / fallback */
#viewer-hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}
#fallback {
  position: fixed;
  left: 10px;
  top: 10px;
  z-index: 70;
  color: #f5f5f5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  white-space: pre-wrap;
  opacity: 0.92;
  pointer-events: none;
}

/* Topbar (filters) */
#viewer-topbar {
  position: fixed;
  left: 16px;
  top: 14px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
  z-index: 40;
}

/* Toolbar (frame controls etc.) */
#viewer-toolbar {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 40;
  pointer-events: auto;
}

/* Document caption */
#doc-caption {
  position: fixed;
  right: 16px;
  top: 14px;
  z-index: 40;
  max-width: min(46vw, 720px);
  text-align: right;
  pointer-events: none;
}

/* Gizmo */
#gizmo-wrapper {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: 140px;
  height: 140px;
  z-index: 40;
  pointer-events: none;
}
#gizmo-slot { position: absolute; inset: 0; }
#gizmo-ui { position: absolute; inset: 0; pointer-events: none; }

/* Mobile: slightly smaller gizmo (keep desktop as-is) */
@media (max-width: 767px) {
  #gizmo-wrapper {
    width: 112px;  /* 80% of 140px */
    height: 112px; /* 80% of 140px */
  }
}

/* Embed mode: hide UI overlays */
body.is-embed #viewer-topbar,
body.is-embed #viewer-toolbar,
body.is-embed #gizmo-ui,
body.is-embed #doc-caption {
  display: none !important;
}

/* Make key UI controls visible even on dark background */
.keycap { color: #f5f5f5; }
.frame-label { color: #f5f5f5; }

/* =====================================================================
   SSOT: public/viewer/index.html layout baseline
   - /viewer is served from /public (NOT Astro), so no scoped [data-astro-*] CSS.
   - IDs / data-role defined in ui/domContract.js are positioned here.
   ===================================================================== */

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  color: #f5f5f5;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

/* Fullscreen canvas underlay */
#viewer-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  z-index: 0;
}

/* Toast / status / fallback */
#viewer-hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}
#fallback {
  position: fixed;
  left: 10px;
  top: 10px;
  z-index: 70;
  color: #f5f5f5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  white-space: pre-wrap;
  opacity: 0.92;
  pointer-events: none;
}

/* Topbar (filters) */
#viewer-topbar {
  position: fixed;
  left: 16px;
  top: 14px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
  z-index: 40;
}

/* Toolbar (frame controls etc.) */
#viewer-toolbar {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 40;
  pointer-events: auto;
}

/* Document caption */
#doc-caption {
  position: fixed;
  right: 16px;
  top: 14px;
  z-index: 40;
  max-width: min(46vw, 720px);
  text-align: right;
  pointer-events: none;
}

/* Gizmo */
#gizmo-wrapper {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: 140px;
  height: 140px;
  z-index: 40;
  pointer-events: none;
}
#gizmo-slot { position: absolute; inset: 0; }
#gizmo-ui { position: absolute; inset: 0; pointer-events: none; }

/* Embed mode: hide UI overlays */
body.is-embed #viewer-topbar,
body.is-embed #viewer-toolbar,
body.is-embed #gizmo-ui,
body.is-embed #doc-caption {
  display: none !important;
}

/* Ensure key controls are visible on dark background */
.keycap { color: #f5f5f5; }
.frame-label { color: #f5f5f5; }

/* Match legacy class names used by public/viewer/index.html */
.doc-caption {
  display: inline-block;
  background: rgba(0,0,0,0.60);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}


/* =====================================================================
   UI Layout override (2026-01-07)
   - Left-bottom: filters (vertical) + frame buttons (row) + slider (bottom)
   - Right-bottom: gizmo + autoOrbit
   - HUD: toast only (top-center)
   ===================================================================== */

#viewer-hud {
  position: fixed;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  width: auto;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.72);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  font-size: 13px;
  line-height: 1.4;
  pointer-events: none;
  z-index: 60;
}

#viewer-hud.hud-hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(-6px);
}
#viewer-hud.hud-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.viewer-dock {
  position: fixed;
  z-index: 40;
  pointer-events: auto;
  display: flex;
  gap: 8px;
}

#viewer-leftdock {
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(12px + env(safe-area-inset-bottom));
  flex-direction: column;
  align-items: flex-start;
}

#viewer-rightdock {
  right: calc(12px + env(safe-area-inset-right));
  bottom: calc(12px + env(safe-area-inset-bottom));
  flex-direction: column;
  align-items: flex-end;
}

/* Move legacy containers into docks */
#viewer-topbar {
  position: static;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

#viewer-toolbar {
  position: static;
  left: auto;
  bottom: auto;
  transform: none;
}

/* Filters: vertical stack */
.filter-stack .filter-toggle {
  justify-content: flex-start;
  width: 60px;
  padding: 6px 10px;
  gap: 6px;
}


.filter-stack .filter-label {
  display: inline;
  font-size: 12px;
  line-height: 1;
  opacity: 0.85;
}


/* Frame controls row: 5 buttons in one line */
.frame-controls {
  display: flex;
  gap: 6px;
  justify-content: flex-start;
}

.frame-icon-img {
  width: 18px;
  height: 18px;
  display: block !important;
  filter: none !important;
}

/* Slider under buttons */
.frame-slider {
  width: 150px;
}

.frame-labels {
  opacity: 0.75;
}

/* Doc meta: no frame/background */
.doc-caption {
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
}

#doc-caption {
  right: 12px;
  top: 10px;
  text-align: right;
}

.doc-caption-title {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0.1rem;
}

/* Gizmo frame & overlay */
#gizmo-wrapper {
  position: relative !important;
  width: 160px;
  height: 160px;
  pointer-events: auto;
}

.gizmo-frame {
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(0,0,0,0.55);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  overflow: hidden;
}

#gizmo-slot {
  position: absolute;
  inset: 0;
}

.gizmo-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* world-axis: always bottom-left inside gizmo (defensive against overrides) */
.world-axes-toggle,
#world-axes-toggle {
  position: absolute;
  left: 6px;
  bottom: 6px;
  top: auto;
  right: auto;
  pointer-events: auto;
  padding: 4px 6px;
}

/* preset view: pill at bottom-right, label as "preset\nview" */
.gizmo-presets-toggle,
#gizmo-presets-toggle {
  position: absolute;
  right: 6px;
  bottom: 6px;
  left: auto;
  top: auto;
  pointer-events: auto;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  min-width: 64px;
  height: 28px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.0;
  opacity: 0.9;
}

.gizmo-presets-toggle .preset-label,
.gizmo-presets-toggle .preset-view-label {
  display: block;
  text-align: center;
}

.gizmo-mode {
  position: absolute;
  top: 6px;
  right: 6px;
  pointer-events: none;
  display: flex;
  gap: 6px;
  align-items: center;
}

.gizmo-mode-label {
  display: inline;
  font-size: 11px;
  opacity: 0.6;
  text-transform: lowercase;
  letter-spacing: 0.12em;
}

.mode-pill {
  display: none;
}


.mode-pill.mode-pill-active {
  opacity: 0.95;
}

/* AutoOrbit: 3 controls (CW / autoOrbit / CCW) */
.auto-orbit-slot {
  width: 172px;
  height: 32px;
}

.auto-orbit-pill {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.65);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.auto-orbit-center {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  letter-spacing: 0.02em;
}

.auto-orbit-btn-dir {
  width: 28px;
  height: 28px;
}

.auto-orbit-btn-dir.is-running.is-speed-1 {
  background: rgba(255, 80, 80, 0.28);
}

.auto-orbit-btn-dir.is-running.is-speed-2 {
  background: rgba(255, 80, 80, 0.50);
}

.auto-orbit-btn-dir.is-running.is-speed-4 {
  background: rgba(255, 80, 80, 0.75);
}


/* === layout tweak (2026-01-07): compact filter + shorter frame bar === */
.filter-stack .filter-toggle {
  justify-content: flex-start;
  width: 62px;
  padding: 6px 10px;
  gap: 6px;
}
.filter-stack .filter-label {
  display: inline;
  font-size: 12px;
  line-height: 1;
  opacity: 0.85;
}
.filter-toggle{
  gap: 0;
}
/* =====================
 *  SSOT override: ensure SVG img are visible (tuning CSS should not hide)
 * ===================== */
.filter-icon-img,
.frame-icon-img,
.auto-orbit-icon-img,
.coordinate-icon-img {
  display: block !important;
  filter: none !important;
}

@media (max-width: 767px){
  /* Mobile: meta is shown in host chrome; hide viewer caption */
  #doc-caption{ display: none !important; }
}


/* === SSOT enforce: icon-only UI bits === */
.filter-label{ display:none !important; }
.frame-icon-img,
.filter-icon-img,
.auto-orbit-icon-img,
.coordinate-icon-img{
  display:block !important;
  visibility:visible !important;
  opacity:0.92 !important;
  filter:none !important;
}
/* filter state: off shows grey via opacity on button */
.filter-toggle[aria-pressed="false"]{ opacity:0.38; }
/* hide doc-caption on mobile (meta is hosted by /app/viewer) */
@media (max-width: 767px){
  #doc-caption{ display:none !important; }
}

/* =========================================================
 *  2026-01-07 (v6) UI tweaks (SSOT hardening)
 *   - prevent iframe/canvas width drift (only-left-half on mobile)
 *   - show filter labels (線/点/他)
 *   - make filter toggles + frame buttons icon-only (no pill frame)
 *   - keep doc-caption as plain text (no card)
 *   - enforce correct frame min/max label alignment
 * ======================================================= */

/* harden canvas sizing against any external tuning css */
html, body {
  width: 100% !important;
  height: 100% !important;
  overflow: hidden !important;
}
#viewer-canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ホストページに埋め込まれた時でも常に最前面で操作できるようにする */
#viewer-root {
  position: fixed;
  inset: 0;
  z-index: 9999;
}

/* doc caption: plain text, no background/frame */
.doc-caption {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  padding: 0 !important;
}
.doc-caption-title {
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Hiragino Mincho Pro", "MS Mincho", serif !important;
}
.doc-caption-body {
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Hiragino Mincho Pro", "MS Mincho", serif !important;
}

/* show labels (override old icon-only rule) */
.filter-label {
  display: inline !important;
}

/* filters: no pill background/border */
.filter-stack .filter-toggle.keycap {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}
.filter-stack .filter-toggle {
  padding: 0 !important;
  width: auto !important;
  min-width: 0 !important;
  justify-content: flex-start;
  gap: 6px;
}

/* frame buttons: no pill background/border */
.frame-controls .keycap {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 4px !important;
}
.frame-controls {
  gap: 8px;
}

/* frame slider: shorter (about 3/4) */
.frame-slider-wrapper {
  width: 150px !important;
}

/* ensure min/max labels sit at ends (avoid bunching left) */
.frame-labels {
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  display: flex !important;
  justify-content: space-between !important;
}
.frame-label-min { text-align: left !important; }
.frame-label-max { text-align: right !important; }


/* =========================================================
 *  2026-01-07 v7: enforce gizmo overlay positions
 * ======================================================= */
#gizmo-wrapper { position: relative !important; }
#world-axes-toggle{
  position:absolute !important;
  left:6px !important;
  bottom:6px !important;
  top:auto !important;
  right:auto !important;
}
#gizmo-presets-toggle{
  position:absolute !important;
  right:6px !important;
  bottom:6px !important;
  top:auto !important;
  left:auto !important;
  border-radius:999px !important;
  padding:4px 10px !important;
  min-width:64px !important;
  height:28px !important;
  display:inline-flex !important;
  flex-direction:column !important;
  align-items:center !important;
  justify-content:center !important;
  line-height:1.0 !important;
}

/* =========================================================
 *  2026-01-07 v8: UI polish fixes
 *    - remove thin panel frames (left filters / timeline)
 *    - frame labels layout + spacing
 *    - restore toast (old HUD) as top-center drop
 * ======================================================= */

/* remove panel outlines / backgrounds */
.leftdock-panel,
.timeline-panel {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

/* frame labels: keep min/max as normal flow, keep zero as absolute */
.frame-labels {
  margin-top: 3px !important; /* closer to bar */
  display: flex !important;
  justify-content: space-between !important;
  width: 100% !important;
  align-items: flex-start !important;
}
.frame-label-min,
.frame-label-max {
  position: static !important;
  transform: none !important;
}

/* toast: top-center, subtle drop */
#viewer-hud {
  /* NOTE: iOS/Safari can mis-handle position:fixed inside iframes (width drift -> only-left-half).
     Use absolute positioning within the iframe viewport instead. */
  position: absolute !important;
  left: 50% !important;
  top: 62px !important;
  transform: translateX(-50%) translateY(-8px) !important;
  width: auto !important;
  max-width: min(520px, calc(100vw - 24px)) !important;
  padding: 10px 12px !important;
  border-radius: 12px !important;
  background: rgba(0, 0, 0, 0.65) !important;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
  color: rgba(255, 255, 255, 0.92) !important;
  font-size: 13px !important;
  line-height: 1.35 !important;
  z-index: 90 !important;
  pointer-events: none !important;
  opacity: 0 !important;
  transition: opacity 180ms ease, transform 180ms ease !important;
}
#viewer-hud.hud-visible {
  opacity: 1 !important;
  transform: translateX(-50%) translateY(0) !important;
}
#viewer-hud.hud-hidden {
  opacity: 0 !important;
  transform: translateX(-50%) translateY(-8px) !important;
}

/* orbit hint (small overlay) */
#orbit-hint,
[data-role="orbit-hint"] {
  position: absolute !important;

  /* fallback -> safe-area対応 */
  left: 12px !important;
  left: calc(env(safe-area-inset-left) + 12px) !important;
  top: 12px !important;
  top: calc(env(safe-area-inset-top) + 12px) !important;

  max-width: min(320px, calc(100vw - 24px)) !important;
  padding: 6px 8px !important;
  display: flex !important;
  gap: 6px !important;
  align-items: flex-start !important;

  font-size: 12px !important;
  line-height: 1.3 !important;
  color: rgba(255, 255, 255, 0.86) !important;
  background: rgba(0, 0, 0, 0.45) !important;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
  border-radius: 10px !important;

  z-index: 80 !important;
  pointer-events: auto !important;

  opacity: 1 !important;
  transition: opacity 160ms ease !important;
}

#orbit-hint.orbit-hint-hidden,
[data-role="orbit-hint"].orbit-hint-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* text: data-role優先 + classも互換 */
#orbit-hint [data-role="orbit-hint-text"],
[data-role="orbit-hint"] [data-role="orbit-hint-text"],
#orbit-hint .orbit-hint__text,
[data-role="orbit-hint"] .orbit-hint__text {
  white-space: pre-line !important;
}

/* close: data-role優先 + classも互換 */
#orbit-hint [data-role="orbit-hint-close"],
[data-role="orbit-hint"] [data-role="orbit-hint-close"],
#orbit-hint .orbit-hint__close,
[data-role="orbit-hint"] .orbit-hint__close {
  border: 0 !important;
  background: transparent !important;
  color: rgba(255, 255, 255, 0.75) !important;
  cursor: pointer !important;

  /* タップしやすく */
  font-size: 14px !important;
  line-height: 1 !important;
  padding: 4px 6px !important;
  border-radius: 8px !important;
}

/* perf HUD (debug only) */
#perf-hud,
[data-role="perf-hud"] {
  position: absolute !important;

  left: 12px !important;
  left: calc(env(safe-area-inset-left) + 12px) !important;
  bottom: 12px !important;
  bottom: calc(env(safe-area-inset-bottom) + 12px) !important;

  padding: 6px 8px !important;
  font-size: 11px !important;
  line-height: 1.35 !important;
  color: rgba(255, 255, 255, 0.85) !important;
  background: rgba(0, 0, 0, 0.5) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  border-radius: 8px !important;

  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace !important;
  white-space: pre !important;

  max-width: min(360px, calc(100vw - 24px)) !important;
  z-index: 80 !important;
  pointer-events: none !important;
}

#perf-hud:empty,
[data-role="perf-hud"]:empty {
  display: none !important;
}

@media (max-width: 767px) {
  #viewer-hud {
    top: 52px !important;
    max-width: min(520px, calc(100vw - 16px)) !important;
  }
}

/* =========================================================
 *  iframe hardening (root-cause fix)
 *  - iOS/Safari has long-standing issues with position:fixed inside iframes
 *    that can produce width drift ("only-left-half" rendering).
 *  - Make the main rendering surface and overlays absolute within the iframe.
 * ======================================================= */

body {
  position: relative !important;
}

#viewer-canvas {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
}

.viewer-dock {
  position: absolute !important;
}

#fallback {
  position: absolute !important;
}

#doc-caption {
  position: absolute !important;
}

/* =========================================================
 *  Mini ad (optional)
 *  - Visible only when enabled by viewerHostBoot.js
 *  - Hidden on small screens to keep the 3D view unobstructed
 * ======================================================= */

.viewer-mini-ad {
  position: absolute !important;
  top: 12px;
  left: 12px;
  z-index: 80;
  display: none;
  max-width: 320px;
}

.viewer-mini-ad[data-on="1"] {
  display: block;
}

.viewer-mini-ad-body {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.72);
  border-radius: 14px;
  padding: 10px;
  backdrop-filter: blur(6px);
}

.viewer-mini-ad-close {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.78);
  color: rgba(255, 255, 255, 0.9);
  line-height: 24px;
  font-size: 18px;
  cursor: pointer;
}

.viewer-mini-ad-close:hover {
  background: rgba(0, 0, 0, 0.9);
}

@media (max-width: 1023px) {
  .viewer-mini-ad {
    display: none !important;
  }
}


/* Back button (return to library/meta) */
.viewer-back {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  top: max(12px, env(safe-area-inset-top));
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.20);
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  color: rgba(255,255,255,0.92);
  display: grid;
  place-items: center;
  z-index: 9999;
  cursor: pointer;
}
.viewer-back:hover {
  background: rgba(0,0,0,0.75);
  border-color: rgba(255,255,255,0.35);
}
.viewer-back:focus-visible {
  outline: 2px solid rgba(255,255,255,0.55);
  outline-offset: 2px;
}
