/* =========================
   Global / 基本設定
   ========================= */
html,
body {
  height: 100%;
}
html {
  -webkit-text-size-adjust: 100%;
  font-size: clamp(15px, 1.8vw, 16px);
}
body {
  font-family: Arial, sans-serif;
  min-height: 100vh;
  background-color: #f8f9fa;
}
input,
select,
textarea,
button {
  font-size: 16px;
} /* iOSの自動ズーム抑止 */
.toggle-password {
  min-width: 64px;
} /* タップ領域確保 */

/* =========================
   Auth系（login / signup）共通：器とロゴのルール
   ========================= */
/* 変数：PC基準 → 下で段階的に調整 */
:root {
  --auth-gutter: 24px; /* 画面左右の最小ガター */
  --auth-max: 420px; /* ロゴ＋カードの共通最大幅（器の上限） */
  --logo-max: 300px; /* ロゴの上限 */
}

/* 外側ガター：セーフエリアも考慮 */
.container.auth {
  padding-left: max(var(--auth-gutter), env(safe-area-inset-left));
  padding-right: max(var(--auth-gutter), env(safe-area-inset-right));
}

/* ロゴ＋カードの“共通の器”（中央寄せ＆幅統一） */
.auth-inner {
  width: min(100%, var(--auth-max));
  margin-left: auto;
  margin-right: auto;
}

/* カードは器いっぱい／中央寄せ */
.auth-card {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

/* カード内パディングは滑らかに可変 */
.auth-card .card-body {
  padding: clamp(0.875rem, 2.5vw, 1.5rem);
}

/* ロゴは器の幅を上限として必ず縮む（カード超え防止） */
.auth-inner .login-logo {
  display: block;
  height: auto;
  max-width: min(100%, var(--logo-max));
  margin-left: auto;
  margin-right: auto;
}

/* ===== Authレスポンシブ（まずガター→次にカード） ===== */
@media (max-width: 991.98px) {
  :root {
    --auth-gutter: 20px;
  }
}
@media (max-width: 767.98px) {
  :root {
    --auth-gutter: 16px;
    --auth-max: 380px;
    --logo-max: 240px;
  }
}
@media (max-width: 399.98px) {
  :root {
    --auth-max: 360px;
    --logo-max: 220px;
  }
}

/* =========================
   サインアップ画面の微調整（既存クラスで変数を上書き）
   ========================= */
/* サインアップでは少し広めに見せたい → 同一カード要素内で変数上書き */
.signup-card {
  --auth-max: 520px; /* PC時の器上限 */
  --logo-max: 300px; /* ロゴ上限（PC） */
}
@media (max-width: 767.98px) {
  .signup-card {
    --auth-max: 440px;
    --logo-max: 280px;
  }
}
@media (max-width: 575.98px) {
  .signup-card {
    --auth-max: 380px;
    --logo-max: 240px;
  }
}

/* 既存の固定幅指定の影響を抑制（器に任せる） */
.auth-inner .signup-card {
  max-width: none;
}
.signup-inner {
  max-width: none;
} /* 文章幅を絞りたいなら削除 */

/* =========================
   画像生成フォーム（Generate）
   ========================= */
#generate-form .card {
  background-color: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 0.5rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
#generate-form .card-body {
  padding: clamp(0.875rem, 2.5vw, 1.25rem);
}
#generate-form .card-title {
  font-size: clamp(1.05rem, 2.4vw, 1.25rem);
  font-weight: 700;
  margin-bottom: 1rem;
}
#generate-form .form-label {
  font-weight: 700;
  font-size: clamp(0.95rem, 2vw, 1rem);
}
#generate-form .form-text {
  font-size: clamp(0.85rem, 1.8vw, 0.95rem);
  color: #6c757d;
}

.btn,
.btn-generate {
  min-height: 44px;
  font-size: clamp(0.95rem, 2.2vw, 1rem);
}
.btn-generate {
  padding: 0.45rem 2.5rem;
  font-weight: 600;
  border-radius: 0.4rem;
}

/* =========================
   スピナー
   ========================= */
@keyframes spin {
  from {
    transform: rotate(0);
  }
  to {
    transform: rotate(360deg);
  }
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #ccc;
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 1rem auto;
}
.image-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(255, 255, 255, 0.65);
  border-radius: 50%;
  padding: 0.5rem;
  display: none;
  z-index: 2;
}
.image-spinner .spinner-border {
  width: 3rem;
  height: 3rem;
  color: var(--bs-primary);
}
.image-spinner.active {
  display: block;
}

