/* ===== 基本設定（色・角丸・影・余白はここで一元管理） ===== */
:root {
  /* ベースカラー */
  --bg: #f6f7fb;
  --card: #ffffff;
  --surface: #f8f9fc;      /* 入力欄・プレビューカードなどの面 */
  --text: #1c2030;
  --muted: #5b6175;        /* 補足テキスト（白背景でコントラスト比 約6:1） */
  --border: #e4e6ee;

  /* メイン：アシスタント = 紫 */
  --assist: #6c4cf1;
  --assist-strong: #5a3be0;
  --assist-soft: #f1edff;

  /* アクセント：生成 = オレンジ（白文字が読める濃さ） */
  --gen: #c94a1a;
  --gen-strong: #b03f14;
  --gen-soft: #fff1ea;

  /* エラー */
  --danger: #b42318;
  --danger-soft: #fef3f2;

  --radius-lg: 20px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28, 32, 48, 0.04), 0 8px 24px rgba(28, 32, 48, 0.06);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }

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

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

/* 線のアイコン（サイズ・線の太さを統一） */
.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 画面には見せず、キーボード操作・読み上げには残す */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ===== ヘッダー ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--assist), #e2622f);
  color: #fff;
  font-weight: 800;
}
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: 0.01em; }
.badge-mock {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border-radius: 999px;
  padding: 4px 12px;
}

.lead {
  margin: 32px 0 24px;
  color: var(--muted);
  font-size: 15px;
}

/* ===== 2カラムレイアウト ===== */
.layout {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 24px;
  align-items: start;
  padding-bottom: 48px;
}

/* ===== カード（パネル） ===== */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px;
}
.panel-assist { --accent: var(--assist); --accent-strong: var(--assist-strong); --soft: var(--assist-soft); }
.panel-generate { --accent: var(--gen); --accent-strong: var(--gen-strong); --soft: var(--gen-soft); }

.panel-head { margin-bottom: 24px; }
.step {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--soft);
  border-radius: 999px;
  padding: 2px 12px;
}
.panel-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 8px;
}
.panel-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--soft);
  color: var(--accent);
}
.panel-icon .icon { width: 22px; height: 22px; }
.panel-head h2 { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.4; }
.panel-desc { margin: 0; color: var(--muted); font-size: 14px; }

/* ===== 入力欄 ===== */
.field { margin-bottom: 20px; }
.field-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: end; /* ラベルが折り返してもセレクトの高さを揃える */
}
.label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}
.input {
  width: 100%;
  min-height: 48px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input::placeholder { color: #8a8fa3; }
.input:hover { border-color: #cfd3df; }
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--soft);
  background: #fff;
}
textarea.input { resize: vertical; line-height: 1.7; }
/* セレクトの矢印をシンプルな線のアイコンに */
select.input {
  appearance: none;
  padding-right: 40px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6175' 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: 18px;
}

/* アップロード欄 */
.upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 160px;
  padding: 24px;
  border: 1.5px dashed #c9bdfa;
  border-radius: var(--radius);
  background: var(--soft);
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.upload:hover, .upload.is-drag { border-color: var(--accent); background: #ebe5ff; }
.upload:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--soft); }
.upload-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 4px;
  border-radius: 50%;
  background: #fff;
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(108, 76, 241, 0.15);
}
.upload-main { font-weight: 700; color: var(--accent); }
.upload-sub { font-size: 13px; color: var(--muted); }
.upload-preview {
  max-width: 100%;
  max-height: 160px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

/* ===== ボタン ===== */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 25%, transparent);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.btn:hover { background: var(--accent-strong); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 3px solid var(--soft); outline-offset: 2px; box-shadow: 0 0 0 2px var(--accent); }
.btn:disabled { opacity: 0.65; cursor: wait; transform: none; }

/* ===== アシスタント回答エリア ===== */
.result {
  margin-top: 24px;
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.result-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
}
.result-head .icon { width: 18px; height: 18px; }
.result-body { padding: 16px 20px 20px; font-size: 15px; line-height: 1.8; }
.result-title { margin: 0 0 8px; font-weight: 700; }
.result-body ul { margin: 0; padding-left: 1.2em; }
.result-body li + li { margin-top: 8px; }
.result-body.is-text { white-space: pre-wrap; } /* AIの回答テキスト（改行をそのまま表示） */

