/* FF14 髪型一覧（ntg-hair）。色と寸法はサイトのデザイン（--ntg2-*）に寄せる。
 * 画像は透過 WebP。一覧は頭に寄せた 360x360、拡大は全身が切れない大きさ（全枚で同じ枠）。
 * 拡大表示は NettogeCore のインラインギャラリー（igl-lightbox）の操作にそろえ（← → / Esc / 下の帯）、
 * 正面と背面を並べる。絵の地はライトなら白、ダークなら濃いグレー（2026-09-23 依頼主）。 */

.ntg-hair {
  --h-bg: var(--ntg2-bg, #fff);
  --h-paper: var(--ntg2-paper, #f6f5f3);
  --h-paper-2: var(--ntg2-paper-2, #edeae6);
  --h-text: var(--ntg2-text, #1a1714);
  --h-sub: var(--ntg2-sub, #5f5a55);
  --h-muted: var(--ntg2-muted, #8a847d);
  --h-line: var(--ntg2-line, #e3e0dc);
  --h-line-2: var(--ntg2-line-2, #d3cec7);
  --h-accent: var(--ntg2-accent, #b72305);
  --h-teal: var(--ntg2-teal, #2f7a72);
  --h-teal-bg: var(--ntg2-teal-bg, #e8f2f0);
  --h-radius: var(--ntg2-radius, 6px);
  --h-radius-sm: var(--ntg2-radius-sm, 4px);
  /* 透過の絵を置く地: ライトは白、ダークは濃いグレー */
  --h-stage: #ffffff;
  --h-card-min: 150px;
  margin: 1.5em 0 2em;
  color: var(--h-text);
}

html[data-nettoge-theme="dark"] .ntg-hair,
html[data-nettoge-theme="dark"] .ntg-hlb {
  --h-stage: #2e3135;
}

/* ---------- 操作の帯 ---------- */
.ntg-hair__bar {
  position: sticky;
  /* ヘッダー（--swl-headerH）と、その下に出る「今読んでいる見出し」の帯（34px）の下で止める */
  top: calc(var(--swl-headerH, var(--ntg2-header-h, 64px)) + 38px);
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: color-mix(in srgb, var(--h-bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--h-line);
  border-radius: var(--h-radius);
}

@media (max-width: 959px) {
  .ntg-hair__bar { top: calc(var(--swl-headerH, var(--ntg2-header-h-sp, 56px)) + 38px); }
}

/* 性別・向き・絞り込み・検索・件数のまとまり。広い画面では帯の中にそのまま並べる（包みは無いものとして扱う） */
.ntg-hair__ctl { display: contents; }

.ntg-hair__seg {
  display: inline-flex;
  padding: 2px;
  background: var(--h-paper);
  border: 1px solid var(--h-line);
  border-radius: 999px;
}

.ntg-hair__seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--h-sub);
  font: inherit;
  font-size: 13.5px;
  line-height: 1;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}

.ntg-hair__seg button[aria-pressed="true"] {
  background: var(--h-bg);
  color: var(--h-text);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.ntg-hair__seg button:focus-visible,
.ntg-hair__search:focus-visible,
.ntg-hair__card:focus-visible {
  outline: 2px solid var(--h-teal);
  outline-offset: 2px;
}

.ntg-hair__seg .n {
  margin-left: 4px;
  font-size: 11.5px;
  color: var(--h-muted);
  font-weight: 400;
}

/* 本文の input の既定（明るい地）に負けないよう、ブロックの中から指す */
.ntg-hair .ntg-hair__bar input.ntg-hair__search {
  flex: 1 1 160px;
  min-width: 0;
  height: 34px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  color: var(--h-text);
  background: var(--h-bg);
  border: 1px solid var(--h-line-2);
  border-radius: 999px;
  box-shadow: none;
}

.ntg-hair__count {
  font-size: 12.5px;
  color: var(--h-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------- 一覧 ---------- */
.ntg-hair__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--h-card-min), 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ntg-hair__grid > li {
  margin: 0;
  padding: 0;
  /* 画面の外のカードは描画を後回しにする（105 枚でもスクロールが重くならない） */
  content-visibility: auto;
  contain-intrinsic-size: auto 200px;
}

.ntg-hair__grid > li::before { display: none !important; }
.ntg-hair__grid > li[hidden] { display: none; }

.ntg-hair__card {
  appearance: none;
  display: block;
  width: 100%;
  padding: 0;
  margin: 0;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--h-bg);
  border: 1px solid var(--h-line);
  border-radius: var(--h-radius);
  overflow: hidden;
  cursor: zoom-in;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.ntg-hair__card:hover {
  border-color: var(--h-line-2);
  box-shadow: var(--ntg2-shadow-float, 0 2px 10px rgba(0, 0, 0, 0.08));
}

.ntg-hair__pic {
  position: relative;
  display: block;
  aspect-ratio: 1 / 1;
  background: var(--h-stage);
  overflow: hidden;
}

.ntg-hair__pic img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: opacity 0.18s ease;
}

.ntg-hair__pic .is-alt { opacity: 0; }

/* マウスを乗せたら裏側（正面↔背面）を見せる。触る画面では出さない */
@media (hover: hover) {
  .ntg-hair__card:hover .has-alt .is-alt { opacity: 1; }
  .ntg-hair__card:hover .has-alt .is-main { opacity: 0; }
}

.ntg-hair__no {
  position: absolute;
  left: 6px;
  top: 6px;
  min-width: 30px;
  padding: 3px 7px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  color: #fff;
  background: rgba(26, 23, 20, 0.78);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.ntg-hair__icon {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 60px;
  height: 60px;
  border-radius: 8px;
  background-size: var(--h-sprite-size);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
}

/* アイコンの画像（105 個を 1 枚にまとめた物）は一覧が画面に近づいてから読む（hair-list.js が一覧の ul に is-live を付ける） */
.ntg-hair__grid.is-live .ntg-hair__icon { background-image: var(--h-sprite); }

.ntg-hair__cap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 8px;
  font-size: 12.5px;
  line-height: 1.35;
  border-top: 1px solid var(--h-line);
}

.ntg-hair__tag {
  flex: 0 0 auto;
  padding: 2px 6px;
  font-size: 11px;
  line-height: 1.3;
  border-radius: var(--h-radius-sm);
  color: var(--h-sub);
  background: var(--h-paper-2);
  white-space: nowrap;
}

.ntg-hair__tag.is-unlock {
  color: var(--h-teal);
  background: var(--h-teal-bg);
}

.ntg-hair__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--h-text);
}

.ntg-hair__empty {
  padding: 24px;
  text-align: center;
  color: var(--h-muted);
  border: 1px dashed var(--h-line-2);
  border-radius: var(--h-radius);
}

@media (max-width: 599px) {
  .ntg-hair { --h-card-min: 104px; }
  .ntg-hair__grid { gap: 6px; }
  .ntg-hair__cap { min-height: 32px; padding: 4px 6px; font-size: 11.5px; }
  .ntg-hair__cap .ntg-hair__name { display: none; }
  .ntg-hair__icon { width: 48px; height: 48px; border-radius: 6px; }
  .ntg-hair__no { font-size: 12px; min-width: 26px; padding: 3px 5px; }
  .ntg-hair__bar { padding: 8px; gap: 6px 8px; }
  /* スマホ: 画面に付いてくる帯を 2 段（種族／ほかの操作）に抑える。2 段目は横に流す */
  .ntg-hair__ctl {
    display: flex;
    flex: 1 1 100%;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .ntg-hair__ctl::-webkit-scrollbar { display: none; }
  .ntg-hair__ctl > * { flex: 0 0 auto; }
  .ntg-hair .ntg-hair__bar input.ntg-hair__search { flex: 0 0 150px; height: 32px; }
  .ntg-hair__seg button,
  .ntg-hair__races button { padding: 6px 9px; font-size: 12.5px; }
}

/* ---------- 拡大表示（ポップアップ） ---------- */
.ntg-hlb {
  --h-bg: var(--ntg2-bg, #fff);
  --h-text: var(--ntg2-text, #1a1714);
  --h-sub: var(--ntg2-sub, #5f5a55);
  --h-muted: var(--ntg2-muted, #8a847d);
  --h-line: var(--ntg2-line, #e3e0dc);
  --h-paper: var(--ntg2-paper, #f6f5f3);
  --h-ctl: color-mix(in srgb, var(--h-text) 7%, transparent);
  --h-ctl-hover: color-mix(in srgb, var(--h-text) 14%, transparent);
  --h-thumbs-h: 92px; /* 下の帯（アイコン 64px ＋余白） */
  /* 1 枚の幅: 横幅・高さのどちらにも収まる大きさ（最大 460px） */
  --h-fig-w: min(460px, calc((96vw - 168px) / 2), calc((92vh - var(--h-thumbs-h) - 40px) * var(--h-full-r, 1.086)));
  position: fixed;
  inset: 0;
  z-index: 1000000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2vh 2vw;
  background: rgba(10, 10, 12, 0.55);
  opacity: 0;
  transition: opacity 0.18s ease;
  overscroll-behavior: contain;
  touch-action: none; /* 指で触っても後ろのページを流さない（下の帯は自分で横に流れる: .ntg-hlb__thumbs） */
  /* ボタンを続けて押しても文字が選ばれない */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html[data-nettoge-theme="dark"] .ntg-hlb { background: rgba(0, 0, 0, 0.7); }
.ntg-hlb[hidden] { display: none; }
.ntg-hlb.is-show { opacity: 1; }

.ntg-hlb__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  max-height: 100%;
  color: var(--h-text);
  background: var(--h-bg);
  border: 1px solid var(--h-line);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  overflow: hidden;
  transform: translateY(8px) scale(0.985);
  transition: transform 0.18s ease;
}

.ntg-hlb.is-show .ntg-hlb__panel { transform: none; }

/* 用語カード（game-terms の吹き出し）は拡大表示より前に出す */
/* 拡大表示の間の後ろのページ: html の overflow は変えない（スクロールバーが消えて横にずれる）。
   ホイールとキーは hair-list.js、指は下の touch-action で止める。用語カードの端まで流しても後ろへ伝えない */
html.ntg-hlb-open #ntg-game-tooltip { overscroll-behavior: contain; }
html.ntg-hlb-open .ntg-game-tooltip { z-index: 1000002; }

.ntg-hlb__stage {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 14px 72px;
  touch-action: none; /* 左右のスワイプで送る（hair-list.js）。上下に動かしても後ろのページは流さない */
}

/* 番号と名前: 絵の上の空いた所に重ねる */
.ntg-hlb__info {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 160px);
  padding: 5px 16px 5px 5px;
  background: color-mix(in srgb, var(--h-bg) 88%, transparent);
  border: 1px solid var(--h-line);
  border-radius: 999px;
  box-shadow: var(--ntg2-shadow-float, 0 2px 10px rgba(0, 0, 0, 0.08));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  white-space: nowrap;
}

.ntg-hlb__icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background-image: var(--h-sprite);
  background-size: var(--h-sprite-size);
}

.ntg-hlb__no {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.ntg-hlb__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
  line-height: 1.4;
  color: var(--h-sub);
}

.ntg-hlb__fig {
  position: relative;
  flex: 0 0 auto;
  width: var(--h-fig-w);
  aspect-ratio: var(--h-full-ratio, 786 / 724);
  margin: 0;
  background: var(--h-stage);
  border: 1px solid var(--h-line);
  border-radius: var(--ntg2-radius, 6px);
  overflow: hidden;
}

.ntg-hlb__fig picture { display: contents; } /* AVIF と WebP の出し分けの包み。箱は作らない */

.ntg-hlb__fig img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: 50% 100%; /* 下そろえ（上は髪型ごとに詰めてある） */
  transition: opacity 0.12s ease;
  -webkit-user-drag: none;
}

.ntg-hlb__fig figcaption {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 3px 10px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--h-sub);
  background: color-mix(in srgb, var(--h-bg) 85%, transparent);
  border: 1px solid var(--h-line);
  border-radius: 999px;
  pointer-events: none;
}

.ntg-hlb__close,
.ntg-hlb__prev,
.ntg-hlb__next {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--h-text);
  background: var(--h-ctl);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation; /* 続けて押してもダブルタップの拡大にしない */
  transition: background-color 0.15s ease;
}

.ntg-hlb__close { top: 10px; right: 10px; width: 40px; height: 40px; }
.ntg-hlb__prev,
.ntg-hlb__next { top: 50%; width: 48px; height: 48px; margin-top: -24px; }
.ntg-hlb__prev { left: 12px; }
.ntg-hlb__next { right: 12px; }
.ntg-hlb__close:hover,
.ntg-hlb__prev:hover,
.ntg-hlb__next:hover { background: var(--h-ctl-hover); }
.ntg-hlb button:focus-visible { outline: 2px solid var(--ntg2-teal, #2f7a72); outline-offset: 2px; }
.ntg-hlb button svg { width: 24px; height: 24px; pointer-events: none; }

/* 下の帯: 髪型のアイコン（ゲームの美容室と同じ絵）。105 個を 1 枚にまとめた画像なので、読み込みは 1 回 */
.ntg-hlb__thumbs {
  position: relative; /* 中のアイコンの offsetLeft を帯からの位置にする（hair-list.js の markThumb） */
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  width: 0;
  min-width: 100%;
  height: var(--h-thumbs-h);
  box-sizing: border-box;
  padding: 10px 14px;
  overflow-x: auto;
  overflow-y: hidden;
  /* 指で流す: 慣性で流れ、端に着いても後ろのページや拡大表示を動かさない。止まるときはアイコンの中央に寄る */
  touch-action: pan-x;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  scroll-padding-inline: 14px;
  background: var(--h-paper);
  border-top: 1px solid var(--h-line);
  scrollbar-width: thin;
  scrollbar-color: var(--ntg2-line-2, #d3cec7) transparent;
}

/* 指で触る画面ではスクロールバーを出さない（帯の高さを取らない・指の邪魔をしない） */
@media (pointer: coarse) {
  .ntg-hlb__thumbs { scrollbar-width: none; }
  .ntg-hlb__thumbs::-webkit-scrollbar { display: none; }
}

.ntg-hlb__thumb {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background-color: transparent;
  background-image: var(--h-sprite);
  background-size: var(--h-sprite-size);
  background-origin: border-box;
  opacity: 0.7;
  cursor: pointer;
  touch-action: pan-x; /* 押しても流せる（帯と同じ）。ダブルタップの拡大もしない */
  scroll-snap-align: center;
  transition: opacity 0.15s ease, border-color 0.15s ease;
}

/* マウスのある画面だけ。指で触った後に明るいまま残らない */
@media (hover: hover) {
  .ntg-hlb__thumb:hover { opacity: 1; }
}
.ntg-hlb__thumb.is-active { opacity: 1; border-color: var(--ntg2-accent, #b72305); }

.ntg-hlb__thumb span {
  position: absolute;
  left: 2px;
  top: 2px;
  min-width: 18px;
  padding: 1px 4px;
  font-size: 10.5px;
  line-height: 1.3;
  text-align: center;
  color: #fff;
  background: rgba(26, 23, 20, 0.72);
  border-radius: 999px;
}

/* 狭い画面: 正面と背面を上下に並べる（横に並べると 1 枚が小さい）。送るボタンは下へ */
@media (max-width: 759px) {
  .ntg-hlb {
    --h-thumbs-h: 76px;
    /* 1 枚の幅: 画面の幅と、高さの半分（2 枚ぶん）のどちらにも収まる大きさ。dvh はスマホのアドレスバーを除いた高さ */
    --h-fig-w: min(calc(96vw - 18px), calc((92vh - var(--h-thumbs-h) - 80px) / 2 * var(--h-full-r, 1.086)));
    --h-fig-w: min(calc(96vw - 18px), calc((92dvh - var(--h-thumbs-h) - 80px) / 2 * var(--h-full-r, 1.086)));
  }
  .ntg-hlb__stage { flex-direction: column; align-items: center; padding: 8px 8px 58px; gap: 6px; }
  .ntg-hlb__info { top: 14px; left: 14px; transform: none; max-width: calc(100% - 70px); gap: 7px; padding: 3px 10px 3px 3px; }
  .ntg-hlb__icon { width: 30px; height: 30px; }
  .ntg-hlb__no { font-size: 15px; }
  .ntg-hlb__label { font-size: 12px; }
  .ntg-hlb__close { top: 12px; right: 12px; width: 36px; height: 36px; }
  .ntg-hlb__prev,
  .ntg-hlb__next { width: 42px; height: 42px; top: auto; bottom: 8px; margin-top: 0; }
  .ntg-hlb__prev { left: calc(50% - 52px); }
  .ntg-hlb__next { right: calc(50% - 52px); }
  .ntg-hlb__thumbs { padding: 8px 10px; }
  .ntg-hlb__thumb { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .ntg-hair__card, .ntg-hair__pic img, .ntg-hlb, .ntg-hlb__panel, .ntg-hlb__fig img { transition: none; }
}

/* ---------- 種族のボタン（操作の帯の 1 段目。帯ごと画面に付いてくる） ---------- */
/* 1 行に並べる。入らない幅では横に流す（折り返して帯を高くしない） */
.ntg-hair__races {
  position: relative; /* 押したボタンを見える所へ送るときの位置の基準（hair-list.js） */
  flex: 1 1 100%;
  display: flex;
  gap: 2px;
  min-width: 0;
  padding: 2px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  background: var(--h-paper);
  border: 1px solid var(--h-line);
  border-radius: 999px;
}

.ntg-hair__races::-webkit-scrollbar { display: none; }

.ntg-hair__races button {
  flex: 0 0 auto;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--h-sub);
  font: inherit;
  font-size: 13px;
  line-height: 1;
  padding: 7px 11px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.ntg-hair__races button[aria-pressed="true"] {
  background: var(--h-bg);
  color: var(--h-text);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.ntg-hair__races button:focus-visible { outline: 2px solid var(--h-teal); outline-offset: -2px; }
.ntg-hair__seg button:disabled { opacity: 0.4; cursor: default; }

.ntg-hair__note {
  margin: 0 0 12px;
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--h-sub);
  background: var(--h-paper);
  border-left: 3px solid var(--h-teal);
}

.ntg-hair__note[hidden] { display: none; }
.ntg-hair__grid[aria-busy="true"] { opacity: 0.5; }
.ntg-hair__seg button[hidden] { display: none; }
