/* ============================================================
   Manga Creative Studio - デザイントークン
   色・余白・角丸・影をここで一元管理する
   ============================================================ */
:root {
  /* 背景と文字 */
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-sub: #fafbfd;
  --text: #171a21;
  --muted: #5b6272;   /* 白背景でコントラスト比 約6:1 */
  --border: #e6e9f0;

  /* アシスタント = 青緑 / 漫画生成 = オレンジ（役割の色分け） */
  --assist: #0f857c;        /* ボタン背景（白文字とのコントラストを確保） */
  --assist-ink: #0a6f67;    /* 白背景に置く文字色 */
  --assist-soft: #e7f5f3;
  --generate: #d9541a;
  --generate-ink: #b8440f;
  --generate-soft: #fdefe7;

  /* エラー */
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --danger-border: #f3c9c6;

  /* 余白（8の倍数で統一） */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  /* 角丸 */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;

  /* 影（薄く広く） */
  --shadow-sm: 0 1px 2px rgba(23, 26, 33, 0.04);
  --shadow-md: 0 2px 4px rgba(23, 26, 33, 0.04), 0 12px 28px rgba(23, 26, 33, 0.06);

  --maxw: 1200px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* 英字は system-ui 系、日本語は読みやすいゴシックを後ろに置く */
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", "Hiragino Sans",
    "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; }

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

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--s5);
}

/* ---------- ヘッダー ---------- */
.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;
  gap: var(--s4);
  height: 72px;
}
.logo { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.logo-mark {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--assist), var(--generate));
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
}
.logo h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge-mock {
  flex: none;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: var(--s1) var(--s3);
}

/* ---------- メイン 2カラム ---------- */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s5);
  padding-top: var(--s6);
  padding-bottom: var(--s6);
  align-items: start;
}

.panel {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: var(--s6);
}
/* 上部の細い帯で、2つの機能の違いを示す */
.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--accent);
}
.panel-assist   { --accent: var(--assist);   --accent-ink: var(--assist-ink);   --accent-soft: var(--assist-soft); }
.panel-generate { --accent: var(--generate); --accent-ink: var(--generate-ink); --accent-soft: var(--generate-soft); }

/* ---------- パネル見出し ---------- */
.panel-head { margin-bottom: var(--s5); }
.panel-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--s3);
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.panel-icon svg { width: 24px; height: 24px; }
.step {
  display: inline-block;
  margin-bottom: var(--s2);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent-ink);
}
.panel-head h2 {
  margin: 0 0 var(--s2);
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.5;
}
.desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.7;
}

/* ---------- 入力欄 ---------- */
.field { margin-bottom: var(--s5); }
.field > label:first-child {
  display: block;
  margin-bottom: var(--s2);
  font-size: 0.875rem;
  font-weight: 700;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s4);
}

select, textarea {
  width: 100%;
  font: inherit;
  font-size: 1rem; /* 16px。これ未満だと iOS でフォーカス時に拡大される */
  line-height: 1.7;
  color: var(--text);
  background: var(--surface-sub);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--s3) var(--s4);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
textarea { resize: vertical; min-height: 112px; }
select {
  /* 矢印を自前で描き、OS標準の古い見た目を避ける */
  appearance: none;
  min-height: 52px;
  padding-right: var(--s7);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6272' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--s4) center;
  background-size: 18px;
  cursor: pointer;
}
select:hover, textarea:hover { border-color: #d3d8e4; }
select:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

/* ---------- 画像アップロード ---------- */
.upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s1);
  padding: var(--s6) var(--s4);
  border: 1.5px dashed #d3d8e4;
  border-radius: var(--r-md);
  background: var(--surface-sub);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.upload:hover { border-color: var(--accent); background: var(--accent-soft); }
.upload:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--s1);
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent-ink);
}
.upload-icon svg { width: 22px; height: 22px; }
.upload-main { font-size: 0.9375rem; font-weight: 700; }
.upload-sub { color: var(--muted); font-size: 0.8125rem; }
.upload-file { color: var(--accent-ink); font-size: 0.875rem; font-weight: 700; }

