/* ============================================================
   Manga Creative Studio
   ------------------------------------------------------------
   配色・余白・角丸は :root の変数にまとめ、各所で使い回します。
   余白は 8px の倍数で段階を揃えています。
   ============================================================ */

:root {
  /* ---- 配色（ベース） ---- */
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-sub: #fafbfd;
  --text: #16191f;
  --text-sub: #5b6472;
  --border: #e5e8ef;

  /* ---- 配色（アクセント）: 2つの機能を色で区別する ---- */
  --assistant: #2563eb;
  --assistant-soft: #eff4ff;
  --generate: #7c3aed;
  --generate-soft: #f5f2ff;
  --danger: #b42318;
  --danger-soft: #fef4f3;
  --danger-border: #f6cfcb;

  /* ---- 余白（8pxの倍数） ---- */
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 40px;
  --s-8: 56px;

  /* ---- 角丸・影 ---- */
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 18px rgba(16, 24, 40, .07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  /* 英字を先に指定し、日本語はヒラギノ以降にフォールバックさせる（混在画面向け） */
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
               "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.8;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; }

.container {
  width: min(1200px, 100%);
  margin-inline: auto;
  padding-inline: var(--s-5);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* キーボード操作時のフォーカスは必ず見えるようにする */
:focus-visible {
  outline: 2px solid var(--assistant);
  outline-offset: 2px;
}

/* ============ ヘッダー ============ */

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header__inner {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  min-height: 68px;
  padding-block: var(--s-3);
}

.header__logo {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -.01em;
}

.header__badge {
  margin: 0;
  font-size: .75rem;
  font-weight: 600;
  line-height: 1.6;
  color: var(--text-sub);
  background: var(--surface-sub);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 12px;
}

/* ============ メイン ============ */

.main { padding-block: var(--s-6) var(--s-8); }

.lead {
  margin: 0 0 var(--s-6);
  max-width: 46em; /* 読みやすい行長に制限 */
  font-size: 1rem;
  color: var(--text-sub);
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-5);
  align-items: start;
}

/* 1カラム時は広がりすぎないよう幅を制限する（タブレット対策） */
@media (max-width: 899px) {
  .layout { max-width: 680px; margin-inline: auto; }
}

@media (min-width: 900px) {
  .layout { grid-template-columns: 1fr 1fr; gap: var(--s-6); }
}

/* ============ カード ============ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.card__head {
  position: relative;
  padding: var(--s-5) var(--s-5) var(--s-4);
  border-bottom: 1px solid var(--border);
}

/* 上端の細いラインで2つの機能を区別する */
.card__head::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
}

.card--assistant .card__head { background: var(--assistant-soft); }
.card--assistant .card__head::before { background: var(--assistant); }
.card--generate .card__head { background: var(--generate-soft); }
.card--generate .card__head::before { background: var(--generate); }

.card__tag {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.8;
  letter-spacing: .06em;
  color: #fff;
  border-radius: 999px;
  padding: 2px 12px;
}

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

.card__title {
  margin: var(--s-3) 0 var(--s-2);
  font-size: 1.5rem; /* 本文16pxとの差をはっきりつける */
  line-height: 1.45;
  letter-spacing: -.01em;
}

.card__desc {
  margin: 0;
  max-width: 34em;
  font-size: .9375rem;
  line-height: 1.75;
  color: var(--text-sub);
}

.card__body { padding: var(--s-5); }

@media (min-width: 600px) {
  .card__head { padding: var(--s-6) var(--s-6) var(--s-5); }
  .card__body { padding: var(--s-6); }
}

/* ============ 入力欄 ============ */

.field { margin-bottom: var(--s-5); }

.field__label {
  display: block;
  margin-bottom: var(--s-2);
  font-size: .9375rem;
  font-weight: 700;
  line-height: 1.6;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 var(--s-4);
}

@media (min-width: 480px) {
  .field-row { grid-template-columns: 1fr 1fr; }
}

.select,
.textarea {
  width: 100%;
  font: inherit;
  font-size: 1rem; /* iOSでフォーカス時に拡大しないよう16px以上を維持 */
  line-height: 1.7;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-4);
  transition: border-color .15s, box-shadow .15s;
}

.textarea { resize: vertical; min-height: 96px; }

