/* =========================================================
   Manga Creative Studio
   色の役割：企画アシスタント = 紫 / 漫画生成 = オレンジ
   赤はエラー表示だけに使う
   ========================================================= */
:root {
  /* ベース */
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-sub: #f9fafc;
  --text: #1c1f2e;
  --text-sub: #545a6e;   /* 白背景でも十分なコントラスト */
  --border: #e6e8f0;
  --border-strong: #d5d9e5;

  /* 役割カラー */
  --assist: #6553e8;
  --assist-hover: #5442d6;
  --assist-soft: #f2f0ff;
  --gen: #ea6a35;
  --gen-hover: #d65a27;
  --gen-soft: #fff4ee;

  /* 状態 */
  --ok: #1f9d61;
  --error: #c93a3a;
  --error-soft: #fdf0f0;
  --error-border: #f2c4c4;

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

  --font: "Inter", "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  background:
    radial-gradient(1200px 400px at 10% -10%, #eeebff 0%, transparent 60%),
    radial-gradient(1000px 400px at 100% -10%, #fff0e8 0%, transparent 55%),
    var(--bg);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

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

/* ===== ヘッダー ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  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 h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.logo-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--assist), var(--gen));
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
}
.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  color: var(--text-sub);
  background: var(--surface);
  border: 1px solid var(--border);
}

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

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

.panel-head { margin-bottom: 28px; }
.panel-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 16px;
}
.step {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--soft);
  padding: 4px 12px;
  border-radius: 999px;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-sub);
}
.status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
}
.status-on::before { background: var(--ok); box-shadow: 0 0 0 3px #e3f5ec; }

.panel-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.panel-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: var(--accent);
  background: var(--soft);
}
.panel-icon .icon { width: 22px; height: 22px; }
.panel-title h2 {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -0.01em;
}
.lead { color: var(--text-sub); font-size: 0.95rem; }

/* ===== フォーム ===== */
.form { display: flex; flex-direction: column; gap: 22px; }
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field > label,
.field > .label {
  font-weight: 700;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.required {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--soft);
  padding: 1px 8px;
  border-radius: 999px;
}
.field-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: end;
}

select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* iOS で入力時にズームしないよう 16px */
  line-height: 1.6;
  color: var(--text);
  background-color: var(--surface-sub);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color .2s, box-shadow .2s, background-color .2s;
}
select {
  appearance: none;
  min-height: 48px;
  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='%23545a6e' 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;
}
textarea { resize: vertical; min-height: 120px; }
textarea::placeholder { color: #8a90a3; }
select:hover, textarea:hover { border-color: #c3c8d8; }
select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--surface);
  box-shadow: 0 0 0 4px var(--soft);
}

/* アップロード欄 */
.upload {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border: 1.5px dashed color-mix(in srgb, var(--accent) 35%, white);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--soft) 60%, white);
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.upload:hover { border-color: var(--accent); background: var(--soft); }
.upload-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(28, 31, 46, 0.08);
}
.upload-icon .icon { width: 22px; height: 22px; }
.upload-text { display: flex; flex-direction: column; line-height: 1.5; }
.upload-text strong { font-size: 0.92rem; color: var(--text); }
.upload-text small { font-size: 0.78rem; color: var(--text-sub); }
.upload-file { margin-left: auto; font-size: 0.82rem; font-weight: 700; color: var(--accent); }

.hint {
  display: flex;
  gap: 8px;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-sub);
}
.hint .icon { width: 16px; height: 16px; margin-top: 2px; }

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  padding: 0 24px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 28%, transparent);
  transition: background .15s, transform .15s, box-shadow .15s;
}
.btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--soft), 0 0 0 6px var(--accent); }
.btn.is-loading { opacity: .8; pointer-events: none; }
.btn.is-loading .icon { display: none; }
.btn.is-loading::before { content: ""; } /* 下のスピナー共通スタイルを適用 */

/* 読み込み中のくるくる（ボタン・回答エリア共通） */
.btn.is-loading::before,
.result.is-loading .result-head::before {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== アシスタント回答エリア ===== */
.result {
  margin-top: 28px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-sub);
  overflow: hidden;
}
.result-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--soft);
}
.result-head .icon { width: 18px; height: 18px; }
.result-body { padding: 18px 20px 20px; font-size: 0.95rem; line-height: 1.85; }
.result-title { margin-bottom: 6px; font-weight: 700; }
.result-body ul { margin: 0; padding-left: 1.2em; }
.result-body li + li { margin-top: 6px; }
.result-text { white-space: pre-wrap; word-break: break-word; }

