/*
 * ビジュアル仕様：インディゴ系ブランドカラー + ダーク Hero、WCAG AA コントラスト、モバイルファースト。
 * CSP（style-src 'self'）下で外部フォント・インラインスタイルを使わず、
 * アイコンは img-src data: が許可する data:image/svg+xml のみを用いる。
 *
 * 主なコントラスト比（実測レンジ、いずれも本文 4.5:1 / 大字 3:1 を満たす）：
 *   --fg #0f172a on --bg #f4f6fb      ≈ 16:1   （本文）
 *   --muted #475569 on #ffffff        ≈ 7.5:1  （補足テキスト）
 *   --brand-strong #4338ca on #ffffff ≈ 7.4:1  （リンク・強調）
 *   white on --brand-strong #4338ca   ≈ 7.4:1  （ボタン文字）
 *   Hero 白 / #c7d2fe / #dbeafe on 濃紺グラデーション＋光斑：いずれも本文 4.5:1 を満たす
 *   footer #cbd5e1 / #a5b4fc on #0f172a：いずれも高コントラスト
 */
:root {
  --fg: #0f172a;
  --muted: #475569;
  --subtle: #5a667a;
  --brand: #4f46e5;
  --brand-strong: #4338ca;
  --brand-soft: #eef2ff;
  --brand-tint: #e0e7ff;
  --card: #ffffff;
  --bg: #f4f6fb;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --row-line: #eef1f6;
  --open: #3730a3;
  --closed: #6b21a8;
  --other: #92400e;
  --focus-ring: #f59e0b;
  --radius: 14px;
  --wrap: 1180px;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.14);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic",
    "Noto Sans JP", Meiryo, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: var(--wrap);
  margin: 0 auto;
  padding: 0 20px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--brand-strong);
  color: #fff;
  padding: 10px 18px;
  z-index: 100;
  border-radius: 0 0 var(--radius) 0;
  font-weight: 700;
}
.skip-link:focus { left: 0; color: #fff; }

/* ---------- フォーカス（共通・高コントラスト） ---------- */
select:focus-visible,
input:focus-visible,
button:focus-visible,
a:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---------- ヘッダー / Hero ---------- */
.site-header {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #0b1120 0%, #1e1b4b 52%, #312e81 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}
.hero-decor {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 16% 18%, rgba(99, 102, 241, 0.42), transparent 46%),
    radial-gradient(circle at 84% 8%, rgba(56, 189, 248, 0.20), transparent 42%),
    radial-gradient(circle at 72% 96%, rgba(168, 85, 247, 0.24), transparent 46%),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: auto, auto, auto, 44px 44px, 44px 44px;
}
.hero-inner {
  position: relative;
  z-index: 1;
  padding: 46px 0 62px;
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #c7d2fe;
}
.eyebrow-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #818cf8;
  box-shadow: 0 0 0 4px rgba(129, 140, 248, 0.22), 0 0 12px rgba(129, 140, 248, 0.8);
}
.site-header h1 {
  margin: 0 0 10px;
  font-size: clamp(1.85rem, 4.2vw, 2.65rem);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: #ffffff;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.25);
}
.tagline {
  margin: 0 0 0;
  max-width: 64ch;
  font-size: 1.05rem;
  color: #c7d2fe;
}
.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 22px 0 16px;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.stat-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #dbeafe;
}
.stat-value {
  font-size: 1.05rem;
  font-weight: 800;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}
.disclaimer {
  margin: 0;
  max-width: 78ch;
  font-size: 0.85rem;
  line-height: 1.7;
  color: rgba(226, 232, 240, 0.82);
  border-left: 3px solid rgba(129, 140, 248, 0.55);
  padding-left: 14px;
}

/* ---------- コントロール（Hero に重ねる） ---------- */
.controls {
  position: relative;
  z-index: 2;
  margin: -30px 0 30px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: var(--shadow-lg);
}
.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 158px;
}
.field-grow { flex: 1 1 240px; }
.field label {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--muted);
}

select,
input[type="search"] {
  font: inherit;
  font-size: 0.9rem;
  color: var(--fg);
  background-color: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 12px;
  min-height: 44px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}
input[type="search"] {
  padding-left: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
}
select:hover,
input[type="search"]:hover { border-color: var(--brand); }
select:focus-visible,
input[type="search"]:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18);
}

.btn-secondary {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--brand-strong);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 16px 9px 36px;
  min-height: 44px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='%234338ca' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='1 4 1 10 7 10'/%3E%3Cpath d='M3.51 15a9 9 0 1 0 2.13-9.36L1 10'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 14px center;
  transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}
