/* ===== 基本設定 ===== */
:root {
  /* ベースカラー */
  --bg: #f4f6f9;
  --card: #ffffff;
  --field: #f8f9fb;
  --border: #dfe3ea;
  --border-strong: #8a91a1;

  /* メインカラー = ペン入れの墨色（文字・漫画生成） */
  --ink: #1b1f2a;
  --muted: #586073;

  /* アクセントカラー = 下描きの青（企画アシスタント・リンク・フォーカス） */
  --blue: #2460d8;
  --blue-soft: #edf3ff;

  /* エラー専用 */
  --error: #b42318;
  --error-soft: #fef3f2;

  --radius-l: 20px;
  --radius-m: 12px;
  --shadow: 0 1px 2px rgba(27, 31, 42, 0.05), 0 8px 24px rgba(27, 31, 42, 0.05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-padding-top: 88px; } /* 固定ヘッダーに隠れないようにする */

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  /* 英字は Segoe UI / SF、日本語は Hiragino / Noto / BIZ UD で表示 */
  font-family: "SF Pro Text", "Segoe UI", "Hiragino Sans", "Noto Sans JP", "BIZ UDPGothic", "Meiryo", sans-serif;
  font-size: 1rem;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { line-height: 1.4; word-break: auto-phrase; text-wrap: balance; }
p, .app-footer { text-wrap: pretty; } /* 最後の行に1〜2文字だけ残るのを防ぐ */

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 32px;
}

/* アイコン共通（大きさ・線の太さを統一） */
.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 見た目だけ隠す（キーボード操作・読み上げは可能） */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ===== ヘッダー ===== */
.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
}
.logo { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}
.logo h1 { margin: 0; font-size: 1.25rem; letter-spacing: -0.01em; }
.badge-mock {
  flex: none;
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ===== メイン 2カラム ===== */
.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 32px;
  padding-top: 40px;
  padding-bottom: 40px;
  align-items: start;
}

/* ===== パネル（カード） ===== */
.panel {
  background: var(--card);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow);
  padding: 36px;
}
.panel-assist   { --accent: var(--blue); --accent-hover: #1a4bb0; --accent-soft: var(--blue-soft); }
.panel-generate { --accent: var(--ink);  --accent-hover: #363c4d; --accent-soft: #eceef3; }

.panel-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 16px;
  align-items: center;
  margin-bottom: 32px;
}
.panel-icon {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  color: #fff;
  background: var(--accent);
}
.panel-icon .icon { width: 28px; height: 28px; }
.step {
  align-self: end;
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.06em;
  color: var(--accent);
}
.panel-head h2 { margin: 0; align-self: start; font-size: 1.5rem; }
.panel-desc { grid-column: 1 / -1; margin: 16px 0 0; color: var(--muted); }

/* ===== フォーム ===== */
.form { display: flex; flex-direction: column; gap: 24px; }
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.label { font-weight: 700; font-size: 0.9375rem; }

select, textarea {
  width: 100%;
  font: inherit; /* 16px を保ち、iOS の自動ズームを防ぐ */
  color: var(--ink);
  background-color: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 12px 16px;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
select {
  min-height: 52px;
  padding-right: 44px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23586073' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 20px;
  cursor: pointer;
}
textarea { display: block; resize: vertical; min-height: 136px; }
textarea::placeholder { color: #697084; opacity: 1; }
select:hover, textarea:hover { border-color: var(--border-strong); }
select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(36, 96, 216, 0.2);
  background-color: #fff;
}

/* 未入力エラー */
textarea[aria-invalid="true"] {
  border-color: #d92d20;
  box-shadow: 0 0 0 3px #fee4e2;
}
.field-error {
  margin: 0;
  color: var(--error);
  font-size: 0.9375rem;
  font-weight: 700;
}

/* アップロード欄 */
.upload {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-m);
  background: var(--field);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.upload:hover, .upload.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.upload:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(36, 96, 216, 0.2);
}
.upload-icon { display: grid; color: var(--accent); }
.upload-icon .icon { width: 28px; height: 28px; }
.upload-text { font-weight: 700; line-height: 1.6; }
.upload-text small { font-size: 0.875rem; font-weight: 400; color: var(--muted); }
.upload-file {
  max-width: 100%;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--accent);
  overflow-wrap: anywhere;
}
.upload-file:empty { display: none; }

/* ===== ボタン ===== */
.btn {
  width: 100%;
  min-height: 56px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-m);
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid rgba(36, 96, 216, 0.45); outline-offset: 3px; }
.btn:disabled { opacity: 0.65; cursor: wait; }

/* ===== 出力エリア ===== */
.output { margin-top: 32px; border-radius: var(--radius-m); background: var(--accent-soft); padding: 24px; }
.preview { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--border); }