/* =========================
   結果カード
   ========================= */
#result-card {
  background-color: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 0.5rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  padding: 1rem;
  margin-top: 1.5rem;
}
.generated-image {
  max-width: 100%;
  display: block;
  margin-bottom: 0.5rem;
  border: 3px solid var(--bs-primary);
  box-shadow: 0 0 5px rgba(13, 110, 253, 0.5);
}
.image-checkbox {
  display: none;
}
.generated-image:hover + .image-checkbox {
  display: inline;
}

/* =========================
   アップロードプレビュー
   ========================= */
.image-wrapper {
  width: 120px;
  height: 120px;
  position: relative;
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid #ccc;
}
.image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 0.5rem;
}
.remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #ccc;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 16px;
  line-height: 22px;
  text-align: center;
  color: #333;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* =========================
   汎用画像ボックス（1:1）
   ========================= */
.image-box {
  position: relative;
  width: 100%;
  padding-top: 100%;
  background: #f8f9fa;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  overflow: hidden;
}
.image-box img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 3:2ボックス（ローディング用など） */
.loading-image-box {
  position: relative;
  width: 100%;
  max-width: 600px;
  padding-top: 66%;
  background: #f8f9fa;
  border-radius: 0.5rem;
  overflow: hidden;
}
.loading-image-box img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0.5rem;
}

/* =========================
   生成中/結果サムネ（可変）
   ========================= */
:root {
  --thumb-min: 140px;
  --thumb-ideal: 45vw;
  --thumb-max: 250px;
}
.thumb-box,
.placeholder-card {
  width: clamp(var(--thumb-min), var(--thumb-ideal), var(--thumb-max));
  height: clamp(var(--thumb-min), var(--thumb-ideal), var(--thumb-max));
}
#result-container {
  gap: clamp(0.5rem, 2vw, 0.75rem);
}

.placeholder-card {
  position: relative;
  border: 1px solid #e0e0e0;
  border-radius: 0.5rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  background: #fff;
}
.thumb-box .initial-placeholder-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  transition: opacity 0.5s ease-in-out, filter 0.5s ease-in-out;
}
.thumb-box img:not(.initial-placeholder-img),
.placeholder-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* =========================
   モバイルメニュー（Offcanvas）
   ========================= */
#mobile-menu {
  transition: transform 0.3s ease-in-out;
}
.offcanvas-title,
.offcanvas-body {
  font-size: clamp(0.95rem, 2.2vw, 1rem);
}
.offcanvas-body .nav-link {
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
}

/* =========================
   レイアウト補助（サイドバー）
   ========================= */
@media (min-width: 992px) {
  .sticky-sidebar {
    position: sticky;
    top: 1rem;
    z-index: 100;
  }
  .container,
  .row {
    overflow: visible !important;
    position: static !important;
  }
  .row {
    display: flex;
    align-items: flex-start;
  }
  .col-lg-3,
  .col-lg-9 {
    display: flex;
    flex-direction: column;
  }
  .col-lg-3 > nav {
    flex-grow: 1;
  }
}

/* =========================
   History（過去生成結果）
   ========================= */
#history-container {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}
.history-group > h5 {
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.history-thumbnails {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(0.5rem, 2vw, 1rem);
}

/* 既定の固定300x200を可変に上書き（3:2維持） */
:root {
  --hist-thumb-min: 140px;
  --hist-thumb-ideal: 46vw;
  --hist-thumb-max: 300px;
}
.history-thumb-box {
  display: inline-block;
  position: relative;
  cursor: pointer;
  line-height: 0;
  width: clamp(
    var(--hist-thumb-min),
    var(--hist-thumb-ideal),
    var(--hist-thumb-max)
  );
  aspect-ratio: 3 / 2;
  height: auto;
  border-radius: 8px;
  overflow: hidden;
}
.history-thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid transparent;
}
.history-thumb-box input[type="checkbox"] {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  accent-color: #0d6efd;
}

/* =========================
   スマホ時のカード内余白（全ページの最後の微調整）
   ========================= */
@media (max-width: 575.98px) {
  .card .card-body {
    padding: 1.25rem;
  } /* 指で触りやすい */
}

/* Login専用：992px以上でもカード幅を991px時と同じに固定 */
@media (min-width: 992px) {
  .login-page .card.shadow-sm {
    max-width: 420px; /* ← 991px時と同じ幅にしたい値。必要なら 400px 等に調整 */
    width: 100%;
    margin-left: auto;
    margin-right: auto; /* 中央寄せ */
  }
}

