.gallery-list .card.gallery-card-bs .bg-body-secondary { background:rgba(30,41,59,.6)!important; border:1px solid rgba(148,163,184,.25); }
.gallery-list .card.gallery-card-bs { padding-left:.35rem; }
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #0f172a;
  color: #f8fafc;
  font-family: 'Noto Sans JP', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  display: flex;
  justify-content: center;
  overflow: hidden; /* 全体ページスクロール抑止。内部パネルでスクロールさせる */
}

#root {
  width: 100%;
}

.app-shell {
  height: 100vh; /* 固定して内部だけをスクロール */
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px clamp(8px, 2vw, 20px);
  overflow: hidden; /* app-main にのみスクロール委譲 */
}

.app-header {
  text-align: center;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.app-title {
  margin: 0;
  font-size: clamp(24px, 4vw, 36px);
  letter-spacing: 0.04em;
}

.app-subtitle {
  margin: 12px 0 0;
  color: #cbd5f5;
  font-size: 16px;
}

.error-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.45);
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 500;
}

.app-main {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
  flex: 1 1 auto; /* ヘッダー/フッターを除き残りを占有 */
  overflow: hidden; /* 個別パネルが内部スクロール */
}

/* 同じサイズの正方形を 3D と テクスチャ で共有するための変数 */
:root {
  /* プレビューサイズを元に戻す: 固定 480px */
  --stage-size: 480px;
  --gallery-card-height: 180px; /* 1カードの基準高さ (画像+本文) */
  --gallery-card-height-small: 90px; /* 2カラム時の半分高さ */
}

