/* ==========================================================
   商品詳細 product_detail.php

   構成
     1. 色の定義・全体
     2. 画像ギャラリー
     3. 商品名・価格・説明
     4. 種類・サイズの選択
     5. 数量・カートに入れる
     6. モーダル（カートに追加しました）
     7. 商品説明の文字装飾（[red]…[/red] など）
     8. 幅が狭い時の表示（768px以下）
========================================================== */


/* ==========================================================
   1. 色の定義・全体
   （style.css の変数を使い、無ければ同じ色を直接指定）
========================================================== */
.pd-container {
  --pd-green: var(--color-green-deep, #234d30);
  --pd-green-ink: var(--color-green-ink, #1a3c24);
  --pd-gold: var(--color-gold, #d4a017);
  --pd-gold-dark: var(--color-gold-dark, #b68e12);
  --pd-text: var(--color-text, #2e2a26);
  --pd-sub: #6b6257;     /* 補足の文字色 */
  --pd-paper: #fcfaf5;   /* 生成り */
  --pd-line: #dcd4c5;    /* 罫線 */
  --pd-shu: #b23a2e;     /* 朱（残りわずか・注意） */

  min-width: 0;
  padding: 24px 24px 40px;
  box-sizing: border-box;
  color: var(--pd-text);
  line-height: 1.7;
}

.pd-back {
  display: inline-block;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--pd-green);
  text-underline-offset: 3px;
}

.pd-back:hover {
  color: var(--pd-gold-dark);
}

/* 画像を上、商品情報を下に置く（縦並び） */
.pd-layout {
  display: block;
}


/* ==========================================================
   2. 画像ギャラリー
========================================================== */
/* 画像は最大600pxで、中央に置く */
.pd-gallery {
  width: 100%;
  max-width: 600px;
  margin: 0 auto 30px;
}

/* メイン画像（正方形の枠の中で、JSが画像を横に動かす） */
.pd-slider-frame {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 1px solid var(--pd-line);
  border-radius: 6px;
  background: #fff;
}

.pd-slider {
  position: relative;
  width: 100%;
  height: 100%;
}

.pd-slider img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover; /* 枠いっぱいに表示する */
}

/* 前へ / 次へ */
.pd-slider-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 45px;
  height: 45px;
  padding: 0;
  border: 1px solid var(--pd-line);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: var(--pd-green);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  z-index: 10;
}

.pd-slider-btn:hover {
  background: #fff;
  border-color: var(--pd-gold);
}

.pd-slider-btn.prev { left: 8px; }
.pd-slider-btn.next { right: 8px; }

/* サムネイル */
.pd-thumbs {
  display: flex;
  justify-content: safe center; /* 収まる時は中央、はみ出す時は左から並べて横スクロール */
  gap: 8px;
  margin-top: 12px;
  padding-bottom: 4px;
  overflow-x: auto;
}

.pd-thumbs .thumb {
  flex: 0 0 80px;
  width: 80px;
  height: 80px;
  box-sizing: border-box;
  object-fit: cover;
  border: 1px solid var(--pd-line);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  opacity: 0.7;
}

.pd-thumbs .thumb:hover {
  opacity: 1;
}

.pd-thumbs .thumb.active-thumb {
  border: 2px solid var(--pd-gold);
  opacity: 1;
}


/* ==========================================================
   3. 商品名・価格・説明
========================================================== */
.pd-info {
  min-width: 0;
}

.pd-code {
  margin: 0;
  font-size: 14px;
  color: var(--pd-sub);
}

.pd-title {
  margin: 0 0 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--pd-line);
  font-size: clamp(1.25rem, 1rem + 1.2vw, 1.75rem);
  line-height: 1.4;
  letter-spacing: 0.04em;
  color: var(--pd-green-ink);
}

/* 価格（サイズを選ぶと、JSがその価格に書き換える） */
.pd-price {
  margin: 0 0 16px;
  font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2rem);
  font-weight: bold;
  line-height: 1.3;
  color: var(--pd-green-ink);
  font-variant-numeric: tabular-nums;
}

.pd-description {
  margin: 0 0 24px;
  font-size: 16px;
  line-height: 1.9;
  overflow-wrap: anywhere;
}


/* ==========================================================
   4. 種類・サイズの選択
========================================================== */
.pd-form {
  padding: 18px 20px 22px;
  border: 1px solid var(--pd-line);
  border-radius: 6px;
  background: var(--pd-paper);
}

.pd-group {
  margin: 0 0 18px;
  padding: 0;
  border: none;
}

.pd-group-title {
  margin: 0 0 8px;
  padding: 0;
  font-size: 15px;
  font-weight: bold;
  color: var(--pd-green-ink);
}

/* 選択肢を札のように並べる（表示・非表示はJSが切り替える） */
.pd-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}

/* style.css に「#sizeContainer { display: none; }」が残っていても表示されるようにする */
#sizeContainer.pd-options {
  display: grid;
}

.pd-option {
  position: relative;
  display: block;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

/* ラジオボタン本体は隠し、キーボード操作は残す */
.pd-option input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.pd-option-body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  min-height: 48px;
  padding: 8px 6px;
  box-sizing: border-box;
  border: 1px solid #b9ae9b;
  border-radius: 6px;
  background: #fff;
  text-align: center;
}

.pd-option:hover .pd-option-body {
  border-color: var(--pd-green);
}

.pd-option input:checked + .pd-option-body {
  border-color: var(--pd-green);
  box-shadow: inset 0 0 0 1px var(--pd-green);
  background: var(--pd-green);
  color: #fff;
}