@media (min-width: 992px) {
  .login-page .auth-card {
    max-width: 420px;
    margin-inline: auto;
  }
}

/* =========================
  Reset：ロゴ余白と上下パディングをさらに最適化
   ========================= */

/* ロゴラッパーの上下マージンを可変に（端末が高くても空き過ぎない） */
.reset-page .logo-wrap {
  margin-block-start: clamp(8px, 1.5dvh, 20px);
  margin-block-end: clamp(10px, 2dvh, 24px);
}

/* ロゴ自体のサイズ上限（高さ優先で縮む） */
.reset-page .login-logo {
  height: auto;
  max-height: clamp(40px, 9dvh, 88px); /* ← iPadでも過剰に大きくならない */
  max-width: min(100%, var(--logo-max));
}

/* 縦方向センタリング。既存より少しタイトに（上の空きが減る） */
.reset-page .container.auth {
  min-block-size: 100dvh; /* 端末UIを除いた実高さに追従 */
  display: grid;
  place-content: center; /* ロゴ＋カードの束を中央に */
  padding-block: clamp(12px, 2.5dvh, 40px); /* 上下パディングを控えめに */
  gap: clamp(10px, 1.8dvh, 20px); /* ロゴとカードの間隔 */
}

/* タブレット以上でさらにタイト（iPad想定） */
@media (min-width: 768px) and (min-height: 900px) {
  .reset-page .container.auth {
    padding-block: clamp(12px, 2dvh, 32px);
    gap: clamp(8px, 1.5dvh, 16px);
  }
}

/* かなり縦が短い端末では詰める（既存のしきい値を少し強めに） */
@media (max-height: 720px) {
  .reset-page .container.auth {
    padding-block: clamp(8px, 2dvh, 24px);
    gap: clamp(6px, 1.2dvh, 12px);
  }
}

/* 戻るボタン（外側）の上余白も可変で控えめに */
.reset-page .btn-return {
  width: clamp(200px, 40vw, 320px);
  min-height: 44px;
  font-size: clamp(0.95rem, 2.2vw, 1rem);
  margin-block-start: clamp(12px, 1.6dvh, 20px);
}

/* =========================
   Email認証送信（verify-page）専用の最適化
   ========================= */

/* 画面の縦長に応じて上下余白＆ロゴ比率を可変（アドレスバー考慮） */
.verify-page {
  --vpad: clamp(16px, 4svh, 56px); /* 器の上下余白 */
  --logo-max-h: clamp(40px, 9svh, 96px); /* ロゴの最大高さ */
}
/* dvhが使える環境ではより正確に */
@supports (height: 100dvh) {
  .verify-page {
    --vpad: clamp(16px, 4dvh, 56px);
    --logo-max-h: clamp(40px, 9dvh, 96px);
  }
}

/* 器：縦センター＆セーフエリア考慮（背の低い端末は後述で上詰め） */
.verify-page .container.auth {
  min-block-size: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: max(var(--vpad), env(safe-area-inset-top))
    max(var(--vpad), env(safe-area-inset-bottom));
  gap: clamp(12px, 2svh, 24px);
}

/* ロゴは“器”の幅以内で必ず縮む＋端末の縦長で最大高さキャップ */
.verify-page .login-logo {
  display: block;
  height: auto;
  max-height: var(--logo-max-h);
  max-width: min(100%, var(--logo-max)); /* 既存の --logo-max を尊重 */
  margin-inline: auto;
}

/* PC幅（>=992px）でも 991px時の見え方に固定：基準のカード幅を指定 */
@media (min-width: 992px) {
  .verify-page {
    --auth-max: 480px;
  } /* PC基準で心地よい幅（必要なら微調整） */
}

/* 極端に縦が短い端末は詰める／横向き等は上詰め */
@media (max-height: 720px) {
  .verify-page {
    --logo-max-h: clamp(36px, 8svh, 72px);
  }
  .verify-page .auth-card .card-body {
    padding: clamp(0.75rem, 2vh, 1rem);
  }
}
@media (max-height: 560px) {
  .verify-page .container.auth {
    justify-content: flex-start;
  }
}

/* 戻るボタン：最小200〜最大320で自然に伸縮 */
.verify-page .btn-return {
  width: clamp(200px, 40vw, 320px);
  min-height: 44px;
  font-size: clamp(0.95rem, 2.2vw, 1rem);
}

