:root {
  /* ベース */
  --bg: #f4f5f9;
  --card: #ffffff;
  --surface: #f8f9fc;
  --text: #1c1f2a;
  --muted: #5b6170;   /* 白背景でコントラスト比 6:1 前後 */
  --border: #e4e7ef;

  /* 機能ごとのメインカラー：アシスタント = ティール / 生成 = パープル */
  --assist: #0f8a7e;
  --assist-soft: #e7f5f3;
  --gen: #6246ea;
  --gen-soft: #efecff;

  /* 状態色（エラー・注意のみで使用） */
  --error: #c0392b;
  --error-soft: #fdeeee;
  --warn: #7a5a00;
  --warn-soft: #fff8e6;

  /* 形・影・余白 */
  --radius: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28, 31, 42, 0.04), 0 8px 24px rgba(28, 31, 42, 0.06);
  --space: 8px;

  /* 英字 → 和文の順に指定し、混在しても自然に見えるようにする */
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 400px at 15% -10%, rgba(15, 138, 126, 0.08), transparent 70%),
    radial-gradient(1200px 400px at 85% -10%, rgba(98, 70, 234, 0.08), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

.container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 calc(var(--space) * 4);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* アイコン（全体で線の太さ・サイズを統一） */
.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  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);
  -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 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.logo-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--assist), var(--gen));
  color: #fff;
  font-weight: 800;
  font-size: 0.8125rem;
}
.badge-api {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge-api .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22a06b;
}

/* ---------- Layout ---------- */
.main-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: calc(var(--space) * 4);
  padding-top: calc(var(--space) * 5);
  padding-bottom: calc(var(--space) * 6);
}
/* タブレットは1カラムのまま、横に伸びすぎないよう幅を制限 */
@media (min-width: 600px) and (max-width: 1023px) {
  .main-grid { max-width: 760px; }
}
@media (min-width: 1024px) {
  .main-grid { grid-template-columns: 1fr 1fr; align-items: start; }
}

/* ---------- Panel (card) ---------- */
.panel {
  position: relative;
  overflow: hidden;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: calc(var(--space) * 5);
}
/* 上部のカラーバーで2つの機能を見分けられるようにする */
.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: var(--accent);
}
.panel-assistant { --accent: var(--assist); --accent-soft: var(--assist-soft); }
.panel-generate  { --accent: var(--gen);    --accent-soft: var(--gen-soft); }

.panel-head { margin-bottom: calc(var(--space) * 4); }
.chips { display: flex; flex-wrap: wrap; gap: var(--space); }
.step {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 12px;
  border-radius: 999px;
}
.step-muted { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.panel-head h2 {
  margin: calc(var(--space) * 2) 0 var(--space);
  font-size: 1.5rem;
  line-height: 1.4;
  font-weight: 700;
  letter-spacing: -0.01em;
  word-break: auto-phrase; /* 対応ブラウザでは文節単位で改行し、1文字だけ次の行に残るのを防ぐ */
}
.desc { margin: 0; color: var(--muted); font-size: 0.9375rem; }

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: calc(var(--space) * 3); }
.field { display: flex; flex-direction: column; gap: var(--space); flex: 1; min-width: 0; }
.field > label,
.field > .label { font-weight: 700; font-size: 0.875rem; }
.field-row { display: flex; gap: calc(var(--space) * 2); }

