/* =========================================================
   shop.css
   ---------------------------------------------------------
   購買部パネル・タブ・アイテムカード・ツールチップ・
   セクション見出し・統計行・実績行・フッターボタン
   ========================================================= */

/* ── ショップ全体パネル ── */
.shop {
  width: 456px; /* 380pxの約20%増し */
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.9);
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── タブ ── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  flex-wrap: nowrap;        /* タブは折り返しさせない */
}

.tab-btn {
  flex: 1;
  padding: 8px 4px;
  min-height: 44px;
  min-width: 0;             /* flex item が収縮できるよう明示 */
  background: transparent;
  border: 2px solid #4b8bea;
  color: #2c5f8d;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  font-weight: bold;
  font-size: clamp(0.65rem, 2.5vw, 0.85rem);  /* 幅が狭くても折り返さない */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s;
}

.tab-btn.active {
  background: #e8f0ff;
  color: #2c5f8d;
  border-color: #ff6578;
}

/* ── アイテムリスト / カード ── */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 44px;
  background: #fafafa;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.item:hover {
  border-color: #4b8bea;
  box-shadow: 0 2px 8px rgba(75, 139, 234, 0.15);
  transform: translateY(-1px);
}

.item.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.item.disabled:hover {
  border-color: #e0e0e0;
  box-shadow: none;
  transform: none;
}

/* サポートキャラ「ルート」の効果：最も費用対効果の高いレベルアップ先を強調表示 */
.item.best-value {
  border-color: #ffb340;
  box-shadow: 0 0 0 2px rgba(255, 179, 64, 0.35);
}

/* ── 購入演出：購入が成立した瞬間だけカードを一瞬光らせる ── */
@keyframes itemPurchaseFlash {
  0%   { box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.55); background-color: #eafff1; }
  100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); background-color: #fafafa; }
}

.item.purchase-flash {
  animation: itemPurchaseFlash 0.4s ease-out;
}

.item.locked-summary,
.item.owned-summary {
  cursor: default;
  justify-content: center;
  color: #999;
  font-size: 0.85rem;
}

.item.locked-summary:hover,
.item.owned-summary:hover {
  border-color: #e0e0e0;
  box-shadow: none;
  transform: none;
}

.item-icon {
  font-size: 1.6rem;
  margin-right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-icon-image {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  background: white;
}

.item-main { flex: 1; min-width: 0; }

.item-name {
  font-weight: bold;
  font-size: 0.95rem;
  color: #2c2c2c;
}

.item-production {
  font-size: 0.72rem;
  color: #5b8dd6;
  font-weight: 600;
  margin: 1px 0;
  /* 数値が大きくなって折り返すとカードの縦幅が変わり、後続の項目の
     表示位置がズレてしまうため、常に1行に収まるよう省略表示にする */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-desc {
  font-size: 0.75rem;
  color: #999;
}

.item-cost {
  font-size: 0.85rem;
  color: #ff6578;
  white-space: nowrap;
  font-weight: bold;
  margin-left: 8px;         /* アイコンとコストが密着しないよう余白 */
  flex-shrink: 0;
}

.item-owned {
  background: transparent;
  color: #ff6578;
  font-weight: bold;
  font-size: 0.8rem;
  border: 1px solid #ff6578;
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: 8px;
}

/* ── 強化アイテム欄：横スクロールの固定サイズカード ──
   購入・自動購入でアイテムが増減してもキャラクター欄（下）の表示
   位置がズレないよう、縦には積まず、常に2枚分の幅を確保した
   固定サイズのカードを横並びにする。3枚目以降は横スクロールで見る。 */
#upgradeList {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 8px;
  height: 188px; /* 説明文を3行まで表示できるよう高さを確保 */
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  padding-bottom: 6px; /* スクロールバー分の余白 */
  /* overflow-x を auto ではなく scroll にして、アイテム数に関わらず
     常にスクロールバー分の高さを確保しておく。auto だと3枚目以降が
     現れてスクロールバーが出た瞬間だけカード内の使える高さが減り、
     align-items:stretch で縮んだカードの説明文が overflow:hidden で
     途中から見えなくなってしまうため。 */
  overflow-x: scroll;
}

#upgradeList .item {
  flex: 0 0 calc(50% - 4px); /* gapの半分を差し引き、ちょうど2枚分の幅にする */
  scroll-snap-align: start;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  gap: 4px;
  min-height: 0;
  overflow: hidden;
}

