/* ==========================================================
   Manga Creative Studio - スタイル
   ========================================================== */

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-soft: #f7f8fb;
  --border: #e4e8f0;

  /* 文字色（白背景でのコントラスト比: 13.6 / 5.4 / 4.8） */
  --text: #1c2436;
  --text-sub: #5f6b83;
  --text-muted: #6b7280;

  /* 企画アシスタント（青系） */
  --assistant: #3b6ef5;
  --assistant-soft: #eef3ff;
  --assistant-line: #c8d8ff;

  /* 漫画生成（オレンジ系） */
  --generate: #e05a2f;
  --generate-soft: #fff2ed;
  --generate-line: #ffd2c2;

  --radius-sm: 12px;
  --radius: 16px;
  --radius-lg: 20px;

  /* 影は薄く重ねる。枠線の代わりに面の浮き上がりで区切る */
  --shadow-sm: 0 1px 2px rgba(28, 36, 54, .04), 0 2px 8px rgba(28, 36, 54, .05);
  --shadow: 0 2px 4px rgba(28, 36, 54, .04), 0 12px 32px rgba(28, 36, 54, .07);
}

* { box-sizing: border-box; }

/* クラス側の display 指定が hidden 属性を打ち消してしまうのを防ぐ */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* 英字を先に置き、日本語はフォールバックさせる（日英が混在する画面のため） */
  font-family: system-ui, -apple-system, "Segoe UI",
               "Hiragino Kaku Gothic ProN", "Hiragino Sans",
               "Yu Gothic UI", "Meiryo", sans-serif;
  line-height: 1.75;
  font-size: 16px;
}

/* キーボード操作でも現在位置が分かるようにする */
:focus-visible {
  outline: 2px solid var(--assistant);
  outline-offset: 2px;
}

/* ---------- ヘッダー ---------- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-logo {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--assistant), var(--generate));
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .2px;
  line-height: 1.4;
}

.app-subtitle {
  margin: 2px 0 0;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

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

/* ---------- カード ----------
   枠線は使わず、影と背景の差だけで区切る（装飾を重ねすぎない） */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* 機能の違いは見出し部分の色で示す */
.card__head { padding: 28px 28px 24px; }
.card--assistant .card__head { background: var(--assistant-soft); }
.card--generate  .card__head { background: var(--generate-soft); }

.card__title {
  margin: 14px 0 10px;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.5;
}

.card__desc {
  margin: 0;
  font-size: 15px;
  color: var(--text-sub);
}

.card__body {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ---------- バッジ / タグ ---------- */
.badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .4px;
  color: #fff;
}

.badge--assistant { background: var(--assistant); }
.badge--generate  { background: var(--generate); }

.tag {
  font-size: 12.5px;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 3px 12px;
  background: var(--surface);
  white-space: nowrap;
}

/* ---------- 入力欄 ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.field__label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-sub);
  line-height: 1.5;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.select,
.textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--text);
  font-family: inherit;
  /* iOSは16px未満の入力欄でタップ時に自動ズームするため下げない */
  font-size: 16px;
  line-height: 1.7;
}

.textarea { resize: vertical; }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9' fill='none'%3E%3Cpath d='M1 1.5L7 7.5L13 1.5' stroke='%235f6b83' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 42px;
  min-height: 52px;
}

/* フォーカスは枠線の色とリングの両方で示す */
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--assistant);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(59, 110, 245, .16);
}

.card--generate .select:focus,
.card--generate .textarea:focus {
  border-color: var(--generate);
  box-shadow: 0 0 0 3px rgba(224, 90, 47, .16);
}

/* ---------- アップロード欄 ----------
   点線枠は「ここに置ける」ことを示す意味があるので残す */
.upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 32px 20px;
  border: 2px dashed var(--assistant-line);
  border-radius: var(--radius-sm);
  background: #fbfcff;
  cursor: pointer;
  text-align: center;
  transition: background .15s, border-color .15s;
}

.upload:hover,
.upload--over {
  background: var(--assistant-soft);
  border-color: var(--assistant);
}

.upload__icon { font-size: 28px; line-height: 1; }
.upload__main { font-size: 15px; font-weight: 700; color: var(--assistant); }
.upload__sub  { font-size: 13px; color: var(--text-muted); }

/* ---------- ボタン ---------- */
.btn {
  width: 100%;
  min-height: 52px;
  padding: 15px 20px;
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: inherit;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  transition: transform .12s, filter .12s, box-shadow .12s;
}

.btn--assistant {
  background: var(--assistant);
  box-shadow: 0 4px 14px rgba(59, 110, 245, .22);
}

.btn--generate {
  background: var(--generate);
  box-shadow: 0 4px 14px rgba(224, 90, 47, .22);
}

.btn:hover  { filter: brightness(1.06); transform: translateY(-1px); }
.btn:active { transform: translateY(0); filter: brightness(.96); }

.btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  filter: none;
  box-shadow: none;
}

/* ---------- 出力エリア（アシスタント）/ プレビュー（漫画生成） ----------
   外枠は付けず、淡い背景で領域を示す */
.result {
  border-radius: var(--radius-sm);
  background: var(--assistant-soft);
  overflow: hidden;
}

.preview {
  border-radius: var(--radius-sm);
  background: var(--generate-soft);
  overflow: hidden;
}

.result__head,
.preview__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
}

.result__label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-sub);
}

.result__body {
  padding: 20px 22px;
  background: var(--surface);
}

.result__lead {
  margin: 0 0 10px;
  font-weight: 700;
  font-size: 15px;
}

.result__list {
  margin: 0;
  padding-left: 1.3em;
  font-size: 15px;
  color: var(--text-sub);
}

.result__list li + li { margin-top: 8px; }

/* ---------- ページカード ----------
   淡い背景の上に白いカードを置くので、枠線は不要 */
.preview__grid {
  display: grid;
  /* PC 2列 / タブレット 2列 / スマホ 1列。
     最小値は実測で決めている（190pxだとタブレットで3列になり絵が小さすぎる） */
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  padding: 18px;
}

.page-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.page-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.page-card__no {
  font-size: 15px;
  font-weight: 700;
  color: var(--generate);
}

.page-card__meta { font-size: 13px; color: var(--text-muted); }

.page-card__frame {
  /* 生成される画像（1024×1536）と同じ比率にして余白が出ないようにする */
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  background: var(--generate-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px;
  text-align: center;
}

/* プレースホルダのアイコンは枠の数だけ並ぶので、目立たせすぎない */
.page-card__frame-icon  { font-size: 22px; line-height: 1; opacity: .55; }
.page-card__frame-title { font-size: 14px; font-weight: 700; color: var(--text-sub); }
.page-card__frame-text  { font-size: 12.5px; color: var(--text-muted); line-height: 1.6; }

/* ---------- 生成済み画像 ---------- */
.page-card__frame--filled {
  padding: 0;
  background: var(--surface-soft);
  overflow: hidden;
}

.page-card__image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.page-card__download {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--generate-soft);
  color: var(--generate);
  font-size: 13.5px;
  font-weight: 700;
  text-decoration: none;
}

.page-card__download:hover { filter: brightness(.97); }

/* ---------- お知らせ / エラー ---------- */
.notice {
  margin: 0;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  line-height: 1.7;
}

.notice--error {
  background: #fdecec;
  border: 1px solid #f5c2c2;
  color: #a32020;
}

.notice--warn {
  background: #fff8e6;
  border: 1px solid #f0dba4;
  color: #7d5800;
}

.notice--global {
  max-width: 1200px;
  margin: 24px auto 0;
  padding: 16px 20px;
}

/* ---------- ローディング ---------- */
.loading,
.placeholder {
  margin: 0;
  font-size: 15px;
  color: var(--text-muted);
}

.loading::after {
  content: "";
  display: inline-block;
  width: 6px;
  text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--generate-line);
  border-top-color: var(--generate);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .loading::after { animation: none; content: "..."; }
  .btn:hover { transform: none; }
}

/* ---------- AI回答テキスト ---------- */
.answer p {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--text-sub);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.answer p:last-child { margin-bottom: 0; }
.answer p:empty { height: 8px; }

/* ---------- アップロード後のプレビュー ---------- */
.upload-preview {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--assistant-soft);
}

.upload-preview__thumb {
  width: 56px;
  height: 56px;
  flex: 0 0 56px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--surface);
}

.upload-preview__name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  color: var(--text-sub);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 副次ボタン。主要ボタンと区別するため塗らずに枠線で表現する */
.upload-preview__clear {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-sub);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}

.upload-preview__clear:hover { background: var(--surface-soft); }

/* ---------- フッター ---------- */
.app-footer {
  padding: 28px 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ==========================================================
   レスポンシブ
   ========================================================== */

/* タブレット以下：1カラムに切り替え */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 28px 20px 48px;
  }

  .notice--global { margin: 20px 20px 0; }
}

/* スマホ */
@media (max-width: 600px) {
  .app-header__inner { padding: 16px; gap: 12px; }
  .app-title { font-size: 19px; }
  .app-subtitle { font-size: 13px; }

  .layout { padding: 20px 16px 40px; gap: 20px; }
  .notice--global { margin: 16px 16px 0; }

  .card__head { padding: 22px 20px 18px; }
  .card__body { padding: 20px; gap: 20px; }
  .card__title { font-size: 19px; }

  /* 枚数・コマ数を横に並べず縦積みにする */
  .field-row { grid-template-columns: 1fr; gap: 20px; }

  .upload { padding: 26px 16px; }

  /* プレビュー枠は1列。縦長のまま表示して漫画ページの形を保つ */
  .preview__grid { grid-template-columns: 1fr; padding: 16px; }
}