/* =========================
   Verify（認証成功）ページ最適化
   ========================= */
.verify-page {
  --vpad: clamp(16px, 4svh, 56px);
  --logo-max-h: clamp(40px, 9svh, 96px);
}

@supports (height: 100dvh) {
  .verify-page {
    --vpad: clamp(16px, 4dvh, 56px);
    --logo-max-h: clamp(40px, 9dvh, 96px);
  }
}

.verify-page .container.auth {
  min-block-size: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: max(var(--vpad), env(safe-area-inset-top))
    max(var(--vpad), env(safe-area-inset-bottom));
  gap: clamp(12px, 2svh, 24px);
}

.verify-page .login-logo {
  display: block;
  height: auto;
  max-height: var(--logo-max-h);
  max-width: min(100%, var(--logo-max));
  margin-inline: auto;
}

/* 縦が短い端末向けの余白調整 */
@media (max-height: 720px) {
  .verify-page {
    --logo-max-h: clamp(36px, 8svh, 72px);
  }
  .verify-page .auth-card .card-body {
    padding: clamp(0.75rem, 2vh, 1rem);
  }
}
@media (max-height: 600px) {
  .verify-page {
    --vpad: clamp(8px, 3svh, 24px);
    --logo-max-h: clamp(32px, 7svh, 64px);
  }
  .verify-page .auth-card .card-body {
    padding: clamp(0.6rem, 1.8vh, 0.9rem);
  }
}
@media (max-height: 500px) {
  .verify-page .container.auth {
    justify-content: flex-start;
  }
}

/* 幅が大きいときでも991px時の幅を維持 */
@media (min-width: 992px) {
  .verify-page {
    --auth-max: 420px;
  }
}

/* 戻るボタンを柔軟に可変 */
.verify-page .btn-return {
  width: clamp(200px, 40vw, 320px);
  min-height: 44px;
  font-size: clamp(0.95rem, 2.2vw, 1rem);
}

/* =========================
   Verify 共通（成功/失敗）
   ========================= */
.verify-page,
.verify-fail-page {
  --vpad: clamp(16px, 4svh, 56px);
  --logo-max-h: clamp(40px, 9svh, 96px);
}
@supports (height: 100dvh) {
  .verify-page,
  .verify-fail-page {
    --vpad: clamp(16px, 4dvh, 56px);
    --logo-max-h: clamp(40px, 9dvh, 96px);
  }
}

.verify-page .container.auth,
.verify-fail-page .container.auth {
  min-block-size: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: max(var(--vpad), env(safe-area-inset-top))
    max(var(--vpad), env(safe-area-inset-bottom));
  gap: clamp(12px, 2svh, 24px);
}

.verify-page .login-logo,
.verify-fail-page .login-logo {
  display: block;
  height: auto;
  max-height: var(--logo-max-h);
  max-width: min(100%, var(--logo-max));
  margin-inline: auto;
}

/* 縦が短い端末向けの余白調整 */
@media (max-height: 720px) {
  .verify-page,
  .verify-fail-page {
    --logo-max-h: clamp(36px, 8svh, 72px);
  }
  .verify-page .auth-card .card-body,
  .verify-fail-page .auth-card .card-body {
    padding: clamp(0.75rem, 2vh, 1rem);
  }
}
@media (max-height: 600px) {
  .verify-page,
  .verify-fail-page {
    --vpad: clamp(8px, 3svh, 24px);
    --logo-max-h: clamp(32px, 7svh, 64px);
  }
  .verify-page .auth-card .card-body,
  .verify-fail-page .auth-card .card-body {
    padding: clamp(0.6rem, 1.8vh, 0.9rem);
  }
}
@media (max-height: 500px) {
  .verify-page .container.auth,
  .verify-fail-page .container.auth {
    justify-content: flex-start; /* 超短縦や横向きで上詰めに */
  }
}

/* 幅が大きいときでも 991px 時のカード幅を維持 */
@media (min-width: 992px) {
  .verify-page,
  .verify-fail-page {
    --auth-max: 420px; /* 必要なら 400〜440px で微調整 */
  }
}

/* 戻るボタン：幅を柔軟に可変 */
.verify-page .btn-return,
.verify-fail-page .btn-return {
  width: clamp(200px, 40vw, 320px);
  min-height: 44px;
  font-size: clamp(0.95rem, 2.2vw, 1rem);
}
