/* ===== 基本設定 ===== */
:root {
  /* ベース */
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --text: #1c2030;
  --text-sub: #3d4258;
  --muted: #61677f; /* 白背景でコントラスト比 5:1 以上 */
  --border: #e3e6ef;
  --border-strong: #cfd3e1;

  /* アシスタント = 青紫系 / 生成 = オレンジ系 で役割を色分け */
  --assist: #5458d6;
  --assist-hover: #4649c4;
  --assist-soft: #eef0fd;
  --gen: #c84c16; /* 白文字とのコントラスト比 4.5:1 以上 */
  --gen-hover: #b0400f;
  --gen-strong: #b8460f; /* 小さい文字用（読みやすい濃さ） */
  --gen-soft: #fff2eb;

  /* エラー */
  --danger: #b42323;
  --danger-soft: #fff3f3;
  --danger-border: #f4caca;

  /* 形・影・余白（8px基準） */
  --radius-lg: 20px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28, 32, 48, 0.04), 0 8px 24px rgba(28, 32, 48, 0.06);
  --shadow-btn: 0 1px 2px rgba(28, 32, 48, 0.08), 0 4px 12px rgba(28, 32, 48, 0.08);
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
/* hidden 属性の要素は、display を指定したクラスより優先して非表示にする */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  background:
    radial-gradient(1200px 400px at 15% -10%, rgba(84, 88, 214, 0.07), transparent 70%),
    radial-gradient(1000px 400px at 90% -10%, rgba(226, 93, 36, 0.06), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-3);
}

/* 見出しや短い説明文は、日本語を文節の区切りで折り返す（対応ブラウザのみ） */
h1, h2, .panel-desc, .upload-text, .label, .preview-caption, .app-footer, .btn { word-break: auto-phrase; }

/* キーボード操作時のフォーカス表示 */
:focus-visible { outline: 3px solid rgba(84, 88, 214, 0.45); outline-offset: 2px; }

/* ===== ヘッダー ===== */
.app-header {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  height: 64px;
}
.logo { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo-mark {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--assist), var(--gen));
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 10px rgba(84, 88, 214, 0.25);
}
.logo h1 {
  font-size: 1.2rem;
  margin: 0;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge-mock {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-sub);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  line-height: 1.4;
}

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

/* ===== パネル（カード） ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}

.panel-head { margin-bottom: var(--space-3); }
.step {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 12px;
  border-radius: 999px;
  line-height: 1.4;
}
.panel-assist .step { background: var(--assist-soft); color: var(--assist); }
.panel-generate .step { background: var(--gen-soft); color: var(--gen-strong); }
.panel h2 { font-size: 1.4rem; line-height: 1.4; margin: 12px 0 8px; letter-spacing: 0.01em; }
.panel-desc { margin: 0; color: var(--muted); font-size: 0.95rem; }

/* ===== 入力欄 ===== */
.field { margin-bottom: 20px; display: flex; flex-direction: column; }
.field-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  align-items: end; /* ラベルが折り返しても選択欄の高さをそろえる */
}
.label { font-size: 0.875rem; font-weight: 700; color: var(--text-sub); margin-bottom: 8px; line-height: 1.5; }

select,
textarea {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select {
  min-height: 48px;
  padding-right: 40px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2361677f' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  cursor: pointer;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.7; }
textarea::placeholder { color: #8a8fa5; }
select:hover,
textarea:hover { border-color: #b9bed0; }
select:focus,
textarea:focus { outline: none; }
.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(--gen); box-shadow: 0 0 0 4px var(--gen-soft); }

/* アップロード欄 */
.upload {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 20px var(--space-3);
  border: 1.5px dashed #c3c6ec;
  border-radius: var(--radius);
  background: #f7f8fe;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.upload:hover { border-color: var(--assist); background: var(--assist-soft); }
.upload:focus-within { border-color: var(--assist); }
.upload-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 1.6rem;
  box-shadow: 0 1px 3px rgba(28, 32, 48, 0.08);
}
.upload-text { font-size: 0.95rem; font-weight: 600; line-height: 1.6; }
.upload-text small { font-size: 0.8rem; font-weight: 400; color: var(--muted); }

/* アップロード画像のサムネイルと取り消しボタン */
.upload-thumb {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
}
.link-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  min-height: 44px; /* スマホでも押しやすい高さ */
  margin-top: 0;
  background: none;
  border: none;
  padding: 0 4px 0 0;
  color: var(--assist);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-btn:hover { color: var(--assist-hover); }

/* ===== ボタン ===== */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  transition: background-color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(28, 32, 48, 0.08), 0 8px 20px rgba(28, 32, 48, 0.1); }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-btn); }
.btn-assist { background: var(--assist); }
.btn-assist:hover { background: var(--assist-hover); }
.btn-generate { background: var(--gen); }
.btn-generate:hover { background: var(--gen-hover); }
/* 保存はサブの操作なので、白地＋枠線で控えめに */
.btn-save {
  margin-top: var(--space-3);
  background: var(--surface);
  color: var(--gen-strong);
  border: 1.5px solid var(--gen);
  box-shadow: none;
}
.btn-save:hover { background: var(--gen-soft); box-shadow: none; }
.btn.is-loading { opacity: 0.7; pointer-events: none; cursor: progress; transform: none; }
.btn:disabled { cursor: not-allowed; opacity: 0.6; transform: none; }

