/* ==========================================================================
   1. グローバルリセットと基本スタイル
   ========================================================================== */
* {
  box-sizing: border-box; /* 枠線を含めた計算でズレを防止 */
  color: #eeeeee;
  font-size: 16px;
}

body {
  background: #4a4842;
  font-family: sans-serif;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

img {
  pointer-events: none; /* 画像のドラッグ防止（全体共通） */
}

/* ==========================================================================
   2. レイアウト構造
   ========================================================================== */
.container {
  display: flex;
  align-items: stretch;
  height: 100vh;
}

.left, .right {
  padding: 8px;
  display: flex;
  flex-direction: column;
}

.left {
  width: 50%;
  border-right: 1px solid #3a3430;
}

.right {
  width: 50%;
}

/* ==========================================================================
   3. ヘッダーとパネル（検索と設定）
   ========================================================================== */
.search-panel, .settings {
  padding: 0px 8px 8px 8px;
  background: #3b3732;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end; /* 中身を下側に強制的に寄せる */
  min-height: 88px;
  flex-shrink: 0;
}

.search-input-group { 
  display: flex;
  gap: 8px;
  align-items: flex-end; /* 子要素の下端を一直線に */
  margin-top: 4px;
}

#searchInput {
  flex: 1;
  height: 36px;
  padding: 0 12px;
  background: #5a5852;
  color: #f5f3f0;
  border: 1px solid #6c6a64;
  border-radius: 4px;
  outline: none;
}

select, .setting input[type="number"] {
  height: 36px;
  width: 110px;
  padding: 0 8px;
  background: #5a5852;
  color: #f5f3f0;
  border: 1px solid #6c6a64;
  border-radius: 4px;
  outline: none;
}

select {
  cursor: pointer;
}

/* 単位を表示するためのラッパー */
.input-wrapper {
  position: relative;
  width: 110px;
}

.setting .input-wrapper input[type="number"] {
  width: 100%;
  padding-right: 28px; /* 単位が被らないように右余白を確保 */
}

.input-wrapper::after {
  content: attr(data-unit);
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  font-size: 16px;
  pointer-events: none;
  z-index: 1;
}

#searchBtn, #generateBtn, #clearBtn, #uploadBtn {
  width: 100px;
  height: 36px;
  padding: 0 16px;
  color: #ffffff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
  box-shadow: 0 2px 4px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: all 0.1s ease;
  border: 1px solid #1a1a1a;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
}

#searchBtn { background: linear-gradient(to bottom, #3a4b5b, #1e2b37); }
#generateBtn { background: linear-gradient(to bottom, #7d5a2a, #4e3516); }
#uploadBtn { background: linear-gradient(to bottom, #4a6b3a, #2e4424); }
#clearBtn { background: linear-gradient(to bottom, #8b0000, #500000); }

#searchBtn:hover, #generateBtn:hover, #clearBtn:hover, #uploadBtn:hover { filter: brightness(1.5); }
#searchBtn:active, #generateBtn:active, #clearBtn:active, #uploadBtn:active { transform: translate(1px, 1px); }

.settings {
  flex-direction: row;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 8px;
  flex-wrap: nowrap;
}

.setting {
  display: flex;
  flex-direction: column;
}

.setting label {
  margin-bottom: 8px;
  position: relative;
  top: -2px;
}

.toggle-row { 
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
  opacity: 0.9;
  align-items: center;
}

.toggle-row label {
  display: flex;
  align-items: center;
  position: relative;
  top: 2px;
}

#infoBtn {
  margin-left: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #888;
  background: transparent;
  color: #aaa;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  position: relative;
  top: 2px;
}
#infoBtn:hover { background: #555; color: #fff; border-color: #fff; }

.push-right {
  margin-left: auto;
}

.icon-link {
  display: block;
  width: 20px;
  height: 20px;
  margin-right: 6px;
  position: relative;
  top: 2px;
}

.icon-link img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid #888;
  transition: transform 0.2s;
}

.icon-link:hover img {
  transform: scale(1.1);
  border-color: #fff;
}