.pd-option input:focus-visible + .pd-option-body {
  outline: 3px solid var(--pd-gold);
  outline-offset: 2px;
}

.pd-option-name {
  font-size: 16px;
  font-weight: bold;
  line-height: 1.4;
}

.pd-option-price {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* 在庫の表示 */
.pd-option-stock {
  font-size: 12px;
  font-weight: bold;
}

.pd-option-stock.is-few {
  color: var(--pd-gold-dark);
}

.pd-option-stock.is-danger {
  color: var(--pd-shu);
}

/* 選択中は背景が緑なので、在庫の文字を白抜きにする */
.pd-option input:checked + .pd-option-body .pd-option-stock {
  color: #fff;
}

/* 売り切れ */
.pd-option.is-soldout {
  cursor: not-allowed;
}

.pd-option.is-soldout .pd-option-body,
.pd-option.is-soldout:hover .pd-option-body {
  border-color: var(--pd-line);
  background: #f1ede4;
  color: #8f877b;
}


/* ==========================================================
   5. 数量・カートに入れる
========================================================== */
.pd-qty-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

/* style.css の .qty-control を、このページ用に整える */
.pd-qty-row .qty-control {
  border-color: #b9ae9b;
  border-radius: 6px;
}

.pd-qty-row .qty-control:focus-within {
  border-color: var(--pd-green);
  outline: 2px solid var(--pd-gold);
  outline-offset: 1px;
}

.pd-qty-row .qty-control input[type="number"] {
  width: 56px;
  height: 44px;
  padding: 0;
  font-family: inherit;
  font-size: 17px;
  outline: none;
}

.pd-qty-row .qty-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  background: #fff;
  color: var(--pd-green);
  font-size: 20px;
  line-height: 44px;
  cursor: pointer;
}

.pd-qty-row .qty-btn:hover {
  background: #efe9dc;
}

.pd-qty-unit {
  font-size: 15px;
  color: var(--pd-sub);
}

/* JSが無効な時に、カート追加の結果を表示する */
.pd-flash {
  margin: 0 0 14px;
  padding: 10px 14px;
  border: 1px solid var(--pd-green);
  border-left-width: 4px;
  border-radius: 6px;
  background: #fff;
  font-weight: bold;
  color: var(--pd-green-ink);
}

.pd-flash.is-error {
  border-color: var(--pd-shu);
  color: var(--pd-shu);
}

.pd-submit {
  display: block;
  width: 100%;
  padding: 16px 12px;
  border: 2px solid var(--pd-gold);
  border-radius: 8px;
  background: var(--pd-green);
  color: #fff;
  font-family: inherit;
  font-size: 19px;
  font-weight: bold;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: background 0.2s;
}

.pd-submit:hover {
  background: var(--pd-green-ink);
}

.pd-submit:focus-visible,
.pd-slider-btn:focus-visible,
.pd-back:focus-visible,
.pd-qty-row .qty-btn:focus-visible {
  outline: 3px solid var(--pd-gold);
  outline-offset: 2px;
}


/* ==========================================================
   6. モーダル（カートに追加しました）
   ※ カート画面（style_cart.css）のモーダルと同じ見た目です
========================================================== */
.cart-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 9999;
}

.cart-modal.show {
  opacity: 1;
  pointer-events: auto;
}

.cart-modal-content {
  width: 90%;
  max-width: 360px;
  padding: 24px 20px 20px;
  box-sizing: border-box;
  border-top: 4px double #d4a017;
  border-radius: 0 0 8px 8px;
  background: #fff;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.cart-modal-message {
  margin: 0 0 18px;
  font-size: 16px;
  line-height: 1.7;
}

.cart-modal-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.modal-btn {
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: inherit;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
}

.modal-btn.confirm {
  background: #234d30;
  color: #fff;
}

.modal-btn.confirm:hover {
  background: #1a3c24;
}

.modal-btn.cancel,
.modal-btn.view-cart {
  border-color: #b9ae9b;
  background: #fff;
  color: #2e2a26;
}

.modal-btn.cancel:hover,
.modal-btn.view-cart:hover {
  background: #fcfaf5;
}


/* ==========================================================
   7. 商品説明の文字装飾（[red]…[/red] など）
========================================================== */
.text-red    { color: #b22222; } /* 落ち着いた赤 */
.text-blue   { color: #1e5aa8; } /* 藍色寄り */
.text-green  { color: #2f6b3f; } /* 深緑 */
.text-yellow { color: #9c7a00; } /* 山吹色 */
.text-orange { color: #c96a00; } /* 柿色 */
.text-purple { color: #6a3d9a; } /* 古代紫 */
.text-gray   { color: #666666; }

.pd-description strong {
  font-weight: 700;
}

.text-underline {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.text-small {
  font-size: 0.9em;
}

.text-large {
  font-size: 1.25em;
  font-weight: 600;
  line-height: 1.5;
}


/* ==========================================================
   8. 幅が狭い時の表示（768px以下）
========================================================== */
@media (max-width: 768px) {

  .pd-gallery {
    margin-bottom: 20px;
  }

  .pd-thumbs .thumb {
    flex-basis: 65px;
    width: 65px;
    height: 65px;
  }

  .pd-slider-btn {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
}

@media (max-width: 640px) {

  .pd-container {
    padding: 16px clamp(8px, 6.15vw - 15.4px, 24px) 28px;
  }

  .pd-form {
    padding: 14px 14px 18px;
  }

  .pd-options {
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  }

  .pd-submit {
    font-size: 17px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cart-modal,
  .pd-submit {
    transition: none;
  }
}