.select::placeholder,
.textarea::placeholder { color: #98a1b0; }

.select:hover,
.textarea:hover { border-color: #cfd6e2; }

.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--assistant);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}

.card--generate .select:focus,
.card--generate .textarea:focus {
  border-color: var(--generate);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, .14);
}

/* セレクトの矢印（線の太さを他のアイコンと揃える） */
.select {
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5l5-5' stroke='%235b6472' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-4) center;
  padding-right: var(--s-7);
}

/* ============ アップロード欄 ============ */

.uploader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: var(--s-6) var(--s-4);
  border: 1.5px dashed #cbd3e1;
  border-radius: var(--radius);
  background: var(--surface-sub);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.uploader:hover {
  border-color: var(--assistant);
  background: var(--assistant-soft);
}

.uploader__icon {
  display: block;
  color: var(--assistant);
}

.uploader__text {
  font-size: .9375rem;
  font-weight: 700;
  line-height: 1.6;
}

.uploader__note {
  font-size: .8125rem;
  line-height: 1.6;
  color: var(--text-sub);
}

.uploader__filename {
  margin: var(--s-2) 0 0;
  font-size: .8125rem;
  color: var(--text-sub);
}

/* ============ ボタン ============ */

.btn {
  display: block;
  width: 100%;
  min-height: 52px; /* スマホでも押しやすい高さ */
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: var(--s-3) var(--s-5);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color .15s, transform .1s, box-shadow .15s;
}

.btn:hover { box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(1px); box-shadow: var(--shadow-sm); }

.btn--assistant { background: var(--assistant); }
.btn--assistant:hover { background: #1d4fd8; }
.btn--generate { background: var(--generate); }
.btn--generate:hover { background: #6d28d9; }

.btn:disabled {
  background: #aab3c2;
  box-shadow: none;
  transform: none;
  cursor: progress;
}

/* ============ 結果エリア ============ */

.result { margin-top: var(--s-5); }

.result__label {
  margin: 0 0 var(--s-3);
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--text-sub);
}

.result__body {
  white-space: pre-wrap;
  font-size: .9375rem;
  line-height: 1.85;
  background: var(--surface-sub);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-4) var(--s-5);
}

/* ============ エラー表示 ============ */

.error {
  display: flex;
  gap: var(--s-2);
  margin: var(--s-4) 0 0;
  padding: var(--s-3) var(--s-4);
  font-size: .875rem;
  line-height: 1.7;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
}

/* hidden 属性が付いているときは表示しない（display:flex に上書きされるのを防ぐ） */
.error[hidden] { display: none; }

.error::before {
  content: "!";
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 3px;
  font-size: .75rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  color: #fff;
  background: var(--danger);
  border-radius: 50%;
}

/* ============ プレビュー ============ */

.preview-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-4);
}

@media (min-width: 520px) {
  .preview-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1400px) {
  .preview-grid { grid-template-columns: repeat(3, 1fr); }
}

.preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.preview__thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 2 / 3; /* 漫画ページの縦横比を崩さない */
  padding: var(--s-4);
  text-align: center;
  background: var(--surface-sub);
  border-bottom: 1px solid var(--border);
}

.preview__thumb-text {
  font-size: .8125rem;
  line-height: 1.6;
  color: var(--text-sub);
}

/* 画像が入ったら内側の余白を外し、2:3の枠いっぱいに表示する */
.preview__thumb:has(.preview__image) { padding: 0; }

.preview__image {
  width: 100%;
  height: 100%;
  object-fit: contain; /* 生成画像を切り取らずに全体を見せる */
}

.preview__meta { padding: var(--s-3) var(--s-4) var(--s-4); }

.preview__title {
  margin: 0;
  font-size: .9375rem;
  font-weight: 700;
  line-height: 1.6;
}

.preview__panels {
  margin: 0 0 6px;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.6;
  color: var(--generate);
}

.preview__note {
  margin: 0;
  font-size: .8125rem;
  line-height: 1.65;
  color: var(--text-sub);
}

/* ============ フッター ============ */

.footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-block: var(--s-5);
  font-size: .8125rem;
  color: var(--text-sub);
  text-align: center;
}

.footer p { margin: 0; }

/* ============ アニメーションを控える設定への配慮 ============ */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
