@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Noto+Sans+JP:wght@300;400;500;600;700&display=swap');

/* === リセット === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-glass: rgba(0, 0, 0, 0.02);

  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --accent-indigo: #4f46e5;
  --accent-indigo-glow: rgba(79, 70, 229, 0.25);
  --accent-emerald: #059669;
  --accent-emerald-glow: rgba(5, 150, 105, 0.25);
  --accent-green: #059669;
  --accent-blue: #2563eb;
  --accent-yellow: #d97706;
  --accent-orange: #ea580c;
  --accent-red: #dc2626;
  --accent-pink: #db2777;

  --border-subtle: rgba(15, 23, 42, 0.1);
  --border-active: rgba(79, 70, 229, 0.5);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.08);
  --shadow-glow-indigo: 0 0 20px rgba(79, 70, 229, 0.15);
  --shadow-glow-emerald: 0 0 20px rgba(5, 150, 105, 0.15);

  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Noto Sans JP', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background:
    radial-gradient(ellipse at 20% 40%, rgba(79, 70, 229, 0.03) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 30%, rgba(5, 150, 105, 0.02) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(217, 119, 6, 0.02) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem;
  position: relative;
  z-index: 1;
}

/* === ヘッダー === */
.header {
  text-align: center;
  margin-bottom: 2rem;
  padding: 1.8rem 0;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: var(--accent-indigo);
  padding: 5px 13px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  margin-bottom: 0.8rem;
}

.header h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #1e293b 0%, #4f46e5 50%, #059669 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.4rem;
  letter-spacing: -0.02em;
}

.header p {
  color: var(--text-secondary);
  font-size: 1rem;
  max-width: 580px;
  margin: 0 auto;
}

/* === セクション === */
.section { margin-bottom: 1.5rem; }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}

.section-title .icon { font-size: 1.15rem; }

/* === リターン期間セレクト（セクションタイトル内） === */
.return-period-wrapper {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-label-inline {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.period-select {
  padding: 4px 10px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}

.period-select:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px var(--accent-indigo-glow);
}

/* === 入力セクション === */
.input-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  box-shadow: var(--shadow-md);
}

.input-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-wrapper { position: relative; }

.input-field {
  width: 100%;
  padding: 12px 14px;
  padding-right: 50px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1.15rem;
  font-family: inherit;
  font-weight: 500;
  transition: var(--transition);
  outline: none;
}

.input-field:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px var(--accent-indigo-glow);
}

.input-field::placeholder { color: var(--text-muted); font-weight: 400; }

.input-unit {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text-primary);
  pointer-events: none;
}

.select-field {
  cursor: pointer;
  padding-right: 12px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* === ファンドライブステータス === */
.fund-live-stats {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding: 8px 14px;
  background: #f1f5f9;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.fund-live-stats strong {
  color: var(--text-primary);
  font-size: 1rem;
}

.fund-live-stats .divider {
  width: 1px;
  height: 14px;
  background: var(--border-subtle);
}

/* === ファンド選択グリッド === */
.fund-select-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.fund-select-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1rem;
  backdrop-filter: blur(8px);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.fund-select-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  opacity: 0.6;
  transition: var(--transition);
}

.fund-card-a::before {
  background: linear-gradient(90deg, var(--accent-indigo), #8b5cf6);
}

.fund-card-b::before {
  background: linear-gradient(90deg, var(--accent-emerald), #34d399);
}

.fund-select-card:hover {
  border-color: rgba(148, 163, 184, 0.2);
}

.fund-select-header { margin-bottom: 0.6rem; }

.slot-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge-fund-a {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-indigo);
}

.badge-fund-b {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
}

.badge-diff {
  background: rgba(251, 191, 36, 0.12);
  color: var(--accent-yellow);
}

.badge-diff.diff-title {
  font-size: 0.95rem;
  font-weight: 800;
  padding: 5px 14px;
}

#fund-a,
#fund-b,
.fund-select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.fund-select:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px var(--accent-indigo-glow);
}

.fund-select option { background: #ffffff; color: var(--text-primary); }

/* === アクション行 === */
.action-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.run-button {
  flex: 1;
  padding: 12px 24px;
  background: linear-gradient(135deg, var(--accent-indigo), #8b5cf6);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.run-button::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 200%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transition: 0.5s;
}

.run-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
}

.run-button:hover::before { left: 100%; }
.run-button:active { transform: translateY(0); }

/* CSV読込ボタン */
.csv-upload { flex-shrink: 0; }

.csv-label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  height: 100%;
}

.csv-label:hover {
  background: var(--bg-card-hover);
  border-color: rgba(148, 163, 184, 0.25);
  color: var(--text-primary);
}

.csv-input-hidden { display: none; }

/* === 結果セクション === */
.results-section {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.5s ease, transform 0.5s ease;
  pointer-events: none;
}

.results-section.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* === 結果グリッド（A, B 横並び） === */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
  max-width: 880px;
  margin-left: auto;
  margin-right: auto;
}