select, textarea {
  width: 100%;
  font: inherit;
  font-size: 1rem; /* 16px以上で iOS の自動ズームを防ぐ */
  line-height: 1.6;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
textarea { resize: vertical; min-height: 120px; }
textarea::placeholder { color: #8a8f9c; }
select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 48px;
  padding-right: 44px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%235b6170' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
select:hover, textarea:hover { border-color: #cfd3de; }
select:focus, textarea:focus {
  outline: none;
  background-color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space);
  min-height: 160px;
  padding: calc(var(--space) * 3);
  text-align: center;
  border: 2px dashed #d5d9e4;
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9375rem;
  cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.upload:hover,
.upload:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.upload-icon { width: 32px; height: 32px; color: var(--accent); stroke-width: 1.75; }
.upload-text small { font-size: 0.8125rem; }
.upload-preview { max-width: 100%; max-height: 200px; object-fit: contain; border-radius: var(--radius-sm); }

.hint { margin: 0; font-size: 0.8125rem; line-height: 1.6; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  width: 100%;
  min-height: 52px;
  padding: 0 calc(var(--space) * 3);
  border: none;
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 8px 20px -8px var(--accent);
  transition: transform .1s, filter .15s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.08); box-shadow: 0 10px 24px -8px var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.btn.is-loading { opacity: .7; cursor: progress; pointer-events: none; }

/* ---------- アイコンの通常 / エラー切り替え ---------- */
.icon-error { display: none; }
.is-error .icon-normal { display: none; }
.is-error .icon-error { display: block; }

/* ---------- Assistant output ---------- */
.output {
  margin-top: calc(var(--space) * 4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: opacity .15s;
}
.output-head {
  display: flex;
  align-items: center;
  gap: var(--space);
  padding: 12px 20px;
  font-weight: 700;
  font-size: 0.875rem;
  background: var(--accent-soft);
  color: var(--accent);
}
.output-body {
  padding: 20px;
  font-size: 0.9375rem;
  line-height: 1.85;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.output.is-loading { opacity: .5; }
.output.is-error { border-color: #f1c0bb; }
.output.is-error .output-head { background: var(--error-soft); color: var(--error); }

/* ---------- Notice ---------- */
.notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: calc(var(--space) * 3);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  background: var(--warn-soft);
  border: 1px solid #f2dc9b;
  color: var(--warn);
  font-size: 0.9375rem;
  line-height: 1.7;
}
.notice .icon { margin-top: 3px; }
.notice.is-error { background: var(--error-soft); border-color: #f1c0bb; color: var(--error); font-weight: 700; }

/* ---------- Generate preview ---------- */
.preview { margin-top: calc(var(--space) * 4); }
.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space);
  margin-bottom: calc(var(--space) * 2);
}
.preview-title {
  display: inline-flex;
  align-items: center;
  gap: var(--space);
  font-weight: 700;
  font-size: 0.9375rem;
}
.preview-title .icon { color: var(--accent); }
.preview-meta {
  font-size: 0.8125rem;
  color: var(--muted);
  background: var(--surface);
  padding: 2px 12px;
  border-radius: 999px;
}

/* スマホ: 1列 / タブレット・PC: 2列（4枚・8枚でも端数が出ない） */
.preview-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: calc(var(--space) * 2);
}
@media (min-width: 600px) {
  .preview-grid { grid-template-columns: repeat(2, 1fr); }
}

.page-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.page-card:hover { border-color: #d5d9e4; box-shadow: var(--shadow); }
.page-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  font-size: 0.875rem;
}
.page-card-head strong { color: var(--accent); }
.tag {
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 999px;
}
.page-art {
  aspect-ratio: 3 / 4;
  margin: 0 16px;
  padding: 8px;
  display: grid;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.page-art span {
  background: repeating-linear-gradient(45deg, #fff, #fff 6px, #f3f4f8 6px, #f3f4f8 12px);
  border: 2px solid #3a3e4c;
  border-radius: 2px;
}
.page-card-foot {
  padding: 12px 16px 16px;
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--muted);
}
.page-card-foot b { display: block; margin-bottom: 2px; color: var(--text); font-size: 0.875rem; }

/* ---------- Footer ---------- */
.app-footer {
  padding: calc(var(--space) * 3) 0 calc(var(--space) * 5);
  text-align: center;
  color: var(--muted);
  font-size: 0.8125rem;
}

/* ---------- Mobile ---------- */
@media (max-width: 599px) {
  .container { padding: 0 16px; }
  .header-inner { height: 56px; }
  .logo h1 { font-size: 1rem; }
  .logo-mark { width: 32px; height: 32px; }
  .main-grid { gap: calc(var(--space) * 3); padding-top: calc(var(--space) * 3); }
  .panel { padding: 28px 20px; border-radius: 16px; }
  .panel-head { margin-bottom: calc(var(--space) * 3); }
  .panel-head h2 { font-size: 1.1875rem; }
  .field-row { flex-direction: column; gap: calc(var(--space) * 3); }
  .page-art { aspect-ratio: 4 / 3; } /* 縦並び時に高くなりすぎないように */
}