.result.is-loading .result-head::before { content: ""; }
.result.is-loading .result-head .icon { display: none; }
.result.is-loading .result-body { color: var(--text-sub); }
.result.is-error { border-color: var(--error-border); background: var(--surface); }
.result.is-error .result-head { background: var(--error-soft); color: var(--error); }
.result.is-error .result-body { color: var(--error); font-weight: 500; }

/* ===== 漫画生成の案内 ===== */
.notice {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--gen-soft);
  border: 1px solid #f7d3c1;
  font-size: 0.9rem;
  line-height: 1.7;
}
.notice[hidden] { display: none; }
.notice .icon { color: var(--gen); margin-top: 2px; }
.notice strong { display: block; }
.notice p { margin-top: 4px; color: var(--text-sub); }
.notice.is-error { background: var(--error-soft); border-color: var(--error-border); color: var(--error); }
.notice.is-error .icon,
.notice.is-error p { color: var(--error); }

/* 空欄エラーの入力欄 */
textarea.is-invalid,
textarea.is-invalid:focus { border-color: var(--error); box-shadow: 0 0 0 4px var(--error-soft); }

/* ===== 生成プレビュー ===== */
.preview {
  margin-top: 32px;
  padding-top: 28px;
  border-top: 1px solid var(--border);
}
.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.preview-head h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 700;
}
.preview-head h3 .icon { width: 18px; height: 18px; color: var(--gen); }
.preview-meta {
  font-size: 0.78rem;
  color: var(--text-sub);
  background: var(--surface-sub);
  border: 1px solid var(--border);
  padding: 2px 10px;
  border-radius: 999px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)); /* PC・タブレットは4列（4枚なら1行に収まる） */
  gap: 12px;
}
.page-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: box-shadow .2s, transform .2s;
}
.page-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.page-frame {
  aspect-ratio: 1 / 1.414; /* 漫画原稿の縦長比率 */
  display: grid;
  gap: 4px;
  padding: 6px;
  background: var(--surface-sub);
  border: 1.5px solid #3a3d4d;
  border-radius: 4px;
}
.koma { background: #fff; border: 1px solid #3a3d4d; }
.page-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.page-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px;
}
.page-card-head strong { font-size: 0.85rem; font-family: "Inter", var(--font); }
.page-card-head span {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--gen);
  background: var(--gen-soft);
  padding: 0 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.page-label { font-size: 0.75rem; font-weight: 700; color: var(--text-sub); line-height: 1.5; }
.page-note { font-size: 0.72rem; color: var(--text-sub); line-height: 1.5; }

/* 画像生成は今後の機能：プレビュー枠を「準備中」に見せる */
.preview-locked .page-frame { opacity: .5; }
.preview-locked .page-label::after {
  content: "準備中";
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  font-size: 0.65rem;
  color: var(--text-sub);
  background: var(--surface-sub);
  border: 1px solid var(--border);
  border-radius: 999px;
}

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

/* ===== タブレット（1カラム・横に伸びすぎないよう幅を制限） ===== */
@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
    max-width: 760px;
    gap: 28px;
  }
}

/* ===== スマホ ===== */
@media (max-width: 640px) {
  body { font-size: 15px; }
  .container { padding: 0 16px; }
  .header-inner { height: 56px; }
  .logo h1 { font-size: 1.02rem; }
  .logo-mark { width: 32px; height: 32px; }

  .main-grid { gap: 20px; padding-top: 20px; padding-bottom: 32px; }
  .panel { padding: 24px 20px; border-radius: 18px; }
  .panel-head { margin-bottom: 24px; }
  .panel-title h2 { font-size: 1.1rem; word-break: auto-phrase; } /* 日本語を文節で折り返す */
  .panel-icon { width: 40px; height: 40px; }

  .form { gap: 20px; }
  .field-row { grid-template-columns: 1fr; }
  .upload { padding: 16px; }
  .upload-text small { font-size: 0.75rem; }

  /* プレビュー：1列の縦並び。カードはサムネイル＋説明の横レイアウトで縦に長くなりすぎないように */
  .preview-grid { grid-template-columns: 1fr; gap: 12px; }
  .page-card {
    display: grid;
    grid-template-columns: 96px 1fr;
    align-items: center;
    gap: 16px;
    padding: 12px;
  }
  .page-card-head { justify-content: flex-start; gap: 8px; }
  .page-card-head strong { font-size: 0.95rem; }
  .page-label { font-size: 0.82rem; }
  .page-note { font-size: 0.8rem; }
}
