/* ====== カラーテーマ変数 ====== */
:root {
  --color-bg-main: #0f172a;
  --color-bg-panel: #1e293b;
  --color-bg-card: #1e293b;
  --color-bg-card-secondary: #334155;
  --color-bg-sort-btn: #f1f5f9;
  --color-border-card: #94a3b8;
  --color-border-sort-btn: #cbd5e1;
  --color-text-main: #f8fafc;
  --color-text-secondary: #94a3b8;
  --color-text-sort-btn: #334155;
  --color-text-sort-btn-hover: #0f172a;
  --color-sort-btn-hover: #e2e8f0;
  --blueprint-card-bg: rgba(15, 23, 42, 0.85);
  --blueprint-card-border: rgba(59, 130, 246, 0.12);
  --blueprint-card-shadow: 0 20px 40px rgba(2, 6, 23, 0.35);
  --blueprint-canvas-bg: #0f172a;
  --blueprint-canvas-border: rgba(148, 163, 184, 0.25);
  --blueprint-canvas-shadow: 0 12px 30px rgba(15, 23, 42, 0.45);
  --blueprint-max-frame: 860px;
  --blueprint-max-canvas: 768px;
}

body[data-theme="light"] {
  --color-text-main: #0b1528;
  --color-text-secondary: #475569;
  --blueprint-card-bg: rgba(255, 255, 255, 0.96);
  --blueprint-card-border: rgba(148, 163, 184, 0.45);
  --blueprint-card-shadow: 0 18px 36px rgba(15, 23, 42, 0.12);
  --blueprint-canvas-bg: #f8fafc;
  --blueprint-canvas-border: rgba(148, 163, 184, 0.45);
  --blueprint-canvas-shadow: 0 18px 38px rgba(15, 23, 42, 0.08);
}

body[data-theme="light"] .app-shell {
  background: linear-gradient(180deg, #f4f6fb 0%, #dfe4ef 70%, #cfd6e4 100%);
  color: #0b1528;
}

body[data-theme="light"] .viewer-panel,
body[data-theme="light"] .controls-panel,
body[data-theme="light"] .texture-editor-panel {
  background: rgba(235, 240, 247, 0.96);
  border-color: rgba(148, 163, 184, 0.45);
  color: #0b1528;
  box-shadow: 0 18px 34px rgba(15, 23, 42, 0.08);
}

body[data-theme="light"] .panel-title,
body[data-theme="light"] .controls-header,
body[data-theme="light"] .texture-editor-header {
  color: #0b1528;
}

body[data-theme="light"] .panel-subtitle,
body[data-theme="light"] .viewer-note-inline {
  color: #475569;
}

body[data-theme="light"] .viewer-tab-bar {
  background: rgba(248, 250, 252, 0.95);
  border: 1px solid rgba(148, 163, 184, 0.35);
}

body[data-theme="light"] .viewer-tab {
  background: rgba(226, 232, 240, 0.9);
  color: #1e293b;
  border-color: rgba(148, 163, 184, 0.45);
}

body[data-theme="light"] .viewer-tab.is-active {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #f8fafc;
  border-color: rgba(37, 99, 235, 0.4);
}

body[data-theme="light"] .secondary-button,
body[data-theme="light"] .viewer-toggle-group .secondary-button {
  background: #f1f5f9;
  border-color: #cbd5f5;
  color: #1e293b;
}

body[data-theme="light"] .viewer-canvas-frame {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(226, 232, 240, 0.85));
  border-color: rgba(148, 163, 184, 0.25);
}

body[data-theme="light"] .texture-blueprint-card,
body[data-theme="light"] .gallery.in-viewer {
  background: rgba(255, 255, 255, 0.92);
  border-color: rgba(148, 163, 184, 0.25);
}

body[data-theme="light"] .texture-blueprint-status {
  color: #475569;
}

body[data-theme="light"] .gallery.in-viewer {
  box-shadow: none;
}

body[data-theme="light"] .panel-subtitle,
body[data-theme="light"] .viewer-note-inline,
body[data-theme="light"] .viewer-toggle-label,
body[data-theme="light"] .selector-label,
body[data-theme="light"] .selector-section-header,
body[data-theme="light"] .selector-button,
body[data-theme="light"] .selector-button.is-overlay,
body[data-theme="light"] .texture-editor-status,
body[data-theme="light"] .file-input-label,
body[data-theme="light"] .file-input-label span,
body[data-theme="light"] .gallery-list .card.gallery-card-bs .card-title,
body[data-theme="light"] .gallery-empty p,
body[data-theme="light"] .ng-files-list {
  color: #1f2937;
}