/* ===== エラー表示 ===== */
.alert {
  margin-top: var(--space-2);
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 600;
}
.error-text { color: var(--danger); }

/* ===== アシスタントの出力 ===== */
.result {
  margin-top: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.result-head {
  color: var(--assist);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.result-body { padding: 16px 18px; font-size: 0.95rem; color: var(--text-sub); }
.result-body p { margin: 0 0 8px; }
.result-body ul { margin: 0; padding-left: 1.2em; }
.result-body li { margin-bottom: 8px; }
.result-body.is-ai { white-space: pre-wrap; } /* AIの回答の改行をそのまま表示 */

/* ===== 生成プレビュー ===== */
.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: var(--space-4) 0 var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.95rem;
}
.preview-meta {
  font-weight: 600;
  color: var(--text-sub);
  font-size: 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 12px;
}

/* PCでは横並び（幅に応じて折り返し） */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-2);
}
.preview-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface-2);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.preview-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 0.85rem;
}
.preview-card-top strong { font-size: 0.95rem; }
.tag {
  background: var(--gen-soft);
  color: var(--gen-strong);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}
/* 漫画ページ風の枠（コマ割り） */
.page {
  aspect-ratio: 3 / 4;
  display: grid;
  gap: 4px;
  padding: 6px;
  background: #fff;
  border: 2px solid var(--text);
  border-radius: 4px;
}
.koma {
  border: 1.5px solid var(--text);
  background: repeating-linear-gradient(45deg, #f6f7fb, #f6f7fb 6px, #eceef5 6px, #eceef5 12px);
}
.preview-caption { margin-top: 10px; font-size: 0.8rem; line-height: 1.6; color: var(--muted); text-align: center; }
.preview-caption a { color: var(--gen-strong); font-weight: 700; }
.preview-caption b { display: block; color: var(--text); font-size: 0.85rem; }
/* 生成された画像 */
.page-image {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}
/* 生成中のカードを点滅させる */
.preview-card.is-generating { border-color: var(--gen); box-shadow: 0 0 0 3px var(--gen-soft); }
.preview-card.is-generating .page { animation: pulse 1.2s ease-in-out infinite; border-color: var(--gen); }
@keyframes pulse { 50% { opacity: 0.45; } }

/* ===== フッター ===== */
.app-footer { color: var(--muted); font-size: 0.82rem; line-height: 1.7; text-align: center; padding: 0 0 40px; }

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

/* ===== タブレット：1カラム（横に伸びすぎないよう幅を制限） ===== */
@media (max-width: 960px) {
  .main-grid { grid-template-columns: 1fr; max-width: 760px; gap: var(--space-3); }
  .preview-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

/* ===== スマホ：すべて縦並び ===== */
@media (max-width: 600px) {
  .container { padding: 0 var(--space-2); }
  .header-inner { height: 56px; }
  .logo-mark { width: 32px; height: 32px; }
  .logo h1 { font-size: 1.05rem; }
  .main-grid { gap: 20px; padding-top: 20px; padding-bottom: 24px; }
  .panel { padding: var(--space-3) 20px; border-radius: 16px; }
  .panel h2 { font-size: 1.2rem; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  select, textarea { font-size: 16px; } /* iOSでの自動ズーム防止 */
  .upload { padding: var(--space-2); }
  .upload-icon { width: 44px; height: 44px; font-size: 1.35rem; }
  .btn { min-height: 56px; font-size: 1rem; padding: 12px 16px; }
  .preview-grid { grid-template-columns: 1fr; }
  .page, .page-image { max-width: 320px; margin: 0 auto; width: 100%; }
}