@media (max-width: 1280px) {
  .app-main {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 960px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }
  body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .app-main {
    overflow: visible;
  }
  .app-main {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .app-shell {
    padding: 8px clamp(4px, 1.5vw, 12px);
    gap: 8px;
  }

  .viewer-panel,
  .controls-panel {
    padding: clamp(10px, 4vw, 18px);
  }

  .viewer-canvas-wrapper {
    width: min(100%, 420px);
  }
}

.viewer-panel,
.controls-panel {
  background: rgba(15, 23, 42, 0.65);
  border-radius: 16px;
  padding: clamp(12px, 2.5vw, 20px);
  border: 1px solid rgba(148, 163, 184, 0.15);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.4);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* スクロールは各パネル内で */
.viewer-panel {
  min-height: 0; /* flex 子要素の正しい縮小 */
  overflow: hidden; /* ビューアーパネルの全体スクロールを無効化 */
}

.controls-panel {
  min-height: 0;
  overflow: auto;
}

/* パネル共通スタイル */

/* テクスチャエディターのヘッダー */
.texture-editor-header {
  flex-shrink: 0;
  margin-bottom: 8px;
}

.texture-editor-header-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

.save-button {
  font-size: 14px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mobile-save {
  padding: 8px 12px;
  font-size: 16px;
  min-width: 44px;
}

.texture-editor-header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* メインエリア（キャンバス部分） */
.texture-editor-main-area {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 2px;
  max-height: calc(100vh - 140px);
}

/* キャンバスラッパー */
.texture-editor-canvas-wrapper {
  flex-shrink: 1;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  aspect-ratio: 1;
  width: min(100%, 500px);
  height: min(100%, 500px);
}

/* キャンバス自体 */
.texture-editor-canvas {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  aspect-ratio: 1;
}

/* セレクター部分 */
.texture-editor-selectors {
  flex-shrink: 0;
  overflow: visible;
}

.panel-subtitle {
  margin: 0;
  font-size: 15px;
  color: #e2e8f0;
}

.panel-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ここで古いviewer-canvas-wrapper定義は削除済み */

/* モバイル時の3Dプレビュー調整 */
@media (max-width: 960px) {
  .viewer-canvas-wrapper {
    width: min(320px, 85vw);
    height: auto;
    max-height: none;
  }
}

@media (max-width: 640px) {
  .viewer-canvas-wrapper {
    width: min(280px, 90vw);
    height: auto;
    max-height: none;
  }
  
  /* テクスチャエディターもサイズ縮小 */
  .texture-editor-canvas {
    width: 100%;
    height: 100%;
    max-width: min(300px, 80vw);
    max-height: min(300px, 80vw);
  }
  
  .texture-editor-canvas-wrapper {
    width: min(300px, 80vw);
    height: min(300px, 80vw);
    max-width: min(300px, 80vw);
    max-height: min(300px, 80vw);
  }
}

/* Viewer tabs */
.viewer-panel.with-tabs { 
  padding-top: 12px; 
  position: relative; 
  display: flex; 
  flex-direction: column; 
  overflow: visible; /* ボタン表示のために変更 */
  height: auto; /* 自然な高さに変更 */
  min-height: 100%; /* 最低高さを確保 */
}

/* ビューアー内のギャラリー高さ制御 */
.viewer-panel.with-tabs .gallery {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.viewer-panel.with-tabs > h2.panel-title { position:sticky; top:0; z-index:10; background:linear-gradient(180deg, rgba(15,23,42,0.95), rgba(15,23,42,0.75)); margin:0 0 4px; padding:8px 6px 6px; backdrop-filter:blur(6px); border-radius:12px; }
.viewer-tab-bar { display:flex; gap:8px; margin:0 0 4px; position:sticky; top:46px; z-index:9; background:linear-gradient(180deg, rgba(15,23,42,0.9), rgba(15,23,42,0.6)); padding:6px 6px 8px; backdrop-filter:blur(6px); border-radius:12px; }
.viewer-panel.with-tabs .gallery-list { margin-top:8px; }
.viewer-tab { flex: 0 0 auto; padding: 6px 14px; border-radius: 999px; background: rgba(30,41,59,0.55); border:1px solid rgba(148,163,184,0.25); color:#cbd5f5; font-size:13px; cursor:pointer; backdrop-filter: blur(4px); }
.viewer-tab.is-active { background: linear-gradient(135deg,#3b82f6,#6366f1); color:#f8fafc; border-color: rgba(255,255,255,0.25); box-shadow:0 4px 14px rgba(59,130,246,0.35); }
.viewer-tab:hover:not(.is-active) { border-color: rgba(148,163,184,0.45); color:#f1f5f9; }
.gallery.in-viewer { background: rgba(15,23,42,0.35); box-shadow:none; border-radius:12px; }
.gallery.in-viewer .gallery-grid { max-height: 320px; }
/* PCでは1列のまま（デフォルト）*/

.viewer-canvas-container,
.skin-canvas {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-canvas-container canvas,
.skin-canvas canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  margin: 0 auto;
}

.viewer-note {
  margin-top: 12px;
  color: #cbd5f5;
  font-size: 14px;
}

.panel-copy {
  margin: 0 0 12px;
  color: #cbd5f5;
}

.file-input-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(99, 102, 241, 0.95));
  color: #f8fafc;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.file-input-label:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(59, 130, 246, 0.35);
}

.file-input-label:active {
  transform: translateY(0);
}

.file-input-control {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.secondary-button {
  margin-top: 12px;

/* Drag & Drop - ボタン中心のシンプルデザイン */
.file-drop-zone {
  position: relative;
  border: 2px dashed rgba(148, 163, 184, 0.4);
  border-radius: 16px;
  padding: 60px 40px; /* パディングを大幅に増加 */
  transition: border-color 0.3s ease, background 0.3s ease, transform 0.2s ease;
  text-align: center;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.05), rgba(139, 92, 246, 0.05));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px; /* 最小高さを大幅に増加 */
}

.file-drop-zone::before {
  content: '';
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: linear-gradient(45deg, #3b82f6, #8b5cf6, #3b82f6);
  border-radius: 16px;
  z-index: -1;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.file-drop-zone.is-dragging {
  border-color: #38bdf8;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.15), rgba(168, 85, 247, 0.15));
  transform: scale(1.02);
}

.file-drop-zone.is-dragging::before {
  opacity: 0.3;
}

/* おしゃれなアップロードボタン - より大きく */
.file-input-label.stylish-upload {
  display: inline-block;
  padding: 20px 40px; /* パディングをさらに増加 */
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: white;
  border-radius: 50px;
  cursor: pointer;
  font-weight: 600;
  font-size: 18px; /* フォントサイズも大きく */
  transition: all 0.3s ease;
  border: none;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
  position: relative;
  overflow: hidden;
  margin: 20px 0; /* 上下にマージンを追加 */
  min-width: 280px; /* 最小幅を設定 */
}

.file-input-label.stylish-upload::before {
  content: '📁';
  margin-right: 8px;
  font-size: 18px;
}

.file-input-label.stylish-upload:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
  background: linear-gradient(135deg, #2563eb, #4f46e5);
}

.file-input-label.stylish-upload:active {
  transform: translateY(0);
}

.drop-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: #94a3b8;
}

/* スマホ用の調整 */
@media (max-width: 768px) {
  .file-drop-zone {
    padding: 40px 20px; /* スマホでは少し小さく */
    min-height: 160px; /* スマホでは高さを調整 */
  }
  
  .file-input-label.stylish-upload {
    padding: 16px 32px; /* スマホでは少し小さく */
    font-size: 16px;
    min-width: 240px; /* スマホでは幅を調整 */
    margin: 16px 0; /* マージンも調整 */
  }
}

/* 点線エリア外のコンテンツ */
.outside-border {
  margin-top: 20px;
}

.original-count-info {
  margin: 0;
  font-size: 12px;
  color: #64748b;
}

/* Gallery */
.gallery {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgba(15,23,42,0.45);
  border: 1px solid rgba(148,163,184,0.15);
  border-radius: 16px;
  padding: 14px 16px 18px;
  max-height: 360px;
  overflow: hidden;
}
.gallery-title {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.05em;
  color: #e2e8f0;
}
.gallery-empty {
  margin: 0;
  font-size: 13px;
  color: #94a3b8;
}
.gallery-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

/* ========================================
   ギャラリー: Bootstrap風モダンデザイン
======================================== */

/* === タイトル === */
.gallery-title {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, #38bdf8, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 18px;
  letter-spacing: 0.5px;
}

/* === コントロールバー === */
.gallery-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: nowrap;
  align-items: stretch;
  width:100%;
}
.gallery-controls > * { flex:0 0 auto; }
.gallery-controls .gallery-search-wrapper { flex:1 1 auto; display:flex; }

/* スマホ: 2カラムレイアウト適用 (再定義確実化) */
@media (max-width:640px) {
  .gallery.in-viewer .gallery-list { display:grid !important; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
  .gallery.in-viewer .gallery-list .card.gallery-card-bs { min-height:var(--gallery-card-height-small); }
}

/* === タブフィルタ === */
.gallery-tabs {
  display: flex;
  gap: 0;
  background: rgba(15,23,42,0.6);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid rgba(148,163,184,0.25);
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: #e2e8f0;
  background: rgba(148,163,184,0.12);
}

.tab-btn.active {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(59,130,246,0.4);
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border-radius: 12px;
  background: rgba(255,255,255,0.15);
  font-size: 12px;
  font-weight: 700;
}

.tab-btn.active .tab-count {
  background: rgba(255,255,255,0.25);
}

/* === 検索ボックス === */
.gallery-search {
  flex: 1;
  min-width: 240px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(15,23,42,0.6);
  border: 2px solid rgba(148,163,184,0.25);
  border-radius: 10px;
  transition: all 0.3s ease;
}

.gallery-search:focus-within {
  border-color: #3b82f6;
  background: rgba(15,23,42,0.8);
  box-shadow: 0 0 0 4px rgba(59,130,246,0.15);
}

.search-icon {
  font-size: 18px;
  color: #64748b;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #f1f5f9;
  font-size: 14px;
  font-weight: 500;
}

.search-input::placeholder {
  color: #64748b;
}

.search-clear {
  width: 24px;
  height: 24px;
  border-radius: 12px;
  border: none;
  background: rgba(239,68,68,0.2);
  color: #f87171;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s ease;
}

.search-clear:hover {
  background: rgba(239,68,68,0.4);
  transform: rotate(90deg) scale(1.1);
}

/* モバイル時の表示切替 */
@media (max-width: 960px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: block !important; }
}

@media (min-width: 961px) {
  .mobile-only { display: none !important; }
  .desktop-only { display: block !important; }
}

/* ヘッダーコントロール */
.texture-editor-header, .controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.texture-editor-header-controls, .controls-header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* モバイル用select */
.mobile-select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(148,163,184,0.35);
  background: rgba(15,23,42,0.8);
  color: #e2e8f0;
  font-size: 12px;
  min-width: 80px;
}

.mobile-select:focus {
  border-color: #38bdf8;
  outline: none;
  box-shadow: 0 0 0 2px rgba(56,189,248,0.2);
}

/* コンパクトファイルアップロード */
.compact-file-upload {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(59,130,246,0.8), rgba(99,102,241,0.8));
  color: #f8fafc;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease;
  position: relative;
}

.compact-file-upload:hover {
  transform: translateY(-1px);
}

.file-input-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* 点線枠 */
.dashed-border {
  border: 2px dashed rgba(148,163,184,0.5) !important;
  border-radius: 12px;
}

.dashed-border.is-dragging {
  border-color: #38bdf8 !important;
}

/* ファイル入力要素の制限とセレクターボタンの修正 */
.action-button .file-input-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.selector-button {
  position: relative;
  z-index: 2;
}

/* === ギャラリーコンテナとリスト === */
.gallery {
  height: 100%;
  overflow: hidden; /* 外側のスクロールバーを非表示 */
}

.gallery-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 6px;
}

.gallery-list::-webkit-scrollbar {
  width: 8px;
}

.gallery-list::-webkit-scrollbar-track {
  background: rgba(15,23,42,0.4);
  border-radius: 4px;
}

.gallery-list::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  border-radius: 4px;
}

.gallery-list::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
}

