/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  background: #f3f5f8;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI',
    'Hiragino Kaku Gothic Pro', 'Yu Gothic', 'Meiryo', sans-serif;
  color: #1f2937;
  line-height: 1.6;
}

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid #2f6fb0;
  outline-offset: 2px;
}

/* ── パンくず ─────────────────────────────────────────────────────── */
.houganshi-breadcrumb {
  max-width: 1120px;
  margin: 14px auto 0;
  padding: 0 16px;
}

/* ── SEO Header ───────────────────────────────────────────────────── */
.seo-header {
  max-width: 1120px;
  margin: 24px auto 16px;
  padding: 0 16px;
}

.seo-header h1 {
  font-size: 1.65rem;
  line-height: 1.4;
  margin-bottom: 10px;
}

.seo-lead {
  color: #444;
  margin-bottom: 10px;
  line-height: 1.75;
}

.tool-note {
  background: #eaf2fb;
  border-left: 4px solid #2f6fb0;
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 0.9rem;
  border-radius: 0 4px 4px 0;
}

/* ── Main Layout ──────────────────────────────────────────────────── */
.main-container {
  max-width: 1120px;
  margin: 0 auto 48px;
  padding: 0 16px;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

@media (min-width: 992px) {
  .main-grid {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    /* align-itemsは既定のstretchのまま。col-previewの外枠（.section-card）を
       設定エリアと同じ高さまで伸ばし、枠の高さを揃える。
       sticky自体は内側の.preview-panel-innerに付けており、外枠の余った高さの
       範囲内で追従できるようにしている（外枠自体をstickyにすると、外枠と
       中身の高さが同じになり追従できる余地がなくなってしまうため）。 */
  }
  .col-preview .section-card {
    height: 100%;
  }
  .preview-panel-inner {
    position: sticky;
    top: 16px;
  }
}

/* ── Section Cards ────────────────────────────────────────────────── */
.section-card {
  background: #fff;
  border-radius: 12px;
  padding: 18px 20px;
  border: 1px solid #e4e9f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.settings-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
}

.setting-section {
  padding-bottom: 16px;
  border-bottom: 1px solid #eef1f5;
}
.setting-section:last-child { border-bottom: none; padding-bottom: 0; }

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1f4f8a;
  margin: 0 0 10px;
}

.section-desc {
  font-size: 0.82rem;
  color: #888;
  margin: -6px 0 10px;
}