/* ===== 生成プレビュー ===== */
.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 32px 0 16px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.preview-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
}
.preview-title .icon { color: var(--accent); }
.preview-meta {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: var(--soft);
  padding: 4px 12px;
  border-radius: 999px;
}
.preview-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr); /* PC・タブレット：4枚横並び（8枚なら2段） */
  gap: 16px;
}
.page-card {
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
}
.page-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 8px;
}
.page-no { font-weight: 700; font-size: 14px; }
.page-koma { font-size: 12px; color: var(--muted); }
.page-sheet {
  position: relative;
  aspect-ratio: 2 / 3; /* 生成画像（1024x1536）と同じ縦横比 */
  display: grid;
  gap: 4px;
  padding: 6px;
  background: #fff;
  border: 1.5px solid #3a3f52;
  border-radius: 4px;
}
.koma {
  background: repeating-linear-gradient(45deg, #f5f6fa, #f5f6fa 6px, #eef0f5 6px, #eef0f5 12px);
  border: 1px solid #3a3f52;
}
.page-sheet[data-koma="1"] { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.page-sheet[data-koma="2"] { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.page-sheet[data-koma="4"] { grid-template-columns: 1fr; grid-template-rows: repeat(4, 1fr); }
.page-sheet[data-koma="6"] { grid-template-columns: 1fr 1fr; grid-template-rows: repeat(3, 1fr); }
.sheet-label {
  position: absolute;
  inset: 50% 8px auto;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-sm);
  padding: 8px 6px;
  text-align: center;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  box-shadow: 0 2px 8px rgba(28, 32, 48, 0.08);
}
.sheet-label strong { display: block; color: var(--gen); font-size: 12px; word-break: keep-all; }

.page-card[data-state="loading"] .page-sheet { animation: pulse 1.2s ease-in-out infinite; }
.page-card[data-state="error"] .sheet-status { color: var(--danger); font-weight: 700; }
@keyframes pulse { 50% { opacity: 0.45; } }

/* 生成された画像 */
.page-image {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: contain;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(28, 32, 48, 0.12);
}
.page-save {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  margin-top: 8px;
  border: 1px solid color-mix(in srgb, var(--gen) 35%, transparent);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 13px;
  font-weight: 700;
  color: var(--gen);
  text-decoration: none;
  transition: background 0.15s;
}
.page-save:hover { background: var(--gen-soft); }

/* ===== エラー表示・補足 ===== */
.alert {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  border: 1px solid #fecdca;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
}
.alert[hidden] { display: none; }
.alert::before {
  content: "";
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E") center / contain no-repeat;
}
.hint { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

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

/* ===== タブレット（〜1100px）：2エリアを縦並び ===== */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; max-width: 760px; margin: 0 auto; }
  .lead { max-width: 760px; margin-left: auto; margin-right: auto; }
}

/* ===== スマホ（〜640px） ===== */
@media (max-width: 640px) {
  body { font-size: 15px; }
  .container { padding: 0 16px; }
  .header-inner { height: 56px; }
  .logo-mark { width: 32px; height: 32px; }
  .logo-text { font-size: 16px; }
  .lead { margin: 24px 0 16px; font-size: 14px; }
  .layout { gap: 16px; padding-bottom: 32px; }
  .panel { padding: 24px 20px; border-radius: 16px; }
  .panel-head h2 { font-size: 20px; }
  .panel-icon { width: 36px; height: 36px; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .input { font-size: 16px; } /* iOSで入力時に拡大されないように */
  .preview-grid { grid-template-columns: 1fr; }
  .page-sheet, .page-image { max-width: 320px; margin: 0 auto; width: 100%; }
  .page-save { min-height: 44px; max-width: 320px; margin: 8px auto 0; }
  .sheet-label { inset: 50% 16px auto; font-size: 13px; }
  .sheet-label strong { font-size: 14px; }
}
