:root {
  --bg: #f4f6fa;
  --bg-alt: #ffffff;
  --panel: #ffffff;
  --text: #1a1f2b;
  --text-strong: #0d1320;
  --muted: #5b6678;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --good: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --border: #e3e7ef;
  --border-strong: #c8d0dc;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 6px rgba(15, 23, 42, 0.05);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:active { opacity: 0.7; }

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding:
    max(20px, var(--safe-top))
    max(16px, var(--safe-right))
    max(40px, var(--safe-bottom))
    max(16px, var(--safe-left));
}

.topnav {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 18px;
  font-size: 15px;
}
.topnav a {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--accent);
  font-weight: 500;
  box-shadow: var(--shadow);
}

header.page { margin: 4px 4px 22px; }
header.page h1 {
  font-size: 24px; font-weight: 800; letter-spacing: 0.01em;
  margin: 0 0 6px; line-height: 1.3; color: var(--text-strong);
}
header.page .sub {
  color: var(--muted); font-size: 14px; line-height: 1.55;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h2 {
  font-size: 16px; font-weight: 700; margin: 0 0 14px;
  color: var(--text-strong);
}
.card .hint {
  font-size: 13px; color: var(--muted);
  margin-top: 10px; line-height: 1.6;
}

/* 見方ガイド */
.guide {
  background: var(--accent-soft);
  border: 1px solid #bfdbfe;
}
.guide h2 { color: #1e3a8a; }
.guide p { margin: 6px 0; font-size: 14px; line-height: 1.7; color: #1e3a8a; }
.guide p strong { color: #1e3a8a; }

/* 直近スコア・サマリー */
.summary {
  display: flex; flex-direction: column; gap: 6px;
  padding: 4px 4px 0;
}
.summary .label {
  font-size: 13px; color: var(--muted);
}
.summary .value-row {
  display: flex; align-items: baseline; gap: 12px;
  flex-wrap: wrap;
}
.summary .value {
  font-size: 44px; font-weight: 800; color: var(--text-strong);
  line-height: 1; font-variant-numeric: tabular-nums;
}
.summary .scale {
  font-size: 16px; color: var(--muted); font-weight: 500;
}
.summary .delta {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 14px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.summary .delta.up   { background: #dcfce7; color: var(--good); }
.summary .delta.down { background: #fee2e2; color: var(--bad); }
.summary .delta.flat { background: #f1f5f9; color: var(--muted); }
.summary .meta {
  font-size: 13px; color: var(--muted); margin-top: 2px;
}

/* 科目別ミニサマリー */
.subj-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 14px;
}
.subj-cell {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
}
.subj-cell .s-name { font-size: 12px; color: var(--muted); }
.subj-cell .s-val {
  font-size: 22px; font-weight: 800; color: var(--text-strong);
  font-variant-numeric: tabular-nums; line-height: 1.2;
  margin-top: 2px;
}
.subj-cell .s-delta {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.subj-cell .s-delta.up   { color: var(--good); }
.subj-cell .s-delta.down { color: var(--bad); }
.subj-cell .s-delta.flat { color: var(--muted); }
.subj-cell .s-score {
  margin-top: 4px;
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* 直近結果の補助統計（得点・平均・順位） */
.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
  padding: 12px 0 0;
  border-top: 1px solid var(--border);
}
.stat-cell { text-align: center; }
.stat-label { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.stat-value {
  font-size: 18px; font-weight: 800; color: var(--text-strong);
  font-variant-numeric: tabular-nums; line-height: 1.2;
  margin-top: 2px;
}
.stat-value .stat-unit { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.rank-sep { color: var(--muted); font-weight: 500; }
.table td.muted { color: var(--muted); }

/* ジャーニー（初回 → 最新） */
.journey .journey-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center;
  gap: 10px;
}
.journey .journey-cell {
  text-align: center;
  padding: 10px 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.journey .journey-label {
  font-size: 11px; color: var(--muted); font-weight: 600;
  letter-spacing: 0.05em;
}
.journey .journey-date {
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.journey .journey-value {
  font-size: 26px; font-weight: 800;
  color: var(--text-strong);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  margin-top: 4px;
}
.journey .journey-arrow {
  font-size: 22px; color: var(--muted);
}
.journey .journey-change {
  font-size: 14px; font-weight: 700;
  padding: 6px 10px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.journey .journey-change.up   { background: #dcfce7; color: var(--good); }
.journey .journey-change.down { background: #fee2e2; color: var(--bad); }
.journey .journey-change.flat { background: #f1f5f9; color: var(--muted); }

.chart-box { position: relative; width: 100%; }
.chart-box.ratio-total { aspect-ratio: 16 / 9; }
.chart-box.ratio-line  { aspect-ratio: 4 / 3; }
.chart-box.ratio-radar { aspect-ratio: 1 / 1; max-width: 360px; margin: 0 auto; }
.chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.table td.date { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.table td.num { font-variant-numeric: tabular-nums; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; padding: 0 10px;
  border-radius: 999px; font-weight: 700; font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* トップページのタイル */
.tile-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.tile {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 16px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow);
}
.tile .tile-icon {
  flex: 0 0 auto;
  width: 48px; height: 48px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  background: var(--accent-soft);
  color: var(--accent);
}
.tile .tile-icon-img {
  flex: 0 0 auto;
  width: 56px; height: 56px;
  border-radius: 14px;
  object-fit: cover;
  display: block;
}
.tile .tile-body { flex: 1; min-width: 0; }
.tile .tile-title {
  font-size: 17px; font-weight: 700; margin: 0 0 2px;
  color: var(--text-strong);
}
.tile .tile-sub {
  font-size: 13px; color: var(--muted);
}
.tile .tile-arrow {
  color: var(--muted); font-size: 22px; flex: 0 0 auto;
}

footer {
  margin-top: 28px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.7;
}

@media (min-width: 640px) {
  body { font-size: 16px; }
  header.page h1 { font-size: 26px; }
  header.page .sub { font-size: 15px; }
  .card { padding: 22px; }
  .card h2 { font-size: 17px; }
  .card .hint { font-size: 13px; }
  .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .grid2 .card { margin-bottom: 0; }
  .grid2-wrap { margin-bottom: 14px; }
  .table th, .table td { padding: 10px 12px; }
  .chart-box.ratio-total { aspect-ratio: 21 / 9; }
  .summary .value { font-size: 52px; }
  .subj-grid { gap: 12px; }
  .subj-cell .s-val { font-size: 26px; }
  .journey .journey-value { font-size: 32px; }
  .journey .journey-arrow { font-size: 28px; }
  .stat-value { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
