/* ============================
   ここに共通部（PC/スマホ共通の基本）
   ============================ */

/* 変数（色・余白は必要に応じて調整） */
:root{
  --modal-header-bg: #003163;     /* タイトル帯の背景 */
  --modal-header-fg: #fff;     /* タイトルの文字色（白抜き） */
  --modal-accent-dot: #fc864c; /* カテゴリの先頭ドット＆現在地の色 */
  --modal-pad-x: 18px;         /* ダイアログ内 右左パディング */
  --modal-pad-y: 16px;         /* ダイアログ内 上下パディング */

  --modal-x-size: 36px;        /* 閉じるボタンのタップ領域（直径） */
  --modal-x-thick: 3px;        /* バッテン線の太さ */

  --modal-v-gap: 6vh;          /* （PC）上下の対称余白 */
  --modal-mobile-gap: 0px;    /* （スマホ）四辺の外余白 12〜18pxで調整 */
}

body.modal-open { overflow: hidden; }

.sr-only{
  position:absolute!important;width:1px;height:1px;padding:0;margin:-1px;
  overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;
}

/* オーバーレイ本体（display:noneは使わず、opacity/visibilityでフェード） */
.modal-overlay{
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .22s ease, visibility 0s linear .22s;
  z-index: 10000;
}
.modal-overlay.show{
  opacity: 1; visibility: visible; pointer-events: auto;
  transition: opacity .22s ease;
}

/* ダイアログ（基本。PC/スマホで上書きあり） */
.modal-dialog{
  background:#fff;
  max-width: 720px; width: 92%;
  margin: 5vh auto;
  padding: var(--modal-pad-y) var(--modal-pad-x);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  max-height: 90vh; overflow: auto;
  position: relative;

  /* じわっと（少し下から） */
  transform: translateY(8px);
  opacity: .98;
  transition: transform .22s ease, opacity .22s ease;
  will-change: transform, opacity;
}
.modal-overlay.show .modal-dialog{
  transform: translateY(0);
  opacity: 1;
}

/* タイトル帯（背景つき／白抜き） */
.modal-title{
  display:block;
  color: var(--modal-header-fg);
  background: var(--modal-header-bg);
  margin: calc(-1 * var(--modal-pad-y)) calc(-1 * var(--modal-pad-x)) .6em;
  padding: 15px var(--modal-pad-x);
  border-radius: 0px 0px 0 0;
  font-size: 1.15em;
}

