    * { margin: 0; padding: 0; box-sizing: border-box; }
    :root {
      --bg: #1a1a2e;
      --surface: #16213e;
      --surface2: #0f3460;
      --accent: #e94560;
      --accent2: #533483;
      --text: #eee;
      --text2: #aaa;
      --success: #4ecca3;
      --border: #2a2a4a;
      --radius: 8px;
    }
    body {
      font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
      background: var(--bg);
      color: var(--text);
      display: flex;
      height: 100vh;
      overflow: hidden;
    }

    /* Sidebar */
    .sidebar {
      width: 340px;
      min-width: 200px;
      background: var(--surface);
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
    .sidebar-header {
      padding: 16px;
      border-bottom: 1px solid var(--border);
      background: var(--surface2);
    }
    .sidebar-header h1 {
      font-size: 16px;
      font-weight: 600;
      margin-bottom: 4px;
    }
    .sidebar-header p { font-size: 11px; color: var(--text2); }

    /* Generator tabs (hidden - replaced by select) */
    .gen-tabs { display: none !important; }
    .gen-select-wrap {
      border-bottom: 1px solid var(--border);
    }
    .gen-select-wrap select {
      appearance: none;
      -webkit-appearance: none;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23aaa' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
      background-repeat: no-repeat;
      background-position: right 12px center;
      padding-right: 32px !important;
    }

    /* Form area */
    .form-area {
      flex: 1;
      overflow-y: auto;
      padding: 12px;
    }
    .form-area::-webkit-scrollbar { width: 6px; }
    .form-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

    .form-group { margin-bottom: 10px; }
    .form-group label {
      display: block;
      font-size: 11px;
      color: var(--text2);
      margin-bottom: 3px;
      font-weight: 500;
    }
    .form-group select,
    .form-group input[type="text"],
    .form-group input[type="number"] {
      width: 100%;
      padding: 7px 10px;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      color: var(--text);
      font-size: 13px;
      outline: none;
    }
    .form-group select:focus,
    .form-group input:focus { border-color: var(--accent); }

    .form-row {
      display: flex;
      gap: 8px;
    }
    .form-row .form-group { flex: 1; }

    .color-row {
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .color-row input[type="color"] {
      width: 36px;
      height: 30px;
      border: 1px solid var(--border);
      border-radius: 4px;
      background: none;
      cursor: pointer;
      padding: 0;
    }
    .color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
    .color-row input[type="color"]::-webkit-color-swatch { border: none; border-radius: 2px; }
    .color-row span { font-size: 11px; color: var(--text2); flex: 1; }

    input[type="range"] {
      width: 100%;
      accent-color: var(--accent);
      height: 4px;
    }
    .range-row {
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .range-row input[type="range"] { flex: 1; }
    .range-val {
      font-size: 11px;
      color: var(--accent);
      min-width: 36px;
      text-align: right;
    }

    .checkbox-row {
      display: flex;
      align-items: center;
      gap: 6px;
      margin-bottom: 8px;
    }
    .checkbox-row input { accent-color: var(--accent); }
    .checkbox-row label { font-size: 12px; color: var(--text2); margin: 0; }

    /* Generate button */
    .gen-btn {
      margin: 12px;
      padding: 12px;
      background: var(--accent);
      border: none;
      border-radius: var(--radius);
      color: #fff;
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.2s;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }
    .gen-btn:hover { background: #d63851; }
    .gen-btn:disabled { opacity: 0.5; cursor: not-allowed; }
    .gen-btn .spinner {
      width: 16px; height: 16px;
      border: 2px solid rgba(255,255,255,0.3);
      border-top-color: #fff;
      border-radius: 50%;
      animation: spin 0.6s linear infinite;
      display: none;
    }
    .gen-btn.loading .spinner { display: block; }
    .gen-btn.loading .btn-text { display: none; }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* Main area (viewer) */
    .main {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      min-width: 0;
    }

    /* Toolbar */
    .toolbar {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 16px;
      background: var(--surface);
      border-bottom: 1px solid var(--border);
    }
    .toolbar-btn {
      padding: 6px 12px;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      color: var(--text2);
      font-size: 12px;
      cursor: pointer;
      transition: all 0.2s;
    }
    .toolbar-btn:hover { border-color: var(--accent); color: var(--text); }
    .toolbar-btn.active { background: var(--surface2); color: var(--text); border-color: var(--accent2); }
    .toolbar-spacer { flex: 1; }
    .toolbar-info { font-size: 11px; color: var(--text2); }

    /* 3D Viewer */
    .viewer-wrap {
      flex: 1;
      position: relative;
      background: #111;
    }
    #viewer-canvas {
      width: 100%;
      height: 100%;
      display: block;
    }
    .viewer-overlay {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      text-align: center;
      color: var(--text2);
      pointer-events: none;
    }
    .viewer-overlay.hidden { display: none; }
    .viewer-overlay svg { width: 48px; height: 48px; opacity: 0.3; margin-bottom: 12px; }
    .viewer-overlay p { font-size: 13px; }

    .viewer-loading {
      position: absolute;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0,0,0,0.55);
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      z-index: 10;
      gap: 16px;
      backdrop-filter: blur(2px);
    }
    .viewer-loading p { font-size: 13px; color: var(--text2); }
    .loading-spinner {
      width: 40px; height: 40px;
      border: 3px solid rgba(255,255,255,0.15);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin 0.7s linear infinite;
    }

    /* Resize handles */
    .resize-h {
      width: 3px;
      cursor: col-resize;
      background: transparent;
      flex-shrink: 0;
      transition: background 0.15s;
    }
    .resize-h:hover, .resize-h.active { background: var(--accent); }

    /* Gallery panel (right side) */
    .gallery-right {
      width: 640px;
      min-width: 200px;
      background: var(--surface);
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    /* Right panel tabs */
    .right-tabs {
      display: flex;
      background: var(--surface2);
      border-bottom: 1px solid var(--border);
      flex-shrink: 0;
    }
    .right-tab {
      flex: 1;
      padding: 10px 12px;
      background: none;
      border: none;
      border-bottom: 2px solid transparent;
      color: var(--text2);
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.2s;
    }
    .right-tab:hover { color: var(--text); }
    .right-tab.active { color: var(--text); border-bottom-color: var(--accent); }
    .panel-hide-btn {
      flex-shrink: 0;
      padding: 4px 10px;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      color: var(--text2);
      font-size: 11px;
      font-weight: 600;
      cursor: pointer;
      white-space: nowrap;
      transition: all 0.15s;
    }
    .panel-hide-btn:hover { color: var(--accent); background: rgba(233,69,96,0.15); border-color: var(--accent); }
    .panel-show-btn {
      position: absolute;
      right: 0;
      top: 50%;
      transform: translateY(-50%);
      z-index: 10;
      width: 28px;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-right: none;
      border-radius: 8px 0 0 8px;
      color: var(--text2);
      cursor: pointer;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 10px 4px;
      gap: 4px;
      transition: all 0.15s;
    }
    .panel-show-btn:hover { color: var(--text); background: var(--accent2); border-color: var(--accent2); }
    .panel-show-icon { font-size: 12px; line-height: 1; }
    .panel-show-text {
      writing-mode: vertical-lr;
      text-orientation: mixed;
      font-size: 11px;
      font-weight: 600;
      letter-spacing: 1px;
    }
    .right-tab-content {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
    .gallery-header {
      display: flex;
      align-items: center;
      padding: 10px 12px;
      border-bottom: 1px solid var(--border);
      font-size: 13px;
      font-weight: 600;
      background: var(--surface2);
    }
    .gallery-header span { flex: 1; }
    .gallery-header button {
      background: none;
      border: 1px solid var(--border);
      color: var(--text2);
      font-size: 11px;
      cursor: pointer;
      padding: 3px 8px;
      border-radius: 4px;
    }
    .gallery-header button:hover { color: var(--accent); border-color: var(--accent); }
    .gallery-filter {
      padding: 8px 12px;
      border-bottom: 1px solid var(--border);
    }
    .gallery-filter select {
      width: 100%;
      padding: 5px 8px;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      color: var(--text);
      font-size: 12px;
      outline: none;
    }
    .gallery-grid {
      flex: 1;
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
      grid-auto-rows: max-content;
      gap: 8px;
      padding: 10px 12px;
      overflow-y: auto;
      align-content: start;
    }
    .gallery-grid::-webkit-scrollbar { width: 5px; }
    .gallery-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

    .gallery-section-label {
      grid-column: 1 / -1;
      font-size: 11px;
      font-weight: 600;
      color: var(--accent);
      padding: 6px 0 2px;
      border-bottom: 1px solid var(--border);
      margin-top: 4px;
    }
    .gallery-section-label:first-child { margin-top: 0; }

    .gallery-card {
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      cursor: pointer;
      transition: all 0.2s;
      overflow: hidden;
      position: relative;
    }
    .gallery-card:hover { border-color: var(--accent); }
    .gallery-card.active { border-color: var(--accent); box-shadow: 0 0 12px rgba(233,69,96,0.3); }
    .gallery-card .thumb {
      height: 60px;
      background: #0a0a1a;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 24px;
    }
    .gallery-card .card-info {
      padding: 5px 6px;
    }
    .gallery-card .card-name {
      font-size: 10px;
      font-weight: 500;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .gallery-card .card-meta {
      font-size: 9px;
      color: var(--text2);
      margin-top: 1px;
    }
    .gallery-card .card-dl {
      position: absolute;
      top: 4px;
      right: 4px;
      background: rgba(0,0,0,0.6);
      border: none;
      color: var(--text2);
      font-size: 10px;
      padding: 2px 5px;
      border-radius: 3px;
      cursor: pointer;
      opacity: 0;
      transition: opacity 0.2s;
    }
    .gallery-card:hover .card-dl { opacity: 1; }
    .gallery-card .card-dl:hover { color: var(--accent); }

    /* Status toast */
    .toast {
      position: fixed;
      bottom: 200px;
      right: 20px;
      padding: 10px 16px;
      background: var(--surface2);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      font-size: 12px;
      z-index: 100;
      transition: all 0.3s;
      opacity: 0;
      transform: translateY(10px);
    }
    .toast.show { opacity: 1; transform: translateY(0); }
    .toast.success { border-color: var(--success); }
    .toast.error { border-color: var(--accent); }

    /* Template cards */
    .tmpl-card {
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      overflow: hidden;
      position: relative;
      transition: all 0.2s;
    }
    .tmpl-card:hover { border-color: var(--accent2); }
    .tmpl-card.generated { border-color: var(--success); }
    .tmpl-card.generating { border-color: var(--accent); }
    .tmpl-card .tmpl-thumb {
      height: 80px;
      background: #0a0a1a;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 20px;
      position: relative;
    }
    .tmpl-card .tmpl-thumb img {
      width: 100%;
      height: 100%;
      object-fit: contain;
    }
    .tmpl-card .tmpl-status {
      position: absolute;
      top: 3px;
      right: 3px;
      font-size: 10px;
      padding: 1px 5px;
      border-radius: 3px;
      background: rgba(0,0,0,0.6);
    }
    .tmpl-card .tmpl-info { padding: 4px 6px; }
    .tmpl-card .tmpl-name {
      font-size: 10px;
      font-weight: 500;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .tmpl-card .tmpl-actions {
      display: flex;
      gap: 3px;
      padding: 0 6px 5px;
    }
    .tmpl-card .tmpl-btn {
      flex: 1;
      padding: 3px 0;
      border: 1px solid var(--border);
      background: var(--surface2);
      color: var(--text2);
      font-size: 9px;
      border-radius: 3px;
      cursor: pointer;
      text-align: center;
      transition: all 0.15s;
    }
    .tmpl-card .tmpl-btn:hover { color: var(--text); border-color: var(--accent); }
    .tmpl-card .tmpl-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
    .tmpl-card .tmpl-btn.primary:hover { background: #d63851; }
    .tmpl-card .tmpl-btn.dl { background: var(--success); color: #fff; border-color: var(--success); }
    .tmpl-card .tmpl-btn:disabled { opacity: 0.4; cursor: not-allowed; }

    /* Section titles in form */
    .section-title {
      font-size: 12px;
      font-weight: 600;
      color: var(--accent);
      margin: 12px 0 6px;
      padding-bottom: 4px;
      border-bottom: 1px solid var(--border);
    }
    .section-title:first-child { margin-top: 0; }

    /* Mobile nav */
    .mobile-nav {
      display: none;
      background: var(--surface);
      border-top: 1px solid var(--border);
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      z-index: 200;
      padding: 4px 0;
    }
    .mobile-nav-inner {
      display: flex;
      justify-content: space-around;
    }
    .mobile-nav-btn {
      background: none;
      border: none;
      color: var(--text2);
      font-size: 10px;
      padding: 6px 12px;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 2px;
      transition: color 0.2s;
    }
    .mobile-nav-btn.active { color: var(--accent); }
    .mobile-nav-btn span.nav-icon { font-size: 20px; }

    /* Mobile responsive — covers phones, folds, small tablets */
    @media (max-width: 1024px) and (hover: none), (max-width: 768px) {
      body {
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
        position: relative;
        overflow: hidden;
      }
      .resize-h { display: none !important; }
      .mobile-nav { display: block !important; }
      .sidebar,
      .main,
      .gallery-right {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        height: auto !important;
        position: absolute !important;
        top: 0; left: 0; right: 0;
        bottom: 48px;
        z-index: 1;
        display: none !important;
      }
      .sidebar.mobile-active,
      .main.mobile-active,
      .gallery-right.mobile-active {
        display: flex !important;
        z-index: 10;
      }
      /* Ensure viewer fills available space on mobile */
      .main.mobile-active {
        flex-direction: column;
      }
      .main.mobile-active .viewer-wrap {
        flex: 1;
        min-height: 0;
        position: relative;
      }
      .main.mobile-active #viewer-canvas {
        position: absolute;
        top: 0; left: 0;
        width: 100% !important;
        height: 100% !important;
      }
      .toolbar {
        flex-wrap: wrap;
        padding: 6px 8px;
        gap: 4px;
        flex-shrink: 0;
      }
      .toolbar-btn { padding: 5px 8px; font-size: 11px; }
      .toolbar-info { display: none; }
      .panel-hide-btn { display: none; }
      #btn-show-right { display: none !important; }
      .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 6px;
        padding: 8px;
      }
      .gallery-card .thumb { height: 50px; }
      .tmpl-card .tmpl-thumb { height: 60px; }
      .sidebar-header h1 { font-size: 14px; }
    }

    /* Fold phones — handle screen size change on fold/unfold */
    @media (max-width: 400px) {
      .sidebar-header { padding: 10px; }
      .sidebar-header h1 { font-size: 13px; }
      .sidebar-header p { font-size: 10px; }
      .form-area { padding: 8px; }
      .form-group label { font-size: 10px; }
      .form-group select,
      .form-group input[type="text"],
      .form-group input[type="number"] { font-size: 12px; padding: 6px 8px; }
      .gen-btn { padding: 10px; font-size: 13px; margin: 8px; }
      .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(85px, 1fr));
        gap: 4px;
        padding: 6px;
      }
      .gallery-card .thumb { height: 40px; }
      .gallery-card .card-name { font-size: 9px; }
      .gallery-card .card-meta { font-size: 8px; }
      .tmpl-card .tmpl-thumb { height: 50px; }
      .tmpl-card .tmpl-name { font-size: 9px; }
      .tmpl-card .tmpl-btn { font-size: 8px; }
      .gallery-header { padding: 6px 8px; }
      .gallery-header select { font-size: 11px; padding: 4px 6px; }
      .toolbar-btn { padding: 4px 6px; font-size: 10px; }
    }
