/* ===== 基本設定 ===== */
:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --surface: #f8f9fc;      /* カード内の薄い面 */
  --text: #1f2330;
  --muted: #5f6577;        /* 補足テキスト（白・背景色どちらでもコントラスト比4.5以上） */
  --border: #d9dce6;
  --border-soft: #eceef4;

  /* 企画アシスタント = 紫系 */
  --assist: #6c5ce7;
  --assist-dark: #5443d6;
  --assist-soft: #f1efff;

  /* 漫画生成 = オレンジ系（白文字とのコントラストを確保した濃さ） */
  --generate: #d1450e;
  --generate-dark: #a93a0c;
  --generate-soft: #fff1e8;

  /* エラー表示 */
  --error: #c0392b;
  --error-soft: #fff1f0;

  /* 角丸は3種類に統一 */
  --radius-lg: 16px;       /* パネル */
  --radius: 12px;          /* ボタン・入力欄・カード */
  --radius-pill: 999px;    /* バッジ */

  --shadow: 0 1px 2px rgba(31, 35, 48, 0.04), 0 8px 24px rgba(31, 35, 48, 0.06);

  /* 英字 → 日本語の順に指定（英字は各OSのUIフォント、日本語はヒラギノ／游ゴシック等） */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "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: 1rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { line-height: 1.4; }

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

/* 共通アイコン（線の太さ・角の形を統一） */
.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 見た目は隠すが、キーボード・読み上げでは操作できる */
.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;
}

/* ===== ヘッダー ===== */
.app-header {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--assist), var(--generate));
}
.logo h1 { margin: 0; font-size: 1.25rem; letter-spacing: 0.01em; }
.mock-badge {
  font-size: 0.8125rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--assist-soft);
  color: var(--assist-dark);
  white-space: nowrap;
}

/* ===== STEP 案内 ===== */
.flow-guide {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 32px 0 24px;
  font-size: 0.875rem;
  font-weight: 700;
}
.flow-step { padding: 6px 16px; border-radius: var(--radius-pill); }
.flow-step.assist { background: var(--assist-soft); color: var(--assist-dark); }
.flow-step.generate { background: var(--generate-soft); color: var(--generate-dark); }
.flow-arrow { color: var(--muted); }

/* ===== 2カラム ===== */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  align-items: start;
  margin-bottom: 48px;
}

/* ===== パネル（カード） ===== */
.panel {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px;
}
/* エリアごとの色は、上部の淡いグラデーションとアイコンで見分ける */
.panel-assist { background: linear-gradient(180deg, #f7f5ff 0, var(--card) 180px); }
.panel-generate { background: linear-gradient(180deg, #fff6f0 0, var(--card) 180px); }

.panel-head { margin-bottom: 24px; }
.panel-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.panel-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
}
.panel-icon .icon { width: 22px; height: 22px; }
.panel-assist .panel-icon { background: var(--assist-soft); color: var(--assist); }
.panel-generate .panel-icon { background: var(--generate-soft); color: var(--generate); }

.panel-label {
  font-size: 0.8125rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
}
.panel-assist .panel-label { background: var(--assist-soft); color: var(--assist-dark); }
.panel-generate .panel-label { background: var(--generate-soft); color: var(--generate-dark); }

.panel-head h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  letter-spacing: 0.01em;
  text-wrap: balance;
}
.panel-desc { margin: 0; color: var(--muted); font-size: 0.9375rem; line-height: 1.8; }
.panel-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 16px 0 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.7;
}
.panel-note .icon { width: 16px; height: 16px; margin-top: 4px; }

/* ===== 入力欄 ===== */
.field { margin-bottom: 24px; min-width: 0; }
.field-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 700;
  margin-bottom: 8px;
}
select, textarea {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background-color: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
select:hover, textarea:hover { border-color: #c5c9d6; }
textarea { resize: vertical; min-height: 120px; line-height: 1.7; }
textarea::placeholder { color: #6f7587; }

/* セレクトの矢印をOSに依存しない見た目に統一 */
select {
  min-height: 48px;
  padding-right: 44px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235f6577' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
}

.panel-assist select:focus, .panel-assist textarea:focus {
  outline: none; border-color: var(--assist); box-shadow: 0 0 0 4px var(--assist-soft);
}
.panel-generate select:focus, .panel-generate textarea:focus {
  outline: none; border-color: var(--generate); box-shadow: 0 0 0 4px var(--generate-soft);
}

/* 空欄エラー（入力欄の下に表示） */
.field textarea.is-invalid,
.field textarea.is-invalid:focus {
  border-color: var(--error);
  background-color: var(--error-soft);
  box-shadow: 0 0 0 4px #ffe3e0;
}
.field-error {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 0;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--error);
}
.field-error::before {
  content: "";
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7.5v5.5M12 16.3v.2'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7.5v5.5M12 16.3v.2'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ラベルが折り返しても入力欄の位置がそろうように下揃え */
.field-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: end;
}

/* アップロード欄 */
.upload-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 24px 16px;
  border: 1.5px dashed #cfc8fb;
  border-radius: var(--radius);
  background: #faf9ff;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.upload-box:hover { background: var(--assist-soft); border-color: var(--assist); }
.upload-box:focus-within { border-color: var(--assist); box-shadow: 0 0 0 4px var(--assist-soft); }
.upload-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
  background: #fff;
  color: var(--assist);
  box-shadow: 0 1px 3px rgba(31, 35, 48, 0.08);
}
.upload-icon .icon { width: 22px; height: 22px; }
.upload-text { font-weight: 700; color: var(--assist-dark); }
.upload-hint { max-width: 36em; font-size: 0.875rem; color: var(--muted); line-height: 1.7; }
.upload-file { font-size: 0.875rem; font-weight: 700; color: var(--text); }
.upload-file:empty { display: none; }

/* ===== ボタン ===== */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  padding: 0 24px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.65; cursor: wait; transform: none; }
.btn:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }
.btn-assist { background: var(--assist); box-shadow: 0 4px 12px rgba(108, 92, 231, 0.25); }
.btn-assist:hover { background: var(--assist-dark); }
.btn-generate { background: var(--generate); box-shadow: 0 4px 12px rgba(209, 69, 14, 0.22); }
.btn-generate:hover { background: var(--generate-dark); }