body[data-theme="light"] .selector-button {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(148, 163, 184, 0.5);
  color: #1f2937;
}

body[data-theme="light"] .selector-button.is-active {
  border-color: rgba(59, 130, 246, 0.75);
  background: rgba(59, 130, 246, 0.18);
  color: #0b1528;
}

body[data-theme="light"] .viewer-toggle-group .secondary-button,
body[data-theme="light"] .secondary-button {
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.95), rgba(230, 235, 245, 0.9));
  border-color: rgba(148, 163, 184, 0.55);
  color: #0b1528;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
}

/* === Gallery Sort Button Wrapper === */
.gallery-sort-btn-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  padding: 0 4px;
  margin: 0 4px 0 0;
  height: 36px;
  min-width: 36px;
  box-shadow: 0 1px 4px rgba(30, 41, 59, 0.07);
  box-sizing: border-box;
}

.gallery-sort-btn {
  background: none;
  border: none;
  color: #334155;
  font-size: 20px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.gallery-sort-btn:hover,
.gallery-sort-btn:focus {
  background: #e2e8f0;
  color: #0f172a;
  outline: none;
}

.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: var(--color-bg-main);
  color: var(--color-text-main);
  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%;
  height: 100%;
}

/* app-shell レイアウト */
.app-shell {
  height: 100%;
  /* 固定して内部だけをスクロール */
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px clamp(8px, 2vw, 20px);
  padding-bottom: 72px;
  /* スマホフッター広告分の余白 */
  overflow: hidden;
  /* app-main にのみスクロール委譲 */
  background: var(--color-bg-main);
  color: var(--color-text-main);
  font-family: 'Noto Sans JP', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

@media (min-width: 768px) {
  .app-shell {
    padding-bottom: 12px;
    /* PCでは元の余白 */
  }
}

.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: start;
  flex: 1 1 auto;
  overflow-y: auto;
  padding-bottom: 20px;
}

@media (max-width: 1500px) {
  .app-main {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* 同じサイズの正方形を 3D と テクスチャ で共有するための変数 */
:root {
  /* PCプレビューサイズをさらに大幅に増加 */
  --stage-size: 560px;
  --gallery-card-height: 180px;
  /* 1カードの基準高さ (画像+本文) */
  --gallery-card-height-small: 90px;
  /* 2カラム時の半分高さ */
}

@media (max-width: 1200px) {

  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;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .app-shell {
    padding: 8px clamp(4px, 1.5vw, 12px);
    gap: 8px;
  }

  .viewer-panel,
  .controls-panel {
    padding: clamp(8px, 3vw, 16px);
  }

  .viewer-canvas-wrapper {
    width: min(100%, 560px);
    /* PCサイズをさらに大きく */
  }
}

.viewer-panel,
.controls-panel {
  background: rgba(15, 23, 42, 0.65);
  border-radius: 12px;
  padding: clamp(8px, 1.5vw, 12px);
  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: 8px;
}

.viewer-panel {
  min-height: 400px;
  /* ビューアーパネルの最小高さを設定 */
  overflow: auto;
  /* 内部スクロールを有効化 */
}

.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: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
  min-height: 36px;
}

.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-area-container {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 1vw, 16px);
  border-radius: 16px;
  background-color: #0b1324;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.05) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.05) 75%),
    linear-gradient(45deg, rgba(255, 255, 255, 0.08) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.08) 75%);
  background-size: 32px 32px;
  background-position: 0 0, 16px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px rgba(2, 6, 23, 0.35);
  margin: 0 auto;
  transition: background 0.25s ease, border-color 0.25s ease;
}

body[data-theme="light"] .texture-editor-canvas-area-container {
  background-color: #e6ecf7;
  background-image:
    linear-gradient(45deg, rgba(148, 163, 184, 0.25) 25%, transparent 25%, transparent 75%, rgba(148, 163, 184, 0.25) 75%),
    linear-gradient(45deg, transparent 25%, rgba(148, 163, 184, 0.2) 25%, rgba(148, 163, 184, 0.2) 75%, transparent 75%);
  border: 1px solid rgba(148, 163, 184, 0.35);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65);
}

/* キャンバス自体 */
.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-title {
  margin: 0;
  font-size: clamp(1.15rem, 1.8vw, 1.35rem);
  line-height: 1.2;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: inherit;
}