#upgradeList .item-icon { margin-right: 0; }
#upgradeList .item-main { width: 100%; }

/* 名前・説明はどちらも行数が伸びるとカード高さがブレるので、
   行数を固定し、それ以上は省略表示にする */
#upgradeList .item-name {
  font-size: 0.82rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#upgradeList .item-desc {
  font-size: 0.7rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#upgradeList .item-cost {
  font-size: 0.8rem;
  margin-left: 0;
  margin-top: auto;
}

#upgradeList .item.locked-summary,
#upgradeList .item.owned-summary {
  flex: 0 0 calc(50% - 4px);
  justify-content: center;
}

/* 「強化可能なキャラクターはいません」の単独メッセージ用（.itemではない） */
#upgradeList > .item-desc {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  margin: 0;
}

/* ── ツールチップ ── */
.item-tooltip {
  display: none;
  position: fixed;
  z-index: 999;
  min-width: 200px;
  max-width: min(260px, 80vw);
  background: #2c2c2c;
  color: #f5f5f5;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.8rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

.item-tooltip .tooltip-title {
  font-weight: bold;
  font-size: 0.85rem;
  color: #ffd166;
  margin-bottom: 6px;
}

.item-tooltip .tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
  color: #ddd;
}

.item-tooltip .tooltip-row.tooltip-highlight {
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  margin-top: 4px;
  padding-top: 5px;
  color: #7bffb0;
  font-weight: bold;
}

.item-tooltip .tooltip-row.tooltip-efficiency {
  color: #8ec5ff;
  font-size: 0.75rem;
  padding-top: 3px;
}

.item-tooltip .tooltip-row.tooltip-wait {
  color: #ffb35c;
  font-size: 0.75rem;
  padding-top: 3px;
}

.item-tooltip .tooltip-row.tooltip-unaffordable {
  color: #ff8fa0;
  font-size: 0.75rem;
  padding-top: 3px;
}

.item-tooltip .tooltip-note {
  margin-top: 6px;
  color: #999;
  font-size: 0.7rem;
}

