*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: #eef1f7;
  color: #1f2937;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* =====================================================
   ヘッダー
===================================================== */
.app-header {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e3a8a 100%);
  color: white;
  padding: 28px 24px 26px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(30, 58, 138, 0.25);
}

.app-header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.subtitle {
  margin: 6px 0 0;
  opacity: 0.85;
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  font-weight: 400;
}

/* =====================================================
   コンテナ
===================================================== */
.container {
  max-width: 900px;
  margin: 28px auto;
  padding: 0 18px;
}

/* =====================================================
   カード
===================================================== */
.card {
  background: #ffffff;
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.04),
    0 4px 16px rgba(0, 0, 0, 0.07);
  border: 1px solid rgba(0,0,0,0.04);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.06),
    0 8px 24px rgba(0, 0, 0, 0.09);
}

.card h2 {
  margin-top: 0;
  font-size: 1.05rem;
  font-weight: 700;
  border-left: 4px solid #2563eb;
  padding-left: 12px;
  color: #111827;
  letter-spacing: 0.01em;
}

/* =====================================================
   クイックプリセット
===================================================== */
.preset-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.preset-btn {
  background: #ffffff;
  color: #1d4ed8;
  border: 1.5px solid #bfdbfe;
  padding: 7px 14px;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 600;
}

.preset-btn:hover {
  background: #eff6ff;
  border-color: #60a5fa;
  color: #1d4ed8;
  transform: translateY(-1px);
}

/* =====================================================
   タスク選択グリッド
===================================================== */
.ui-hint {
  font-size: 0.83rem;
  color: #6b7280;
  margin: 0 0 16px;
  letter-spacing: 0.02em;
}

.task-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.task-card {
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 8px 10px;
  cursor: pointer;
  background: #f9fafb;
  transition:
    border-color 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.12s ease;
  user-select: none;
}

.task-card:hover {
  border-color: #93c5fd;
  background: #eff6ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

.task-card.selected {
  border-color: #2563eb;
  background: #eff6ff;
  box-shadow:
    0 0 0 3px rgba(37, 99, 235, 0.18),
    0 4px 12px rgba(37, 99, 235, 0.12);
  transform: translateY(-1px);
}

.task-card-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.task-icon {
  font-size: 1.65rem;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.08));
}

.task-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  color: #374151;
  line-height: 1.4;
}

/* カウンター */
.task-counter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}

.task-counter.hidden {
  display: none;
}

.counter-btn {
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 1px 4px rgba(37,99,235,0.25);
}

.counter-btn:hover {
  background: #1e40af;
  transform: scale(1.12);
}

.counter-val {
  font-size: 0.82rem;
  font-weight: 700;
  color: #1e40af;
  min-width: 34px;
  text-align: center;
}

/* =====================================================
   緊急度
===================================================== */
.urgency-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.urgency-label {
  font-size: 0.88rem;
  font-weight: 700;
  color: #374151;
  letter-spacing: 0.02em;
}

.urgency-buttons {
  display: flex;
  gap: 7px;
}

.urgency-btn {
  background: #f3f4f6;
  color: #374151;
  border: 2px solid #e5e7eb;
  padding: 5px 18px;
  border-radius: 99px;
  font-size: 0.84rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.18s ease;
  letter-spacing: 0.03em;
}

.urgency-btn:hover {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
}

.urgency-btn.active {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border-color: #2563eb;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

/* =====================================================
   任意補足メモ
===================================================== */
.optional-row {
  margin-bottom: 16px;
}

.toggle-optional {
  background: transparent;
  color: #2563eb;
  border: 1.5px dashed #93c5fd;
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 0.84rem;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
  letter-spacing: 0.02em;
}

.toggle-optional:hover {
  background: #eff6ff;
  border-color: #60a5fa;
}

textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  font-size: 0.94rem;
  resize: vertical;
  font-family: inherit;
  color: #1f2937;
  transition: border-color 0.18s, box-shadow 0.18s;
  outline: none;
  line-height: 1.6;
}

textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* =====================================================
   送信プレビュー
===================================================== */
.send-preview {
  background: #f0fdf4;
  border-left: 4px solid #059669;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
}

.send-preview-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #059669;
  margin-bottom: 5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.send-preview-body {
  font-size: 0.84rem;
  color: #1f2937;
  white-space: pre-wrap;
  margin: 0;
  font-family: inherit;
  line-height: 1.7;
}