.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-preview-section {
    width: 100%;
    margin: 0;
  }

  .viewer-canvas-frame {
    width: 100%;
    margin: 0;
    border-radius: 16px;
    padding: clamp(6px, 3vw, 12px);
  }

  .viewer-canvas-wrapper {
    width: 100% !important;
    max-width: none !important;
    height: auto;
    max-height: none;
    aspect-ratio: 16 / 9;
    padding: clamp(4px, 2vw, 8px);
  }

  /* スマホではコンテナを縦方向にコンパクトに */
  .viewer-canvas-container {
    aspect-ratio: 16 / 9;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
  }

  /* テクスチャエディターもサイズ縮小 */
  .texture-editor-canvas {
    width: 100%;
    height: 100%;
    max-width: min(320px, 92vw);
    max-height: min(320px, 92vw);
  }

  .texture-editor-canvas-wrapper {
    width: min(320px, 92vw);
    height: min(320px, 92vw);
    max-width: min(320px, 92vw);
    max-height: min(320px, 92vw);
  }
}

/* Viewer tabs */
.viewer-panel.with-tabs {
  padding-top: 4px;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: auto;
  /* パネル全体をスクロール可能に */
  height: 100%;
  /* 親の高さを使用 */
  min-height: 0;
  /* flexbox内で縮小可能に */
}

/* ビューアー内のギャラリー高さ制御 - ギャラリーが大きくなれるように */
.viewer-panel.with-tabs .gallery {
  flex: 1 1 auto;
  min-height: 250px;
  /* 最小高さ */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ギャラリーリスト部分をスクロール可能に */
.viewer-panel.with-tabs .gallery-list-compact,
.gallery-list-compact {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 150px;
  /* リストの最小高さ */
}

.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-panel.with-tabs>h2.panel-title {
  border: 1px solid rgba(59, 130, 246, 0.18);
}

body[data-theme="light"] .viewer-panel.with-tabs>h2.panel-title {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(238, 241, 248, 0.84));
  color: #0b1528;
  border: 1px solid rgba(148, 163, 184, 0.35);
}

/* モバイル用タブバー軽量化 */
.viewer-tab-bar.mobile-only {
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
  margin: 0 0 2px;
  min-height: 0;
}

.viewer-tab-bar.mobile-only select {
  margin: 0;
  height: 34px;
  min-height: 0;
  padding-top: 2px;
  padding-bottom: 2px;
}

.viewer-tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 2px;
  position: sticky;
  top: 40px;
  z-index: 9;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.92), rgba(15, 23, 42, 0.65));
  padding: 2px 4px;
  backdrop-filter: blur(6px);
  border-radius: 14px;
  border: 1px solid rgba(59, 130, 246, 0.15);
}

.viewer-panel.with-tabs .gallery-list {
  margin-top: 8px;
}

.viewer-tab {
  flex: 0 0 auto;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(14, 165, 233, 0.45);
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.65), rgba(59, 130, 246, 0.85));
  color: #f8fafc;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(14, 165, 233, 0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  white-space: nowrap;
}

.viewer-tab.is-active {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border-color: rgba(99, 102, 241, 0.7);
  box-shadow: 0 16px 32px rgba(99, 102, 241, 0.35);
}

.viewer-tab:hover {
  transform: translateY(-1px);
}

.viewer-tab:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

body[data-theme="light"] .viewer-tab-bar {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(231, 236, 247, 0.85));
  border: 1px solid rgba(148, 163, 184, 0.35);
}

body[data-theme="light"] .viewer-tab {
  border-color: rgba(59, 130, 246, 0.35);
  box-shadow: 0 12px 26px rgba(59, 130, 246, 0.2);
}

body[data-theme="light"] .viewer-tab.is-active {
  border-color: rgba(79, 70, 229, 0.4);
  box-shadow: 0 16px 32px rgba(79, 70, 229, 0.3);
}

.viewer-tab-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 8px;
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 0px;
}

.viewer-title-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.viewer-header .panel-title {
  margin: 0;
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
}

.viewer-note-inline {
  font-size: 0.85rem;
  color: #cbd5f5;
}

.viewer-toggle-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.viewer-toggle-group .secondary-button {
  min-width: 140px;
  padding: 6px 12px;
  justify-content: center;
}

.viewer-toggle-label {
  font-weight: 600;
  letter-spacing: 0.04em;
}

.viewer-toggle-group.mobile-toggle {
  width: 100%;
  justify-content: flex-start;
  margin-top: 8px;
}

.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列のまま（デフォルト）*/

/* === 3Dプレビュー左右のレイアウト制御 === */
.viewer-preview-section {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  align-items: center;
  text-align: center;
}

.viewer-side-by-side {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  max-width: 100%;
  align-items: stretch;
}

.viewer-canvas-frame,
.viewer-blueprint-wrapper {
  max-width: 100%;
}