/* Bootstrap gallery overrides */
.gallery-list .card.gallery-card-bs { background:linear-gradient(135deg,#142132,#0f172a); border-radius:14px; border:1px solid rgba(148,163,184,.18); }
.gallery-list .card.gallery-card-bs:hover { border-color:#3b82f6; box-shadow:0 4px 14px -2px rgba(59,130,246,.35); }
.gallery-list .card.gallery-card-bs.border-primary { border-color:#3b82f6 !important; }
.gallery-list .card.gallery-card-bs .card-title { font-size:15px; }
.gallery-list .card.gallery-card-bs .badge { font-weight:500; letter-spacing:.03em; }
.gallery-list .card.gallery-card-bs img { image-rendering:pixelated; }
.gallery-list .card.gallery-card-bs .thumb-full { padding:0; margin:0; }
.gallery-list .card.gallery-card-bs .icon-btn-cluster .btn { display:inline-flex; align-items:center; justify-content:center; width:34px; }
.gallery-list .card.gallery-card-bs .icon-btn-cluster .btn svg { pointer-events:none; }
.pixel-thumb { image-rendering:pixelated; image-rendering:-moz-crisp-edges; }
.gallery-list .card.gallery-card-bs .thumb-full img { transition:transform .25s ease; }
.gallery-list .card.gallery-card-bs:hover .thumb-full img { transform:translateY(-4px); }
.gallery-list .card.gallery-card-bs { overflow:hidden; }
.gallery-list .card.gallery-card-bs .image-col { width:180px; background:rgba(30,41,59,.55); position:relative; padding:0; height:180px; min-height:180px; }
.gallery-list .card.gallery-card-bs .image-col .preview-box.no-gap img.fill-vert { margin-top:1px; margin-bottom:1px; }
/* スマホ時は足側を半分だけマスク（縦長を圧縮） */
@media (max-width: 640px) {
  /* 2カラム化 (col-6 相当) */
  .gallery-list { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; max-height:none; overflow:visible; }
  .gallery-list .card.gallery-card-bs { min-height:140px; height:auto; display:flex; flex-direction:row; padding-left:0; }
  .gallery-list .card.gallery-card-bs .row { flex:1 1 auto; flex-wrap:nowrap; }
  /* 画像領域をさらに半分縮小 */
  .gallery-list .card.gallery-card-bs .image-col { width:110px; height:100px; min-height:100px; padding:1px; box-sizing:border-box; border-right:1px solid rgba(148,163,184,.18); }
  .gallery-list .card.gallery-card-bs .image-col .preview-box.no-gap { padding:0; height:100%; display:flex; align-items:flex-start; justify-content:center; }
  .gallery-list .card.gallery-card-bs .image-col .preview-box.no-gap img.fill-vert { margin:0; height:100%; width:auto; object-fit:cover; clip-path:inset(0 0 60% 0); }
  /* ボタン列を右上にコンパクト配置 */
  .gallery-list .card.gallery-card-bs .card-body { position:relative; padding:8px 8px 8px 10px; min-height:100px; }
  .gallery-list .card.gallery-card-bs .icon-btn-cluster { position:absolute; top:6px; right:6px; display:flex; gap:4px; }
  .gallery-list .card.gallery-card-bs .icon-btn-cluster .btn { width:30px; height:30px; padding:0; }
  /* 編集中バッジ位置調整 */
  .gallery-list .card.gallery-card-bs .editing-badge { top:auto; bottom:6px; right:6px; }
}
.gallery-list .card.gallery-card-bs .preview-box.no-gap { padding:0; }
.gallery-list .card.gallery-card-bs .preview-box.no-gap img.fill-vert { display:block; height:auto; max-height:160px; width:auto; }
.gallery-list .card.gallery-card-bs .preview-box { image-rendering:pixelated; }
.gallery-list .card.gallery-card-bs .card-body { min-height:180px; }
.gallery-list .card.gallery-card-bs { min-height:180px; display:flex; flex-direction:column; }
.gallery-list .card.gallery-card-bs .row { flex:1 1 auto; }
.gallery-list .card.gallery-card-bs .image-col { min-height:180px; }
.gallery .gallery-controls { margin-bottom:8px; }

/* === 空状態 === */
.gallery-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 40px;
  background: linear-gradient(135deg, rgba(248,250,252,0.8) 0%, rgba(241,245,249,0.8) 100%);
  border-radius: 12px;
  border: 2px dashed rgba(148,163,184,0.3);
}

.empty-icon {
  font-size: 72px;
  margin-bottom: 20px;
  opacity: 0.4;
  filter: grayscale(100%);
}

.gallery-empty p {
  font-size: 16px;
  font-weight: 600;
  color: #64748b;
  margin: 0;
}

/* === 旧スタイル（互換性） === */
.skin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
}
.skin-list::-webkit-scrollbar { width: 8px; }
.skin-list::-webkit-scrollbar-track { background: rgba(148,163,184,0.08); border-radius: 4px; }
.skin-list::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.35); border-radius: 4px; }