.generate-box {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#sizeInfo {
  position: relative;
  right: 2px;
}

.button-group {
  display: flex;
  gap: 8px;
}

/* ==========================================================================
   4. メインコンテンツエリア（結果とドロップゾーン）
   ========================================================================== */
.results, #dropArea {
  margin-top: 8px;
  background: #3b3732;
  border-radius: 8px;
  flex: 1; 
  overflow-y: auto;
}

.results {
	padding: 10px 0px 10px 10px;
}

#dropArea {
  background: #2a2824;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0px 8px;
  transition: all 0.2s;
}

/* ドラッグオーバー時の視覚効果 */
#dropArea.dragover {
  background: #3e3a32 !important;
  border-color: #ffd700 !important;
  box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.2);
}

/* ローディングスピナー */
.loader {
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-left-color: #ffd700;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  animation: spin 1s linear infinite;
  margin: 30px auto 10px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  text-align: center;
  color: #ffd700;
  font-size: 13px;
}

/* ==========================================================================
   5. カード要素（検索結果）
   ========================================================================== */
.card-item {
  display: inline-block;
  width: 100%; /* resultsの中では幅調整される */
  max-width: 220px;
  margin: 0px 10px 8px 0px;
  cursor: grab;
  position: relative;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  user-select: none; /* テキスト選択を無効にしてドラッグしやすく */
}

.card-item:active { cursor: grabbing; }

/* カード内の要素がドラッグイベントを遮断しないように徹底 */
.card-item * {
  pointer-events: none;
}

.card-item img {
  width: 100%;
  display: block;
}

.card-item.dragging {
  opacity: 0.5;
}

.card-overlay {
  position: absolute;
  left: 0; right: 0; bottom: 26px;
  padding: 4px 8px 0 8px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  pointer-events: none;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.card-overlay .name,
.card-overlay .set-name,
.card-overlay .size {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11px;
  line-height: 1.4;
}

.card-overlay .name {
  font-weight: bold;
  font-size: 12px;
}

.card-overlay .name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
}

.card-overlay .copy-btn {
  background: transparent;
  border: none;
  color: #ccc;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  transition: color 0.2s;
}

.card-overlay .copy-btn:hover {
  color: #fff;
}

.card-overlay .set-name {
  color: #ddd;
}

.card-overlay .size {
  color: #ccc;
}

.card-footer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 26px;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  padding: 0 8px;
  pointer-events: auto; /* フッター内の操作は許可 */
}

.card-link {
  color: #fff !important;
  text-decoration: none;
  font-weight: bold;
  padding-right: 8px;
  font-size: 12px;
  pointer-events: auto;
}

/* ==========================================================================
   6. キャンバス要素（プレビューと出力）
   ========================================================================== */