.btn-secondary:hover {
  background-color: var(--brand-soft);
  border-color: var(--brand);
}
.btn-secondary:active { transform: translateY(1px); }

/* ---------- 見出し ---------- */
main h2 {
  position: relative;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 34px 0 12px;
  padding-left: 15px;
}
main h2::before {
  content: "";
  position: absolute;
  left: 0; top: 0.18em; bottom: 0.18em;
  width: 5px;
  border-radius: 4px;
  background: linear-gradient(180deg, #818cf8, var(--brand-strong));
}
h3 { font-size: 1.05rem; font-weight: 700; margin: 0 0 6px; }
.hint {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 0 0 12px;
}

/* ---------- 一覧テーブル ---------- */
.table-scroll {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}
#ranking-table th,
#ranking-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--row-line);
  vertical-align: middle;
}
#ranking-table thead th {
  background: #f1f5fb;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.79rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  position: sticky;
  top: 0;
  border-bottom: 2px solid var(--brand-tint);
}
#ranking-table thead th:first-child { border-top-left-radius: var(--radius); }
#ranking-table thead th:last-child { border-top-right-radius: var(--radius); }
#ranking-table tbody tr { transition: background-color 0.14s ease; }
#ranking-table tbody tr:nth-child(even) { background: #fafbfe; }
#ranking-table tbody tr:hover { background: var(--brand-soft); }
#ranking-table tbody tr:focus-within { background: #e6e9ff; }
#ranking-table .num { text-align: right; font-variant-numeric: tabular-nums; }
#ranking-table .unit {
  font-weight: 500;
  font-size: 0.72rem;
  color: var(--subtle);
}
.col-rank { width: 3.5rem; }
.rank-cell { text-align: center; }
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border-radius: 9px;
  background: #eef1f6;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.rank-badge.top {
  background: linear-gradient(135deg, #6366f1, var(--brand-strong));
  color: #fff;
  box-shadow: 0 3px 8px rgba(67, 56, 202, 0.35);
}
.loading-cell, .empty-state {
  text-align: center;
  color: var(--muted);
  padding: 28px;
}
.empty-state {
  margin-top: 12px;
  background: var(--card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.model-name { font-weight: 700; color: var(--fg); }
.model-id {
  display: block;
  font-size: 0.72rem;
  color: var(--subtle);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-open { background: #eef2ff; color: var(--open); border-color: #c7d2fe; }
.badge-closed { background: #f5f3ff; color: var(--closed); border-color: #ddd6fe; }
.badge-other { background: #fffbeb; color: var(--other); border-color: #fde68a; }
.btn-detail {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--brand-strong);
  background: var(--brand-soft);
  border: 1px solid var(--brand-tint);
  border-radius: 9px;
  padding: 6px 12px;
  min-height: 34px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}
.btn-detail::after { content: " \203A"; font-size: 1rem; line-height: 0; }
.btn-detail:hover { background: var(--brand-strong); color: #fff; border-color: var(--brand-strong); }
.btn-detail:active { transform: translateY(1px); }
.empty-val { color: var(--subtle); font-style: italic; }

/* ---------- グラフ ---------- */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}
.chart-card {
  margin: 0;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.chart-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.chart-card figcaption { margin-bottom: 12px; }
.chart-card figcaption h3 {
  position: relative;
  padding-left: 11px;
  font-size: 1rem;
}
.chart-card figcaption h3::before {
  content: "";
  position: absolute;
  left: 0; top: 0.18em; bottom: 0.18em;
  width: 3px;
  border-radius: 3px;
  background: var(--brand);
}
.chart-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  margin-top: 8px;
  font-size: 0.875rem;
}
.chart-controls label { font-weight: 600; color: var(--muted); }
.chart-controls select {
  min-height: 38px;
  min-width: 0;
  flex: 1 1 200px;
  max-width: 100%;
  padding-top: 6px;
  padding-bottom: 6px;
}
.chart {
  width: 100%;
  height: 360px;
}
.chart-alt { margin-top: 12px; }
.chart-alt summary {
  cursor: pointer;
  color: var(--brand-strong);
  font-size: 0.85rem;
  font-weight: 600;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 8px;
  display: inline-block;
  list-style: none;
}
.chart-alt summary::-webkit-details-marker { display: none; }
.chart-alt summary::before { content: "\25B8\00A0"; font-size: 0.8rem; }
.chart-alt[open] summary::before { content: "\25BE\00A0"; }
.chart-alt summary:hover { background: var(--brand-soft); }
.alt-table {
  margin-top: 8px;
  font-size: 0.85rem;
}
.alt-table th, .alt-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--row-line);
  text-align: left;
}
.alt-table th { color: var(--muted); font-size: 0.78rem; }
.alt-table td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- モーダル ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.62);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 28px 16px;
  overflow-y: auto;
  z-index: 50;
  animation: fade-in 0.18s ease both;
}
.overlay[hidden] { display: none; }
.modal {
  background: var(--card);
  border-radius: 18px;
  max-width: 760px;
  width: 100%;
  overflow: hidden;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.38);
  animation: modal-in 0.22s ease both;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px;
  background: linear-gradient(135deg, #1e1b4b, var(--brand-strong));
}
.modal-header h2 { margin: 0; padding: 0; font-size: 1.3rem; font-weight: 800; color: #fff; }
.modal-header h2::before { display: none; }
.btn-close {
  font-size: 1.5rem;
  line-height: 1;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 9px;
  width: 40px; height: 40px;
  cursor: pointer;
  color: #fff;
  transition: background-color 0.16s ease;
}
.btn-close:hover { background: rgba(255, 255, 255, 0.28); }
.modal-body { padding: 22px 24px 28px; }
.detail-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0 20px;
  margin-bottom: 18px;
}
.detail-grid dt,
.detail-grid dd {
  padding: 8px 0;
  border-bottom: 1px solid var(--row-line);
}
.detail-grid dt {
  font-weight: 700;
  color: var(--muted);
  font-size: 0.85rem;
}
.detail-grid dd { margin: 0; color: var(--fg); }
.detail-section { margin-top: 20px; }
.detail-section h3 {
  font-size: 1rem;
  padding-left: 11px;
  border-left: 3px solid var(--brand);
  border-bottom: 1px solid var(--row-line);
  padding-bottom: 6px;
  margin-bottom: 8px;
}
.source-list { list-style: none; padding: 0; margin: 0; }
.source-list li {
  padding: 8px 6px;
  border-bottom: 1px dashed var(--border-strong);
  border-radius: 8px;
  transition: background-color 0.14s ease;
}
.source-list li:hover { background: var(--brand-soft); }
.source-list a { color: var(--brand-strong); font-weight: 600; word-break: break-all; }
.source-list .retrieved {
  display: block;
  font-size: 0.78rem;
  color: var(--subtle);
  word-break: break-all;
}
.notes-box {
  background: var(--brand-soft);
  border-left: 3px solid var(--brand);
  border-radius: 0 10px 10px 0;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 8px;
}

/* ---------- フッター ---------- */
.site-footer {
  margin-top: 52px;
  padding: 40px 0 34px;
  background: linear-gradient(160deg, #0f172a, #1e1b4b);
  border-top: 3px solid var(--brand);
  font-size: 0.875rem;
  color: #cbd5e1;
}
.site-footer h2 {
  font-size: 1.15rem;
  color: #fff;
  margin-top: 0;
  padding: 0;
}
.site-footer h2::before { display: none; }
.site-footer p { max-width: 84ch; }
.site-footer a { color: #a5b4fc; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.site-footer a:hover { color: #fff; }
.site-footer .sep { margin: 0 8px; color: #818cf8; }
.site-footer code {
  background: rgba(255, 255, 255, 0.10);
  color: #e0e7ff;
  padding: 2px 7px;
  border-radius: 5px;
}
.fine { font-size: 0.8rem; color: #94a3b8; }

/* ---------- スクロールバー ---------- */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid var(--bg);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: var(--subtle); }

/* ---------- アニメーション ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- レスポンシブ ---------- */
@media (max-width: 720px) {
  .wrap { padding: 0 14px; }
  .hero-inner { padding: 34px 0 52px; }
  .site-header h1 { font-size: 1.55rem; }
  .tagline { font-size: 0.95rem; }
  .hero-stats { gap: 10px; margin: 18px 0 14px; }
  .stat { min-width: 0; flex: 1 1 130px; padding: 9px 14px; }
  .stat-value { font-size: 0.95rem; }
  .controls { margin: -22px 0 24px; padding: 16px; border-radius: 14px; }
  .control-row { flex-direction: column; align-items: stretch; gap: 12px; }
  .field { min-width: 0; width: 100%; }
  main h2 { font-size: 1.2rem; margin: 26px 0 10px; }
  .chart { height: 300px; }
  .chart-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .chart-card:hover { transform: none; }
  .detail-grid { grid-template-columns: 1fr; gap: 0; }
  .detail-grid dt { border-bottom: none; padding-bottom: 0; }
  .detail-grid dd { margin-bottom: 8px; }
  .overlay { padding: 12px 8px; }
  .modal { border-radius: 14px; }
  .modal-header, .modal-body { padding-left: 16px; padding-right: 16px; }
  .site-footer { margin-top: 36px; padding: 30px 0 26px; }
}

/* ---------- モーションの削減 ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