.output-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  font-weight: 700;
  margin-bottom: 12px;
}
.output-head .icon { color: var(--accent); }
.preview .output-head { margin-bottom: 20px; }
.ai-badge {
  margin-left: auto;
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--muted);
}

.output-body { overflow-wrap: anywhere; line-height: 1.85; }
.output-body.is-placeholder { color: var(--muted); }
.output-body.is-loading { display: flex; align-items: flex-start; gap: 12px; color: var(--accent); font-weight: 700; }
.output-body.is-loading::before {
  content: "";
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 5px;
  border: 3px solid rgba(36, 96, 216, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.output-body.is-error {
  color: var(--error);
  background: var(--error-soft);
  border: 1px solid #fecdca;
  border-radius: 10px;
  padding: 12px 16px;
}

/* AIの回答（見出し・箇条書き） */
.answer-text { margin: 0; }
.answer-heading { margin: 20px 0 6px; font-weight: 700; }
.answer-heading:first-child { margin-top: 0; }
.answer-item { margin: 0 0 6px; padding-left: 1em; text-indent: -1em; }
.output-meta { margin: 16px 0 0; font-size: 0.8125rem; color: var(--muted); text-align: right; }

/* 補足・案内 */
.hint { margin: 0; font-size: 0.875rem; line-height: 1.65; color: var(--muted); }
.api-note, .notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border-radius: var(--radius-m);
  padding: 14px 16px;
  font-size: 0.9375rem;
  line-height: 1.65;
}
.api-note { grid-column: 1 / -1; margin: 16px 0 0; color: var(--muted); background: var(--field); }
.notice { margin-top: 20px; color: var(--ink); background: var(--blue-soft); font-weight: 700; }
.notice .icon { color: var(--blue); }
.api-note .icon, .notice .icon { margin-top: 1px; }

/* ===== プレビュー（カード） ===== */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px 20px;
}
.page-card {
  display: grid;
  grid-template-areas: "art" "head" "caption";
  align-content: start;
  gap: 10px;
  min-width: 0;
}
.page-card-head {
  grid-area: head;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0 8px;
}
.page-card-head strong { font-size: 1rem; }
.page-tag { font-size: 0.875rem; color: var(--muted); }
.page-art {
  grid-area: art;
  aspect-ratio: 3 / 4;
  padding: 10px;
  display: grid;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(27, 31, 42, 0.08);
}
/* コマ枠：漫画のスクリーントーン風 */
.page-art .koma {
  border: 1.5px solid var(--border-strong);
  background: radial-gradient(#d5dae4 1px, transparent 1.4px) 0 0 / 7px 7px;
}
.page-caption { grid-area: caption; margin: 0; font-size: 0.875rem; line-height: 1.6; color: var(--muted); }
.page-caption b { display: block; color: var(--ink); word-break: auto-phrase; }

/* ===== フッター ===== */
.app-footer {
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
  padding: 0 0 40px;
}

/* ===== タブレット：1カラム、プレビューは横長カード2列 ===== */
@media (max-width: 960px) {
  .container { max-width: 760px; }
  .main-grid { grid-template-columns: minmax(0, 1fr); gap: 28px; padding-top: 32px; }
  .page-card {
    grid-template-columns: 124px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "art head" "art caption";
    gap: 6px 16px;
  }
  .page-card-head { flex-direction: column; }
  .page-art { padding: 8px; gap: 6px; align-self: start; }
}

/* ===== スマホ ===== */
@media (max-width: 600px) {
  html { scroll-padding-top: 76px; }
  .container { padding: 0 16px; }
  .header-inner { min-height: 60px; gap: 8px; }
  .logo { gap: 10px; }
  .logo-mark { width: 34px; height: 34px; }
  .logo h1 { font-size: 1.0625rem; }
  .main-grid { padding-top: 20px; padding-bottom: 28px; gap: 20px; }
  .panel { padding: 24px 20px; border-radius: 16px; }
  .panel-head { column-gap: 12px; margin-bottom: 28px; }
  .panel-icon { width: 48px; height: 48px; border-radius: 14px; }
  .panel-icon .icon { width: 24px; height: 24px; }
  .panel-head h2 { font-size: 1.25rem; }
  .field-row { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .output { padding: 20px; }
  .preview-grid { grid-template-columns: minmax(0, 1fr); gap: 24px; } /* プレビューは縦並び */
}

/* とても狭いスマホ：アプリ名を優先し、ヘッダーの補足は次の行へ */
@media (max-width: 360px) {
  .header-inner { flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; gap: 2px 8px; }
  .panel-icon { grid-row: auto; }
  .step { align-self: center; }
  .panel-head h2 { grid-column: 1 / -1; margin-top: 12px; } /* 見出しを全幅にして途中改行を防ぐ */
}

/* 動きを減らす設定の利用者向け */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
  .output-body.is-loading::before { animation-duration: 3s; }
}
