body {
  margin-top: 0; /* グローバルの --header-height + luxury-band に委譲 */
  background-color: #f5f7fa;
}

/* ======= Expand Animations (selected 時の“うにょうにょ”演出) ======= */
@keyframes cardWiggleExpand {
  0% { transform: scale(0.98); filter: saturate(0.98); }
  48% { transform: scale(1.015); }
  72% { transform: scale(0.997); }
  100% { transform: scale(1); filter: none; }
}

@keyframes contentReveal {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes rowLift {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* スマートフォン（480px以下）：固定ヘッダー分の二重オフセットを解消 */
@media (max-width: 480px) {
  body { margin-top: 0; }
}

/* luxury-band の余白はグローバル(style.css)に統一。ここでの個別調整は削除 */
/* 全体コンテナ */
.container {
  max-width: var(--content-max);
  margin: 0 auto 0;
  padding: var(--section-pad-y) var(--section-pad-x);
}

/* ヘッダーはグローバル管理（ここでは高さを上書きしない） */
header .container { padding: 0 20px !important; }

/* サービスページのサブヘッダー帯をタイトに（vh依存を緩和） */
#sub-header.luxury-band {
  margin-top: var(--header-height) !important; /* 念のため強制 */
  padding: clamp(28px, 5vw, 72px) 0; /* 画面幅基準で安定させる */
}

/* サービスグリッド */
.service-grid {
  display: grid;
  gap: clamp(0.8rem, 2vw, 1.2rem);
  justify-content: center;
  position: relative;
  transition: all 0.3s ease;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

/* 初期2×2 */
.service-grid.initial { grid-auto-rows: auto; }

/* 拡大表示用レイアウト（3上段＋1下段） */
.service-grid.focused {
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  grid-auto-rows: auto;
  justify-content: center;
  gap: clamp(0.8rem, 2vw, 1.2rem);
}

/* デスクトップは上段3枚を横並び、わずかに幅差をつける */
@media (min-width: 1200px) {
  .service-grid.focused {
    grid-template-columns: 1fr 0.98fr 1.04fr; /* ほんの少しだけ幅差 */
    grid-auto-flow: row dense;
    align-items: start;
  }
  .service-grid.focused .service-item.selected {
    grid-column: 1 / -1; /* 下段で全幅 */
  }
}

/* 画面が狭まるほどカードをより大きく（比率を上げる） */
@media (max-width: 1100px) {
  .service-grid,
  .service-grid.focused {
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  }
}

@media (max-width: 900px) {
  .service-grid,
  .service-grid.focused {
    grid-template-columns: 1fr;
  }
}

/* サービスアイテム共通 */
.service-item {
  background: #fff;
  border-radius: 12px;
  padding: clamp(0.8rem, 2vw, 1rem);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  width: 100%;
  max-width: 100%;
  height: auto;
  min-height: clamp(140px, 22vw, 220px);
  display: block;
  justify-self: center;
  align-self: start;
  will-change: transform;
}

.service-item:hover {
  transform: translateY(-5px);
}

/* タイトル・本文 */
.service-item h3 {
  font-size: clamp(1rem, 1.6vw, var(--fs-h3));
  margin-bottom: 0.6rem;
  color: #005999;
  text-align: center; /* タイトルは中央寄せに変更 */
  line-height: 1.2;
  min-height: 2.4em; /* 2行分をフォントサイズ連動で確保 */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  overflow-wrap: anywhere; /* 長い語での見切れ防止 */
}

.service-item p {
  font-size: var(--fs-body);
  line-height: 1.6;
  color: #444;
  text-align: left; /* 本文は左寄せに統一 */
  margin: 0;
}

/* 拡大表示状態 */
.service-item.selected {
  width: 100%;
  max-width: none;
  height: auto;
  min-height: clamp(360px, 70vw, 640px);
  padding: clamp(1.2rem, 3vw, 2.5rem);
  border-radius: 16px;
  background: #f4faff;  /* 明るい背景 */
  color: #003366;
  display: block;
  box-shadow: 0 6px 20px rgba(0, 64, 128, 0.15);
  cursor: default;
  grid-row: auto;
  grid-column: 1 / -1;
  z-index: 10;
  position: relative;
  animation: cardWiggleExpand 420ms cubic-bezier(.2,.7,.2,1) both;
}

/* 左側（アイコン・タイトル） */
.service-item.selected .profile-section {
  flex: 1;
  min-width: 200px;
}

.service-item.selected h3 {
  font-size: clamp(1.2rem, 2.4vw, var(--fs-h2));
  font-weight: 700;
  margin-bottom: 1rem;
  color: #005580;
  /* 選択時も中央寄せにして、左のボーダーは外す（見た目が中央に寄るため） */
  text-align: center;
  border-left: none;
  padding-left: 0;
}

/* 拡大表示時の詳細テキスト */
.service-detail { display: none; }

.service-item.selected .service-detail {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(0.8rem, 2vw, 1.2rem);
  align-items: flex-start;
  animation: contentReveal 360ms ease-out 80ms both;
}

/* 選択時は写真を本文の直後（提供リストの直前）に配置 */
.service-item.selected .service-image-wrapper {
  order: 1;
  flex: 1 1 100%;
  width: 100%;
  margin: 0 0 1rem;
  display: flex;
  justify-content: flex-start;
}
.service-item.selected .service-image {
  width: 100%;
  max-width: clamp(300px, 75%, 960px); /* デスクトップで横幅約3/4（約1.5倍） */
  height: auto; /* 縦も比率で約1/2になる */
  aspect-ratio: var(--service-img-ratio, 16/9);
  object-fit: cover;
}

/* 並び順の制御：本文(p) → 画像 → 提供サービス */
.service-item.selected .service-detail p { order: 0; }
.service-item.selected .service-detail-example { order: 2; }

.service-detail-example {
  flex: 1 1 360px;
  max-width: 600px;
  margin: 0;
}

.service-detail p {
  font-size: var(--fs-body);
  line-height: 1.7;
  color: #333;
  margin-bottom: 1rem;
  text-align: left;
}

.service-detail h4 {
  font-size: var(--fs-h4);
  font-weight: 700;
  color: #005580;
  margin-top: 1.5rem;
  margin-bottom: 0.8rem;
  text-align: left;
}

.service-detail ul {
  list-style-type: none;
  padding-left: 1.5rem;
  text-align: left;
}

.service-detail li {
  font-size: var(--fs-body);
  line-height: 1.6;
  color: #333;
  margin-bottom: 0.5rem;
  position: relative;
  padding-left: 1rem;
}

.service-detail li:before {
  content: "•";
  position: absolute;
  left: 0;
  color: #00aaff;
  font-weight: bold;
}

/* 右側（本文） */
.service-item.selected p {
  font-size: var(--fs-body);
  line-height: 1.7;
  color: #333;
  margin-bottom: 1rem;
  text-align: left;
}

/* 閉じるボタン */
.service-item.selected .close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: clamp(12px, 1.6vw, 16px);
  line-height: 1;
  padding: 0.35rem 0.6rem;
  background: #ffffffee;
  backdrop-filter: saturate(1.1);
  border: 1px solid #e3e8ef;
  border-radius: 9999px;
  color: #666;
  cursor: pointer;
  z-index: 20;
  transition: color 0.2s ease, background-color 0.2s ease, transform 0.15s ease;
  white-space: nowrap; /* 折り返しで広がらないように */
}

.service-item.selected .close-btn:hover {
  color: #005999;
  background: #fff;
  transform: translateY(-1px);
}

.service-item:not(.selected) .close-btn {
  display: none;
}

/* タイトルと重ならないように右側に余白を確保 */
.service-item.selected h3 {
  padding-right: clamp(40px, 6vw, 84px);
}


/* 上段の3アイテム */
.service-grid.focused .service-item:not(.selected) {
  grid-row: auto;
  width: 100%;
  height: auto;
  min-height: clamp(120px, 24vw, 200px);
  align-self: start;
  z-index: 1;
  animation: rowLift 260ms ease-out 40ms both;
}

/* 非選択時の小さいカードのタイトル調整（折り返しを抑えて高さを安定させる） */
.service-grid.focused .service-item:not(.selected) h3 {
  font-size: clamp(0.95rem, 1.4vw, 1.2rem);
  line-height: 1.15;
  min-height: 2.2em;
  margin-bottom: 0.4rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center; /* 小カードも中央寄せ */
}

.service-image-wrapper {
  text-align: center;
  margin-top: 1rem;
}

.service-image{
  max-width: 50%;
  height: auto;
}

/* 列の固定指定は撤廃し、柔軟に自動配置する（選択カードは span） */

/* ========================================
   レスポンシブ対応
   ======================================== */

/* タブレット（768px以下） */
@media (max-width: 768px) {
  body { margin-top: 0; }

  .container {
    max-width: 100%;
    padding: 1.5rem 1rem;
  }

  /* 初期2×2レイアウト → 1列に変更 */
  .service-grid.initial {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 1rem;
  }

  .service-item {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 150px;
  }

  .service-item h3 {
    font-size: 1.1rem;
    min-height: auto;
  }

  .service-item p {
    font-size: 0.95rem;
  }

  /* 拡大レイアウト → 1列に変更 */
  .service-grid.focused {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 1rem;
  }

  .service-grid.focused .service-item:not(.selected) {
    grid-row: auto;
    width: 100%;
    height: auto;
    min-height: 120px;
  }

  .service-item.selected {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 400px;
    padding: 1.5rem;
    grid-column: 1;
    grid-row: auto;
  }

  /* モバイルはアイコンのみでコンパクトに */
  .service-item.selected .close-btn {
    top: 6px;
    right: 6px;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    font-size: 0; /* テキスト非表示 */
  }
  .service-item.selected .close-btn::before {
    content: "×";
    display: block;
    font-size: 20px;
    line-height: 36px;
    text-align: center;
    color: #555;
  }
  .service-item.selected h3 {
    padding-right: 52px; /* ボタンの占有分を確保 */
  }

  /* Landscape の小型デバイスで選択パネルが画面外に切れるのを防止
     高さをビューポートに合わせて内部スクロールさせる */
  @media (orientation: landscape) {
    .service-item.selected {
      max-height: calc(100vh - 80px); /* ヘッダー等を差し引いた高さ */
      overflow: auto;
      padding-bottom: 2rem; /* 下の余白を確保 */
    }
  }

  .service-detail-example {
    max-width: 100%;
    float: none;
    margin-bottom: 1rem;
  }

  .service-image {
    max-width: 70%;
  }

  /* 選択時の写真はモバイルでも全幅優先 */
  .service-item.selected .service-image {
    max-width: 100%;
  }
}

/* 小型デバイスの横向き（ランドスケープ）専用：選択カードを大きく見せる */
@media (max-width: 768px) and (orientation: landscape) {
  .service-grid.initial,
  .service-grid.focused {
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .service-item {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 140px;
    margin: 0;
  }

  /* 選択時は画面の大部分を使って見やすくする */
  .service-item.selected {
    order: 99;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 60vh; /* 高さを確保して大きく表示 */
    max-height: calc(100vh - 80px);
    overflow: auto;
    padding: 1.5rem 1rem;
    box-sizing: border-box;
    margin-bottom: 0.5rem;
  }

  /* 非選択カードは通常に表示（必要なら縮小） */
  .service-grid.focused .service-item:not(.selected) {
    order: 0;
    opacity: 0.95;
  }
}

/* スマートフォン（480px以下） */
@media (max-width: 480px) {
  .container {
    max-width: 100%;
    padding: 1rem;
  }

  .service-grid.initial,
  .service-grid.focused {
    grid-template-columns: 1fr;
    gap: 0.8rem;
  }

  .service-item {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 130px;
    padding: 1rem;
    border-radius: 8px;
  }

  .service-item h3 {
    font-size: 1rem;
    min-height: auto;
    margin-bottom: 0.5rem;
  }

  .service-item p {
    font-size: 0.9rem;
    line-height: 1.5;
  }

  .service-item:hover {
    transform: translateY(-3px);
  }

  .service-item.selected {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 350px;
    padding: 1.5rem 1rem;
    border-radius: 12px;
    margin-top: 1rem;
  }

  /* 横向き（ランドスケープ）で切れるのを防ぐ（スマホ向け） */
  @media (orientation: landscape) {
    .service-item.selected {
      max-height: calc(100vh - 70px);
      overflow: auto;
      padding-bottom: 2rem;
      order: 99;
    }
  }

  /* モバイル（特に縦向き）ではグリッドを縦並びにして、
     選択アイテムを最後に回す（画面いっぱいに広がりすぎないよう制限） */
  .service-grid.initial,
  .service-grid.focused {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.8rem;
  }

  .service-item {
    order: 0; /* デフォルト */
  }

  .service-item.selected {
    order: 99; /* 選択時は末尾に表示 */
    min-height: auto;
    max-height: 80vh; /* 画面をバカ長くしない */
    overflow: auto; /* 内容が長ければスクロール可能に */
    padding-bottom: 2rem;
  }

  .service-item.selected h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
  }

  .service-detail p {
    font-size: 0.95rem;
    line-height: 1.6;
  }

  .service-detail h4 {
    font-size: 1rem;
    margin-top: 1rem;
    margin-bottom: 0.6rem;
  }

  .service-detail ul {
    padding-left: 1.2rem;
  }

  .service-detail li {
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
  }

  .service-detail-example {
    max-width: 100%;
    float: none;
    margin-bottom: 1rem;
  }

  .service-image-wrapper {
    margin-top: 1rem;
  }

  .service-image {
    max-width: 85%;
    max-height: 200px;
  }

  /* 選択時の写真は全幅＋高さ制御を解除（比率優先） */
  .service-item.selected .service-image {
    max-width: 100%;
    max-height: none;
  }

  .service-item.selected .close-btn {
    top: 5px;
    right: 5px;
    width: 32px;
    height: 32px;
  }
  .service-item.selected .close-btn::before {
    font-size: 18px;
    line-height: 32px;
  }
}

/* スマホ横向き（狭いランドスケープ）向け調整：選択カードを下に大きく表示 */
@media (max-width: 480px) and (orientation: landscape) {
  .service-grid.initial,
  .service-grid.focused {
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .service-item {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0;
  }

  .service-item.selected {
    order: 99;
    width: 100% !important;
    min-height: 55vh;
    max-height: calc(100vh - 70px);
    overflow: auto;
    padding: 1.2rem;
    box-sizing: border-box;
  }

  .service-grid.focused .service-item:not(.selected) {
    order: 0;
  }
}

/* 超小型デバイス（320px以下） */
@media (max-width: 320px) {
  .container {
    padding: 0.8rem;
  }

  .service-item {
    padding: 0.8rem;
    min-height: 120px;
  }

  .service-item h3 {
    font-size: 0.95rem;
  }

  .service-item p {
    font-size: 0.85rem;
  }

  .service-item.selected {
    padding: 1rem 0.8rem;
    min-height: 300px;
  }

  .service-image {
    max-width: 100%;
  }
}

/* ==============================
   オプション: 常にカードを画面幅にフィット（フルブリード）
   使い方: services.html の <section class="services"> に full-bleed を付与
   例) <section class="services full-bleed" data-section>
   ============================== */
.services.full-bleed .container {
  --svc-cont-pad: clamp(8px, 2vw, 24px);
  padding-left: var(--svc-cont-pad);
  padding-right: var(--svc-cont-pad);
}

.services.full-bleed .service-grid {
  grid-template-columns: 1fr !important;
}

.services.full-bleed .service-item,
.services.full-bleed .service-item.selected {
  width: min(100%, calc(100vw - (2 * var(--svc-cont-pad, 0px)))) !important;
  max-width: unset !important;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

/* 単一カラム化したらカード幅を画面にフィット（約95%）させる */
@media (max-width: 900px) {
  .service-grid,
  .service-grid.focused {
    grid-template-columns: 1fr;
  }
  /* コンテナ左右の余白を少し絞って、カードを広げやすく */
  .services .container { 
    --svc-cont-pad: 0px; /* サービス単一列時は左右余白ゼロ */
    padding-left: 0; 
    padding-right: 0;
  }

  /* 単一カラム時は画面幅基準(95vw)でフィット。コンテナ幅より広げない */
  .service-item,
  .service-item.selected {
    width: min(100%, calc(100vw - (2 * var(--svc-cont-pad, 0px)))) !important;
    max-width: unset !important;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
  }
}