/* ---------- ボタン ---------- */
.btn {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: var(--s3) var(--s5);
  border: none;
  border-radius: var(--r-md);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 28%, transparent);
  transition: transform .1s ease, filter .15s ease, box-shadow .15s ease;
}
.btn:hover { filter: brightness(1.08); box-shadow: 0 8px 20px color-mix(in srgb, var(--accent) 34%, transparent); }
.btn:active { transform: translateY(1px); box-shadow: var(--shadow-sm); }
.btn.is-loading { opacity: .65; pointer-events: none; }

/* ---------- 補足・お知らせ ---------- */
.note {
  margin: var(--s2) 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.6;
}
.alert {
  margin-top: var(--s4);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-sm);
  font-size: 0.875rem;
  line-height: 1.7;
}
.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-border);
}
.alert-info {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

/* ---------- アシスタントの回答 ---------- */
.output {
  margin-top: var(--s5);
  border-radius: var(--r-md);
  background: var(--surface-sub);
  border: 1px solid var(--border);
  overflow: hidden;
}
.output-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3) var(--s5);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 0.875rem;
  font-weight: 700;
}
.output-head svg { width: 18px; height: 18px; flex: none; }
.output-body { padding: var(--s5); }
.output-title { margin: 0 0 var(--s2); font-weight: 700; }
.output-body ul { margin: 0; padding-left: 1.2em; }
.output-body li { margin-bottom: var(--s2); }
.answer-item { margin: 0 0 var(--s3); padding-left: 1em; text-indent: -1em; }
.answer-item:last-child { margin-bottom: 0; }

/* ---------- 生成プレビュー ---------- */
.preview-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin: var(--s6) 0 var(--s4);
  color: var(--accent-ink);
  font-size: 0.875rem;
  font-weight: 700;
}
.preview-head svg { width: 18px; height: 18px; flex: none; }
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--s4);
}
.preview-card {
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.preview-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s2);
  padding: var(--s3) var(--s3) var(--s2);
}
.preview-meta strong { font-size: 0.875rem; }
.preview-meta span {
  flex: none;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0 var(--s2);
  font-size: 0.75rem;
  font-weight: 700;
}
.preview-image {
  aspect-ratio: 1 / 1.414; /* 漫画原稿（A判）の比率 */
  margin: 0 var(--s3);
  display: grid;
  gap: var(--s1);
  padding: var(--s1);
  background: var(--surface);
  border: 1.5px solid #2b2f3a;
  border-radius: 2px;
}
.preview-image div { background: #eef0f5; border-radius: 2px; }
.preview-label { padding: var(--s3); text-align: center; }
.preview-label b { display: block; font-size: 0.8125rem; }
.preview-label small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
}

/* ---------- フッター ---------- */
.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8125rem;
  padding: 0 var(--s4) var(--s7);
}

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

/* タブレット横・小さめのPC */
@media (max-width: 1080px) {
  .panel { padding: var(--s5); }
  .main-grid { gap: var(--s4); }
}

/* タブレット縦以下：2カラムをやめて縦に並べる */
@media (max-width: 900px) {
  .main-grid {
    grid-template-columns: 1fr;
    max-width: 720px; /* 横に伸びすぎないように読みやすい幅で止める */
  }
  .preview-grid { grid-template-columns: repeat(2, 1fr); }
}

/* スマホ */
@media (max-width: 600px) {
  body { line-height: 1.7; }
  .container { padding: 0 var(--s4); }
  .header-inner { height: 64px; }
  .logo h1 { font-size: 1.0625rem; }
  .main-grid { padding-top: var(--s5); gap: var(--s4); }
  .panel { padding: var(--s5) var(--s4); border-radius: var(--r-md); }
  .panel-head h2 { font-size: 1.1875rem; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .output-head, .output-body { padding-left: var(--s4); padding-right: var(--s4); }
  .btn { min-height: 52px; font-size: 1rem; }
  .preview-grid { grid-template-columns: 1fr; gap: var(--s3); }
  .preview-card { display: grid; grid-template-columns: 96px 1fr; align-items: center; }
  .preview-meta { flex-direction: column; align-items: flex-start; grid-column: 2; padding-bottom: 0; }
  .preview-image { grid-row: 1 / 3; grid-column: 1; margin: var(--s3); }
  .preview-label { grid-column: 2; text-align: left; padding-top: var(--s1); }
}

/* 動きを減らす設定の端末では、アニメーションを止める */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
