/* =========================================
   Manga Creative Studio - Styles
   ========================================= */

:root {
  /* ベース */
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2030;
  --muted: #5b6275;          /* 補足テキスト（白背景でコントラスト比 約6:1） */
  --border: #e2e6ef;
  --field-bg: #f8f9fc;

  /* 機能ごとの色分け：アシスタント = 青 / 生成 = オレンジ */
  --assist: #3563e9;
  --assist-strong: #264fd0;
  --assist-soft: #edf2ff;
  --assist-line: #c9d6fb;
  --gen: #d4450f;            /* 白文字とのコントラスト比 4.5:1 以上 */
  --gen-strong: #b83b0c;
  --gen-soft: #fff1ea;
  --gen-text: #b93d0f;       /* 淡いオレンジ背景の上の文字色 */

  /* 状態 */
  --danger: #b42318;
  --danger-soft: #fef0ef;
  --danger-line: #f6cdc9;
  --success: #1c7c45;
  --success-soft: #e9f7ef;

  /* 形 */
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.04), 0 8px 24px rgba(20, 30, 60, 0.06);

  --font: "Inter", "Noto Sans JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }

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

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

/* アイコン共通（線画アイコンで統一） */
.icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 64px;
}
.logo { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.logo-mark {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  flex-shrink: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--assist), var(--gen));
  color: #fff;
  font-weight: 800;
}
.badge-mock {
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge-mock.ok { background: var(--success-soft); color: var(--success); border-color: #c3e7d1; }
.badge-mock.ng { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }

/* ---------- Layout ---------- */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;   /* PC: 2カラム */
  gap: 32px;
  padding-top: 40px;
  padding-bottom: 40px;
  align-items: start;
}

/* ---------- Panel (Card) ---------- */
.panel {
  position: relative;
  overflow: hidden;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 32px 32px;
}
/* 上部のアクセントライン（機能の色分け） */
.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
}
.panel-assistant::before { background: var(--assist); }
.panel-generate::before  { background: var(--gen); }

.panel-head { margin-bottom: 28px; }
.step {
  display: inline-block;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 12px;
  border-radius: 999px;
}
.panel-assistant .step { background: var(--assist-soft); color: var(--assist); }
.panel-generate  .step { background: var(--gen-soft);    color: var(--gen-text); }

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

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: 22px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9375rem;
  font-weight: 700;
}
/* 必須・任意のラベル */
.tag {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
  background: #eef0f5;
  color: var(--muted);
}
.tag-required { background: var(--danger-soft); color: var(--danger); }

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

/* Upload */
.upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 28px 16px;
  border: 1.5px dashed var(--assist-line);
  border-radius: var(--radius);
  background: var(--assist-soft);
  cursor: pointer;
  text-align: center;
  transition: background .15s, border-color .15s;
}
.upload:hover { background: #e3eaff; border-color: var(--assist); }
.upload-icon {
  display: grid;
  place-items: center;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: #fff;
  color: var(--assist);
  font-size: 22px;
  box-shadow: 0 2px 8px rgba(53, 99, 233, 0.12);
}
.upload-text { font-weight: 700; color: var(--assist); }
.upload-sub { font-size: 0.8125rem; color: var(--muted); word-break: break-all; }
.upload-thumb {
  margin-top: 10px;
  max-width: 100%;
  max-height: 180px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
}
.link-btn {
  align-self: flex-start;
  background: none;
  border: none;
  padding: 6px 2px;
  font: inherit;
  font-size: 0.875rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-btn:hover { color: var(--text); }

/* ---------- Buttons ---------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 54px;
  padding: 0 20px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s, opacity .15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .8; cursor: wait; transform: none; }
/* 処理中（ボタンが無効の間）はスピナーを表示 */
.btn:disabled::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; }
.btn-assistant { background: var(--assist); box-shadow: 0 6px 16px rgba(53, 99, 233, .28); }
.btn-assistant:hover:not(:disabled) { background: var(--assist-strong); }
.btn-assistant:focus-visible { outline-color: var(--assist); }
.btn-generate  { background: var(--gen); box-shadow: 0 6px 16px rgba(212, 69, 15, .28); }
.btn-generate:hover:not(:disabled) { background: var(--gen-strong); }
.btn-generate:focus-visible { outline-color: var(--gen); }

/* ---------- メッセージ ---------- */
.notice,
.error {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  line-height: 1.6;
}
/* 注意アイコン（線画で統一。色は文字色に合わせる） */
.notice::before,
.error::before {
  content: "";
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  margin-top: 3px;
  background: 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' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%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' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E") center / contain no-repeat;
}
.notice[hidden],
.error[hidden] { display: none; }
.notice {
  margin-top: 24px;
  background: #fff8e6;
  border: 1px solid #f1dca0;
  color: #7a5200;
}
.notice code { background: #fff; padding: 1px 6px; border-radius: 4px; color: var(--text); }
.error {
  background: var(--danger-soft);
  border: 1px solid var(--danger-line);
  color: var(--danger);
}
.hint { margin: -10px 0 0; font-size: 0.8125rem; color: var(--muted); line-height: 1.6; }

/* ---------- Assistant output ---------- */
.output {
  margin-top: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.output-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--assist-soft);
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--assist);
}
.output-avatar {
  display: grid; place-items: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--assist);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}