/* アートボード（出力画像のプレビュー領域） */
.artboard {
  background-color: #404040;
  background-image:
    linear-gradient(45deg, #505050 25%, transparent 25%, transparent 75%, #505050 75%, #505050),
    linear-gradient(45deg, #505050 25%, transparent 25%, transparent 75%, #505050 75%, #505050);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  border: 1px solid #777; /* 指定の細い実線 */
  display: grid;
  padding: 0;
  margin: 0;
  box-shadow: 0 0 15px rgba(0,0,0,0.5);
  transition: width 0.3s ease;
  min-height: 100px; /* 空の状態でも枠が見えるように */
}

/* ドロップエリアのドラッグオーバー反応 */
#dropArea.dragover {
  background: rgba(255, 215, 0, 0.1) !important;
  box-shadow: inset 0 0 30px rgba(0,0,0,0.5);
  border-color: #ffd700 !important;
}

.remove-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  background: rgba(255, 0, 0, 0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto !important;
  z-index: 10;
  font-size: 16px;
  font-weight: bold;
  opacity: 0.3;
}

.rotate-btn {
  position: absolute;
  top: 5px;
  background: rgba(0, 123, 255, 0.8);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto !important;
  z-index: 10;
  font-size: 14px;
  transition: background 0.2s;
  opacity: 0.3;
}

.rotate-l {
  left: 5px;
}

.rotate-r {
  left: 35px;
}

.grayscale-btn {
  position: absolute;
  top: 5px;
  left: 65px;
  background: rgba(80, 80, 80, 0.8);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto !important;
  z-index: 10;
  font-size: 14px;
  transition: background 0.2s;
  opacity: 0.3;
}

/* ドロップ後のカードスタイル */
.canvas-card {
  position: relative;
  line-height: 0; /* 画像下の余計な隙間を消す */
  cursor: grab;
  transition: transform 0.1s ease;
  user-select: none;
}

.canvas-card:hover .remove-btn,
.canvas-card:hover .rotate-btn,
.canvas-card:hover .grayscale-btn {
  opacity: 1;
}

.canvas-card:active {
  cursor: grabbing;
}

.canvas-card.moving {
  border: 2px solid #ffd700;
  border-radius: 4px;
}

.canvas-card img {
  width: 100%;
  display: block;
  border-radius: 0; /* 出力画像用なので角丸なし */
  pointer-events: none;
}

/* ドロップ位置のガイドバー */
.canvas-card.drop-target-left::before,
.canvas-card.drop-target-right::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4px;
  background: #ffd700;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.8);
  z-index: 100;
  pointer-events: none;
}
.canvas-card.drop-target-left::before { left: calc(var(--gap-size, 0px) * -0.5 - 2px); }
.canvas-card.drop-target-right::after { right: calc(var(--gap-size, 0px) * -0.5 - 2px); }

/* ==========================================================================
   7. UIコンポーネント（言語セレクタなど）
   ========================================================================== */
.langArea {
  display: flex;
  flex: 1; /* 残りの幅を埋める */
  margin-left: 8px;
  gap: 4px;
  overflow-x: auto; /* 横スクロール可能に */
  scrollbar-width: none; /* Firefox用スクロールバー非表示 */
  -ms-overflow-style: none; /* IE/Edge用 */
  align-items: center;
  pointer-events: auto;
}
/* Chrome/Safari用スクロールバー非表示 */
.langArea::-webkit-scrollbar {
  display: none;
}

.langBtn {
  background: #333;
  color: #ccc;
  border: 1px solid #555;
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 10px;
  cursor: pointer;
  min-width: 24px;
  text-align: center;
  flex-shrink: 0; /* 縮まないように */
  font-weight: bold;
  transition: all 0.1s;
  pointer-events: auto;
}

.langBtn:hover {
  background: #555;
  color: #fff;
}

.langBtn.active {
  background: #ffd700;
  color: #000;
  border-color: #ffd700;
}

/* ==========================================================================
   8. スクロールバーのカスタマイズ
   ========================================================================== */

/* スクロールバー全体の幅（細めに設定） */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

/* スクロールバーの通り道（背景） */
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

/* スクロールバーのつまみ（動く部分） */
::-webkit-scrollbar-thumb {
  background: #6b6659;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #8e8877;
}

/* Firefox用の設定 */
* {
  scrollbar-width: thin;
  scrollbar-color: #6b6659 transparent;
}

/* ==========================================================================
   9. モーダルスタイル
   ========================================================================== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  z-index: 2000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }

.modal-content {
  background: #3b3732;
  padding: 24px;
  border-radius: 8px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 4px 15px rgba(0,0,0,0.6);
  color: #eee;
  line-height: 1.5;
  font-size: 14px;
}
.modal-content h3 { margin-top: 0; color: #ffd700; }
.modal-content p { font-size: 13px; color: #ccc; }
.modal-content a { color: #ffd700; text-decoration: none; }
.modal-content a:hover { text-decoration: underline; }

#closeModalBtn {
  margin-top: 12px;
  width: auto;
  min-width: 80px;
  height: 36px;
  padding: 0 16px;
  background: #555;
  color: #fff;
  border: 1px solid #777;
  border-radius: 4px;
  cursor: pointer;
}
#closeModalBtn:hover { background: #666; }
