:root {
  /* ベース：紙とインク */
  --bg: #f4f4f1;
  --card: #ffffff;
  --text: #1b1d23;
  --muted: #5c606b;
  --border: #e2e2dd;
  --field: #fbfbf9;

  /* メイン：藍色（ボタンや重要な要素に統一して使う） */
  --accent: #27468f;
  --accent-strong: #1d3674;
  --accent-soft: #edf1f9;
  --accent-ring: rgba(39, 70, 143, 0.22);

  /* エラー専用 */
  --danger: #b42318;
  --danger-soft: #fdf1ef;

  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(27, 29, 35, 0.04), 0 8px 24px rgba(27, 29, 35, 0.05);

  /* 線画アイコン（output-head で使用） */
  --icon-chat: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12a8 8 0 0 1-8 8H4l1.8-3.2A8 8 0 1 1 21 12Z'/%3E%3C/svg%3E");
  --icon-alert: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7.5v5.5M12 16.5v.01'/%3E%3C/svg%3E");
  --icon-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='2.5'/%3E%3Ccircle cx='8.5' cy='9.5' r='1.5'/%3E%3Cpath d='m21 15.5-4.5-4.5L6 20'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

/* display を指定した要素でも hidden 属性を確実に効かせる */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", "Meiryo", sans-serif;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
}

h1, h2 { font-feature-settings: "palt"; }

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}
@media (min-width: 600px) { .container { padding: 0 24px; } }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Header ---------- */
.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}
.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { flex: none; width: 30px; height: 30px; color: var(--text); }
.logo {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.01em;
}
.badge-mock {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--muted);
  white-space: nowrap;
}
.badge-mock::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
@media (min-width: 600px) { .logo { font-size: 1.25rem; } }

/* ---------- Layout ---------- */
.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);   /* スマホ：縦並び */
  gap: 20px;
  padding-top: 20px;
  padding-bottom: 28px;
}
@media (min-width: 600px) {
  /* タブレット：1列のまま横に伸びすぎないようにする */
  .main-grid { max-width: 768px; gap: 24px; padding-top: 32px; padding-bottom: 32px; }
}
@media (min-width: 1000px) {
  .main-grid {
    max-width: 1200px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;   /* 回答欄を不自然に伸ばさず、内容に合わせた高さにする */
    gap: 28px;
    padding-top: 40px;
    padding-bottom: 40px;
  }
}

/* ---------- Panel (card) ---------- */
.panel {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  box-shadow: var(--shadow);
}
@media (min-width: 600px) { .panel { padding: 36px; } }

.panel-head { margin-bottom: 24px; }
.step {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.03em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 12px;
  border-radius: 999px;
}
.panel-head h2 {
  margin: 14px 0 8px;
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.4;
}
.lead { margin: 0; color: var(--muted); font-size: 0.9375rem; }
@media (min-width: 600px) { .panel-head h2 { font-size: 1.5rem; } }

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: 22px; }
.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field > label, .field-label {
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.5;
}
.field-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
@media (min-width: 480px) { .field-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; } }

select, textarea {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 16px; /* iOSでのズーム防止 */
  line-height: 1.6;
  color: var(--text);
  background-color: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 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' viewBox='0 0 24 24' fill='none' stroke='%235c606b' 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 12px center;
  background-size: 18px;
  cursor: pointer;
}
textarea { resize: vertical; min-height: 124px; }
textarea::placeholder { color: #70747f; opacity: 1; }
select:hover, textarea:hover { border-color: #c9c9c2; }
select:focus, textarea:focus {
  outline: none;
  background-color: var(--card);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.dropzone {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1.5px dashed #c5c5bd;
  border-radius: var(--radius-md);
  background: var(--field);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.dropzone:hover, .dropzone.has-file { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.has-file { border-style: solid; }
.dropzone:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.dropzone-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  color: var(--accent);
  background: var(--accent-soft);
}
.dropzone:hover .dropzone-icon, .dropzone.has-file .dropzone-icon { background: var(--card); }
.dropzone-icon svg { width: 22px; height: 22px; }
.dropzone-text {
  min-width: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.dropzone-text small { color: var(--muted); font-size: 0.8125rem; font-weight: 400; }

/* ---------- Buttons ---------- */
.btn {
  width: 100%;
  min-height: 52px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.5;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
}
.btn:hover { background: var(--accent-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--accent-ring); outline-offset: 2px; }
.btn:disabled { opacity: 0.6; cursor: wait; }

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

.notice {
  margin: 20px 0 0;
  padding: 14px 16px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  line-height: 1.7;
}
.notice-error { color: var(--danger); background: var(--danger-soft); font-weight: 600; }

/* ---------- Output ---------- */
.output, .preview {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.output-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  font-weight: 700;
  font-size: 0.9375rem;
  line-height: 1.5;
  margin-bottom: 12px;
}
.output-head::before {
  content: "";
  flex: none;
  width: 20px;
  height: 20px;
  background: currentColor;
  -webkit-mask: var(--icon-chat) center / contain no-repeat;
  mask: var(--icon-chat) center / contain no-repeat;
}
.output-head.is-image::before {
  -webkit-mask-image: var(--icon-image);
  mask-image: var(--icon-image);
}
.output-head.is-error { color: var(--danger); }
.output-head.is-error::before {
  -webkit-mask-image: var(--icon-alert);
  mask-image: var(--icon-alert);
}
.output-body {
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  font-size: 0.9375rem;
}
.output-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.output-error { color: var(--danger); background: var(--danger-soft); }
.output-title { margin: 0 0 6px; font-weight: 700; }
.output-body ul { margin: 0; padding-left: 1.2em; }
.output-body li + li { margin-top: 8px; }

/* ---------- Preview cards ---------- */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
/* 出力枚数は1・2・4・8枚なので、2列か4列なら4枚以上で端数の行が出ない */
@media (min-width: 720px) and (max-width: 999px) {
  .preview-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1000px) {
  .preview-grid { gap: 16px; }
}

.page-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--card);
}
.page-card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 2px 6px;
  padding: 10px 12px 0;
  font-size: 0.8125rem;
}
.page-card-head strong { font-size: 0.875rem; font-weight: 700; }
.tag {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 9px;
  border-radius: 999px;
}
.page-canvas {
  aspect-ratio: 3 / 4;
  margin: 10px 12px 0;
  padding: 6px;
  display: grid;
  gap: 5px;
  background: var(--bg);
  border-radius: 4px;
}
/* コマの枠線だけは漫画らしくインクの線で見せる */
.koma { background: var(--card); border: 1.5px solid #3a3d46; }
.page-canvas-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px 12px;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--muted);
}
.page-canvas-label b { color: var(--text); font-weight: 700; }

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

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