.skin-item {
  display: flex;
  gap: 10px;
  padding: 8px;
  background: rgba(30,41,59,0.5);
  border: 1px solid rgba(148,163,184,0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.skin-item:hover {
  background: rgba(30,41,59,0.7);
  border-color: #38bdf8;
  transform: translateX(2px);
}
.skin-item.active {
  background: rgba(56,189,248,0.15);
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56,189,248,0.3);
}

.skin-thumb {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 6px;
  object-fit: cover;
  background: rgba(15,23,42,0.8);
  border: 1px solid rgba(148,163,184,0.2);
}
.skin-thumb.placeholder {
  background: repeating-conic-gradient(#1e293b 0% 25%, #334155 0% 50%) 50% / 12px 12px;
}

.skin-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}

.skin-name {
  font-size: 13px;
  font-weight: 500;
  color: #e2e8f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.skin-name-input {
  width: 100%;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid #38bdf8;
  background: #0f172a;
  color: #f8fafc;
  outline: none;
}

.skin-btns {
  display: flex;
  gap: 4px;
}

.skin-btn {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(148,163,184,0.3);
  background: rgba(15,23,42,0.6);
  color: #cbd5e1;
  cursor: pointer;
  transition: all 0.15s ease;
}
.skin-btn:hover {
  border-color: #38bdf8;
  color: #f1f5f9;
  background: rgba(56,189,248,0.1);
}
.skin-btn.fav {
  color: #fbbf24;
  border-color: rgba(251,191,36,0.4);
}
.skin-btn.del {
  border-color: rgba(239,68,68,0.4);
  color: #fca5a5;
}
.skin-btn.del:hover {
  background: rgba(239,68,68,0.15);
  border-color: #ef4444;
}

/* === 旧ギャラリースタイル（削除可能だが互換性のため残す） === */
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 14px; max-height: 420px; overflow-y: auto; padding-right:4px; }
.gallery-grid::-webkit-scrollbar { width: 8px; }
.gallery-grid::-webkit-scrollbar-track { background: rgba(148,163,184,0.08); border-radius:4px; }
.gallery-grid::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.35); border-radius:4px; }
.gallery-card { position: relative; display: flex; flex-direction: column; gap:6px; padding:8px 8px 10px; background: linear-gradient(145deg, rgba(30,41,59,0.65), rgba(15,23,42,0.55)); border:1px solid rgba(148,163,184,0.18); border-radius:14px; box-shadow:0 4px 10px -2px rgba(0,0,0,0.4); transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease; }
.gallery-card:hover { border-color:#38bdf8; transform:translateY(-2px); box-shadow:0 8px 18px -2px rgba(56,189,248,0.25); }
.gallery-card.is-active { border-color:#38bdf8; box-shadow:0 0 0 2px rgba(56,189,248,0.4),0 6px 18px -4px rgba(56,189,248,0.35); }
.gallery-card-thumb { width:100%; height:100px; flex-shrink:0; background-size:cover; background-position:center; border-radius:8px; outline:1px solid rgba(255,255,255,0.06); cursor:pointer; position:relative; }
.gallery-card-thumb::after { content:''; position:absolute; inset:0; border-radius:inherit; background:radial-gradient(circle at 30% 25%, rgba(255,255,255,0.12), rgba(255,255,255,0)); opacity:0; transition:opacity .25s ease; }
.gallery-card-thumb:hover::after { opacity:1; }
.gallery-card-meta { display:flex; flex-direction:column; gap:4px; }
.gallery-card-name { font-size:11px; font-weight:500; letter-spacing:.02em; color:#e2e8f0; line-height:1.2; max-height:2.4em; overflow:hidden; }
.gallery-card-actions { display:flex; gap:4px; }
.gallery-strip::-webkit-scrollbar { height: 8px; }
.gallery-strip::-webkit-scrollbar-track { background: rgba(148,163,184,0.1); border-radius: 4px; }
.gallery-strip::-webkit-scrollbar-thumb { background: rgba(148,163,184,0.35); border-radius: 4px; }
/* old gallery-item removed in favor of gallery-card */
.mini-btn { font-size: 10px; padding: 2px 5px; border-radius: 6px; border: 1px solid rgba(148,163,184,0.35); background: rgba(15,23,42,0.6); color:#cbd5f5; cursor:pointer; }
.mini-btn:hover { border-color: rgba(148,163,184,0.6); color:#f1f5f9; }
.mini-btn.danger { border-color: rgba(239,68,68,0.55); color: #fecaca; }
.mini-btn.danger:hover { background: rgba(239,68,68,0.15); }
.rename-box { display:flex; gap:4px; align-items:center; }
.rename-input { flex:1; min-width:0; font-size:11px; padding:3px 5px; border-radius:6px; border:1px solid rgba(148,163,184,0.45); background:#0f172a; color:#f8fafc; }
.rename-input:focus { outline:1px solid #38bdf8; border-color:#38bdf8; }
  padding: 10px 16px;
  border-radius: 999px;
  background: transparent;
  color: #cbd5f5;
  border: 1px solid rgba(148, 163, 184, 0.35);
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.secondary-button:hover {
  border-color: rgba(148, 163, 184, 0.55);
  color: #f8fafc;
  transform: translateY(-1px);
}

.secondary-button:disabled,
.file-input-label:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.panel-hint {
  margin-top: 16px;
  background: rgba(30, 41, 59, 0.55);
  border-radius: 12px;
  padding: 16px 18px;
  color: #cbd5f5;
}

.panel-hint h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.panel-hint ul {
  margin: 0;
  padding-left: 20px;
}

.panel-hint li {
  margin-bottom: 6px;
}

.panel-subtitle {
  margin: 0 0 12px;
  font-size: 16px;
  color: #e2e8f0;
}

.panel-group {
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.app-footer {
  margin-top: auto;
  text-align: center;
  color: rgba(148, 163, 184, 0.75);
  font-size: 13px;
}

.texture-editor-panel {
  background: rgba(15, 23, 42, 0.65);
  border-radius: 16px;
  padding: clamp(4px, 1vw, 8px);
  border: 1px solid rgba(148, 163, 184, 0.15);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.4);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow: hidden;
  height: 100%;
}
.texture-editor-panel .texture-editor-status.top { display:flex; align-items:center; gap:12px; margin:0 0 4px; }
.texture-editor-panel .texture-editor-status.top .texture-editor-meta { display:flex; flex-direction:column; gap:2px; font-size:12px; }
.texture-editor-panel .texture-editor-status.top .color-preview-chip { width:28px; height:28px; border:1px solid rgba(148,163,184,0.35); }
.texture-editor-panel .texture-editor-canvas-wrapper { margin-top:4px; }

.texture-editor-selectors {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  min-height: 0;
}
.texture-editor-selectors.below {
  margin-top: 0;
}

.selector-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.selector-label {
  font-size: 13px;
  color: #cbd5f5;
  letter-spacing: 0.05em;
}

.selector-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selector-button {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.55);
  color: #e2e8f0;
  font-size: 12px;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.selector-button.small {
  padding: 4px 10px;
}

.selector-button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: rgba(148, 163, 184, 0.6);
}

.selector-button.is-active {
  border-color: rgba(56, 189, 248, 0.95);
  background: rgba(56, 189, 248, 0.15);
  color: #f8fafc;
}

/* ==== Layer (内層/外層) differentiation ==== */
.selector-button.is-overlay { position: relative; background: rgba(120,53,15,0.35); }
.selector-button.is-overlay.is-active { background: rgba(234,88,12,0.45); border-color: rgba(234,88,12,0.9); }
.selector-button.is-base { position: relative; }
.layer-badge { display:inline-block; margin-left:6px; padding:0 4px; border-radius:3px; font-size:10px; line-height:14px; font-weight:600; vertical-align:middle; }
.layer-badge.base { background:#334155; color:#cbd5e1; }
.layer-badge.overlay { background:#92400e; color:#ffedd5; }

/* Overlay / Highlight toggle buttons reuse secondary-button */
.secondary-button.is-active { outline:2px solid #3b82f6; outline-offset:1px; }

.selector-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.selector-toggle {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(56, 189, 248, 0.12);
  color: #f8fafc;
  font-size: 13px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.selector-toggle.is-active {
  border-color: rgba(56, 189, 248, 0.9);
  background: rgba(56, 189, 248, 0.25);
}

.selector-toggle:hover:not(:disabled) {
  transform: translateY(-1px);
}

.selector-toggle:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.controls-panel {
  gap: 16px;
}

.texture-editor-canvas-wrapper {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background-color: #1f2937;
  background-image: linear-gradient(45deg, rgba(148, 163, 184, 0.4) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(148, 163, 184, 0.4) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(148, 163, 184, 0.4) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(148, 163, 184, 0.4) 75%);
  background-size: 32px 32px;
  background-position: 0 0, 0 16px, 16px -16px, -16px 0;
  border: 1px solid rgba(148, 163, 184, 0.15);
  width: var(--stage-size);
  height: var(--stage-size);
  max-width: 100%;
  max-height: 80vh;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.texture-editor-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  cursor: crosshair;
}

.texture-editor-overlay-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  image-rendering: pixelated;
  z-index: 1;
}

.texture-editor-selection-chip {
  position: absolute;
  top: 16px;
  left: 16px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.45);
  font-size: 13px;
  color: #f8fafc;
  letter-spacing: 0.04em;
  pointer-events: none;
  backdrop-filter: blur(6px);
  z-index: 2;
}

.texture-editor-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.65);
  color: #f8fafc;
  font-weight: 600;
  letter-spacing: 0.08em;
  z-index: 3;
}

.texture-editor-status {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Undo / Redo ボタン */
.history-button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.history-button {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(148,163,184,0.35);
  background: rgba(15,23,42,0.6);
  color: #e2e8f0;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease, border-color .15s ease;
}
.history-button:hover:not(:disabled){
  background: rgba(56,189,248,0.15);
  border-color: rgba(56,189,248,0.6);
  transform: translateY(-1px);
}
.history-button:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

.color-preview-chip {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background-image: linear-gradient(45deg, rgba(148, 163, 184, 0.45) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(148, 163, 184, 0.45) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(148, 163, 184, 0.45) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(148, 163, 184, 0.45) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.color-preview-transparent {
  width: 100%;
  height: 100%;
  display: block;
}

.texture-editor-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: #cbd5f5;
}

.texture-editor-brush {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-label {
  font-size: 14px;
  color: #cbd5f5;
}

.brush-slider {
  width: 100%;
}

.panel-hint-text {
  margin: 12px 0 0;
  color: #cbd5f5;
  font-size: 13px;
}

.palette-groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.palette-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.palette-group-title {
  font-size: 14px;
  color: #cbd5f5;
  margin-bottom: 6px;
}

.palette-swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid transparent;
  background-image: linear-gradient(45deg, rgba(148, 163, 184, 0.45) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(148, 163, 184, 0.45) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(148, 163, 184, 0.45) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(148, 163, 184, 0.45) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease;
}

.color-swatch:hover {
  transform: translateY(-2px);
}

.color-swatch:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.color-swatch.is-active {
  border-color: rgba(59, 130, 246, 0.85);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.color-swatch.is-transparent {
  color: #0f172a;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.05em;
}

.custom-color-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.color-input {
  width: 48px;

@media (max-width: 640px) {
  /* ビューア内ギャラリーのみ 2 カラム & 半分高さ */
  .gallery.in-viewer .gallery-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding-right: 4px;
    max-height: none;
    overflow-y: auto;
  }
  .gallery.in-viewer .gallery-list .card.gallery-card-bs {
    min-height: var(--gallery-card-height-small);
    display: flex;
    flex-direction: column;
  }
  .gallery.in-viewer .gallery-list .card.gallery-card-bs .row {
    flex: 1 1 auto;
  }
  .gallery.in-viewer .gallery-list .card.gallery-card-bs .image-col {
    height: var(--gallery-card-height-small);
    min-height: var(--gallery-card-height-small);
    width: 120px;
    padding: 1px;
    box-sizing: border-box;
  }
  .gallery.in-viewer .gallery-list .card.gallery-card-bs .image-col .preview-box.no-gap img.fill-vert {
    max-height: calc(var(--gallery-card-height-small) - 2px);
    margin: 0;
  }
  .gallery.in-viewer .gallery-list .card.gallery-card-bs .card-body {
    min-height: var(--gallery-card-height-small);
    padding: 8px 10px;
  }
}
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(15, 23, 42, 0.55);
  color: #e2e8f0;
}

.checkbox-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #cbd5f5;
}

.checkbox-control input {
  width: 18px;
  height: 18px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.primary-button {
  padding: 10px 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(129, 140, 248, 0.95));
  color: #f8fafc;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(59, 130, 246, 0.35);
}

.primary-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

@media (max-width: 768px) {
  .app-shell {
    padding: 16px;
    gap: 16px;
  }

  .panel-title {
    font-size: 18px;
  }

  .texture-editor-panel,
  .viewer-panel,
  .controls-panel {
    padding: 16px;
  }

  .texture-editor-main-area {
    max-height: calc(100vh - 280px);
  }

  .texture-editor-selectors {
    max-height: 120px;
  }

  .texture-editor-selection-chip {
    top: 12px;
    left: 12px;
    font-size: 12px;
  }

  .button-row {
    flex-direction: column;
    align-items: stretch;
  }
}

/* --- Reinforce horizontal gallery row card styling (specificity bump) --- */
/* removed old custom row card helpers */

/* =============================
   Mobile Responsive Enhancements
============================= */

/* モバイル時の表示切替 */
@media (max-width: 960px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: flex !important; }
}

@media (min-width: 961px) {
  .mobile-only { display: none !important; }
  .desktop-only { display: flex !important; }
}

/* ヘッダーコントロール */
.texture-editor-header, .controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.texture-editor-header-controls, .controls-header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* モバイル用select */
.mobile-select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(148,163,184,0.35);
  background: rgba(15,23,42,0.8);
  color: #e2e8f0;
  font-size: 12px;
  min-width: 80px;
}

.mobile-select:focus {
  border-color: #38bdf8;
  outline: none;
  box-shadow: 0 0 0 2px rgba(56,189,248,0.2);
}

/* コンパクトファイルアップロード */
.compact-file-upload {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(59,130,246,0.8), rgba(99,102,241,0.8));
  color: #f8fafc;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease;
  position: relative;
}

.compact-file-upload:hover {
  transform: translateY(-1px);
}

.file-input-hidden {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* 点線枠 */
.dashed-border {
  border: 2px dashed rgba(148,163,184,0.5) !important;
  border-radius: 12px;
}

.dashed-border.is-dragging {
  border-color: #38bdf8 !important;
}

/* テクスチャエディター調整 */
@media (max-width: 640px) {
  .texture-editor-canvas {
    max-width: 100%;
    max-height: 300px;
  }
  
  .texture-editor-canvas-wrapper {
    max-height: 300px;
  }
}

/* ビューアーヘッダー */
.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.viewer-header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* テクスチャエディターメインエリア */
.texture-editor-main-area {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: center;
}

.texture-editor-side-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 100px;
  flex: 0 0 auto;
}

.texture-editor-side-info.left {
  align-items: flex-end;
  text-align: right;
}

.texture-editor-side-info.right {
  align-items: flex-start;
  text-align: left;
}

.color-info-text, .hover-info, .operation-hint {
  font-size: 12px;
  color: #cbd5f5;
  line-height: 1.4;
  white-space: pre-line;
}

.hover-info {
  color: #38bdf8;
  font-weight: 600;
}

.operation-hint {
  color: #94a3b8;
  font-style: italic;
}

/* 座標情報の固定サイズ表示 */
.coord-info-fixed {
  font-size: 12px;
  color: #38bdf8;
  font-weight: 600;
  line-height: 1.4;
  white-space: pre-line;
  min-height: 32px; /* 固定高さで変動を防ぐ */
  margin-top: 8px;
  margin-bottom: 8px;
}

/* モバイル時のサイド情報非表示 */
@media (max-width: 960px) {
  .texture-editor-main-area {
    flex-direction: column;
    align-items: center;
  }
  
  .texture-editor-side-info {
    display: none;
  }
  
  .texture-editor-canvas-wrapper {
    width: 100% !important;
    max-width: 100%;
  }
}

/* カラーパレット（プルダウン形式） */
.color-palette-compact {
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(15, 23, 42, 0.8);
  border-radius: 8px;
  border: 1px solid #334155;
}

.color-palette-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #cbd5f5;
  margin-bottom: 8px;
}

.color-controls-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.color-select {
  flex: 1;
  padding: 6px 8px;
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 4px;
  color: #e2e8f0;
  font-size: 13px;
}

.color-preview-display {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  border: 1px solid #475569;
  flex-shrink: 0;
}

.color-input-picker {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}

/* 3Dプレビューのヘッダー改善 */
.viewer-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.viewer-note-inline {
  font-size: 12px;
  color: #94a3b8;
  font-style: italic;
}

/* モバイルでのキャンバスサイズ調整 */
@media (max-width: 640px) {
  .texture-editor-canvas {
    max-width: 100%;
    max-height: 280px;
  }
  
  .texture-editor-canvas-wrapper {
    max-height: 280px;
  }
  
  .viewer-canvas-wrapper canvas {
    max-height: 240px;
    max-width: 100%;
    margin: 0 auto;
  }
}

/* テクスチャエディターのヘッダー統一 */
.texture-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.texture-editor-header-controls {
  display: flex;
  gap: 8px;
}

/* レスポンシブレイアウト調整 */
@media (max-width: 960px) {
  .app-container {
    padding: 8px;
    gap: 12px;
  }
  
  .panel-title {
    font-size: 18px;
    margin-bottom: 8px;
  }
  
  .texture-editor-panel,
  .viewer-panel,
  .controls-panel {
    padding: 12px;
    margin-bottom: 12px;
  }
  
  .texture-editor-main-area {
    flex-direction: column;
    align-items: center;
    margin-bottom: 8px;
  }
  
  .texture-editor-side-info {
    display: none;
  }
  
  .texture-editor-canvas-wrapper {
    width: 100% !important;
    max-width: 100%;
  }
  
  .viewer-note-inline {
    display: none;
  }
  
  .viewer-title-group {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  
  /* コンパクトな表示 */
  .color-palette-compact {
    margin-bottom: 12px;
    padding: 8px;
  }
  
  .panel-group {
    margin-bottom: 12px;
  }
}

/* 小画面でのさらなる最適化 */
@media (max-width: 640px) {
  .app-container {
    padding: 4px;
    gap: 8px;
  }
  
  .texture-editor-panel,
  .viewer-panel,
  .controls-panel {
    padding: 8px;
    margin-bottom: 8px;
  }
  
  .texture-editor-canvas {
    width: 100%;
    height: 100%;
    max-width: min(260px, 75vw);
    max-height: min(260px, 75vw);
  }
  
  .texture-editor-canvas-wrapper {
    width: min(260px, 75vw);
    height: min(260px, 75vw);
    max-width: min(260px, 75vw);
    max-height: min(260px, 75vw);
  }
  
  .viewer-canvas-wrapper canvas {
    max-height: 220px;
    width: auto !important;
  }
  
  .panel-title {
    font-size: 16px;
    margin-bottom: 6px;
  }
  
  .color-palette-compact {
    margin-bottom: 8px;
    padding: 6px;
  }
  
  .panel-group {
    margin-bottom: 8px;
  }
}

/* Undo/Redoボタンのスタイル */
.history-button-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.history-button {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid #475569;
  background: #374151;
  color: #e5e7eb;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-button:hover:not(:disabled) {
  background: #4b5563;
  border-color: #6b7280;
}

.history-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #1f2937;
  border-color: #374151;
  color: #6b7280;
}

/* ギャラリーのコンパクトスタイル */
.gallery-header-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 8px 0;
  flex-shrink: 0;
}

.gallery-title {
  margin: 0;
  font-size: 16px;
  color: #e2e8f0;
}

.gallery-controls-compact {
  display: flex;
  gap: 8px;
  align-items: center;
}

.gallery-search-compact,
.gallery-filter-compact {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(15, 23, 42, 0.8);
  color: #e2e8f0;
  font-size: 12px;
}

.gallery-search-compact {
  min-width: 120px;
}

.gallery-filter-compact {
  min-width: 80px;
}

.gallery-list-compact {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 6px;
}

.gallery-list-compact::-webkit-scrollbar {
  width: 6px;
}

.gallery-list-compact::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.4);
  border-radius: 3px;
}

.gallery-list-compact::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  border-radius: 3px;
}

.gallery-list-compact::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
}