.viewer-canvas-wrapper {
  width: min(100%, 520px);
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  padding: 8px;
}

body[data-theme="light"] .viewer-canvas-frame {
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.12);
}

body[data-theme="light"] .viewer-canvas-wrapper {
  background: radial-gradient(circle at 40% 10%, rgba(59, 130, 246, 0.18), rgba(30, 64, 175, 0.08)), #e7ecf7;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.viewer-blueprint-wrapper {
  margin-top: 18px;
  display: flex;
  justify-content: center;
  width: min(100%, var(--blueprint-max-frame));
  padding: 24px 18px;
  border-radius: 20px;
  background: var(--blueprint-card-bg);
  border: 1px solid var(--blueprint-card-border);
  box-shadow: var(--blueprint-card-shadow);
}

.blueprint-layout,
.texture-blueprint-card {
  width: min(100%, var(--blueprint-max-frame));
}

.texture-blueprint-canvas-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
}

.texture-blueprint-canvas {
  width: min(100%, var(--blueprint-max-canvas)) !important;
  max-width: var(--blueprint-max-canvas);
  height: auto !important;
}

.texture-blueprint-canvas-wrapper,
.texture-blueprint-canvas {
  max-width: 100%;
  height: auto;
}

/* 3D側の外枠だけを縮める（中の人型は維持） */
.viewer-preview-inner {
  width: 100%;
  max-width: 900px;
  /* テクスチャ編集のキャンバス枠に近いサイズ */
  margin: 0 auto;
}

.viewer-canvas-frame {
  display: flex;
  align-items: center;
  justify-content: center;
}

.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;
  width: 100%;
  height: 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;
}

/* Drag & Drop - ボタン中心のシンプルデザイン */
.file-drop-zone {
  position: relative;
  border: 2px dashed rgba(148, 163, 184, 0.4);
  border-radius: 12px;
  padding: 16px 12px;
  /* パディングをさらに抑えめにして高さを節約 */
  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: 72px;
}

.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-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-size: 0.95rem;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: white;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 700;
  font-size: 16px;
  transition: all 0.25s ease;
  border: none;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.28);
  position: relative;
  overflow: hidden;
  margin: 8px 0;
  min-width: 260px;
}

.file-input-label.stylish-upload::before {
  content: '📁';
  margin-right: 10px;
  font-size: 18px;
}

.file-input-label.stylish-upload:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.35);
  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 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.controls-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 12px;
}

.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;
}

/* Upload progress */
.upload-progress {
  width: 100%;
  margin-top: 8px;
}

.upload-progress .bar {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  overflow: hidden;
}

.upload-progress .bar .fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #10b981, #06b6d4);
  transition: width 250ms ease;
}

.upload-progress .meta {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 6px;
}

/* Toasts */
.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  min-width: 220px;
  padding: 10px 14px;
  border-radius: 10px;
  color: white;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.6);
}

.toast.info {
  background: linear-gradient(90deg, #3b82f6, #06b6d4);
}

.toast.success {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.toast.error {
  background: linear-gradient(90deg, #ef4444, #f97316);
}

/* 点線枠 */
.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;
}


.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, 480px);
  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: 4px;
}

.extracted-colors-row {
  max-height: 140px;
  overflow-y: auto;
  align-content: flex-start;
  padding-right: 4px;
}

.extracted-colors-row::-webkit-scrollbar {
  width: 4px;
}

.extracted-colors-row::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

.extracted-colors-row::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.5);
  border-radius: 4px;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px 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: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 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;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  margin: 0 auto 8px auto;
  box-sizing: border-box;
}

.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;
}

.action-buttons-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.action-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 10px;
  border: 1px solid rgba(37, 99, 235, 0.65);
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
  color: #f8fafc;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.25);
  text-decoration: none;
}

.action-button.upload-button {
  background: linear-gradient(135deg, #0ea5e9, #3b82f6);
  border-color: rgba(14, 165, 233, 0.6);
}

.action-button.download-button {
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  border-color: rgba(79, 70, 229, 0.55);
}

.action-button:hover:not(.is-disabled):not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 16px 28px rgba(37, 99, 235, 0.35);
}

.action-button:disabled,
.action-button.is-disabled {
  opacity: 0.65;
  cursor: not-allowed;
  box-shadow: none;
  background: #94a3b8;
  border-color: #94a3b8;
  color: #f8fafc;
}

.primary-button,
.secondary-button {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 6px;
  border: 1px solid;
  cursor: pointer;
  transition: all 0.2s ease;
  /* 高さの不一致をなくすために共通のレイアウトを強制 */
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
  min-height: 36px;
}

