/* ===== デザイントークン ===== */
:root {
  /* ベース */
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1c2033;
  --muted: #5d6278;        /* 白背景で 4.5:1 以上 */
  --border: #e6e8f0;
  --field-bg: #f9fafc;

  /* 機能ごとのメインカラー */
  --assist: #6d4cff;       /* 企画アシスタント：紫 */
  --assist-dark: #5a38f0;
  --assist-soft: #f2efff;
  --generate: #f2622e;     /* 漫画生成：オレンジ（アイコン・ライン用） */
  --generate-btn: #cf4410; /* ボタン背景：白文字で 4.5:1 以上 */
  --generate-dark: #b23a0c;
  --generate-text: #c2410c;/* 小さい文字用：白背景で 4.5:1 以上 */
  --generate-soft: #fff2ec;

  /* 補助テキストの最小サイズ（小さくなりすぎないよう統一） */
  --fs-small: .85rem;
  --fs-xsmall: .8rem;

  --danger: #c0262d;
  --danger-soft: #fff1f1;

  --radius-lg: 20px;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(28, 32, 51, .04), 0 8px 24px rgba(28, 32, 51, .06);
  --font: "Inter", "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

/* 見た目は隠し、キーボード・読み上げからは操作できるようにする */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

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

svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ===== ヘッダー ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, .8);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) 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 h1 { font-size: 1.15rem; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.logo-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--assist), var(--generate));
  color: #fff;
  font-weight: 800;
}
.badge-mock {
  font-size: var(--fs-xsmall);
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 999px;
  color: var(--assist);
  background: var(--assist-soft);
}