/* ── フッターボタン（保存・リセット・全データ削除）── */
.footer-buttons {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.footer-buttons button {
  flex: 1;
  padding: 10px 8px;
  min-height: 44px;
  border: 2px solid #4b8bea;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s;
}

.footer-buttons button:active { transform: scale(0.95); }

.btn-save {
  background: transparent;
  color: #4b8bea;
}
.btn-save:hover { background: rgba(75, 139, 234, 0.1); }

.btn-reset {
  background: transparent;
  color: #ff6578;
  border-color: #ff6578;
}
.btn-reset:hover { background: rgba(255, 101, 120, 0.1); }

.save-status {
  font-size: 0.8rem;
  color: #999;
  margin-top: 8px;
  text-align: center;
}
.save-status.saved { color: #5ad864; }

/* ── セクション見出し（折りたたみ対応）── */
.section-label {
  font-size: 0.85rem;
  font-weight: bold;
  color: #2c5f8d;
  margin: 14px 0 8px;
  padding-bottom: 4px;
  border-bottom: 2px solid #4b8bea;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* buyModeToggle・autoGeneratorToggleWrapをまとめて右端に寄せるラッパー */
.section-label-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

#buyModeToggle {
  display: inline-flex;
  gap: 4px;
}

#autoGeneratorToggleWrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.buy-mode-btn {
  font-size: 0.75rem;
  font-weight: bold;
  padding: 2px 10px;
  border: 1.5px solid #4b8bea;
  border-radius: 999px;
  background: transparent;
  color: #4b8bea;
  cursor: pointer;
  touch-action: manipulation;
  line-height: 1.6;
  transition: background 0.12s, color 0.12s;
}

.buy-mode-btn.active {
  background: #4b8bea;
  color: #fff;
}

/* ── 自動購入トグルスイッチ ── */
#autoUpgradeToggleWrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.toggle-label {
  font-size: 0.75rem;
  font-weight: bold;
  color: #4b8bea;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: #4b8bea;
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

.section-label:first-child { margin-top: 0; }

.section-label.collapsible {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.section-label.collapsible .section-label-text { flex: 1; }

/* .section-rate と .section-toggle-text は同じ「バッジ」スタイルをまとめて定義 */
.section-label.collapsible .section-rate,
.section-label.collapsible .section-toggle-text {
  font-size: 0.72rem;
  font-weight: bold;
  color: #4b8bea;
  background: #e8f0ff;
  border-radius: 10px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.section-label.collapsible .section-toggle-arrow {
  font-size: 0.75rem;
  color: #4b8bea;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.section-label.collapsible.collapsed .section-toggle-arrow {
  transform: rotate(-90deg);
}

.item-list.collapsed,
.collapsible-content.collapsed {
  display: none;
}

/* ── 統計行 ── */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fafafa;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  /* stat-label が長くても overflow しないよう最小幅を制限 */
  min-width: 0;
}

/* ── 統計グループ ── */
.stat-group {
  background: #fafafa;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
}

.stat-group-header {
  background: #eef3fb;
  border-bottom: 1px solid #d0dff5;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: bold;
  color: #4b8bea;
  letter-spacing: 0.03em;
}

.stat-table {
  width: 100%;
  border-collapse: collapse;
}

.stat-table tr + tr td {
  border-top: 1px solid #ebebeb;
}

.stat-table td {
  padding: 8px 12px;
  vertical-align: middle;
}

.stat-label {
  font-size: 0.85rem;
  color: #2c2c2c;
  font-weight: bold;
  min-width: 0;
  flex: 1;
  padding-right: 8px;
  overflow-wrap: break-word;
  width: 100%;
}

.stat-value {
  font-size: 0.85rem;
  font-weight: bold;
  color: #4b8bea;
  white-space: nowrap;
  flex-shrink: 0;
  text-align: right;
}

.achievement-bonus-row {
  background: #fff8e1;
  border-color: #ffd54f;
}

.achievement-bonus-text { color: #e07b00; }

/* ── 実績トースト通知 ── */
.achievement-toast-container {
  position: fixed;
  top: calc(24px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  width: min(92vw, 420px);
  pointer-events: none;
}

.achievement-toast {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: #2c5f8d;
  color: #ffffff;
  padding: 12px 20px;
  border-radius: 8px;
  border-left: 4px solid #ff6578;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  font-weight: bold;
  animation: toastInOut 3.5s ease forwards;
}

.achievement-toast .toast-icon  { font-size: 1.5rem; }
.achievement-toast .toast-label { font-size: 0.7rem; opacity: 0.75; }
.achievement-toast .toast-name  { font-size: 1rem; }

@keyframes toastInOut {
  0%   { opacity: 0; transform: translateY(-20px); }
  10%  { opacity: 1; transform: translateY(0); }
  85%  { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-20px); }
}

/* ── 実績リスト行 ── */
.achievement-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff9f0;
  border: 2px solid #ffd0c0;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.achievement-row .item-icon { font-size: 1.6rem; }

.achievement-info { flex: 1; min-width: 0; }

.achievement-title {
  font-weight: bold;
  color: #2c2c2c;
  overflow-wrap: break-word;
}

.achievement-desc {
  font-size: 0.75rem;
  color: #999;
}

.achievement-time {
  font-size: 0.7rem;
  color: #d98a5f;
  margin-top: 2px;
}

.achievement-unlocked {
  color: #ff6578;
  font-size: 0.8rem;
  font-weight: bold;
  white-space: nowrap;
  flex-shrink: 0;
}
