/* Book Maker v3 UI ── 紺/金/朱 統一（landing と同トーン）・3STEP・レスポンシブ
   フォント: 和文システムフォント基調（.exe オフライン対応・CDN非依存）
   見出し=serif（Yu Mincho / Hiragino Mincho）／本文=sans（Yu Gothic / Hiragino / Meiryo） */
:root {
  --bg: #FAF7F0;         /* 生成り */
  --card: #ffffff;
  --ink: #0E1826;        /* 紺 */
  --ink2: #12202E;       /* 濃紺（本文・構造アクセント） */
  --primary: #12202E;    /* 構造アクセント（番号・選択・STEP）＝紺 */
  --primary-dark: #0E1826;
  --coral: #E8523F;      /* 主CTA・警告 */
  --coral-dark: #c8412f;
  --gold: #C8952F;       /* アクセント・枠・フォーカス */
  --gold-lt: #e6b856;
  --accent: #C8952F;
  --success: #16a34a;
  --danger: #E8523F;
  --text: #12202E;
  --muted: #5c6b7a;
  --border: #ece4d5;     /* 温かいボーダー */
  --focus: rgba(200,149,47,.35); /* 金のフォーカスリング */
  --serif: 'Noto Serif JP', "Yu Mincho", "Hiragino Mincho ProN", "YuMincho", serif;
  --sans: 'Noto Sans JP', "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.9;
  -webkit-font-smoothing: antialiased;
}