.gallery-card {
  display: flex;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 90px;
  flex-shrink: 0;
}

.gallery-card:hover {
  border-color: rgba(59, 130, 246, 0.5);
  transform: translateY(-1px);
}

.gallery-card.active {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.gallery-card-preview {
  position: relative;
  width: 80px;
  height: 80px;
  background: rgba(30, 41, 59, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-preview-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  image-rendering: pixelated;
}

.gallery-favorite-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  color: #fbbf24;
  font-size: 12px;
}

.gallery-active-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: #3b82f6;
  color: white;
  font-size: 8px;
  padding: 2px 4px;
  border-radius: 2px;
}

.gallery-card-content {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 90px;
}

.gallery-card-title {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: #e2e8f0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-rename-input {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 4px;
  padding: 2px 6px;
  color: #e2e8f0;
  font-size: 14px;
  margin: 0 0 8px 0;
}

.gallery-card-actions {
  display: flex;
  gap: 4px;
}

.gallery-action-btn {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 4px;
  padding: 4px 6px;
  color: #e2e8f0;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s ease;
}

.gallery-action-btn:hover {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.5);
}

.gallery-action-btn.favorite-btn.active {
  color: #fbbf24 !important;
  background: rgba(251, 191, 36, 0.2) !important;
  border-color: rgba(251, 191, 36, 0.5) !important;
}