.output-body { padding: 18px 20px; }
.output-title { margin: 0 0 6px; font-weight: 700; }
.output-body ul { margin: 0; padding-left: 1.2em; }
.output-body li { margin-bottom: 6px; }
.output-text { white-space: pre-wrap; }

/* ---------- Generate preview ---------- */
.preview { margin-top: 32px; }
.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-bottom: 14px;
  font-weight: 700;
}
.preview-meta { font-size: 0.8125rem; font-weight: 500; color: var(--muted); }

.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 .15s;
}
.page-card:hover { box-shadow: 0 4px 16px rgba(20, 30, 60, 0.08); }
.page-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 10px 12px 8px;
}
.page-card-head strong { font-size: 0.9375rem; }
.page-tag {
  background: var(--gen-soft);
  color: var(--gen-text);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

/* 漫画ページ風の枠（コマ割りを点線で表現） */
.page-canvas {
  aspect-ratio: 2 / 3;      /* 生成画像（1024x1536）と同じ比率 */
  margin: 0 12px;
  padding: 6px;
  background: #f1f2f6;
  border: 2px solid #2b2f3a;
  border-radius: 4px;
  display: grid;
  gap: 5px;
  position: relative;
}
.page-canvas .koma {
  border: 1.5px dashed #a3a9ba;
  border-radius: 2px;
  background: repeating-linear-gradient(45deg, #fff, #fff 6px, #f6f7fa 6px, #f6f7fa 12px);
}
.page-canvas-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  pointer-events: none;
}
.page-canvas-label span {
  background: rgba(255, 255, 255, .92);
  padding: 3px 10px;
  border-radius: 999px;
  box-shadow: 0 1px 4px rgba(20, 30, 60, 0.08);
}
.page-card-foot {
  margin: 0;
  padding: 10px 12px 14px;
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.5;
}

.page-card.is-loading .page-canvas { animation: pulse 1.2s ease-in-out infinite; }
.page-card.is-error .page-canvas-label span { color: var(--danger); }
@keyframes pulse { 50% { opacity: 0.45; } }

.page-image { display: block; margin: 0 12px; }
.page-image img {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border: 2px solid #2b2f3a;
  border-radius: 4px;
}
.download { color: var(--gen-text); font-weight: 700; }

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8125rem;
  padding: 8px 24px 48px;
}

/* =========================================
   Responsive
   ========================================= */

/* タブレット：1カラムにし、横に伸びすぎないよう幅を制限 */
@media (max-width: 960px) {
  .main-grid { grid-template-columns: 1fr; gap: 28px; max-width: 760px; padding-top: 32px; }
  .notice { max-width: 712px; margin-left: auto; margin-right: auto; }
}

/* スマホ */
@media (max-width: 600px) {
  .container { padding: 0 16px; }
  .header-inner { height: 56px; }
  .logo { gap: 10px; }
  .logo-mark { width: 32px; height: 32px; border-radius: 9px; }
  .logo h1 { font-size: 1.0625rem; }
  .badge-mock { font-size: 0.75rem; padding: 3px 10px; }
  .main-grid { padding-top: 20px; padding-bottom: 28px; gap: 20px; }
  .panel { padding: 28px 18px 22px; border-radius: 16px; }
  .panel-head { margin-bottom: 22px; }
  .panel-head h2 { font-size: 1.0625rem; gap: 10px; }
  .panel-icon { width: 34px; height: 34px; font-size: 18px; border-radius: 10px; }
  .upload-text { font-size: 0.9375rem; }
  .field-row { grid-template-columns: 1fr; }
  .output-body { padding: 16px; }
  .preview-grid { grid-template-columns: 1fr; }   /* スマホ: 縦並び */
  .page-canvas, .page-image { max-width: 240px; margin: 0 auto; width: calc(100% - 24px); }
}