/* =====================================================
   コントロール行
===================================================== */
.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.mode-help {
  margin-left: 4px;
  cursor: help;
  color: #6b7280;
  font-size: 0.85rem;
}

select {
  padding: 7px 12px;
  border-radius: 8px;
  border: 1.5px solid #d1d5db;
  font-size: 0.9rem;
  color: #1f2937;
  background: #f9fafb;
  cursor: pointer;
  outline: none;
  transition: border-color 0.18s;
  font-family: inherit;
}

select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

button {
  background: #2563eb;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 0.94rem;
  font-family: inherit;
  font-weight: 600;
  transition: background 0.18s, transform 0.1s, box-shadow 0.18s;
  letter-spacing: 0.02em;
}

button:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,235,0.25);
}

button:active {
  transform: translateY(0);
}

.run-btn {
  background: #9ca3af;
  font-weight: 800;
  font-size: 0.98rem;
  padding: 13px 28px;
  border-radius: 10px;
  transition: background 0.22s, box-shadow 0.22s, transform 0.1s;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.run-btn:hover {
  background: #9ca3af;
  transform: none;
  box-shadow: none;
}

.run-btn.run-btn-active {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
}

.run-btn.run-btn-active:hover {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e3a8a 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.run-btn:disabled {
  cursor: not-allowed;
  opacity: 0.65;
  transform: none;
  box-shadow: none;
}

.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.5);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* =====================================================
   ステップ可視化
===================================================== */
.steps {
  padding-left: 22px;
  margin: 0;
}

.steps li {
  margin: 8px 0;
  color: #9ca3af;
  font-size: 0.9rem;
  transition: color 0.2s;
  padding-left: 4px;
}

.steps li.active {
  color: #2563eb;
  font-weight: 700;
}

.steps li.done {
  color: #059669;
  font-weight: 500;
}

/* =====================================================
   出力エリア
===================================================== */
.output {
  white-space: pre-wrap;
  background: #f8fafc;
  border: 1.5px solid #e5e7eb;
  padding: 16px 18px;
  border-radius: 12px;
  min-height: 88px;
  font-size: 0.93rem;
  line-height: 1.75;
  color: #1f2937;
  font-family: inherit;
}

.output-heading {
  font-weight: 800;
  color: #1d4ed8;
  margin: 14px 0 6px;
  font-size: 0.98rem;
  border-bottom: 1.5px dashed #bfdbfe;
  padding-bottom: 4px;
}

.output-heading:first-child {
  margin-top: 0;
}

.output-section {
  margin-bottom: 4px;
}

.output-line {
  font-size: 0.92rem;
  line-height: 1.75;
}

.output-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.ghost-btn {
  background: #ffffff;
  color: #2563eb;
  border: 1.5px solid #bfdbfe;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
}

.ghost-btn:hover {
  background: #eff6ff;
  color: #1d4ed8;
  box-shadow: none;
  transform: none;
}

/* =====================================================
   再試行エリア
===================================================== */
.retry-area {
  margin-top: 14px;
}

/* =====================================================
   保存タスクリスト・フィルタ
===================================================== */
.task-filter-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 0.86rem;
  color: #374151;
}

.task-filter-row select {
  margin-left: 6px;
}

.task-buttons-row {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.task-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
}

.task-list li {
  padding: 9px 14px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 0.88rem;
  color: #374151;
  transition: background 0.15s;
  border-radius: 6px;
}

.task-list li:hover {
  background: #f9fafb;
}

.task-list li:last-child {
  border-bottom: none;
}

