/* === ベーススタイル (ダークモード統合済み) === */
body {
  background-color: #121212;
  color: #e0e0e0;
  margin: 0;
  padding: 0;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  height: 100vh;
  overflow: hidden;
}

h1, h2, h3, .title, h2.panel-title {
  color: #ffffff;
}

input, textarea, select {
  background-color: #2a2a2a;
  color: #ffffff;
  border: 1px solid #444;
}

/* === レイアウトコンテナ === */
.main-container {
  display: flex;
  gap: 20px;
  max-width: 1800px;
  margin: 0 auto;
  padding: 20px;
  width: calc(100% - 40px);
  height: calc(100vh - 40px);
  box-sizing: border-box;
}

.panel {
  background: #1e1e1e;
  border-radius: 12px;
  padding: 20px;
  border: 1px solid #333;
  display: flex;
  flex-direction: column;
  height: 100%;
  box-sizing: border-box;
}

/* PC用 1:4:5 の比率 */
.info-side { 
  flex: 1.1; 
  min-width: 0; 
  width: 11%; 
  overflow-y: auto; 
}
.left-side { 
  flex: 3.9; 
  min-width: 0; 
  width: 39%; 
}
.right-side { 
  flex: 5; 
  min-width: 0; 
  width: 50%; 
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  border-bottom: 3px solid #444;
  padding-bottom: 8px;
  flex-shrink: 0;
}

/* 基本のスクロール領域 */
.scrollable-zone {
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
}

/* 右側（画像一覧側）の2重スクロール防止設定（PC版） */
.right-side .scrollable-zone {
  display: flex;
  flex-direction: column;
  overflow: hidden; /* 外側のスクロールを非表示 */
}

/* === 情報エリア === */
.info-content {
  font-size: 0.85rem;
  color: #e0e0e0;
  line-height: 1.6;
  word-break: break-word;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.info-images-layout {
  display: flex;
  flex-direction: column; 
  align-items: stretch;
  gap: 5px !important;
  margin: 0 !important;
  padding: 0 !important;
}
  
.info-img-card {
  width: 100%;
  max-width: 100%;
  height: auto;
  aspect-ratio: auto;
  border: none !important;
  background: transparent !important;
  padding: 0 !important;
  margin: 0 !important;
  display: block;
  cursor: pointer;
  appearance: none;
}
  
.info-img-card.selected {
  box-shadow: inset 0 0 0 3px #f59e0b; 
}

.info-img-card img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  margin: 0 !important;
  padding: 0 !important;
  pointer-events: none;
}

.info-description-box {
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 6px;
  padding: 10px;
  font-size: 0.8rem;
  color: #e0e0e0;
  min-height: 80px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  
  /* スマホのスクロール最適化 */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: none; /* containからnoneに変更し、背景の引っ張りを強力に防ぐ */
}