.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;
    min-height: 32px;
  }

  .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;
  gap: 8px;
  margin-top: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  position: static;
  z-index: auto;
  min-height: 0;
}

/* デスクトップ版のボタンスタイル */
.viewer-preview-controls .secondary-button {
  padding: 8px 12px;
  margin: 0;
  /* 間隔は gap で統一 */
}

.viewer-preview-section {
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 0;
  overflow: visible;
  gap: 16px;
  /* キャンバスとボタンの間隔を確保 */
}

/* Frame wrapping the canvas; visually separate 3D from blueprint */
.viewer-canvas-frame {
  border-radius: 18px;
  padding: 10px;
  background: linear-gradient(180deg, rgba(10, 16, 24, 0.6), rgba(12, 18, 26, 0.6));
  border: 1px solid rgba(148, 163, 184, 0.08);
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.4);
}

.viewer-canvas-wrapper {
  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: 100%;
  height: auto;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .viewer-preview-controls {
    gap: 10px;
    margin-top: 6px;
    flex-direction: row;
    padding: 0;
    min-height: 0;
  }

  .viewer-preview-controls .secondary-button {
    flex: 1;
    min-width: 100px;
    font-size: 12px;
    padding: 8px 16px;
    white-space: nowrap;
    margin: 0;
  }

  /* スマホ時のプレビューセクション調整 */
  .viewer-preview-section {
    gap: 8px;
    /* gapをより小さく */
    padding: 0;
    /* プレビューセクション自体のパディングを削除 */
    margin: 0;
    /* マージンも削除 */
  }

  .viewer-canvas-wrapper {
    flex: 0 0 auto;
    min-height: 0;
    height: auto;
    margin: 0 auto;
    /* 中央配置のみ維持 */
    /* スマホではより横長の比率で縦を詰める */
    aspect-ratio: 2 / 1;
  }

  /* パネル全体の高さ制限を緩和 */
  .viewer-panel.with-tabs {
    height: auto;
    min-height: auto;
    overflow: visible;
  }
}

/* さらに小さいスマホ向けの追加調整 */
@media (max-width: 640px) {
  .viewer-preview-section {
    gap: 4px;
    /* より小さなgap */
    padding: 0;
    /* パディング完全削除 */
    margin: 0;
    /* マージン完全削除 */
  }

  .viewer-preview-controls {
    margin-top: 4px;
    /* 上マージンをさらに削減 */
    padding: 6px 10px;
    /* パディングをさらに削減 */
  }

  /* 3Dビューアの縦幅を最大化 */
  .viewer-canvas-container {
    /* 上下の余白を完全に削除 */
    padding: 0 !important;
    margin: 0 !important;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* パネル全体の余白も削減 */
  .viewer-panel.with-tabs {
    padding: clamp(8px, 2vw, 16px);
    /* パディングを削減 */
  }

  /* プレビューセクション専用の余白削減 */
  .viewer-panel.with-tabs .viewer-preview-section {
    margin: 0;
    padding: 0;
  }
}

/* Blueprint wrapper moved to the right column */
.viewer-blueprint-wrapper {
  margin: 0 auto;
  padding: 28px 32px;
  border-radius: 24px;
  background: var(--blueprint-card-bg);
  border: 1px solid var(--blueprint-card-border);
  box-shadow: var(--blueprint-card-shadow);
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: min(100%, var(--blueprint-max-frame));
  min-width: min(320px, 100%);
}

.texture-blueprint-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.texture-blueprint-canvas-wrapper {
  width: min(100%, var(--blueprint-max-canvas));
  display: flex;
  align-items: center;
  justify-content: center;
}

.texture-blueprint-canvas {
  width: min(100%, var(--blueprint-max-canvas));
  height: auto;
  display: block;
  margin: 0 auto;
}

.texture-blueprint-status {
  color: #94a3b8;
  font-size: 0.9rem;
  margin: 4px 0 0 0;
}

.texture-blueprint-status.error {
  color: #f87171;
}

.blueprint-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: center;
  justify-content: center;
  width: 100%;
}

/* Small screens: 既に縦並びなので主要な調整のみ */
@media (max-width: 960px) {
  .viewer-canvas-frame {
    padding: 6px;
    border-radius: 12px;
  }

  .viewer-blueprint-wrapper {
    width: 100%;
    max-width: none;
    min-width: 0;
    padding: 20px;
  }
}

/* アクションボタン群のスタイル */
.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;
  line-height: 1;
  min-height: 36px;
}

.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;
  }
}