/* ── よく使われる方眼紙（プリセットカード） ───────────────────────── */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
@media (min-width: 480px) {
  .preset-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.preset-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: #f8fafc;
  border: 1px solid #d7e2ee;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #1f4f8a;
  font-weight: 600;
  transition: background 0.12s, border-color 0.12s;
  min-height: 56px;
  justify-content: center;
  text-align: center;
}
.preset-card:hover { background: #eaf2fb; border-color: #2f6fb0; }
.preset-card.is-active {
  background: #2f6fb0;
  border-color: #2f6fb0;
  color: #fff;
}
.preset-card.is-active:hover { background: #245a91; }

/* ── ボタン群（用紙サイズ・向き・マス目・線幅など共通） ───────────── */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #333;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 42px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.seg-btn:hover { background: #f3f7fc; }
.seg-btn.is-active {
  background: #2f6fb0;
  border-color: #2f6fb0;
  color: #fff;
  font-weight: 600;
}

.seg-btn-sub {
  font-size: 0.78rem;
  color: #666;
  padding: 8px 12px;
  min-height: 36px;
}
.seg-btn-sub.is-active { color: #fff; }

.text-btn {
  background: none;
  border: 1px dashed #b8c4d4;
  border-radius: 8px;
  color: #2f6fb0;
  font-size: 0.85rem;
  padding: 8px 14px;
  cursor: pointer;
}
.text-btn:hover { background: #eaf2fb; }

/* ── 色選択 ───────────────────────────────────────────────────────── */
.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.color-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 6px;
  border: 2px solid #d7e2ee;
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-size: 0.82rem;
  color: #444;
  min-height: 40px;
}
.color-btn:hover { border-color: #93b6dc; }
.color-btn.is-active {
  border-color: #1f4f8a;
  background: #eaf2fb;
  font-weight: 700;
  color: #1f4f8a;
}

.color-btn-other {
  padding: 6px 14px;
  border-style: dashed;
}

.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.color-btn.is-active .color-swatch::after {
  content: '✓';
  display: block;
  color: #fff;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
}

.custom-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: #555;
}

input[type="color"] {
  width: 40px;
  height: 34px;
  padding: 2px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  cursor: pointer;
  background: #fff;
}

/* ── トグルスイッチ ───────────────────────────────────────────────── */
.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  color: #333;
}

.switch-row input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch-track {
  position: relative;
  width: 42px;
  height: 24px;
  background: #cbd5e1;
  border-radius: 999px;
  flex-shrink: 0;
  transition: background 0.15s;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch-row input:checked + .switch-track { background: #2f6fb0; }
.switch-row input:checked + .switch-track::after { transform: translateX(18px); }
.switch-row input:focus-visible + .switch-track { outline: 2px solid #2f6fb0; outline-offset: 2px; }

/* ── 条件付き表示ブロック ─────────────────────────────────────────── */
.conditional-wrap {
  margin-top: 12px;
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px solid #e4e9f0;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.conditional-wrap[hidden] { display: none; }

/* ── 数値入力フィールド ───────────────────────────────────────────── */
.field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.87rem;
  color: #444;
}

.field-row label { white-space: nowrap; }

.field-row input[type="number"],
.field-row input[type="text"] {
  width: 90px;
  padding: 7px 9px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.9rem;
}
.field-row input[type="text"] { width: 100%; max-width: 260px; }
.field-row input:focus { outline: none; border-color: #2f6fb0; box-shadow: 0 0 0 2px rgba(47, 111, 176, 0.2); }

.margin-fields-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (min-width: 480px) {
  .margin-fields-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.margin-fields-grid .field-row { flex-direction: column; align-items: flex-start; }
.margin-fields-grid input[type="number"] { width: 100%; }

.field-error {
  display: block;
  width: 100%;
  color: #cc2222;
  font-size: 0.78rem;
  min-height: 1.1em;
}

/* ── 詳細設定アコーディオン ───────────────────────────────────────── */
.advanced-details {
  margin-top: 4px;
}

.advanced-details summary {
  cursor: pointer;
  font-weight: 700;
  color: #1f4f8a;
  padding: 6px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.advanced-details summary::-webkit-details-marker { display: none; }
.advanced-details summary::before {
  content: '▶';
  font-size: 0.7rem;
  transition: transform 0.15s;
}
.advanced-details[open] summary::before { transform: rotate(90deg); }

.advanced-body {
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.advanced-sub-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #333;
  margin: 0 0 8px;
}

/* ── プレビュー ───────────────────────────────────────────────────── */
.preview-panel-inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.current-settings-label {
  font-size: 0.85rem;
  color: #666;
  background: #f8fafc;
  border: 1px solid #e4e9f0;
  border-radius: 6px;
  padding: 6px 10px;
  text-align: center;
}

.preview-frame {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  aspect-ratio: 210 / 297;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  border-radius: 2px;
  overflow: hidden;
}

.preview-frame svg {
  display: block;
  width: 100%;
  height: 100%;
}

.zoom-btn-row {
  display: flex;
  justify-content: center;
}

/* ── 出力エリア ───────────────────────────────────────────────────── */
.export-panel {
  border-top: 1px solid #eef1f5;
  padding-top: 14px;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-summary-list {
  list-style: none;
  margin: 0;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #e4e9f0;
  border-radius: 8px;
  font-size: 0.85rem;
  color: #444;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.export-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  color: #333;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}
.btn:hover { background: #eef2f7; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: #2f6fb0;
  border-color: #2f6fb0;
  color: #fff;
  font-size: 1rem;
  padding: 14px 20px;
}
.btn-primary:hover { background: #245a91; }

.btn-outline {
  background: #fff;
  border-color: #2f6fb0;
  color: #2f6fb0;
}
.btn-outline:hover { background: #eaf2fb; }

.btn-reset {
  background: #fff;
  border-color: #e0b0b0;
  color: #a83232;
  align-self: flex-start;
  font-weight: 500;
  padding: 8px 14px;
  font-size: 0.85rem;
}
.btn-reset:hover { background: #fdf0f0; }

.print-note {
  font-size: 0.78rem;
  color: #888;
  line-height: 1.6;
}

.print-troubleshoot {
  font-size: 0.78rem;
  color: #666;
}

.print-troubleshoot summary {
  cursor: pointer;
  color: #2f6fb0;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.print-troubleshoot summary::-webkit-details-marker { display: none; }
.print-troubleshoot summary::before {
  content: '▶';
  font-size: 0.6rem;
  transition: transform 0.15s;
}
.print-troubleshoot[open] summary::before { transform: rotate(90deg); }

.print-troubleshoot ul {
  margin: 6px 0 0;
  padding-left: 1.2em;
  line-height: 1.7;
}

.export-error {
  color: #cc2222;
  font-size: 0.85rem;
  min-height: 1.1em;
}

/* ── モーダル（拡大プレビュー） ───────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: #fff;
  border-radius: 10px;
  width: min(96vw, 1200px);
  height: 94vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
}

.modal-title { font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: #666;
  padding: 4px 8px;
}
.modal-close:hover { color: #222; }

.modal-body {
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow: auto;
  display: flex;
}

/* 実際の幅・高さはJS（sizeZoomFrame）が設定する。縦長の用紙をウィンドウの
   縦幅が低い環境で開いた場合は、意図的にモーダルの高さを超えて拡大し、
   縦スクロールで見られるようにするため、max-heightは指定しない
  （指定するとJSが計算した高さが縦横比を保てず変形してしまう）。
   中央寄せは modal-body 側の align-items/justify-content ではなく
   margin: auto で行う。align-items: center のままだと、内容が
   はみ出した際に先頭（上端・左端）側へスクロールできなくなるため。 */
.modal-body .preview-frame {
  max-width: 100%;
  flex-shrink: 0;
  margin: auto;
}

/* ── SEOコンテンツ（noshi-maker等の.nm-doc-sectionと統一した見出し・表組み） ── */
.seo-content {
  max-width: 960px;
  margin: 40px auto 60px;
  padding: 0 16px;
  line-height: 1.8;
  color: #374151;
}
.seo-content h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 40px 0 14px;
  color: #111827;
  border-left: 4px solid #2f6fb0;
  padding-left: 10px;
}
.seo-content h2:first-of-type { margin-top: 0; }
.seo-content h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 20px 0 8px;
  color: #1f4f8a;
  border-left: 3px solid #a9c8e8;
  padding-left: 8px;
}
.seo-content p,
.seo-content li {
  font-size: 0.92rem;
  line-height: 1.85;
  color: #374151;
}
.seo-content p { margin: 0 0 12px; }
.seo-content ul,
.seo-content ol { margin: 0 0 12px; padding-left: 1.4em; }
.seo-content li { margin-bottom: 4px; }

/* 使い方の手順（丸数字つきステップ） */
.seo-content ol.hgs-steps {
  list-style: none;
  counter-reset: hgs-step;
  padding: 0;
  margin: 0 0 14px;
}
.seo-content ol.hgs-steps li {
  position: relative;
  padding: 8px 0 10px 34px;
  margin-bottom: 0;
  border-bottom: 1px solid #f3f4f6;
}
.seo-content ol.hgs-steps li:last-child { border-bottom: none; }
.seo-content ol.hgs-steps li::before {
  counter-increment: hgs-step;
  content: counter(hgs-step);
  position: absolute;
  left: 0;
  top: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #2f6fb0;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 表（マス目サイズの目安など） */
.seo-content table.hgs-table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 14px;
  font-size: 0.88rem;
}
.seo-content table.hgs-table th,
.seo-content table.hgs-table td {
  border: 1px solid #e5e7eb;
  padding: 8px 12px;
  text-align: left;
}
.seo-content table.hgs-table th {
  background: #f2f6fb;
  color: #1f4f8a;
  font-weight: 700;
}

/* 補足の注意書きボックス */
.seo-content .hgs-doc-box {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px 18px;
  margin: 0 0 14px;
}
.seo-content .hgs-doc-box p:last-child { margin-bottom: 0; }

/* 関連するツール（カード状のリンク一覧） */
.seo-content ul.hgs-related-links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.seo-content ul.hgs-related-links li { margin-bottom: 0; }
.seo-content ul.hgs-related-links li a {
  display: block;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px 14px;
  color: #1d4ed8;
  text-decoration: none;
  font-size: 0.875rem;
  background: #fff;
}
.seo-content ul.hgs-related-links li a:hover { background: #eff6ff; }

/* ── スマホ用: 追従PDF保存バー ────────────────────────────────────── */
.mobile-pdf-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 900;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid #e4e9f0;
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.12);
  transform: translateY(100%);
  transition: transform 0.2s ease;
}
.mobile-pdf-bar.is-visible { transform: translateY(0); }
.mobile-pdf-bar .btn { width: 100%; padding: 12px 18px; }

@media (min-width: 992px) {
  .mobile-pdf-bar { display: none; }
}

/* ── 印刷 ─────────────────────────────────────────────────────────── */
#printArea { display: none; }

@media print {
  /* ブラウザ既定のbodyマージン(約8px)が残っていると、@pageで指定した
     用紙サイズをわずかに超えて、内容のない2枚目のページが生成されてしまう。
     html/bodyのmargin/paddingを0にし、heightを100%指定して
     #printAreaとsvgのheight:100%が正しくページいっぱいに解決されるようにする。 */
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    height: 100% !important;
    overflow: visible !important;
  }
  body > *:not(#printArea) { display: none !important; }
  #printArea {
    display: block !important;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
  }
  #printArea svg {
    display: block;
    width: 100%;
    height: 100%;
  }
}

/* ── アクセシビリティ：十分なタップ領域 ───────────────────────────── */
@media (max-width: 600px) {
  .seg-btn { min-height: 44px; padding: 10px 14px; }
  .color-btn { min-height: 44px; }
}