/* ===== アシスタント回答エリア ===== */
.result-box {
  margin-top: 24px;
  border: 1px solid #e4e0ff;
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}
.result-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--assist-soft);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--assist-dark);
}
.result-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: #fff;
  background: var(--assist);
}
.result-body {
  padding: 16px 20px;
  font-size: 1rem;
  line-height: 1.85;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 状態ごとの見た目（data-state を JS で切り替え） */
.result-box[data-state="idle"] .result-body,
.result-box[data-state="loading"] .result-body { color: var(--muted); }
.result-box[data-state="loading"] .result-avatar { animation: pulse 1s ease-in-out infinite; }
.result-box[data-state="error"] { border-color: #f5c2bd; background: var(--error-soft); }
.result-box[data-state="error"] .result-head { background: #ffe3e0; color: var(--error); }
.result-box[data-state="error"] .result-avatar { background: var(--error); }
.result-box[data-state="error"] .result-body { color: var(--error); font-weight: 700; }

@keyframes pulse { 50% { opacity: 0.35; } }

/* ===== 漫画生成の案内 ===== */
.notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 24px;
  padding: 16px 20px;
  border-radius: var(--radius);
  background: var(--generate-soft);
  color: #7c2d12;
  font-size: 0.9375rem;
  line-height: 1.75;
}
.notice-icon { width: 22px; height: 22px; margin-top: 2px; color: var(--generate); }
.notice p { margin: 4px 0 0; }

/* ===== 生成プレビュー ===== */
.preview-area { margin-top: 32px; }
.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.preview-title { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.preview-tag {
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: #eef0f5;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}
.preview-meta { font-size: 0.875rem; color: var(--muted); }

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.page-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
}
.page-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.page-no { font-weight: 800; font-size: 0.9375rem; }
.page-koma {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--generate-soft);
  color: var(--generate-dark);
  white-space: nowrap;
}

/* 漫画ページ風の枠（コマ割り） */
.page-sheet {
  aspect-ratio: 1 / 1.414;
  display: grid;
  gap: 4px;
  padding: 6px;
  background: #fff;
  border: 2px solid #2b2f3a;
  border-radius: 4px;
}
.koma {
  background: repeating-linear-gradient(45deg, #f4f5f8, #f4f5f8 6px, #eceef3 6px, #eceef3 12px);
  border: 1.5px solid #2b2f3a;
}
.page-sheet.koma-1 { grid-template: 1fr / 1fr; }
.page-sheet.koma-2 { grid-template: 1fr 1fr / 1fr; }
.page-sheet.koma-4 { grid-template: repeat(4, 1fr) / 1fr; }
.page-sheet.koma-6 { grid-template: repeat(3, 1fr) / 1fr 1fr; }

.page-label { font-size: 0.8125rem; font-weight: 700; color: var(--generate-dark); }
.page-note { margin: 0; font-size: 0.8125rem; color: var(--muted); line-height: 1.6; }

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

/* ===== タブレット（〜960px）: 縦並び・横に伸びすぎない幅 ===== */
@media (max-width: 960px) {
  .main-grid {
    grid-template-columns: 1fr;
    gap: 24px;
    max-width: 720px;
    margin: 0 auto 48px;
  }
  .preview-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ===== スマホ（〜600px） ===== */
@media (max-width: 600px) {
  .container { padding: 0 16px; }
  .header-inner { height: 56px; }
  .logo h1 { font-size: 1.0625rem; }
  .logo-mark { width: 32px; height: 32px; }
  .mock-badge { display: none; }
  .flow-guide { flex-direction: column; gap: 4px; margin: 24px 0 16px; font-size: 0.8125rem; }
  .flow-arrow { transform: rotate(90deg); }
  .panel { padding: 24px 20px; }
  .panel-head h2 { font-size: 1.2rem; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .btn { font-size: 1rem; }
  .result-body { padding: 16px; }
  .preview-grid { grid-template-columns: 1fr; }
  .page-sheet { max-width: 320px; width: 100%; margin: 0 auto; }
  .page-label, .page-note { font-size: 0.875rem; }
}

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