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

    :root {
      --bg: #ffffff;
      --surface: rgba(0, 0, 0, 0.04);
      --text: #2c2c2e;
      --text-secondary: #8e8e93;
      --accent: #2979c1;
      --radius: 12px;
      --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
      background: var(--bg);
      color: var(--text);
      overflow: hidden;
      height: 100dvh;
      width: 100vw;
      -webkit-tap-highlight-color: transparent;
      -webkit-font-smoothing: antialiased;
      user-select: none;
      -webkit-user-select: none;
      touch-action: manipulation;
    }

    /* Canvas fills the entire viewport */
    #canvas-container {
      position: fixed;
      inset: 0;
      z-index: 0;
      transition: opacity 1s ease;
    }
    #canvas-container.fading { opacity: 0.15; }
    canvas {
      display: block;
    }

    /* ─────────────── Switch Loading ─────────────── */
    #switch-loading {
      position: fixed;
      bottom: 40px;
      left: 50%;
      transform: translateX(-50%);
      z-index: 110;
      display: none;
      align-items: center;
      gap: 10px;
      padding: 10px 22px;
      border-radius: 24px;
      background: rgba(0,0,0,0.7);
      color: #fff;
      font-size: 13px;
      letter-spacing: 0.03em;
      pointer-events: none;
    }
    #switch-loading.show { display: flex; }
    .switch-spinner {
      width: 16px; height: 16px;
      border: 2px solid rgba(255,255,255,0.2);
      border-top-color: #fff;
      border-radius: 50%;
      animation: spin .6s linear infinite;
    }

    /* ─────────────── Loading Overlay ─────────────── */
    #loading-overlay {
      position: fixed;
      inset: 0;
      z-index: 100;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background: var(--bg);
      transition: opacity 0.5s ease, visibility 0.5s ease;
    }
    #loading-overlay.hidden {
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
    }

    .loader-ring {
      width: 56px;
      height: 56px;
      border: 3px solid rgba(0,0,0,0.08);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin 1s linear infinite;
      margin-bottom: 24px;
    }
    @keyframes spin { to { transform: rotate(360deg); } }
    @keyframes arSlideUp { from { opacity:0; transform:translateX(-50%) translateY(20px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }

    .loader-title {
      font-size: 18px;
      font-weight: 500;
      letter-spacing: 0.02em;
      color: var(--text);
      margin-bottom: 16px;
    }

    .loader-bar-track {
      width: 260px;
      max-width: 70vw;
      height: 4px;
      background: rgba(0,0,0,0.06);
      border-radius: 2px;
      overflow: hidden;
    }
    .loader-bar-fill {
      height: 100%;
      background: var(--accent);
      border-radius: 2px;
      width: 0%;
      transition: width 0.3s ease;
    }
    .loader-percent {
      margin-top: 10px;
      font-size: 13px;
      color: var(--text-secondary);
      letter-spacing: 0.04em;
    }
    .loader-hint {
      margin-top: 32px;
      font-size: 12px;
      color: #bbb;
      letter-spacing: 0.03em;
    }

    /* ─────────────── Top Bar ─────────────── */
    #top-bar {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      z-index: 50;
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 12px 14px;
      pointer-events: none;
      flex-wrap: wrap;
    }
    #top-bar > * {
      pointer-events: auto;
    }

    .top-actions {
      display: flex;
      flex-direction: column;
      gap: 6px;
      position: fixed;
      right: 14px;
      top: 12px;
      z-index: 50;
      pointer-events: auto;
    }

    .top-actions .btn {
      padding: 8px 12px;
      font-size: 12px;
    }

    /* ─────────────── Buttons ─────────────── */
    .btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      padding: 10px 16px;
      border: 1px solid rgba(0,0,0,0.1);
      border-radius: var(--radius);
      background: rgba(255, 255, 255, 0.75);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      color: var(--text);
      font-size: 13px;
      font-weight: 500;
      letter-spacing: 0.02em;
      cursor: pointer;
      transition: background var(--transition), border-color var(--transition), transform var(--transition), box-shadow var(--transition);
      white-space: nowrap;
      text-decoration: none;
      box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    }
    .btn:hover {
      background: rgba(255,255,255,0.95);
      border-color: rgba(0,0,0,0.2);
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    .btn:active {
      transform: scale(0.96);
    }
    .btn-accent {
      background: rgba(41, 121, 193, 0.12);
      border-color: rgba(41, 121, 193, 0.3);
      color: var(--accent);
    }
    .btn-accent:hover {
      background: rgba(41, 121, 193, 0.2);
      border-color: rgba(41, 121, 193, 0.5);
    }

    .btn svg {
      width: 16px;
      height: 16px;
      flex-shrink: 0;
    }

    /* ─────────────── Model Selector ─────────────── */
    .model-group {
      display: flex;
      align-items: center;
      gap: 8px;
      flex-shrink: 0;
    }
    .model-select-wrap {
      display: flex;
      align-items: center;
      gap: 8px;
      flex: 0 1 auto;
    }
    .model-select {
      padding: 10px 36px 10px 14px;
      border: 1px solid rgba(0,0,0,0.1);
      border-radius: var(--radius);
      background: rgba(255, 255, 255, 0.75);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      color: var(--text);
      font-size: 13px;
      font-weight: 500;
      letter-spacing: 0.02em;
      cursor: pointer;
      outline: none;
      appearance: none;
      -webkit-appearance: none;
      width: 100px;
      box-shadow: 0 1px 4px rgba(0,0,0,0.06);
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 12px center;
      transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
    }
    #btn-search, #btn-model { padding: 10px 10px; min-width: 36px; z-index: 2; position: relative; }
    #category-select { width: 160px; }
    #btn-model svg { width: 15px; height: 15px; pointer-events: none; }
    .model-popup { position: absolute; top: 100%; left: 0; margin-top: 4px; z-index: 999; display: none; }
    .model-popup.show { display: block; }
    .model-list { width: 200px; max-height: 300px; overflow-y: auto; padding: 4px 0; border-radius: var(--radius); background: rgba(255,255,255,.95); box-shadow: 0 4px 16px rgba(0,0,0,.1); }
    .model-list .ml-item { padding: 8px 14px; cursor: pointer; font-size: 13px; color: var(--text); }
    .model-list .ml-item:hover { background: rgba(41,121,193,.08); }
    @media (max-width: 640px) {
      .model-popup { left: auto; right: 0; }
      .model-list { width: 220px; max-height: 280px; }
    }
    #btn-search svg { width: 15px; height: 15px; pointer-events: none; }
    .search-wrap { position: relative; flex-shrink: 0; }
    .model-search {
      padding: 7px 14px;
      border: 1px solid rgba(0,0,0,0.1);
      border-radius: var(--radius);
      background: rgba(255,255,255,0.95);
      color: var(--text);
      font-size: 13px;
      font-weight: 500;
      letter-spacing: 0.02em;
      outline: none;
      width: 160px;
      display: none;
      box-sizing: border-box;
    }
    .model-search.visible { display: block; }
    .model-search::placeholder { color: #bbb; }
    .model-search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(41,121,193,0.1); }
    .model-search.visible { display: block; }
    .search-dropdown {
      position: absolute;
      top: 100%;
      left: 0;
      right: 0;
      z-index: 60;
      background: rgba(255,255,255,.95);
      border: 1px solid rgba(0,0,0,.1);
      border-radius: 0 0 var(--radius) var(--radius);
      box-shadow: 0 4px 12px rgba(0,0,0,.1);
      max-height: 200px;
      overflow-y: auto;
      display: none;
    }
    .search-dropdown.show { display: block; }
    .search-dropdown .sd-item {
      padding: 8px 12px;
      cursor: pointer;
      font-size: 12px;
      border-bottom: 1px solid rgba(0,0,0,.05);
    }
    .search-dropdown .sd-item:hover { background: rgba(41,121,193,.08); }
    .model-select:hover {
      border-color: rgba(0,0,0,0.2);
      background-color: rgba(255,255,255,0.95);
      box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    .model-select option {
      background: #fff;
      color: #333;
      padding: 8px;
    }

    /* ─────────────── View Popup ─────────────── */
    #view-popup {
      position: fixed;
      z-index: 55;
      display: none;
      flex-direction: column;
      gap: 2px;
      padding: 6px;
      border: 1px solid rgba(0,0,0,0.1);
      border-radius: var(--radius);
      background: rgba(255,255,255,0.9);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
      box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    }
    #view-popup.open { display: flex; }
    #view-popup .btn {
      padding: 7px 14px;
      gap: 6px;
      font-size: 13px;
      justify-content: flex-start;
      border: none;
      background: transparent;
      box-shadow: none;
    }
    #view-popup .btn:hover {
      background: rgba(0,0,0,0.05);
    }

    /* ─────────────── Info Panel ─────────────── */
    #info-trigger {
      position: fixed;
      left: 16px;
      bottom: 28px;
      z-index: 46;
      width: 28px;
      height: 28px;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 50%;
      background: rgba(0,0,0,0.35);
      color: rgba(255,255,255,0.7);
      font-size: 14px;
      cursor: pointer;
      transition: background 0.2s;
    }
    #info-trigger:hover { background: rgba(0,0,0,0.55); }
    #info-panel {
      position: fixed;
      left: 50px;
      bottom: 28px;
      z-index: 45;
      padding: 10px 14px;
      border-radius: var(--radius);
      background: rgba(0,0,0,0.45);
      backdrop-filter: blur(8px);
      -webkit-backdrop-filter: blur(8px);
      font-size: 11px;
      color: rgba(255,255,255,0.85);
      line-height: 1.6;
      min-width: 150px;
      pointer-events: none;
      opacity: 0;
      visibility: hidden;
      transition: opacity 0.2s, visibility 0.2s;
    }
    #info-panel.show { opacity: 1; visibility: visible; }
    #info-panel .info-label { color: rgba(255,255,255,0.5); font-size: 10px; }
    #info-panel .info-val { font-weight: 500; }

    @media (max-width: 640px) {
      #info-trigger { left: 6px; bottom: 16px; }
      #info-panel { left: 38px; bottom: 16px; font-size: 10px; padding: 8px 10px; }
    }

    /* ─────────────── Error Toast ─────────────── */
    #error-toast {
      position: fixed;
      bottom: 50%;
      left: 50%;
      transform: translate(-50%, 50%);
      z-index: 200;
      padding: 14px 24px;
      border-radius: var(--radius);
      background: rgba(0, 0, 0, 0.8);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      color: #fff;
      font-size: 13px;
      letter-spacing: 0.03em;
      opacity: 0;
      visibility: hidden;
      transition: opacity 0.3s ease, visibility 0.3s ease;
      max-width: 90vw;
      text-align: center;
    }
    #error-toast.show {
      opacity: 1;
      visibility: visible;
    }

    /* ─────────────── Responsive ─────────────── */
    @media (max-width: 640px) {
      #top-bar {
        padding: 12px 14px;
      }
      .btn {
        padding: 8px 12px;
        font-size: 12px;
        border-radius: 10px;
      }
      .btn span.label {
        display: none;
      }
      .btn svg {
        width: 18px;
        height: 18px;
      }
      #hint-bar {
        bottom: 16px;
        gap: 12px;
        font-size: 10px;
      }
      #light-panel {
        right: 6px;
        top: 70px;
        width: 240px;
      }
    }

    /* ─────────────── Lighting Panel ─────────────── */
    #light-panel {
      position: fixed;
      right: 12px;
      top: 88px;
      z-index: 50;
      width: 260px;
      padding: 16px;
      border: 1px solid rgba(0,0,0,0.1);
      border-radius: var(--radius);
      background: rgba(255, 255, 255, 0.82);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
      box-shadow: 0 4px 20px rgba(0,0,0,0.08);
      color: var(--text);
      font-size: 12px;
      transform: translateX(calc(100% + 20px));
      transition: transform var(--transition);
    }
    #light-panel.open {
      transform: translateX(0);
    }
    #light-panel .panel-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 14px;
      font-weight: 600;
      font-size: 13px;
      letter-spacing: 0.03em;
      color: #555;
    }
    #light-panel .panel-header button {
      background: none;
      border: none;
      cursor: pointer;
      color: #999;
      padding: 2px;
      line-height: 1;
    }
    #light-panel .slider-row {
      display: flex;
      align-items: center;
      gap: 10px;
      margin-bottom: 10px;
    }
    #light-panel .slider-row label {
      width: 40px;
      flex-shrink: 0;
      color: #888;
      font-size: 11px;
      text-align: right;
    }
    #light-panel .slider-row input[type="range"] {
      flex: 1;
      -webkit-appearance: none;
      appearance: none;
      height: 4px;
      border-radius: 2px;
      background: #ddd;
      outline: none;
      cursor: pointer;
    }
    #light-panel .slider-row input[type="range"]::-webkit-slider-thumb {
      -webkit-appearance: none;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: var(--accent);
      cursor: pointer;
      border: 2px solid #fff;
      box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    }
    #light-panel .slider-row .val {
      width: 28px;
      flex-shrink: 0;
      text-align: left;
      font-size: 11px;
      color: #999;
      font-variant-numeric: tabular-nums;
    }

    /* ─────────────── View Cube ─────────────── */
    #view-cube-wrap {
      position: fixed;
      bottom: 24px;
      right: 16px;
      z-index: 50;
      width: 130px;
      height: 130px;
      cursor: pointer;
      border-radius: 16px;
      overflow: hidden;
      transition: opacity 0.5s ease;
    }
    #view-cube-wrap canvas {
      display: block;
    }
    #axis-gizmo {
      position: fixed;
      bottom: 24px;
      left: 16px;
      z-index: 45;
      width: 100px;
      height: 100px;
      pointer-events: none;
    }
    #axis-gizmo canvas { display: block; }
    @media (max-width: 640px) {
      #axis-gizmo { bottom: 12px; left: 6px; width: 72px; height: 72px; }
      #view-cube-wrap {
        width: 100px;
        height: 100px;
        bottom: 12px;
        right: 8px;
        border-radius: 12px;
      }
      .model-search { padding: 7px 14px; position: fixed !important; top: 52px; left: 50%; transform: translateX(-50%); width: 220px; z-index: 55; }
      .search-dropdown { position: fixed !important; top: 88px; left: 50%; transform: translateX(-50%); width: 220px; z-index: 56; max-height: 160px; }
    }