/* 投稿画像メーカー - メインスタイル */

:root {
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --accent: #f59e0b;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-sub: #64748b;
  --text-light: #94a3b8;
  --success: #22c55e;
  --error: #ef4444;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ヘッダー */
.app-header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 50;
}

.app-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.app-title i { color: var(--primary); margin-right: 6px; }

.app-subtitle {
  font-size: 0.75rem;
  color: var(--text-sub);
  margin-top: 2px;
}

/* メインコンテナ */
.main-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

/* セクション */
.section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.section-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title i {
  color: var(--primary);
  font-size: 1rem;
}

/* APIキー入力 */
.api-key-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
}

.api-key-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
  font-family: monospace;
}

.api-key-input:focus { border-color: var(--primary); }

.api-key-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--text-sub);
}

.api-key-status {
  font-size: 0.75rem;
  margin-top: 6px;
  color: var(--text-light);
}

.api-key-status.saved { color: var(--success); }

.api-key-link {
  font-size: 0.75rem;
  color: var(--primary);
  text-decoration: none;
  margin-top: 4px;
  display: inline-block;
}

.api-key-link:hover { text-decoration: underline; }

/* 画像アップロード */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #fafbfc;
}

.upload-area:hover {
  border-color: var(--primary-light);
  background: #f0f0ff;
}

.upload-area.has-image {
  padding: 0;
  border-style: solid;
  border-color: var(--primary-light);
  overflow: hidden;
  position: relative;
}

.upload-icon {
  font-size: 2.5rem;
  color: var(--text-light);
  margin-bottom: 8px;
}

.upload-text {
  font-size: 0.85rem;
  color: var(--text-sub);
}

.upload-hint {
  font-size: 0.7rem;
  color: var(--text-light);
  margin-top: 4px;
}

.upload-preview {
  width: 100%;
  display: block;
  max-height: 400px;
  object-fit: contain;
  background: #f0f0f0;
}

.upload-change-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.75rem;
  cursor: pointer;
}

/* テキスト入力 */
.form-group { margin-bottom: 14px; }

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.form-label-hint {
  font-weight: 400;
  color: var(--text-light);
  font-size: 0.7rem;
}

.form-input,
.form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-input:focus,
.form-textarea:focus {
  border-color: var(--primary);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.6;
}

/* スタイル選択 */
.style-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.style-option {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: white;
}

.style-option:hover {
  border-color: var(--primary-light);
  background: #f8f7ff;
}

.style-option.selected {
  border-color: var(--primary);
  background: #eef2ff;
}

.style-emoji { font-size: 1.5rem; }

.style-name {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 4px;
}

/* カスタムプロンプト */
.custom-prompt-area {
  margin-top: 10px;
  display: none;
}

.custom-prompt-area.visible { display: block; }

.prompt-example {
  font-size: 0.7rem;
  color: var(--text-light);
  margin-top: 4px;
  line-height: 1.5;
}

/* アスペクト比 */
.aspect-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.aspect-option {
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  background: white;
  flex: 1;
  min-width: 70px;
}

.aspect-option:hover { border-color: var(--primary-light); }

.aspect-option.selected {
  border-color: var(--primary);
  background: #eef2ff;
}

.aspect-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
}

.aspect-desc {
  font-size: 0.6rem;
  color: var(--text-light);
  margin-top: 2px;
}

/* 生成枚数 */
.count-selector {
  display: flex;
  gap: 8px;
}

.count-option {
  width: 48px;
  height: 48px;
  border: 2px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  background: white;
  color: var(--text);
}

.count-option:hover { border-color: var(--primary-light); }

.count-option.selected {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.count-note {
  font-size: 0.7rem;
  color: var(--text-light);
  margin-top: 6px;
}

/* 生成ボタン */
.generate-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.generate-btn:hover { background: var(--primary-dark); }

.generate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 生成中オーバーレイ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.92);
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.loading-overlay.active { display: flex; }

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.loading-sub {
  font-size: 0.8rem;
  color: var(--text-sub);
}

.loading-progress {
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 600;
}

/* 結果エリア */
.results-section {
  display: none;
}

.results-section.visible { display: block; }

.result-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
}

.result-image {
  width: 100%;
  display: block;
  background: #f0f0f0;
}

.result-actions {
  padding: 12px 16px;
  display: flex;
  gap: 8px;
}

.result-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  background: white;
  color: var(--text);
}

.result-btn:hover { background: #f8fafc; }

.result-btn.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.result-btn.primary:hover { background: var(--primary-dark); }

.result-number {
  font-size: 0.75rem;
  color: var(--text-sub);
  padding: 8px 16px 0;
  font-weight: 600;
}

/* トースト */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 0.85rem;
  z-index: 300;
  opacity: 0;
  transition: all 0.3s;
  white-space: nowrap;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error { background: var(--error); }

/* エラー表示 */
.error-msg {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--error);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.8rem;
  margin-top: 8px;
  display: none;
}

.error-msg.visible { display: block; }

/* レスポンシブ */
@media (max-width: 480px) {
  .main-container { padding: 10px; }
  .section { padding: 16px; }
  .style-grid { grid-template-columns: repeat(2, 1fr); }
}