/* === 結果ブロック === */
.result-block {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.diff-block {
  margin-bottom: 14px;
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
}

.result-block-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border-subtle);
  height: 68px;
  overflow: hidden;
}

.result-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
}

.result-fund-name {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 500;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

.result-meta {
  display: flex;
  gap: 14px;
  padding: 8px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.2);
  flex-wrap: wrap;
}

.result-meta strong {
  color: var(--text-secondary);
}

/* === FANG+ 注記 === */
.fang-warning {
  padding: 10px 14px;
  background: rgba(251, 191, 36, 0.08);
  border-top: 1px solid rgba(251, 191, 36, 0.15);
  font-size: 0.85rem;
  color: var(--accent-yellow);
  font-weight: 500;
  text-align: center;
}

/* === テーブル === */
table {
  width: 100%;
  border-collapse: collapse;
}

thead tr { background: #f8fafc; }

th {
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

td {
  padding: 10px 14px;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border-subtle);
}

tr:last-child td { border-bottom: none; }
tbody tr { transition: var(--transition); }
tbody tr:hover { background: rgba(99, 102, 241, 0.03); }

.value { font-weight: 600; font-variant-numeric: tabular-nums; }
.value.positive { color: var(--accent-green); }
.value.negative { color: var(--accent-red); }

.case-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.case-badge.case-top5    { background: rgba(16, 185, 129, 0.1);  color: var(--accent-green); }
.case-badge.case-top30   { background: rgba(59, 130, 246, 0.1);  color: var(--accent-blue); }
.case-badge.case-median  { background: rgba(251, 191, 36, 0.1);  color: var(--accent-yellow); }
.case-badge.case-bot30   { background: rgba(249, 115, 22, 0.1);  color: var(--accent-orange); }
.case-badge.case-bot5    { background: rgba(239, 68, 68, 0.1);   color: var(--accent-red); }
.case-badge.case-principal { background: rgba(148, 163, 184, 0.08); color: var(--text-secondary); }

.principal-row { background: rgba(148, 163, 184, 0.02); }

/* === グラフ === */
.chart-container {
  position: relative;
  width: 100%;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  backdrop-filter: blur(8px);
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
  gap: 8px;
}

.chart-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-case-switch {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  background: #f1f5f9;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.case-radio {
  cursor: pointer;
}

.case-radio input {
  display: none;
}

.case-radio span {
  display: block;
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 5px;
  transition: var(--transition);
}

.case-radio input:checked + span {
  background: var(--accent-indigo);
  color: #fff;
}

.case-radio:hover span {
  color: var(--text-primary);
}

.chart-container {
  position: relative;
  height: 380px;
}

/* === トースト === */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 10px 22px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 9999;
  backdrop-filter: blur(12px);
}

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

/* === フッター === */
.footer {
  text-align: center;
  padding: 1.2rem 0;
  margin-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

.footer p {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.8;
}

/* === レスポンシブ === */
@media (max-width: 860px) {
  .fund-select-grid,
  .results-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .container { padding: 1rem; }
  .header h1 { font-size: 1.4rem; }
  .input-grid-3 { grid-template-columns: 1fr; }
  .action-row { flex-direction: column; }
  .chart-container { height: 320px; }
  .chart-container-histogram { height: 280px; }
  th, td { padding: 6px 8px; font-size: 0.75rem; }

  /* 投資信託選択プルダウンの幅制御（対象限定） */
  #fund-a,
  #fund-b {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
    white-space: normal;
    word-break: break-word;
    overflow: hidden;
  }
  .fund-select-card {
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  .header h1 { font-size: 1.2rem; }
  .chart-container { height: 280px; }
  .chart-container-histogram { height: 260px; }
  .chart-header { flex-direction: column; align-items: flex-start; }
}

/* === スクロールバー === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.3); }

/* === アニメーション === */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.section { animation: fadeInUp 0.45s ease forwards; }
.section:nth-child(2) { animation-delay: 0.08s; }
.section:nth-child(3) { animation-delay: 0.16s; }
.section:nth-child(4) { animation-delay: 0.24s; }

/* === エクストラ・インライン抽出クラス === */
.summary-box {
  margin: 20px auto;
  padding: 15px 20px;
  background: rgba(99, 102, 241, 0.08);
  border-left: 4px solid #6366f1;
  border-radius: 4px;
  max-width: 880px;
}

.beginner-guide-details {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  padding: 12px 18px;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  max-width: 900px;
  margin: 0 auto;
}

.beginner-guide-content {
  margin-top: 15px;
  color: #475569;
  font-size: 0.95em;
  line-height: 1.6;
  border-top: 1px solid #e2e8f0;
  padding-top: 12px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  margin-top: 24px;
}

.footer-links a {
  color: #64748b;
  text-decoration: none;
  font-size: 0.8rem;
}

.footer-links a:hover {
  text-decoration: underline;
  color: #475569;
}

.footer-copyright {
  margin-top: 16px;
  font-size: 0.75rem;
  color: #94a3b8;
  text-align: center;
}

/* === 実行ボタンセクション余白 === */
.section-action {
  margin-top: 0.75rem;
}