.gallery-action-btn.favorite-btn.active:hover {
  color: #f59e0b !important;
  background: rgba(251, 191, 36, 0.3) !important;
  border-color: rgba(251, 191, 36, 0.7) !important;
}

.gallery-action-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed !important;
  pointer-events: none;
}
.selector-group {
  margin-bottom: 6px;
}

.selector-section-header {
  font-size: 14px;
  font-weight: 600;
  color: #e2e8f0;
  margin: 6px 0 4px 0;
  padding-bottom: 2px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.3);
}

/* 最初のセクションヘッダーの上マージンを削除 */
.selector-group:first-child .selector-section-header {
  margin-top: 0;
}

/* インデントクラス */
.indented {
  margin-left: 20px;
}

/* 部位グループのコンパクトレイアウト */
.part-group-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.part-group-container.indented {
  margin-left: 16px;
}

.part-subgroup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.part-subgroup-label {
  font-size: 10px;
  color: #94a3b8;
  font-weight: 500;
  text-align: center;
  min-width: 36px;
}

.part-subgroup-buttons {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.part-subgroup-buttons .selector-button {
  min-width: 28px;
  padding: 3px 5px;
  font-size: 10px;
}

/* 面の字下げ */
.face-buttons.indented {
  margin-left: 20px;
}

/* モードと履歴の水平配置 */
.mode-history-row {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}

.mode-group-inline,
.history-group-inline {
  flex: 1;
}

.mode-group-inline .selector-label,
.history-group-inline .selector-label {
  margin-bottom: 8px;
}

/* レスポンシブ調整 */
@media (max-width: 960px) {
  .part-group-container.indented {
    margin-left: 12px;
    gap: 8px;
  }
  
  .part-subgroup-buttons .selector-button {
    min-width: 28px;
    padding: 3px 5px;
    font-size: 10px;
  }
  
  .mode-history-row {
    flex-direction: column;
    gap: 16px;
  }
  
  .face-buttons.indented {
    margin-left: 12px;
  }
  
  .indented {
    margin-left: 12px;
  }
  
  .selector-section-header {
    font-size: 14px;
    margin: 16px 0 8px 0;
  }
  
  /* 最初のセクションヘッダーの上マージンを削除（モバイル） */
  .selector-group:first-child .selector-section-header {
    margin-top: 0;
  }
}

/* セレクターのスペーシングとモードの字下げを改善 */
.selector-spacer {
  height: 20px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  margin: 16px 0;
}

.selector-label {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  color: #cbd5f5;
  margin-bottom: 8px;
  margin-left: 4px;
}

/* ボタンサイズの最適化 */
.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-button, .secondary-button {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid;
  cursor: pointer;
  transition: all 0.2s ease;
}

.primary-button {
  background: #3b82f6;
  border-color: #2563eb;
  color: white;
}

.secondary-button {
  background: #374151;
  border-color: #4b5563;
  color: #e5e7eb;
}

/* モバイルでのボタンサイズ縮小 */
@media (max-width: 640px) {
  .primary-button, .secondary-button {
    padding: 6px 10px;
    font-size: 12px;
  }
  
  .button-row {
    gap: 6px;
  }
  
  .panel-group {
    margin-bottom: 10px;
    padding: 8px;
  }
  
  .panel-subtitle {
    font-size: 14px;
    margin-bottom: 8px;
  }
}

/* ギャラリーのスクロール設定 */
.gallery-container {
  height: 100%;
  overflow: hidden; /* 外側のスクロールバーを非表示 */
}

.gallery-list {
  height: 100%;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 8px;
}

@media (max-width: 640px) {
  .gallery-list {
    max-height: 100%;
  }
}

/* サイド情報パネルのモバイル非表示調整 */
@media (max-width: 960px) {
  .texture-editor-main-area {
    flex-direction: column;
    align-items: center;
  }
  
  .texture-editor-side-info {
    display: none;
  }
  
  .texture-editor-canvas-wrapper {
    width: 100% !important;
    max-width: 100%;
  }
}

/* 3Dプレビューコントロール */
.viewer-preview-controls {
  display: flex !important; /* 強制表示 */
  gap: 16px; /* ボタン間の隙間を増加 */
  margin-top: 16px;
  justify-content: center;
  align-items: center; /* 垂直方向の中央配置 */
  flex-wrap: wrap;
  padding: 12px 16px; /* 左右にもパディングを追加、上下を調整 */
  background: rgba(15, 23, 42, 0.8) !important; /* 背景色で視認性向上 */
  border-radius: 8px;
  border: 2px solid rgba(59, 130, 246, 0.5) !important; /* 青い境界線で目立たせる */
  position: relative;
  z-index: 10; /* 前面に表示 */
  min-height: 48px; /* 最小高さを設定 */
}

/* デスクトップ版のボタンスタイル */
.viewer-preview-controls .secondary-button {
  padding: 8px 20px; /* 左右のパディングを増加 */
  margin: 0 8px; /* ボタンの左右にマージンを追加 */
  min-width: 120px; /* 最小幅を設定 */
}

.viewer-preview-section {
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 0;
  overflow: visible;
  gap: 16px; /* キャンバスとボタンの間隔を確保 */
}

.viewer-canvas-wrapper {
  flex: 1;
  min-height: 0;
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: radial-gradient(circle at 30% 15%, rgba(59, 130, 246, 0.35), rgba(15, 23, 42, 0.85));
  width: var(--stage-size);
  height: auto;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}
@media (max-width: 768px) {
  .viewer-preview-controls {
    gap: 12px; /* スマホでは少し狭める */
    margin-top: 12px;
    flex-direction: row;
    padding: 10px 12px; /* 上下パディングを削減、左右は維持 */
    min-height: 44px; /* スマホでは少し低く */
  }
  
  .viewer-preview-controls .secondary-button {
    flex: 1;
    min-width: 100px; /* 最小幅を維持 */
    font-size: 12px;
    padding: 8px 16px; /* 左右のパディングを増加 */
    white-space: nowrap;
    margin: 0 4px; /* ボタンの左右にマージンを追加 */
  }
  
  /* スマホ時のプレビューセクション調整 */
  .viewer-preview-section {
    gap: 12px; /* gapを増加 */
  }
  
  .viewer-canvas-wrapper {
    flex: 0 0 auto;
    min-height: 0;
    height: auto;
  }
  
  /* パネル全体の高さ制限を緩和 */
  .viewer-panel.with-tabs {
    height: auto;
    min-height: auto;
    overflow: visible;
  }
}

/* アクションボタン群のスタイル */
.action-buttons-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.action-button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 6px;
  background: rgba(30, 41, 59, 0.8);
  color: #e2e8f0;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  text-decoration: none;
  position: relative;
}

.action-button:hover {
  background: rgba(59, 130, 246, 0.8);
  border-color: rgba(59, 130, 246, 0.5);
  transform: translateY(-1px);
}

.action-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.action-button .button-icon {
  font-size: 16px;
}

.action-button .button-text {
  font-weight: 500;
}

/* スマホレイアウトでテキストを隠す */
@media (max-width: 959px) {
  .action-button .button-text {
    display: none;
  }
  
  .action-button {
    padding: 8px;
    min-width: 40px;
    justify-content: center;
  }
}