/* 閉じるボタン：枠なし・白い太いX（疑似要素） */
.modal-close{
  position:absolute; right:12px; top:10px; z-index:2;
  width:var(--modal-x-size); height:var(--modal-x-size);
  border:0; border-radius:50%;
  background:transparent;
  display:inline-block;
  cursor:pointer;
  color:transparent; font-size:0; line-height:0;
  outline:none; -webkit-tap-highlight-color: transparent;
}
.modal-close::before,
.modal-close::after{
  content:"";
  position:absolute; left:50%; top:50%;
  width:62%; height:var(--modal-x-thick);
  background:#fff;               /* いつも白 */
  border-radius:2px;
  transform: translate(-50%, -50%) rotate(45deg);
  transition: transform .22s ease;
}
.modal-close::after{
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* リスト（カテゴリ） */
.modal-list{
  max-height: 65vh; overflow:auto;
  border-top:0px solid #eee; margin-top:0em;
}
.modal-grid{
  list-style:none; margin:0; padding:.4em 0;
  display:grid; grid-template-columns:repeat(auto-fill, minmax(160px, 1fr));
  grid-row-gap:.2em; grid-column-gap:12px;
  justify-items: start;                 /* ← 左寄せ */
}
.modal-grid li{ margin:0; padding:.1em 0; justify-self: start; }
.modal-grid a{
  display:block;                        /* ← テキスト幅いっぱいで左寄せ安定 */
  padding:.2em .2em .2em 1em;          /* ドット分の左インデント */
  text-decoration:none;
  border-bottom:1px dotted transparent;
  text-align:left;                      /* ← 念のため左寄せ */
  color: inherit;
  position: relative;
}
.modal-grid a:hover{ border-bottom-color:#aaa; }
/* 先頭の小丸（#fc864c） */
.modal-grid a::before{
  content: "";
  position: absolute;
  left: 0;
  top: 0.85em;                           /* ベースラインに合わせ微調整 */
  transform: translateY(-50%);
  width: 6px; height: 6px;
  background: var(--modal-accent-dot);
  border-radius: 50%;
}
/* 現在地：テキストもオレンジ＋太字 */
.modal-grid a.current{
  color: var(--modal-accent-dot);
  font-weight: 700;
}

/* 動きを好まない設定 */
@media (prefers-reduced-motion: reduce){
  .modal-overlay, .modal-dialog{ transition: none !important; }
}

/* ============================
   @media only screen and (max-width: 480px)
   スマホ表示
   ============================ */
@media only screen and (max-width: 480px) {

  /* スマホ専用UIの表示切替（必要に応じて） */
  .mobile-only { display: block; }

  /* モーダルを全画面“風”にしつつ四辺に余白を確保 */
  .modal--picker .modal-dialog{
    width: calc(100vw - (var(--modal-mobile-gap) * 2));
    max-width: none;
    height: auto;
    max-height: calc(100vh - (var(--modal-mobile-gap) * 2));
    margin: var(--modal-mobile-gap) auto; /* 上下左右に同じ外余白 */
    border-radius: 12px;
    overflow: hidden;                     /* 内側のみスクロールへ */
    padding: var(--modal-pad-y) var(--modal-pad-x);
    display:flex; flex-direction:column;
  }
  .modal--picker .modal-title{
    margin: calc(-1 * var(--modal-pad-y)) calc(-1 * var(--modal-pad-x)) .6em;
  }
  .modal--picker .modal-list{
    flex: 1 1 auto;
    overflow: auto;
    max-height: none;                     /* 二重制限を避ける */
    border-top: 1px solid #eee;
    margin-top: .6em;
  }
  .modal--picker .modal-close{
    right: 12px;
    top: 12px;
  }

  /* 狭幅ではグリッドの最小幅を小さく */
  .modal-grid{
    grid-template-columns:repeat(auto-fill, minmax(130px, 1fr));
  }

}/*//end  max-width: 480px ///////////////////////*/


/* ============================
   @media only screen and (min-width: 481px)
   PC表示
   ============================ */
@media only screen and (min-width: 481px) {

  /* （任意）スマホ専用UIの非表示 */
  .mobile-only { display: none; }

  /* オーバーレイをflex中央揃えにして上下対称余白をpaddingで確保 */
  .modal-overlay{
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--modal-v-gap) 0;                 /* 上下対称 */
  }
  /* ダイアログ側はmargin 0にして、overlayのpaddingに委ねる */
  .modal-dialog{
    margin: 0;
    max-height: calc(100vh - (var(--modal-v-gap) * 2));
    overflow: auto;
  }
  /* 内側のリストは高さ制限を解除（外側でスクロール） */
  .modal-list{ max-height: none; }

}/*//end  min-width: 481px ///////////////////////*/



/* ====== SPだけの上書き ====== */
@media (max-width: 480px){

  /* 1) タイトル直下の細い線を消す
     （.modal-list に付けていた border-top をOFF） */
  .modal--picker .modal-list{
    border-top: none;
  }

  /* 2) スクロールバー右の白い帯（余白）を無くす
     右側だけスクロール領域を外側へ広げ、内側に同量パディングで帳尻合わせ */
  .modal--picker .modal-list{
    margin-right: calc(-1 * var(--modal-pad-x));
    padding-right: var(--modal-pad-x);
    /* あればレイアウト揺れ防止。対応ブラウザのみ効く */
    scrollbar-gutter: stable both-edges;
  }

  /* 3) 下部の角のアールを無くす（上は丸、下は角） */
  .modal--picker .modal-dialog{
    border-radius: 12px 12px 0 0;  /* ← 全部角にしたいなら 0 に */
  }

  /* （保険）iOSでまれに出る“1pxヘアライン”対策 */
  .modal--picker .modal-title{
    transform: translateZ(0);            /* 合成レイヤー化で継ぎ目を消す */
    /* それでも出る場合は、下線を同色で塗りつぶす裏ワザ：
       box-shadow: inset 0 -1px 0 var(--modal-header-bg); */
  }
}


@media (max-width:480px){
  /* 1) iOSでスクロールを滑らかに */
  .modal--picker .modal-list{ -webkit-overflow-scrolling: touch; }

  /* 2) 背景へのスクロール連鎖＆引っ張り更新を抑制 */
  .modal-overlay{ overscroll-behavior: contain; }

  /* 3) iOSの動的ビューポート＆セーフエリアにフィット */
  .modal--picker .modal-dialog{
    max-height: calc(100dvh - (var(--modal-mobile-gap) * 2));
    padding-bottom: calc(var(--modal-pad-y) + env(safe-area-inset-bottom));
  }
}


/* ============================
   和本カテゴリーモーダルだけ 2列（PCのみ）
   ※ モーダルのラッパーIDを #wahonCatModal とする想定
   ============================ */
@media only screen and (min-width: 481px){
  #wahonCatModal .modal-grid{
    /* 既存のgridをそのまま2列固定に */
    grid-template-columns: 1fr 1fr !important;
    grid-column-gap: 16px;   /* 列間 */
    grid-row-gap: .2em;      /* 行間（既定と同じ） */
  }
  /* 長いタイトルの可読性強化（任意） */
  #wahonCatModal .modal-grid a{
    line-height: 1.5;
    word-break: break-word;        /* 英文の長語切り */
    overflow-wrap: anywhere;       /* どこでも折り許可（ブラウザ対応広め） */
  }
}


