/* ==========================================================================
   Tool Pages Responsive Override — v1.0
   全ツールページ共通のレスポンシブ対応
   インラインスタイルのハードコード値を上書きする
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. ツールページ共通 — デスクトップベース
   -------------------------------------------------------------------------- */

/* コンテンツラッパー最大幅 */
.content-wrapper {
  width: 100%;
  padding: 0 var(--space-4, 16px);
}

/* 結果セクションのヘッダーテキスト */
.result-and-action-unit {
  border-radius: var(--radius-lg, 20px) !important;
  overflow: hidden;
}

/* ツールヘッダー */
.tool-header {
  padding: 0 var(--space-4, 16px);
}

/* プリセットボタン群の共通スタイル */
.gacha-preset-btn,
.preset-btn,
[class*="preset"] button {
  min-height: 44px;
  touch-action: manipulation;
}

/* アクションボタン群 */
.btn-copy,
.btn-share,
button[onclick*="copy"],
button[onclick*="share"] {
  min-height: 48px;
  min-width: 48px;
  touch-action: manipulation;
}

/* --------------------------------------------------------------------------
   2. タブレット (max-width: 768px)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* ツールタイトル — インラインの font-size: 1.85rem 等を縮小 */
  .tool-title,
  .tool-header h1,
  .sc-tool-page-header h1 {
    font-size: 1.5rem !important;
    line-height: 1.35 !important;
    word-break: keep-all;
    overflow-wrap: anywhere;
  }

  /* コンテンツラッパー */
  .content-wrapper {
    max-width: 100% !important;
    padding: 0 var(--space-3, 12px) !important;
  }

  /* Calculator-card パディング調整 */
  .calculator-card {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .calculator-card .input-section {
    padding: 1.5rem 1.25rem !important;
  }

  /* インラインの grid-template-columns: repeat(3, 1fr) → 2列に */
  .calculator-card [style*="grid-template-columns: repeat(3"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* インラインの grid-template-columns: 1fr 1fr → そのまま(まだ収まる) */

  /* 結果セクション内パディング調整 */
  .result-section,
  .result-and-action-unit .result-section {
    padding: 20px 16px !important;
  }

  /* 巨大数値の縮小 (font-size: 2.75rem+ → 2.1rem) */
  [style*="font-size: 3rem"],
  [style*="font-size: 3.2rem"],
  [style*="font-size: 3.5rem"] {
    font-size: 2.25rem !important;
  }

  [style*="font-size: 2.75rem"] {
    font-size: 2.1rem !important;
  }

  /* 2.5rem系の値 */
  .res-value[style*="font-size: 2.5rem"],
  .res-value[style*="font-size: 2.8rem"] {
    font-size: 2rem !important;
  }

  /* テーブルのセルパディング調整 */
  table th,
  table td {
    padding: 10px 12px !important;
  }

  /* ツール説明文 */
  .tool-description {
    font-size: 0.95rem !important;
  }

  /* FAQ下のツール関連カード群 */
  [style*="grid-template-columns: repeat(auto-fit, minmax(260px"] {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
}

/* --------------------------------------------------------------------------
   3. モバイル (max-width: 480px)
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  /* ツールタイトルさらに縮小 */
  .tool-title,
  .tool-header h1,
  .sc-tool-page-header h1 {
    font-size: 1.3rem !important;
    margin-bottom: 8px !important;
  }

  /* コンテンツラッパー */
  .content-wrapper {
    padding: 0 var(--space-2, 8px) !important;
  }

  /* 入力セクション */
  .calculator-card .input-section {
    padding: 1.25rem 1rem !important;
  }

  /* 全てのインライン grid: 2列以上 → 1列にスタック */
  .calculator-card [style*="grid-template-columns: repeat(auto-fit"],
  .calculator-card [style*="grid-template-columns: repeat(3"],
  .calculator-card [style*="grid-template-columns: 1fr 1fr"],
  .result-section [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* 結果ハイライトの巨大数値 → さらに縮小 */
  [style*="font-size: 3rem"],
  [style*="font-size: 3.2rem"],
  [style*="font-size: 3.5rem"] {
    font-size: 1.85rem !important;
  }

  [style*="font-size: 2.75rem"] {
    font-size: 1.75rem !important;
  }

  .res-value[style*="font-size: 2.5rem"],
  .res-value[style*="font-size: 2.8rem"],
  .res-value[style*="font-size: 2.3rem"],
  .res-value[style*="font-size: 2.2rem"] {
    font-size: 1.65rem !important;
  }

  /* テーブルのスマホ表示（文字あふれ防止） */
  table th,
  table td {
    padding: 8px 10px !important;
    font-size: 0.85rem !important;
    word-break: break-word;
  }

  /* 結果セクション */
  .result-section,
  .result-and-action-unit .result-section {
    padding: 16px 12px !important;
  }

  /* 結果ヒーロー（グラデーション背景のもの）パディング */
  .result-section [style*="padding: 24px"],
  .result-section [style*="padding: 20px"] {
    padding: 16px 12px !important;
  }

  /* プリセットボタン群 — 横スクロール防止 */
  .calculator-card [style*="display: flex"][style*="flex-wrap: wrap"] {
    gap: 6px !important;
  }

  .gacha-preset-btn,
  .preset-btn {
    font-size: 11px !important;
    padding: 8px 10px !important;
  }

  /* セクション見出し */
  .calculator-card h3[style*="font-size: 1.35rem"],
  .calculator-card h3[style*="font-size: 1.25rem"] {
    font-size: 1.1rem !important;
  }

  /* ツールバッジ（カテゴリタグ）*/
  [style*="display: inline-flex"][style*="padding: 6px 16px"] {
    padding: 4px 12px !important;
  }
  [style*="display: inline-flex"][style*="padding: 6px 16px"] span {
    font-size: 12px !important;
  }

  /* 結果内のサブ情報グリッド */
  .result-sub-info {
    flex-direction: column !important;
    gap: 0.75rem !important;
  }

  /* アクションボタン群 */
  [style*="display: flex"][style*="justify-content: center"][style*="gap: 12px"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  [style*="display: flex"][style*="justify-content: center"][style*="gap: 12px"] button {
    width: 100% !important;
  }

  /* ツール説明テキスト */
  .tool-description,
  .seo-description p {
    font-size: 0.9rem !important;
    line-height: 1.7 !important;
  }

  /* FAQ セクション — ツールページ内 */
  .faq-section {
    padding: 1.5rem 1rem !important;
    margin: 1.5rem 0 !important;
  }

  /* 関連ツールカード */
  .related-tool-links {
    padding: 1.25rem 1rem !important;
  }

  /* フォームラベル */
  .form-group label[style*="font-size: 0.85rem"] {
    font-size: 0.85rem !important;
  }

  /* ヘルプテキスト */
  .help-text,
  span[style*="font-size: 0.8rem"] {
    font-size: 0.75rem !important;
    line-height: 1.5 !important;
  }
}

/* --------------------------------------------------------------------------
   4. 超小型デバイス (max-width: 360px)
   -------------------------------------------------------------------------- */
@media (max-width: 360px) {
  .tool-title,
  .tool-header h1,
  .sc-tool-page-header h1 {
    font-size: 1.15rem !important;
  }

  [style*="font-size: 3rem"],
  [style*="font-size: 3.2rem"],
  [style*="font-size: 3.5rem"] {
    font-size: 1.5rem !important;
  }

  .res-value {
    font-size: 1.5rem !important;
  }

  .calculator-card .input-section {
    padding: 1rem 0.75rem !important;
  }

  .gacha-preset-btn,
  .preset-btn {
    font-size: 10px !important;
    padding: 6px 8px !important;
    min-height: 40px;
  }
}

/* --------------------------------------------------------------------------
   5. タッチデバイス共通 — タップターゲット最小48px
   -------------------------------------------------------------------------- */
@media (pointer: coarse) {
  input[type="number"],
  input[type="text"],
  select {
    min-height: 48px !important;
    font-size: 16px !important; /* iOS ズーム防止 */
  }

  button,
  .btn-copy,
  .btn-share,
  .gacha-preset-btn,
  .preset-btn {
    min-height: 44px !important;
  }
}

/* --------------------------------------------------------------------------
   6. 印刷時
   -------------------------------------------------------------------------- */
@media print {
  .result-and-action-unit {
    break-inside: avoid;
  }

  [style*="display: flex"][style*="justify-content: center"][style*="gap: 12px"] {
    display: none !important;
  }
}

/* --------------------------------------------------------------------------
   7. ダークモード対応（ツール固有のハードコードカラー上書き）
   -------------------------------------------------------------------------- */
[data-theme="dark"] [style*="color: #1E293B"],
[data-theme="dark"] [style*="color: #475569"],
[data-theme="dark"] [style*="color: #334155"] {
  color: var(--color-text-primary) !important;
}

[data-theme="dark"] [style*="color: #64748B"],
[data-theme="dark"] [style*="color: #94A3B8"] {
  color: var(--color-text-secondary) !important;
}

[data-theme="dark"] [style*="background: #F8FAFC"],
[data-theme="dark"] [style*="background: #FFFFFF"],
[data-theme="dark"] [style*="background: #EEF2FF"],
[data-theme="dark"] [style*="background: #F1F5F9"] {
  background: var(--color-bg-card) !important;
}

[data-theme="dark"] [style*="border: 1px solid #E2E8F0"],
[data-theme="dark"] [style*="border: 1px solid #CBD5E1"],
[data-theme="dark"] [style*="border: 1px solid #C7D2FE"] {
  border-color: rgba(255, 255, 255, 0.1) !important;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) [style*="color: #1E293B"],
  html:not([data-theme="light"]) [style*="color: #475569"],
  html:not([data-theme="light"]) [style*="color: #334155"] {
    color: var(--color-text-primary) !important;
  }

  html:not([data-theme="light"]) [style*="color: #64748B"],
  html:not([data-theme="light"]) [style*="color: #94A3B8"] {
    color: var(--color-text-secondary) !important;
  }

  html:not([data-theme="light"]) [style*="background: #F8FAFC"],
  html:not([data-theme="light"]) [style*="background: #FFFFFF"],
  html:not([data-theme="light"]) [style*="background: #EEF2FF"],
  html:not([data-theme="light"]) [style*="background: #F1F5F9"] {
    background: var(--color-bg-card) !important;
  }
}

/* --------------------------------------------------------------------------
   8. アニメーション最適化 (reduced motion)
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .result-and-action-unit,
  .calculator-card,
  .tool-card-link,
  .category-card {
    transition: none !important;
    animation: none !important;
  }
}