.global-reset-btn {
  background-color: #ef4444;
  color: white;
  border: none;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: bold;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.2s;
}
.global-reset-btn:hover { background-color: #dc2626; }

/* === チームエリア === */
.team-box {
  background: #1e1e1e;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 10px;
  animation: fadeIn 0.3s ease-out; 
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

.team-header { 
  margin-bottom: 6px; 
  cursor: grab; 
  user-select: none;
}
.team-header:active { cursor: grabbing; }
.team-title { font-weight: bold; color: #e0e0e0; font-size: 0.95rem; pointer-events: none; }

/* 各チームの配置エリア（キャラ置き場） */
.grid-layout {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  min-height: 45px; 
  max-height: 150px;      
  overflow-y: auto;       
  background: #1e1e1e;
  border: 2px dashed #444;
  border-radius: 6px;
  padding: 6px;
  align-content: start;
  
  /* スマホのスクロール最適化 */
  -webkit-overflow-scrolling: touch; 
  overscroll-behavior-y: none; /* 背景が一緒にスクロールされるのを完全にブロック */
}

.new-team-zone {
  border: 2px dashed #555;
  border-radius: 8px;
  background: #2a2a2a;
  color: #aaa;
  text-align: center;
  padding: 15px;
  margin-top: 10px;
  font-weight: bold;
  font-size: 0.95rem;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, border-color 0.2s;
}
.new-team-zone:hover {
  background: #333;
  border-color: #3b82f6;
  color: #4dabf7;
}

/* === コントロールパネル === */
.control-panel {
  background: #1e1e1e;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.attr-group {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: #e0e0e0;
  font-weight: bold;
  flex-wrap: wrap;
}
.attr-btn-group { display: flex; gap: 6px; flex-wrap: wrap; }
.attr-btn {
  padding: 4px 12px;
  background: transparent !important;
  border: none !important;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
}
.attr-btn img {
  width: 18px;
  height: 18px;
  display: block;
  margin: 0 auto;
  pointer-events: none;
}

.flex-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.control-item { display: flex; align-items: center; gap: 4px; font-size: 0.85rem; color: #e0e0e0; }

select, .sort-btn {
  padding: 6px 8px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #2a2a2a;
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
}
.sort-btn:hover { background: #333; }
#sort-rank-toggle { width: 100px; text-align: center; font-weight: bold; }

/* === キャラクター一覧（画像プール） === */
.pool-layout {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  
  /* Flexboxで余った高さを自動で埋める（PC版） */
  flex: 1;
  min-height: 0; 
  overflow-y: auto;       
  
  background: #1e1e1e;
  border: 2px dashed #444;
  border-radius: 6px;
  padding: 10px;
  align-content: start;

  /* スマホのスクロール最適化 */
  -webkit-overflow-scrolling: touch; 
  overscroll-behavior-y: none; /* 背景が一緒にスクロールされるのを完全にブロック */
}

/* === 一覧側の説明文表示エリア (下部) === */
.description-box {
  margin-top: 15px;
  padding: 15px;
  background: #1e1e1e;
  border: 1px solid #444;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #ccc;
  line-height: 1.6;
  height: 110px;          
  overflow-y: auto;       
  box-sizing: border-box;
  transition: all 0.2s;
  white-space: pre-wrap;
  word-break: break-word; 
  flex-shrink: 0; 

  /* スマホのスクロール最適化 */
  -webkit-overflow-scrolling: touch; 
  overscroll-behavior-y: none; 
}
.description-box.active { background: #2a2a2a; border-color: #3b82f6; color: #fff; }

/* === 画像カード === */
.img-card {
  background: #2a2a2a;
  padding: 2px; 
  border-radius: 4px;
  cursor: grab;
  box-sizing: border-box;
  border: 1px solid #444;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 55px; 
  margin: 0 auto; 
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
  transition: border-color 0.1s, box-shadow 0.1s;
  
  /* 画像カードを直接触っても縦スクロールを優先する */
  touch-action: pan-y; 
}
.img-card:active { cursor: grabbing; box-shadow: 0 2px 4px rgba(0,0,0,0.4); }
.img-card.is-hidden { display: none !important; }

.img-card.selected-card {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px #3b82f6;
  background: rgba(59, 130, 246, 0.2);
}

.img-wrapper {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.img-card img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 2px;
  pointer-events: none;
}

.img-info {
  font-size: 0.6rem;
  font-weight: bold;
  color: #aaa;
  text-align: center;
  width: 100%;
  border-top: 1px solid #444;
  padding-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ghost { opacity: 0.2; background: rgba(59, 130, 246, 0.2); border: 2px dashed #3b82f6; }
#loading-message { grid-column: 1 / -1; text-align: center; color: #aaa; padding: 20px; font-size: 0.9rem; }
a { color: #4dabf7; }

/* === スマホ用のレイアウト === */
@media (max-width: 1000px) {
  body { overflow: auto; height: auto; }
  
  .main-container {
    display: grid;
    grid-template-columns: 1fr 1fr; 
    grid-template-rows: auto auto; 
    gap: 6px;
    padding: 6px;
    width: 100vw;
    height: auto;   
    min-height: 100vh;
  }

  .panel { height: auto; padding: 6px; }
  
  /* ★重要変更：スマホ版では基本のスクロール領域を「無効化」し、中の要素だけに任せる */
  .scrollable-zone { overflow: visible !important; flex: auto; }

  .info-side {
    grid-column: 1 / 3;
    grid-row: 1;
    width: 100%;
    max-height: 40vh; 
    overflow-y: auto; 
  }
  
  .info-images-layout {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: hidden;
    width: 100%;
    gap: 5px !important;
    margin: 0;
    padding: 0;
    line-height: 0;
    align-items: flex-start;
  }

  .info-img-card {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    max-width: none;
    height: auto;
    border: none;
    padding: 0 !important;
    margin: 0 !important;
    min-height: 0 !important;
    line-height: 0;
    display: block;
  }

  .info-img-card img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
    margin: 0;
    padding: 0;
  }

  .info-description-box { 
    font-size: 0.7rem; 
    padding: 6px; 
    min-height: 60px;
    margin-top: 5px; 
  }

  .left-side { grid-column: 1; grid-row: 2; width: 100%; }
  .right-side { grid-column: 2; grid-row: 2; width: 100%; }

  h2.panel-title { font-size: 0.8rem; }
  .global-reset-btn { padding: 4px; font-size: 0.65rem; }
  .panel-header { margin-bottom: 6px; padding-bottom: 4px; }
  .control-panel { padding: 4px; gap: 6px; margin-bottom: 6px; }
  
  .attr-group { display: flex; flex-wrap: nowrap; width: 100%; gap: 4px; }
  .attr-group span { font-size: 0.6rem; white-space: nowrap; }
  .attr-btn-group { display: flex; flex-wrap: nowrap; flex: 1; gap: 2px; width: 100%; }
  .attr-btn { flex: 1; padding: 4px 0; font-size: 0.6rem; min-width: 0; text-align: center; white-space: nowrap; }

  select, .sort-btn { padding: 2px 4px; font-size: 0.65rem; }
  .flex-controls { gap: 4px; }
  .control-item { font-size: 0.7rem; gap: 2px; }
  .control-item label { display: none; } 
  #sort-rank-toggle { width: 70px; }

  .grid-layout { grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 4px; max-height: 120px; overflow-y: auto; }
  
  .pool-layout { 
    grid-template-columns: repeat(3, 1fr); 
    gap: 4px; 
    padding: 4px; 
    height: 200px; 
    flex: none; 
    overflow-y: auto; 
  }
  
  /* ★重要変更：右側の外枠は「スクロールしない（visible）」設定にして入れ子を解消 */
  .right-side .scrollable-zone {
    display: block; 
    max-height: none !important; 
    overflow-y: visible !important; 
    border-bottom: 1px solid #444; 
    padding-bottom: 4px;
    margin-bottom: 4px;
  }

  .img-card { max-width: 100%; }
  .img-info { display: none !important; }

  .description-box { margin-top: 2px; padding: 6px; font-size: 0.7rem; height: 70px; overflow-y: auto; }
  
  .team-box { padding: 6px; margin-bottom: 6px; }
  .team-header { margin-bottom: 4px; }
  .team-title { font-size: 0.75rem; }
  .new-team-zone { padding: 6px; min-height: 35px; font-size: 0.7rem; margin-top: 5px; }

/* === 画像書き出しボタン（コンパクト・左揃え） === */
.export-btn {
  background-color: #10b981;
  color: white;
  border: none;
  padding: 6px 12px;     /* パディングを少し小さくしてコンパクトに */
  font-size: 0.8rem;     /* フォントサイズを少し小さく */
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;

  /* === コンパクト＆左揃えの設定 === */
  width: fit-content;    /* 内容物の幅に合わせる（これがコンパクトの秘訣） */
  margin: 0;             /* 余白を消す */
  margin-bottom: 10px;   /* 下に少しだけ空ける */
  flex-grow: 0;          /* 横に広がらないように固定 */
}

.export-btn:hover { 
  background-color: #059669; 
}

}