:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --win: #16a34a;
  --reject: #dc2626;
  --muted: #64748b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

.app-header {
  background: var(--primary);
  color: #fff;
  padding: 24px 16px;
  text-align: center;
}

.app-header h1 { margin: 0; font-size: 1.5rem; }
.subtitle { margin: 4px 0 0; opacity: 0.9; font-size: 0.9rem; }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

h2 { font-size: 1.15rem; margin-top: 0; }

label {
  display: block;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 0.9rem;
}

input, select, textarea {
  width: 100%;
  padding: 10px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-weight: normal;
  font-family: inherit;
}

button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 8px;
}

button:hover { background: var(--primary-dark); }

/* 生成中などボタン無効時の見た目 */
button:disabled {
  background: #94a3b8;
  cursor: not-allowed;
  opacity: 0.8;
}

.loading { color: var(--muted); margin-top: 12px; }

.privacy-note {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.85rem;
  margin-bottom: 16px;
  line-height: 1.6;
}

/* 金額補助UI */
.price-block {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

.price-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.9rem;
}

.price-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 8px 0 0;
}

.price-row {
  margin-top: 12px;
  padding: 10px;
  background: #f8fafc;
  border-radius: 8px;
}

.price-row-top {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 0.9fr auto;
  gap: 8px;
  align-items: center;
}

.price-row-top input,
.price-row-top select { margin-top: 0; }

.price-amount { text-align: right; font-weight: 600; }

.quick-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.quick-btns button {
  padding: 5px 10px;
  font-size: 0.8rem;
  margin-top: 0;
  background: #e0e7ff;
  color: var(--primary-dark);
}
.quick-btns button:hover { background: #c7d2fe; }

.quick-btns .btn-clear {
  background: #f1f5f9;
  color: var(--muted);
}

.btn-remove {
  background: var(--reject);
  padding: 8px 12px;
  margin-top: 0;
}
.btn-remove:hover { background: #b91c1c; }

.btn-add {
  padding: 6px 12px;
  font-size: 0.85rem;
  margin-top: 0;
}

/* キャンペーン動的フィールド */
.campaign-block {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

.campaign-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.9rem;
}

.campaign-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.5fr auto;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.campaign-row input,
.campaign-row select { margin-top: 0; }

@media (max-width: 700px) {
  .price-row-top { grid-template-columns: 1fr 1fr; }
  .campaign-row { grid-template-columns: 1fr 1fr; }
}

.ab-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 700px) {
  .ab-wrapper { grid-template-columns: 1fr; }
}

.script-card h3 {
  margin-top: 0;
  color: var(--primary-dark);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-copy {
  font-size: 0.75rem;
  padding: 5px 10px;
  margin-top: 0;
}

.script-body {
  white-space: pre-wrap;
  background: #f8fafc;
  border-radius: 8px;
  padding: 14px;
  font-size: 0.9rem;
  min-height: 120px;
}

/* 生成結果の編集用テキストエリア */
.script-edit {
  width: 100%;
  min-height: 220px;
  margin-top: 0;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: 14px;
  font-size: 0.9rem;
  line-height: 1.7;
  white-space: pre-wrap;
  resize: vertical;
}

.feedback {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-win { background: var(--win); }
.btn-win:hover { background: #15803d; }
.btn-reject { background: var(--reject); }
.btn-reject:hover { background: #b91c1c; }
.btn-save { background: var(--primary); }
.btn-edit { background: var(--muted); }
.btn-edit:hover { background: #475569; }

.stats-desc { color: var(--muted); font-size: 0.9rem; }

#stats-body, #saved-list {
  background: #f8fafc;
  border-radius: 8px;
  padding: 14px;
  font-size: 0.9rem;
}

.app-footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
}

/* ========== 品質バッジ・検証表示 ========== */
.quality-box {
  margin-bottom: 10px;
  min-height: 1px;
}

.q-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  color: #fff;
}

.q-high { background: var(--win); }
.q-mid { background: var(--primary); }
.q-low { background: #d97706; }

.q-refined {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: #ede9fe;
  color: #6d28d9;
  margin-left: 6px;
}

.q-notes {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 6px 0 0;
}

.input-issues {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.85rem;
  margin-bottom: 16px;
  line-height: 1.6;
}

/* ========== 音声入力（マイクボタン） ========== */
.input-with-mic {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.input-with-mic input,
.input-with-mic textarea {
  flex: 1;
}

.btn-mic {
  margin-top: 6px;
  padding: 10px 12px;
  font-size: 1rem;
  line-height: 1;
  background: #e0e7ff;
  color: var(--primary-dark);
  border-radius: 8px;
  flex-shrink: 0;
}

.btn-mic:hover { background: #c7d2fe; }

/* 録音中の見た目（赤く点灯） */
.btn-mic.mic-active {
  background: var(--reject);
  color: #fff;
  animation: micpulse 1s infinite;
}

@keyframes micpulse {
  0%   { opacity: 1; }
  50%  { opacity: 0.6; }
  100% { opacity: 1; }
}

/* 非対応ブラウザ時 */
.btn-mic.mic-unsupported {
  background: #e2e8f0;
  color: #94a3b8;
  cursor: not-allowed;
}