/* ヘッダーのナビ（各機能へジャンプ） */
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-nav { display: flex; gap: 4px; }
.nav-link {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: .9rem; font-weight: 700;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .2s, color .2s;
}
.nav-step {
  display: grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  font-family: "Inter", sans-serif; font-size: .75rem;
  color: #fff;
}
.nav-assist .nav-step   { background: var(--assist); }
.nav-generate .nav-step { background: var(--generate-btn); }
.nav-assist:hover   { background: var(--assist-soft);   color: var(--assist); }
.nav-generate:hover { background: var(--generate-soft); color: var(--generate-text); }
.nav-link:focus-visible { outline: 3px solid #b9abff; outline-offset: 2px; }

/* ジャンプ時に固定ヘッダーで見出しが隠れないように */
.panel { scroll-margin-top: 80px; }

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

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px;
  position: relative;
  overflow: hidden;
}
/* 機能ごとの色分け（上部の細いライン） */
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
}
.panel-assist::before   { background: linear-gradient(90deg, var(--assist), #9b84ff); }
.panel-generate::before { background: linear-gradient(90deg, var(--generate), #ff9a6b); }

.panel-head { margin-bottom: 28px; }
.panel-title { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.panel-title h2 {
  margin: 2px 0 0; font-size: 1.35rem; font-weight: 700; line-height: 1.4;
  word-break: auto-phrase;   /* 日本語を文節で改行（対応ブラウザのみ） */
  text-wrap: balance;
}
.panel-icon {
  flex-shrink: 0;
  display: grid; place-items: center;
  width: 48px; height: 48px;
  border-radius: 14px;
}
.panel-icon svg { width: 24px; height: 24px; }
.panel-assist .panel-icon   { background: var(--assist-soft);   color: var(--assist); }
.panel-generate .panel-icon { background: var(--generate-soft); color: var(--generate); }

.desc { margin: 0; color: var(--muted); font-size: .95rem; }

.step {
  display: inline-block;
  font-family: "Inter", sans-serif;
  font-size: .75rem; font-weight: 700; letter-spacing: .08em;
  line-height: 1.6;
}
.panel-assist .step   { color: var(--assist); }
.panel-generate .step { color: var(--generate-text); }

/* ===== フォーム ===== */
.form { display: flex; flex-direction: column; gap: 22px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > label { font-weight: 700; font-size: .9rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;          /* iOSでのズーム防止 */
  color: var(--text);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--field-bg);
  transition: border-color .2s, box-shadow .2s, background-color .2s;
}
select { min-height: 48px; cursor: pointer; }
textarea { resize: vertical; line-height: 1.7; }
textarea::placeholder { color: #80859a; }
select:hover, textarea:hover { border-color: #cfd3e0; }
select:focus, textarea:focus { outline: none; background-color: #fff; }
.panel-assist select:focus, .panel-assist textarea:focus {
  border-color: var(--assist); box-shadow: 0 0 0 4px var(--assist-soft);
}
.panel-generate select:focus, .panel-generate textarea:focus {
  border-color: var(--generate); box-shadow: 0 0 0 4px var(--generate-soft);
}

/* アップロード欄 */
.upload {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 28px 16px;
  border: 1.5px dashed #c9bfff;
  border-radius: var(--radius);
  background: #faf9ff;
  text-align: center;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.upload:hover { background: var(--assist-soft); border-color: var(--assist); }
.upload-icon {
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  background: #fff;
  color: var(--assist);
  box-shadow: 0 2px 8px rgba(109, 76, 255, .15);
}
.upload-icon svg { width: 22px; height: 22px; }
.upload-text { font-size: .9rem; font-weight: 500; }
.upload-text small { color: var(--muted); font-weight: 400; font-size: var(--fs-xsmall); }
.upload-file { font-size: var(--fs-small); font-weight: 700; color: var(--assist); word-break: break-all; }
.upload-thumb { max-width: 100%; max-height: 160px; border-radius: 8px; border: 1px solid var(--border); }

.hint { margin: -10px 0 0; font-size: var(--fs-small); color: var(--muted); text-align: center; line-height: 1.6; }

/* ===== ボタン ===== */
.btn {
  width: 100%;
  min-height: 54px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: #fff;
  cursor: pointer;
  transition: transform .15s, box-shadow .2s, background-color .2s, opacity .2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .7; cursor: wait; transform: none; box-shadow: none; }
.btn-assist   { background: var(--assist);   box-shadow: 0 6px 18px rgba(109, 76, 255, .3); }
.btn-assist:hover   { background: var(--assist-dark); box-shadow: 0 8px 22px rgba(109, 76, 255, .38); }
.btn-generate { background: var(--generate-btn); box-shadow: 0 6px 18px rgba(207, 68, 16, .28); }
.btn-generate:hover { background: var(--generate-dark); box-shadow: 0 8px 22px rgba(207, 68, 16, .36); }

/* キーボード操作時のフォーカス表示 */
.btn:focus-visible, .upload:focus-within { outline: 3px solid #b9abff; outline-offset: 3px; }
.btn-generate:focus-visible { outline-color: #ffb08f; }

/* ===== エラー表示 ===== */
.error-box {
  margin-top: 20px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  border: 1px solid #ffd0d0;
  border-left: 4px solid var(--danger);
  color: var(--danger);
  font-size: .9rem;
  font-weight: 700;
  line-height: 1.6;
}

/* ===== アシスタント回答 ===== */
.result {
  margin-top: 28px;
  padding: 22px 24px;
  border-radius: var(--radius);
  background: var(--assist-soft);
  transition: opacity .2s;
}
.result-label {
  display: inline-block;
  font-size: var(--fs-xsmall); font-weight: 700; color: var(--muted);
  letter-spacing: .04em;
}
.result-title { font-weight: 700; margin: 10px 0 4px; }
.result ul { margin: 0; padding-left: 1.2em; }
.result li { margin-bottom: 6px; }
#assist-answer.ai { white-space: pre-wrap; margin-top: 8px; }

/* ===== 生成プレビュー ===== */
.preview-section {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.preview-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 16px;
}
.preview-meta {
  font-size: var(--fs-xsmall); color: var(--generate-text); font-weight: 700;
  background: var(--generate-soft); padding: 4px 12px; border-radius: 999px;
}
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));  /* PC：横並び */
  gap: 16px;
}
.page-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  transition: box-shadow .2s, transform .2s;
}
.page-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.page-card-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px;
  font-size: var(--fs-xsmall);
  background: #fbfbfd;
  border-bottom: 1px solid var(--border);
}
.page-card-head strong { color: var(--generate-text); font-family: "Inter", sans-serif; }
.page-card-head span { color: var(--muted); }
.page-canvas {
  aspect-ratio: 2 / 3;      /* 生成画像（1024x1536）と同じ比率 */
  margin: 10px;
  display: grid;
  gap: 4px;
}
.koma {
  background: repeating-linear-gradient(45deg, #f4f5f9, #f4f5f9 6px, #eef0f5 6px, #eef0f5 12px);
  border: 2px solid #2b2f40;
  border-radius: 2px;
}
.page-image {
  display: block;
  width: calc(100% - 20px);
  aspect-ratio: 2 / 3;
  object-fit: cover;
  margin: 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}
.page-caption {
  padding: 0 12px 12px;
  text-align: center;
}
.page-caption .label { font-size: var(--fs-small); font-weight: 700; }
.page-caption .note  { font-size: var(--fs-xsmall); color: var(--muted); line-height: 1.5; }

.page-card.loading .koma { animation: pulse 1s ease-in-out infinite; }
.page-card.failed .note { color: var(--danger); font-weight: 700; }
@keyframes pulse { 50% { opacity: .4; } }

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

/* ===== タブレット ===== */
@media (max-width: 960px) {
  .main-grid {
    grid-template-columns: 1fr;   /* 縦並び */
    max-width: 680px;             /* 横に伸びすぎないよう幅を抑える */
    gap: 24px;
  }
  .preview-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

/* ===== スマホ ===== */
@media (max-width: 600px) {
  .container { padding: 0 16px; }
  .logo h1 { font-size: 1rem; }
  .logo-mark { width: 32px; height: 32px; }
  .logo { gap: 10px; }
  /* ナビはヘッダー下段に横いっぱいのタブとして表示 */
  .header-inner { flex-wrap: wrap; height: auto; padding-top: 10px; padding-bottom: 10px; row-gap: 8px; }
  .header-actions { width: 100%; }
  .badge-mock { display: none; }
  .header-nav { flex: 1; padding: 4px; border-radius: 999px; background: var(--field-bg); border: 1px solid var(--border); }
  .nav-link { flex: 1; justify-content: center; min-height: 40px; }
  .panel { scroll-margin-top: 124px; }
  .main-grid { padding-top: 20px; gap: 20px; }
  .card { padding: 24px 18px; border-radius: 16px; }
  .panel-title { gap: 12px; }
  .panel-icon { width: 42px; height: 42px; border-radius: 12px; }
  .panel-title h2 { font-size: 1.15rem; }
  .field-row { grid-template-columns: 1fr; }
  .result { padding: 18px; }
  .preview-grid { grid-template-columns: 1fr; }            /* プレビュー縦並び */
  .page-canvas, .page-image { max-width: 300px; margin: 10px auto; }
  .page-card:hover { transform: none; }
}

/* ===== 動きを減らす設定の利用者向け ===== */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