/* =====================================================
   フッター
===================================================== */
.app-footer {
  text-align: center;
  padding: 24px 16px;
  color: #9ca3af;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

/* =====================================================
   お知らせカード・PII
===================================================== */
.notice {
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  border-left: 4px solid #f59e0b;
  border-radius: 16px;
}

.notice h2 {
  border-left-color: #f59e0b;
}

.notice ul {
  margin: 10px 0 0;
  padding-left: 20px;
  line-height: 1.8;
  font-size: 0.92rem;
  color: #78350f;
}

.notice ul strong {
  color: #92400e;
}

.pii-alert {
  margin-top: 10px;
  padding: 11px 14px;
  background: #fef2f2;
  border-left: 4px solid #dc2626;
  border-radius: 8px;
  color: #991b1b;
  font-size: 0.88rem;
  white-space: pre-wrap;
  line-height: 1.6;
}

.masked-preview {
  margin-top: 10px;
  padding: 11px 14px;
  background: #f0fdf4;
  border-left: 4px solid #059669;
  border-radius: 8px;
  font-size: 0.88rem;
  color: #1f2937;
}

.masked-preview pre {
  margin: 7px 0 0;
  white-space: pre-wrap;
  font-family: inherit;
  line-height: 1.6;
  color: #374151;
}

/* =====================================================
   チェックボックス・危険ボタン
===================================================== */
.check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.88rem;
  color: #374151;
  cursor: pointer;
  font-weight: 500;
}

.check input[type="checkbox"] {
  accent-color: #2563eb;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.danger {
  background: #dc2626;
  margin-left: 8px;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.2);
}

.danger:hover {
  background: #b91c1c;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

/* =====================================================
   トースト通知
===================================================== */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  min-width: 220px;
  max-width: 320px;
  background: #1f2937;
  color: white;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.86rem;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: pre-wrap;
  line-height: 1.5;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success { background: #059669; }
.toast-error   { background: #dc2626; }
.toast-warn    { background: #d97706; }
.toast-info    { background: #1f2937; }

/* =====================================================
   レスポンシブ調整
===================================================== */
@media (max-width: 480px) {
  .container {
    padding: 0 12px;
  }
  .task-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
  .controls {
    flex-direction: column;
    align-items: stretch;
  }
  .controls .run-btn {
    width: 100%;
    justify-content: center;
  }
  .task-filter-row {
    flex-direction: column;
    gap: 8px;
  }
}

/* 学習状況メーター */
.metrics-card {
  background: linear-gradient(135deg, #f0f9ff 0%, #eef2ff 100%);
  border-left: 4px solid #2563eb;
}

.metrics-card h2 {
  border-left-color: #2563eb;
}

.metrics-body {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.metric-item {
  flex: 1;
  min-width: 120px;
  background: #ffffff;
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-num {
  font-size: 1.5rem;
  font-weight: 800;
  color: #1d4ed8;
  line-height: 1.1;
}

.metric-label {
  font-size: 0.76rem;
  color: #6b7280;
  font-weight: 600;
}

.metrics-learned {
  margin-top: 14px;
  background: #ffffff;
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.metrics-learned-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: #1d4ed8;
  margin-bottom: 8px;
}

.metrics-learned-item {
  font-size: 0.84rem;
  color: #374151;
  line-height: 1.7;
}

/* 使用モデルバッジ */
.model-badge {
  display: inline-block;
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 12px;
}

/* フィードバックエリア */
.feedback-area {
  margin-top: 16px;
  padding: 16px;
  background: #f8fafc;
  border: 1.5px dashed #bfdbfe;
  border-radius: 12px;
}

.feedback-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #374151;
  margin-bottom: 10px;
}

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

.fb-btn {
  font-size: 0.84rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1.5px solid transparent;
}

.fb-up {
  background: #ecfdf5;
  color: #059669;
  border-color: #a7f3d0;
}

.fb-up:hover {
  background: #d1fae5;
  color: #047857;
  box-shadow: none;
  transform: none;
}

.fb-down {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

.fb-down:hover {
  background: #fee2e2;
  color: #b91c1c;
  box-shadow: none;
  transform: none;
}

.fb-adopt {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.fb-adopt:hover {
  background: #dbeafe;
  color: #1e40af;
  box-shadow: none;
  transform: none;
}

.fb-edit {
  background: #fffbeb;
  color: #d97706;
  border-color: #fde68a;
}

.fb-edit:hover {
  background: #fef3c7;
  color: #b45309;
  box-shadow: none;
  transform: none;
}

.feedback-status {
  margin-top: 12px;
  padding: 10px 14px;
  background: #ecfdf5;
  border-left: 4px solid #059669;
  border-radius: 8px;
  color: #065f46;
  font-size: 0.85rem;
  white-space: pre-wrap;
  line-height: 1.6;
}

@media (max-width: 480px) {
  .metrics-body {
    flex-direction: column;
  }
  .feedback-buttons {
    flex-direction: column;
  }
  .fb-btn {
    width: 100%;
  }
}
