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

    :root {
      --bg: #0c0f14;
      --surface: #161a22;
      --surface2: #202633;
      --surface3: #0f141d;
      --accent: #5aa7ff;
      --accent2: #2dd4bf;
      --success: #34d399;
      --warn: #fbbf24;
      --danger: #f87171;
      --text: #eef4ff;
      --muted: #93a4ba;
      --border: #303849;
      --radius: 8px;
      --shadow: 0 16px 48px rgba(0,0,0,0.28);

      /* タイポグラフィ・スケール。これまで 0.65〜2.6rem で 20 種類以上に
         分散していたフォントサイズを 8 段階のトークンに集約する。
         本文まわり（0.65〜0.92rem）は 2xs/xs/sm/md の 4 段に統合。 */
      --text-2xs: 0.69rem;
      --text-xs:  0.74rem;
      --text-sm:  0.8rem;
      --text-md:  0.88rem;
      --text-lg:  1rem;
      --text-xl:  1.32rem;
      --text-2xl: 1.9rem;
      --text-3xl: 2.6rem;
    }

    body {
      font-family: 'Segoe UI', system-ui, sans-serif;
      background: var(--bg);
      color: var(--text);
      /* ビューポート高に固定する（min-height だと、左パネルの中身が増えて
         縦に長くなったとき body 自体が伸び、flex:1 の .main → ビューア列が
         パネル高まで肥大して 3D キャンバスが画面外へ押し出され「ビューが黒く
         なる」。固定高にすればパネルは内部スクロール（.panel の overflow-y:auto）
         で収まり、ビューアは常にビューポート高に収まる。モバイルでは下の
         @media で height:auto に戻してページスクロールにする。 */
      height: 100vh;
      height: 100dvh; /* モバイルの URL バー伸縮に追従 */
      display: flex;
      flex-direction: column;
      line-height: 1.5;
      overflow: hidden;
      text-rendering: optimizeLegibility;
      -webkit-font-smoothing: antialiased;
    }

    header {
      min-height: 57px;
      padding: 12px 24px;
      background: rgba(22,26,34,0.96);
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
    }
    .brand {
      display: flex;
      align-items: baseline;
      gap: 14px;
      min-width: 0;
    }
    header .logo { font-size: var(--text-xl); font-weight: 750; letter-spacing: 0; white-space: nowrap; }
    header .logo span { color: var(--accent); }
    header .tagline { font-size: var(--text-sm); color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .header-lp-link {
      color: var(--muted);
      font-size: var(--text-xs);
      text-decoration: none;
      white-space: nowrap;
    }
    .header-lp-link:hover { color: var(--text); text-decoration: underline; }
    .header-status {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      padding: 6px 10px;
      border: 1px solid var(--border);
      border-radius: 999px;
      background: rgba(255,255,255,0.03);
      color: var(--muted);
      font-size: var(--text-xs);
      white-space: nowrap;
    }
    .status-dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: var(--muted);
      box-shadow: 0 0 0 3px rgba(147,164,186,0.12);
    }
    .header-status[data-state="loading"] .status-dot {
      background: var(--warn);
      box-shadow: 0 0 0 3px rgba(251,191,36,0.16);
    }
    .header-status[data-state="ready"] .status-dot {
      background: var(--success);
      box-shadow: 0 0 0 3px rgba(52,211,153,0.16);
    }
    .header-status[data-state="error"] .status-dot {
      background: var(--danger);
      box-shadow: 0 0 0 3px rgba(248,113,113,0.16);
    }

    .main {
      flex: 1;
      display: grid;
      grid-template-columns: clamp(360px, 31vw, 440px) minmax(0, 1fr);
      gap: 0;
      min-height: 0;
      height: calc(100vh - 57px);
      height: calc(100dvh - 57px); /* モバイルの URL バー伸縮に追従 */
    }

    /* ── Left panel ── */
    .panel {
      background: var(--surface);
      border-right: 1px solid var(--border);
      padding: 22px 20px;
      display: flex;
      flex-direction: column;
      gap: 18px;
      overflow-y: auto;
      max-height: none;
      min-width: 0;
      scrollbar-color: rgba(147,164,186,0.35) transparent;
    }

    .section-title {
      font-size: var(--text-xs);
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: #8fb9ff;
      margin-bottom: 8px;
    }

    /* Drop zone */
    .dropzone {
      border: 1.5px dashed rgba(90,167,255,0.42);
      border-radius: var(--radius);
      padding: 24px 16px;
      text-align: center;
      cursor: pointer;
      transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.15s;
      position: relative;
      min-height: 160px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 8px;
      background:
        linear-gradient(180deg, rgba(90,167,255,0.08), rgba(45,212,191,0.03)),
        var(--surface3);
    }
    .dropzone.dragover, .dropzone:hover, .dropzone:focus-within {
      border-color: var(--accent);
      background:
        linear-gradient(180deg, rgba(90,167,255,0.14), rgba(45,212,191,0.06)),
        var(--surface3);
      box-shadow: inset 0 0 0 1px rgba(90,167,255,0.14), var(--shadow);
      transform: translateY(-1px);
    }
    .dropzone input[type="file"] {
      position: absolute; inset: 0; opacity: 0; cursor: pointer;
    }
    .dropzone .icon {
      width: 54px;
      height: 54px;
      border-radius: 8px;
      display: grid;
      place-items: center;
      background: rgba(90,167,255,0.12);
      border: 1px solid rgba(90,167,255,0.24);
      font-size: var(--text-2xl);
      margin-bottom: 2px;
    }
    .upload-title { color: var(--text); font-size: var(--text-lg); font-weight: 750; }
    .upload-sub { color: var(--muted); font-size: var(--text-sm); }
    .upload-formats {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 6px;
      margin-top: 2px;
    }
    .upload-formats span {
      border: 1px solid rgba(147,164,186,0.24);
      border-radius: 999px;
      padding: 3px 8px;
      color: var(--muted);
      font-size: var(--text-2xs);
      background: rgba(255,255,255,0.03);
    }
    .preprocess-toggle {
      display: flex;
      align-items: flex-start;
      gap: 8px;
      margin-top: 10px;
      padding: 9px 10px;
      border-radius: var(--radius);
      border: 1px solid transparent;
      color: var(--muted);
      cursor: pointer;
      user-select: none;
      font-size: var(--text-xs);
      line-height: 1.45;
    }
    .preprocess-toggle:hover {
      border-color: rgba(45,212,191,0.24);
      background: rgba(45,212,191,0.05);
      color: #b9c8da;
    }
    .preprocess-toggle input { margin-top: 2px; accent-color: var(--accent2); flex-shrink: 0; }
    .preprocess-toggle span { min-width: 0; overflow-wrap: anywhere; }
    .quick-flow {
      display: grid;
      grid-template-columns: repeat(4, minmax(0, 1fr));
      gap: 6px;
      margin-top: 10px;
    }
    .quick-flow-step {
      min-width: 0;
      border: 1px solid var(--border);
      border-radius: 999px;
      padding: 5px 7px;
      color: var(--muted);
      background: rgba(255,255,255,0.025);
      font-size: var(--text-2xs);
      font-weight: 700;
      text-align: center;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .quick-flow-step.active {
      border-color: rgba(90,167,255,0.62);
      color: #d9ecff;
      background: rgba(90,167,255,0.13);
    }

    /* File info card */
    .file-card {
      background: linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.015)), var(--surface2);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 12px 14px;
      display: none;
      gap: 10px;
      align-items: flex-start;
    }
    .file-card.show { display: flex; }
    .file-card .file-icon {
      width: 36px;
      height: 36px;
      display: grid;
      place-items: center;
      border-radius: 8px;
      background: rgba(90,167,255,0.12);
      font-size: var(--text-xl);
      flex-shrink: 0;
    }
    .file-card .file-meta { flex: 1; min-width: 0; }
    .file-card .file-name {
      font-weight: 600; font-size: var(--text-md);
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .file-card .file-sub { font-size: var(--text-xs); color: var(--muted); margin-top: 2px; }

    /* ─── History timeline bar (bottom-fixed) ─── */
    #history-bar {
      position: fixed; left: 0; right: 0; bottom: 0;
      background: rgba(15, 23, 42, 0.92);
      backdrop-filter: blur(8px);
      -webkit-backdrop-filter: blur(8px);
      border-top: 1px solid rgba(34, 211, 238, 0.25);
      padding: 8px 14px 10px;
      z-index: 100;
      display: none;
    }
    #history-bar.show { display: block; }
    #history-bar .history-header {
      display: flex; align-items: center; gap: 8px;
      font-size: var(--text-xs); color: var(--muted); margin-bottom: 6px;
      cursor: pointer; user-select: none;
    }
    #history-bar .history-toggle { margin-left: 4px; transition: transform 0.15s; opacity: 0.7; }
    #history-bar.collapsed .history-toggle { transform: rotate(-90deg); }
    #history-bar.collapsed #history-items { display: none; }
    #history-bar.collapsed { padding-bottom: 6px; }
    #history-bar .history-header .history-count {
      background: rgba(34, 211, 238, 0.15);
      color: #22d3ee;
      border-radius: 999px; padding: 1px 8px;
      font-variant-numeric: tabular-nums; font-weight: 600;
    }
    #history-items { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
    #history-items::-webkit-scrollbar { height: 6px; }
    #history-items::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
    .history-item {
      flex-shrink: 0;
      background: rgba(255,255,255,0.04);
      border: 1px solid rgba(255,255,255,0.1);
      border-radius: 8px;
      padding: 6px 10px;
      cursor: pointer;
      font-size: var(--text-xs);
      color: var(--muted);
      white-space: nowrap;
      transition: border-color 0.12s, background 0.12s, color 0.12s;
      display: flex; flex-direction: column; gap: 2px; align-items: flex-start;
      min-width: 70px;
    }
    .history-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
    .history-item.current {
      border-color: #22d3ee;
      background: rgba(34,211,238,0.18);
      color: #22d3ee;
    }
    .history-item.future { opacity: 0.55; }
    .history-item .history-label { font-weight: 600; font-size: var(--text-xs); }
    .history-item .history-meta { font-size: var(--text-2xs); opacity: 0.85; }
    /* 履歴バーの分だけ .main を縮める。body に padding を足すと
       body 全体が 100vh を超えて html がスクロールし、3D ビューが
       画面外へ流れてしまうため、ここで高さを調整する。 */
    body.history-visible .main { height: calc(100vh - 57px - 84px); height: calc(100dvh - 57px - 84px); }

    /* ─── Parts panel (multi-mesh transform mode) ─── */
    #parts-panel {
      display: none;
      background: var(--surface);
      border-radius: 10px;
      padding: 12px;
      margin-top: 12px;
      border: 1px solid rgba(168,85,247,0.25);
    }
    #parts-panel .panel-title {
      font-size: var(--text-md); font-weight: 600; color: #a855f7;
      margin-bottom: 6px;
    }
    #parts-panel .panel-desc {
      font-size: var(--text-xs); color: var(--muted); line-height: 1.5; margin-bottom: 10px;
    }
    .transform-mode-row {
      display: flex; gap: 4px; margin-bottom: 8px;
    }
    .transform-mode-row button {
      flex: 1; padding: 6px 4px; border-radius: 6px;
      background: rgba(255,255,255,0.04); color: var(--muted);
      border: 1px solid rgba(255,255,255,0.1);
      cursor: pointer; font-size: var(--text-xs);
      transition: all 0.12s;
    }
    .transform-mode-row button.active {
      background: rgba(168,85,247,0.2); color: #a855f7; border-color: #a855f7;
    }
    #parts-list { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; }
    .part-row {
      display: flex; align-items: center; gap: 8px;
      padding: 6px 8px; border-radius: 6px; cursor: pointer;
      background: rgba(255,255,255,0.03);
      border: 1px solid transparent;
      transition: background 0.12s, border-color 0.12s;
    }
    .part-row:hover { background: rgba(255,255,255,0.06); }
    .part-row.selected { border-color: #a855f7; background: rgba(168,85,247,0.12); }
    .part-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
    .part-label { flex: 1; font-size: var(--text-sm); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .part-icon-btn {
      background: transparent; border: none; cursor: pointer;
      color: var(--muted); padding: 2px 6px; border-radius: 4px;
      font-size: var(--text-md);
    }
    .part-icon-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
    #parts-empty {
      font-size: var(--text-xs); color: var(--muted); text-align: center;
      padding: 16px 8px; font-style: italic;
    }

    /* Stats grid */
    .stats-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
    }
    .stat-card {
      background: var(--surface2);
      border-radius: 8px;
      padding: 10px 12px;
      border: 1px solid rgba(255,255,255,0.04);
    }
    .stat-card .stat-label { font-size: var(--text-2xs); color: var(--muted); margin-bottom: 3px; }
    .stat-card .stat-value { font-size: var(--text-lg); font-weight: 700; color: var(--accent); }

    /* Buttons */
    .btn {
      display: inline-flex; align-items: center; justify-content: center;
      gap: 8px; padding: 11px 18px; border-radius: 8px;
      font-size: var(--text-md); font-weight: 600; cursor: pointer;
      border: none; transition: opacity 0.15s, transform 0.1s, border-color 0.15s, background 0.15s;
      width: 100%;
      min-height: 40px;
      line-height: 1.25;
      text-wrap: balance;
    }
    .btn:active { transform: scale(0.98); }
    .btn:disabled { opacity: 0.4; cursor: not-allowed; }
    .btn:focus-visible,
    .tool-tab:focus-visible,
    .axis-btn:focus-visible,
    .vt-btn:focus-visible,
    .form-input:focus-visible,
    .form-select:focus-visible {
      outline: 2px solid rgba(90,167,255,0.75);
      outline-offset: 2px;
    }
    .btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #061019; }
    .btn-success { background: var(--success); color: #0f1117; }
    .btn-warn { background: var(--warn); color: #0f1117; }
    .btn-outline {
      background: transparent; color: var(--text);
      border: 1px solid var(--border);
    }
    .btn-outline:hover { border-color: var(--accent); color: var(--accent); }
    .btn-sm { padding: 8px 14px; font-size: var(--text-sm); }

    /* Progress */
    .progress-wrap { display: none; flex-direction: column; gap: 6px; }
    .progress-wrap.show { display: flex; }
    .progress-label { font-size: var(--text-sm); color: var(--muted); }
    .progress-bar-bg {
      height: 6px; background: var(--surface2); border-radius: 99px; overflow: hidden;
    }
    .progress-bar-fill {
      height: 100%; border-radius: 99px;
      background: linear-gradient(90deg, var(--accent), var(--accent2));
      width: 0%; transition: width 0.4s;
    }

    /* Tool tabs */
    .tool-tabs {
      display: flex;
      gap: 4px;
      background: var(--surface2);
      border-radius: 10px;
      padding: 4px;
      border: 1px solid rgba(255,255,255,0.04);
    }
    .tool-tab {
      flex: 1;
      padding: 9px 4px;
      border-radius: 7px;
      border: none;
      background: transparent;
      color: var(--muted);
      font-size: var(--text-md);
      font-weight: 600;
      cursor: pointer;
      text-align: center;
      transition: all 0.15s;
      min-height: 38px;
      white-space: nowrap;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 3px;
    }
    /* タブの ⤢ 切り離しアイコン（アクティブ／ホバー時に表示） */
    .tool-tab .tab-detach {
      font-size: 0.82em; line-height: 1; opacity: 0; cursor: pointer;
      padding: 0 1px; transition: opacity 0.12s, color 0.12s;
    }
    .tool-tab:hover .tab-detach,
    .tool-tab.active .tab-detach { opacity: 0.5; }
    .tool-tab .tab-detach:hover { opacity: 1; color: var(--accent); }
    .tool-tab.detached { opacity: 0.5; }
    .tool-tab.detached .tab-label { text-decoration: line-through; }

    /* 切り離したタブのフローティング窓 */
    .float-win {
      position: fixed; z-index: 500;
      width: clamp(300px, 30vw, 420px); max-height: 82vh;
      display: flex; flex-direction: column;
      background: var(--surface); border: 1px solid var(--accent);
      border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
    }
    .float-titlebar {
      display: flex; align-items: center; justify-content: space-between; gap: 8px;
      padding: 8px 12px; background: var(--surface2);
      cursor: move; user-select: none; border-bottom: 1px solid var(--border);
    }
    .float-title {
      font-weight: 700; font-size: var(--text-sm); color: var(--text);
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .float-redock {
      background: none; border: 1px solid var(--border); color: var(--muted);
      border-radius: 6px; padding: 2px 9px; cursor: pointer;
      font-size: var(--text-xs); white-space: nowrap;
    }
    .float-redock:hover { color: var(--text); border-color: var(--accent); }
    .float-body { padding: 14px; overflow-y: auto; flex: 1; min-height: 0; }
    /* 浮動中のパネルは .active でなくても表示する */
    .tool-panel.floating { display: flex !important; }
    /* Inspect tab internal section */
    .inspect-section { display: none; flex-direction: column; gap: 14px; }
    .inspect-section.active { display: flex; }
    /* Outputs grid in 出力 tab */
    .outputs-grid { display: flex; flex-direction: column; gap: 6px; }
    .outputs-grid .btn { width: 100%; }
    .outputs-empty {
      color: var(--muted);
      font-size: var(--text-sm);
      text-align: center;
      padding: 8px 0;
      font-style: italic;
    }
    .tool-tab:hover { color: var(--text); }
    .tool-tab.active {
      background: var(--surface);
      color: var(--accent);
      box-shadow: 0 1px 4px rgba(0,0,0,0.3);
    }

    /* Tool panels */
    .tool-panel { display: none; flex-direction: column; gap: 14px; }
    .tool-panel.active { display: flex; }

    /* Form controls */
    .form-group { display: flex; flex-direction: column; gap: 6px; }
    .form-label { font-size: var(--text-sm); color: var(--muted); font-weight: 600; }
    .form-input {
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 9px 12px;
      color: var(--text);
      font-size: var(--text-md);
      width: 100%;
    }
    .form-input:focus { outline: none; border-color: var(--accent); background: #242b39; }
    .form-select {
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 9px 12px;
      color: var(--text);
      font-size: var(--text-md);
      width: 100%;
      cursor: pointer;
    }
    .form-select:focus { outline: none; border-color: var(--accent); background: #242b39; }

    /* Slider */
    .slider-row {
      display: flex;
      align-items: center;
      gap: 10px;
    }
    .slider-row input[type="range"] {
      flex: 1;
      accent-color: var(--accent2);
      height: 4px;
      cursor: pointer;
    }
    .slider-val {
      font-size: var(--text-sm);
      font-weight: 700;
      color: var(--accent2);
      min-width: 70px;
      text-align: right;
    }

    /* Result card */
    .result-card {
      background: var(--surface2);
      border-radius: var(--radius);
      padding: 14px;
      display: none;
      flex-direction: column;
      gap: 10px;
    }
    .result-card.show { display: flex; }
    .result-title {
      font-size: var(--text-sm); font-weight: 700; color: var(--success);
      display: flex; align-items: center; gap: 6px;
    }
    .result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .result-item { font-size: var(--text-sm); }
    .result-label { color: var(--muted); }
    .result-val { color: var(--text); font-weight: 600; }

    /* Diag box */
    .diag-box {
      background: rgba(79,142,247,0.06);
      border: 1px solid rgba(79,142,247,0.2);
      border-radius: 8px;
      padding: 12px;
      font-size: var(--text-sm);
      line-height: 1.8;
    }
    .diag-box .diag-title {
      font-size: var(--text-xs); font-weight: 700;
      color: var(--accent); text-transform: uppercase;
      letter-spacing: 0.8px; margin-bottom: 8px;
    }
    .diag-issue { color: var(--danger); }
    .diag-warn { color: var(--warn); }
    .diag-ok { color: var(--success); }

    /* Error */
    .error-box {
      background: rgba(248,113,113,0.1); border: 1px solid var(--danger);
      border-radius: 8px; padding: 12px; font-size: var(--text-sm);
      color: var(--danger); display: none; white-space: pre-wrap; word-break: break-all;
    }
    .error-box.show { display: block; }

    /* ── Right panel: 3D viewer ── */
    .viewer-wrap {
      position: relative;
      background:
        radial-gradient(ellipse at 55% 58%, rgba(90,167,255,0.16) 0%, rgba(12,15,20,0.96) 48%, #080b10 100%);
      display: flex;
      flex-direction: column;
      min-width: 0;
      min-height: 0;
      overflow: hidden;
    }
    #viewer-canvas {
      flex: 1;
      display: block;
      width: 100%;
      min-height: 0;
      touch-action: none;
    }
    .viewer-toolbar {
      position: absolute;
      top: 16px; right: 16px;
      display: flex; flex-direction: column; gap: 8px;
      align-items: flex-end; /* 1列ボタンとパン行(2列)を右端で揃える */
    }
    .vt-pan-row { display: flex; gap: 8px; }
    .vt-btn {
      width: 36px; height: 36px;
      background: rgba(26,29,39,0.85);
      border: 1px solid var(--border);
      border-radius: 8px;
      color: var(--text);
      font-size: var(--text-lg);
      cursor: pointer;
      display: flex; align-items: center; justify-content: center;
      transition: background 0.15s;
    }
    .vt-btn:hover { background: var(--surface2); border-color: var(--accent); }
    .vt-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

    .viewer-hint {
      position: absolute;
      bottom: 16px; left: 50%; transform: translateX(-50%);
      font-size: var(--text-xs); color: var(--muted);
      background: rgba(12,15,20,0.78);
      padding: 5px 14px; border-radius: 99px;
      pointer-events: none;
      border: 1px solid rgba(255,255,255,0.06);
      max-width: calc(100% - 32px);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .viewer-placeholder {
      position: absolute; inset: 0;
      display: flex; flex-direction: column;
      align-items: center; justify-content: center;
      gap: 10px; color: var(--muted);
      pointer-events: none;
      text-align: center;
      padding: 24px;
    }
    .viewer-placeholder .ph-icon {
      width: 74px;
      height: 74px;
      display: grid;
      place-items: center;
      border-radius: 8px;
      font-size: var(--text-3xl);
      background: rgba(90,167,255,0.11);
      border: 1px solid rgba(90,167,255,0.18);
      box-shadow: 0 18px 56px rgba(90,167,255,0.10);
    }
    .viewer-placeholder .ph-title,
    .viewer-placeholder .ph-sub {
      width: calc(100vw - 48px);
      max-width: 420px;
      overflow-wrap: anywhere;
    }
    .viewer-placeholder .ph-title { font-size: var(--text-lg); font-weight: 700; color: #c9d8ec; }
    .viewer-placeholder .ph-sub { font-size: var(--text-sm); color: var(--muted); }

    .loading-overlay {
      position: absolute; inset: 0;
      background: rgba(10,12,20,0.7);
      display: none; align-items: center; justify-content: center;
      flex-direction: column; gap: 12px;
      backdrop-filter: blur(4px);
    }
    .loading-overlay.show { display: flex; }
    .spinner {
      width: 40px; height: 40px;
      border: 3px solid var(--border);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }
    @keyframes spin { to { transform: rotate(360deg); } }
    .loading-overlay p { font-size: var(--text-md); color: var(--muted); }

    /* Thickness heatmap legend */
    .heatmap-legend {
      display: flex; align-items: center; gap: 8px;
      font-size: var(--text-xs); color: var(--muted);
    }
    .heatmap-bar {
      flex: 1; height: 8px; border-radius: 4px;
      background: linear-gradient(to right, #f87171, #fbbf24, #34d399, #4f8ef7);
    }

    /* Checkbox */
    .chk-row {
      display: flex; align-items: center; gap: 8px;
      cursor: pointer; font-size: var(--text-md); color: var(--text);
    }
    .chk-row input[type="checkbox"] {
      width: 16px; height: 16px; accent-color: #22d3ee; cursor: pointer;
    }

    /* Plane cut axis buttons */
    .axis-btns { display: flex; gap: 6px; }
    .axis-btn {
      flex: 1; padding: 8px 4px;
      border-radius: 8px; border: 1px solid var(--border);
      background: var(--surface); color: var(--muted);
      font-size: var(--text-sm); font-weight: 700;
      cursor: pointer; text-align: center;
      transition: all 0.15s;
      min-height: 36px;
      white-space: nowrap; /* 「ミラー」が「ミラ_」と途中で折れて読めなくなるのを防ぐ */
      min-width: 68px;
      line-height: 1.25;
    }
    .axis-btn:hover { border-color: var(--accent2); color: var(--text); }
    .axis-btn.active {
      background: rgba(124,92,252,0.2);
      border-color: var(--accent2); color: var(--accent2);
    }

    /* サブモード切替バー（検査タブ・形状タブの中の「診断/修復/…」「平面/部位/…」）。
       タブ(.tool-tab)や軸選択ボタンと見た目を分け、いま選んでいるモードが
       はっきり分かるよう、帯状のセグメントコントロールにする。 */
    .submode-bar {
      flex-wrap: wrap;
      gap: 4px; padding: 4px;
      background: rgba(124,92,252,0.06);
      border: 1px solid rgba(124,92,252,0.22);
      border-radius: 10px;
    }
    .submode-bar .axis-btn {
      border-color: transparent; background: transparent;
      min-height: 34px; font-size: var(--text-sm);
    }
    .submode-bar .axis-btn:hover { background: rgba(124,92,252,0.1); border-color: transparent; }
    .submode-bar .axis-btn.active {
      background: var(--accent2); color: #fff; border-color: var(--accent2);
      box-shadow: 0 2px 8px rgba(124,92,252,0.35);
    }

    /* Part preview split */
    .part-preview-row {
      display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    }
    .part-preview-btn {
      padding: 8px; border-radius: 8px;
      border: 1px solid var(--border);
      background: var(--surface2); color: var(--text);
      font-size: var(--text-sm); font-weight: 600;
      cursor: pointer; text-align: center;
      transition: all 0.15s;
    }
    .part-preview-btn:hover { border-color: var(--accent); }
    .part-preview-btn.active { border-color: var(--accent); background: rgba(79,142,247,0.15); }

    /* ── 決済モーダル ── */
    .pay-modal-backdrop {
      position: fixed; inset: 0; z-index: 300;
      background: rgba(8,10,16,0.72); backdrop-filter: blur(3px);
      display: none; align-items: center; justify-content: center;
    }
    .pay-modal-backdrop.show { display: flex; }
    .pay-modal {
      width: min(420px, calc(100vw - 32px));
      background: var(--surface); border: 1px solid var(--border);
      border-radius: 14px; padding: 26px 24px;
      box-shadow: 0 18px 50px rgba(0,0,0,0.5);
    }
    .pay-modal h2 { margin: 0 0 10px; font-size: var(--text-lg); display: flex; align-items: center; gap: 8px; }
    .pay-modal p { margin: 0 0 10px; font-size: var(--text-md); line-height: 1.7; color: var(--muted); }
    .pay-modal .pay-price {
      text-align: center; font-size: var(--text-2xl); font-weight: 700; color: var(--text);
      padding: 10px 0; margin: 6px 0 12px;
      background: rgba(79,142,247,0.08); border: 1px solid rgba(79,142,247,0.3); border-radius: 10px;
    }
    .pay-modal .pay-price small { display: block; font-size: var(--text-xs); font-weight: 400; color: var(--muted); margin-top: 2px; }
    .pay-modal .pay-methods { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 0 0 4px; }
    .pay-modal .pay-method-chip {
      font-size: var(--text-2xs); color: var(--muted); white-space: nowrap;
      border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px;
      background: rgba(255,255,255,0.03);
    }
    .pay-modal .pay-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
    .pay-modal .pay-note { font-size: var(--text-xs); color: var(--muted); margin-top: 10px; text-align: center; }

    /* ── トースト通知 ── */
    #toast-wrap {
      position: fixed; top: 70px; right: 16px; z-index: 400;
      display: flex; flex-direction: column; gap: 8px; pointer-events: none;
    }
    .toast {
      min-width: 220px; max-width: 340px; padding: 11px 16px;
      border-radius: 10px; font-size: var(--text-md); line-height: 1.5;
      background: var(--surface); border: 1px solid var(--border); color: var(--text);
      box-shadow: 0 8px 26px rgba(0,0,0,0.45);
      opacity: 0; transform: translateX(12px);
      transition: opacity 0.25s, transform 0.25s;
      pointer-events: auto;
    }
    .toast.show { opacity: 1; transform: translateX(0); }
    .toast.toast-success { border-color: rgba(52,211,153,0.5); }
    .toast.toast-error { border-color: rgba(248,113,113,0.6); }

    /* 汎用ユーティリティ */
    .is-hidden { display: none !important; }

    /* 注意・補足ボックス（実験的機能の説明など）。アクセント色は
       インラインの --c（"R,G,B"）で差し替える。既定は青系。 */
    .callout {
      margin-top: 12px; padding: 10px; border-radius: 8px;
      background: rgba(var(--c, 90,167,255), 0.06);
      border: 1px solid rgba(var(--c, 90,167,255), 0.25);
    }
    .callout-title {
      font-size: var(--text-sm); font-weight: 600;
      color: rgb(var(--c, 90,167,255)); margin-bottom: 4px;
    }
    .callout-body {
      font-size: var(--text-xs); color: var(--muted);
      line-height: 1.5; margin-bottom: 8px;
    }

    @media (max-width: 980px) {
      .main { grid-template-columns: minmax(330px, 36vw) minmax(0, 1fr); }
      .panel { padding: 18px 16px; }
      .axis-btns { flex-wrap: wrap; }
    }

    @media (max-width: 768px) {
      body { height: auto; overflow-y: auto; overflow-x: hidden; }
      header { align-items: flex-start; padding: 12px 16px; }
      .brand { flex-direction: column; gap: 2px; }
      header .tagline { white-space: normal; }
      .header-status { display: none; }
      .main { grid-template-columns: minmax(0, 1fr); height: auto; min-height: calc(100vh - 57px); overflow-x: hidden; }
      /* モバイルでは縦積みでページ全体がスクロールするので、履歴バー分の
         高さ固定は無効化する（デスクトップ用の calc を上書き）。 */
      body.history-visible .main { height: auto; min-height: calc(100vh - 57px); }
      .panel { max-height: none; border-right: none; border-bottom: 1px solid var(--border); }
      .dropzone { width: 100%; min-width: 0; }
      .viewer-wrap { min-height: 54vh; }
      .viewer-toolbar { top: 12px; right: 12px; }
      /* 「読込→検査→形状→出力」の順序が伝わるよう横 1 列を維持（2×2 にしない）。
         入りきらない場合は横スクロール。 */
      .quick-flow { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 6px; }
      .quick-flow-step { flex: 0 0 auto; white-space: nowrap; }
      /* 固定の履歴バーが画面を占有しないよう、本文は下に余白を確保 */
      body.history-visible { padding-bottom: 96px; }
    }