/* ---------- ヘッダー ---------- */
header {
  background: radial-gradient(900px 400px at 80% -40%, rgba(200,149,47,.20), transparent 60%),
              linear-gradient(135deg, #0E1826, #152438);
  color: #fff;
  padding: 26px 20px 22px;
  text-align: center;
  border-bottom: 1px solid rgba(200,149,47,.25);
}
header h1 { margin: 0 0 6px; font-family: var(--serif); font-weight: 900; font-size: 32px; letter-spacing: .02em; color: #FAF7F0; }
header .lead { margin: 0; font-size: 16px; font-weight: 700; color: #e6b856; }
header .lead2 { margin: 5px 0 0; font-size: 13px; color: #c3cedb; }

/* ---------- STEP インジケーター ---------- */
.steps {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
  max-width: 1080px; margin: 18px auto 4px; padding: 0 16px;
}
.step {
  flex: 1 1 0; min-width: 200px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 10px; color: var(--muted);
}
.step .step-num {
  width: 30px; height: 30px; border-radius: 50%;
  background: #efe7d6; color: #9a8a63;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex: 0 0 auto;
}
.step .step-label { font-weight: 700; font-size: 15px; }
.step.active { border-color: var(--gold); background: #fdf6e9; color: var(--ink2); box-shadow: 0 6px 18px rgba(200,149,47,.18); }
.step.active .step-num { background: var(--ink2); color: #fff; }
.step.done { border-color: var(--success); color: var(--success); }
.step.done .step-num { background: var(--success); color: #fff; }

/* ---------- レイアウト ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 8px 16px 40px; }
.layout { display: grid; grid-template-columns: 1fr; gap: 24px; align-items: start; }

#form-section { background: transparent; border: none; box-shadow: none; padding: 8px 0; }
#form-section > h2 { margin-left: 4px; }

/* 必須入力カード / 任意ブロック / 次にやること */
.required-card { padding: 28px; }
.optional-block { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 6px 16px; margin-top: 16px; }
.optional-block summary { cursor: pointer; font-weight: 700; color: var(--gold); padding: 10px 0; }
.optional-block[open] { padding-bottom: 16px; }
.guide-card { background: #fdf6e9; border: 1px solid #f0e0b8; }
.guide-card h3 { color: var(--ink2); font-family: var(--serif); font-weight: 700; }

/* 過去プロジェクト（控えめ・折りたたみ） */
.project-history { max-width: 1180px; margin: 12px auto; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 10px 16px; }
.project-history summary { cursor: pointer; font-weight: 700; color: var(--gold); }
#project-list-wrap { max-height: 180px; overflow-y: auto; margin-top: 10px; }
#project-list li { font-size: 12px; max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- カード ---------- */
.card, section {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 10px 30px -18px rgba(18,32,46,.35); padding: 24px; margin: 16px 0;
}
section h2 { margin: 0 0 6px; font-family: var(--serif); font-weight: 900; font-size: 23px; color: var(--ink2); }
.note { color: var(--muted); font-size: 14px; }

/* ---------- フォーム ---------- */
.field { display: block; margin: 18px 0; }
.field .label-title { font-size: 16px; font-weight: 700; display: inline-block; }
.field .num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--ink2); color: #fff; font-size: 13px; font-weight: 700; margin-right: 8px;
}
.field .hint { display: block; color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 8px; vertical-align: middle; }
.badge-req { background: #fdeae6; color: #c0442f; }
.badge-opt { background: #f1efe9; color: #7a8794; }

input[type="text"], input[type="password"], textarea, select {
  width: 100%; font-size: 16px; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--text); font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--focus);
}
textarea { resize: vertical; }

.reference-block { border: 1px dashed var(--border); border-radius: 12px; padding: 16px; background: #fbf8f1; }
.reference-block legend { font-weight: 700; padding: 0 6px; }
.ref-row { margin: 12px 0; }
.ref-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.ref-hint-small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.ref-counter { font-size: 12px; color: var(--muted); }
.upload-list { font-size: 13px; color: var(--muted); padding-left: 18px; }

/* APIキー */
.apikey-help {
  background: #fdf6e9; border: 1px solid #f0e0b8; color: #8a6d2a;
  border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 6px 0 8px;
}
.apikey-help a { color: var(--gold); }
.apikey-row { position: relative; display: flex; gap: 8px; }
.apikey-row input { flex: 1; }
.toggle-btn {
  border: 1.5px solid var(--border); background: #f8f4ec; color: var(--text);
  border-radius: 10px; padding: 0 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
}

/* ---------- ボタン ---------- */
button, .dl-btn { font-family: inherit; cursor: pointer; }
/* 主CTA = 朱 */
.primary-button, #submit-btn, .primary-btn, #confirm-title-btn, #approve-structure-btn {
  background: var(--coral); color: #fff; border: none; border-radius: 12px;
  padding: 15px 22px; font-weight: 900; font-size: 17px; width: 100%;
  box-shadow: 0 14px 34px -14px rgba(232,82,63,.65); transition: background .15s, transform .15s;
}
.primary-button:hover, #submit-btn:hover, .primary-btn:hover, #confirm-title-btn:hover, #approve-structure-btn:hover { background: var(--coral-dark); }
button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
/* 副CTA = 白地・紺枠（ゴースト） */
.secondary-btn, #regen-titles-btn, #regen-structure-btn, #open-modify-btn, #back-btn, #back-to-form-btn, #cancel-modify-btn {
  background: #fff; color: var(--ink2); border: 1.5px solid #d9ccb2;
  border-radius: 12px; padding: 12px 18px; font-weight: 700; font-size: 15px;
}
.secondary-btn:hover { background: #f6f2ea; }
#reset-btn, #retry-btn {
  background: #fff; color: var(--ink2); border: 1.5px solid #d9ccb2;
  border-radius: 12px; padding: 12px 18px; font-weight: 700; margin-top: 14px;
}

/* ---------- 注意・警告（黄系維持） ---------- */
.notice-warning, .references-warning-banner, .persistence-warning {
  background: #fffbeb; border: 1px solid var(--gold); color: #92400e;
  border-radius: 12px; padding: 12px 16px; margin: 14px auto; max-width: 1080px;
  font-size: 14px; font-weight: 600;
}
.persistence-warning { display: block; }

/* ---------- 進捗 ---------- */
.progress-wrap { margin: 16px 0; }
.progress-bar { width: 100%; height: 18px; background: #efe7d6; border-radius: 999px; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--coral), var(--gold)); transition: width .4s; }
.progress-bar .indeterminate { height: 100%; width: 40%; background: var(--gold); border-radius: 999px; animation: slide 1.2s infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
#progress-pct { font-weight: 700; font-size: 18px; text-align: center; margin: 8px 0; color: var(--ink2); }
#progress-message { text-align: center; font-size: 15px; }

.checklist { list-style: none; padding: 0; margin: 16px auto; max-width: 460px; }
.checklist li { padding: 8px 12px; border-radius: 8px; font-size: 15px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.checklist li.done { color: var(--success); }
.checklist li.active { color: var(--ink2); background: #fdf6e9; font-weight: 700; }
.checklist .mark { width: 20px; text-align: center; }

.spinner {
  display: inline-block; width: 16px; height: 16px; border: 2.5px solid rgba(255,255,255,.5);
  border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- タイトル候補 ---------- */
#title-cards { list-style: none; padding: 0; display: grid; gap: 12px; }
#title-cards li {
  border: 2px solid var(--border); border-radius: 12px; padding: 16px; cursor: pointer; background: #fff; transition: all .12s;
}
#title-cards li:hover { border-color: var(--gold-lt); background: #fdfaf2; }
#title-cards li.selected { border-color: var(--gold); background: #fdf6e9; box-shadow: 0 6px 18px rgba(200,149,47,.2); }
#title-cards .t-title { font-family: var(--serif); font-size: 18px; font-weight: 700; color: var(--ink2); }
#title-cards .t-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
#title-cards .t-reason { font-size: 13px; color: #475569; margin-top: 6px; }
.title-pick-actions, .structure-actions, .references-actions, .modify-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.title-pick-actions button, .structure-actions button { flex: 1 1 auto; }

/* ---------- 章立て ---------- */
.structure-title-banner { font-family: var(--serif); font-size: 18px; font-weight: 700; background: #fdf6e9; border: 1px solid #f0e0b8; border-radius: 10px; padding: 12px; margin-bottom: 12px; color: var(--ink2); }
.structure-tree { display: grid; gap: 10px; }
.structure-tree .chapter-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: #fff; }
.structure-tree .chapter-card h3 { margin: 0 0 4px; font-family: var(--serif); font-size: 16px; color: var(--ink2); }
.structure-tree .chapter-card .role { font-size: 13px; color: var(--gold); font-weight: 700; }
.structure-tree .chapter-card .km { font-size: 14px; color: var(--muted); }
.modify-panel { margin-top: 14px; background: #fbf8f1; border: 1px dashed var(--border); border-radius: 12px; padding: 14px; }

/* ---------- 完成 ---------- */
.result-title { font-family: var(--serif); font-size: 20px; font-weight: 700; color: var(--ink2); }
.result-stats { color: var(--muted); }
.downloads { display: grid; gap: 10px; margin: 18px 0; }
.dl-btn {
  display: block; text-align: center; text-decoration: none;
  border: 1.5px solid var(--border); border-radius: 12px; padding: 14px; font-weight: 700; color: var(--ink2); background: #f8f4ec;
}
.dl-btn:hover { background: #f1ebdf; }
.dl-btn.primary { background: var(--coral); color: #fff; border: none; font-size: 18px; font-weight: 900; box-shadow: 0 14px 34px -14px rgba(232,82,63,.65); }
.dl-btn.primary:hover { background: var(--coral-dark); }
.next-steps { background: #fdf6e9; border: 1px solid #f0e0b8; border-radius: 12px; padding: 14px 18px; margin-top: 12px; }
.next-steps li { margin: 4px 0; }
.copy-box { display: flex; gap: 8px; margin-top: 8px; }
.copy-box textarea { min-height: 90px; }

/* ---------- プロジェクト ---------- */
#project-sidebar { max-width: 1080px; margin: 12px auto 0; padding: 0 16px; }
#project-sidebar h3 { font-size: 15px; margin: 8px 0; }
.side-btn { background: var(--ink2); color: #fff; border: none; border-radius: 10px; padding: 10px 14px; font-weight: 700; }
.side-btn:hover { background: var(--ink); }
#project-list { list-style: none; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; }
#project-list li { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
#project-list li:hover { border-color: var(--gold); }
.side-note { color: var(--muted); font-size: 12px; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }
.hidden { display: none !important; }

/* ---------- レスポンシブ ---------- */
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1.2fr) 360px; align-items: start; }
  .guide-card { position: sticky; top: 16px; }
}
@media (max-width: 768px) {
  header h1 { font-size: 26px; }
  .layout { grid-template-columns: 1fr; }
  .guide-card { position: static; }
  .step { min-width: 100%; }
  button, .primary-button, .secondary-btn { width: 100%; }
  .title-pick-actions, .structure-actions, .references-actions { flex-direction: column; }
  section, .card, .required-card { padding: 18px; }
}
