:root {
  --paper: #F1F7F7;
  --card: #FFFFFF;
  --ink: #142A2C;
  --ink-soft: #4C6669;
  --ink-faint: #86A0A3;
  --line: #D7E8E7;
  --brand: #07575B;
  --brand-deep: #003B46;
  --brand-tint: #C4DFE6;
  --shadow: rgba(0, 45, 50, 0.10);
  --font-display: -apple-system, "Hiragino Sans", "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  --font-body: -apple-system, "Hiragino Kaku Gothic ProN", "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", "Menlo", monospace;
}

* { box-sizing: border-box; }
.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;
}
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 20px 64px;
}
@media (max-width: 480px) {
  .wrap { padding: 28px 16px 48px; }
}

/* ---- Header ---- */
h1 {
  font-family: var(--font-display);
  font-size: clamp(28px, 6vw, 38px);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
  text-wrap: balance;
}
.lede {
  color: var(--ink-soft);
  font-size: 15px;
  margin: 0 0 22px;
}
/* ---- Card ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 8px 24px var(--shadow);
  margin-bottom: 24px;
}
@media (max-width: 480px) {
  .card, .results-card { padding: 20px 16px; border-radius: 14px; }
}
.field-label {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-faint);
  font-weight: 700;
  margin: 0 0 12px;
}
.section + .section { margin-top: 28px; }

/* ---- Distance segmented control ---- */
.distance-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
@media (max-width: 420px) {
  .distance-grid { grid-template-columns: repeat(3, 1fr); }
}
.manual-row { display: none; margin-top: 12px; }
.manual-row.active { display: flex; }
.dist-btn {
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 6px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
@media (max-width: 480px) {
  .dist-btn { font-size: 14px; }
}
.dist-btn:hover { border-color: var(--brand); color: var(--ink); }
.dist-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.dist-btn:focus-visible, .mode-btn:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ---- Mode tabs ---- */
.mode-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}
.mode-btn {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-faint);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 4px 14px;
  margin-right: 14px;
  cursor: pointer;
}
@media (max-width: 480px) {
  .mode-btn { font-size: 15px; margin-right: 10px; }
}
.mode-btn.active { color: var(--brand); border-bottom-color: var(--brand); }

.input-row { display: none; align-items: end; gap: 10px; flex-wrap: wrap; }
.input-row.active { display: flex; }
.digit-group { display: flex; align-items: baseline; gap: 16px; }
.digit-field { display: flex; flex-direction: column; gap: 6px; }
.digit-field label {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-faint);
}
.digit-field input {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 600;
  width: 68px;
  padding: 12px 8px;
  text-align: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}
.digit-field.wide input { width: 96px; }
@media (max-width: 480px) {
  .digit-field input { width: 74px; font-size: 24px; padding: 14px 8px; }
  .digit-field.wide input { width: 110px; }
}
.digit-select {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 600;
  width: 68px;
  padding: 12px 22px 12px 8px;
  text-align: center;
  text-align-last: center;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%2386A0A3" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6 6-6"/></svg>') no-repeat right 4px center / 16px 16px;
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
@media (max-width: 480px) {
  .digit-select { width: 74px; font-size: 24px; padding: 14px 24px 14px 8px; }
}
.unit-suffix {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-faint);
  padding-bottom: 10px;
}

.calc-btn {
  margin-top: 24px;
  width: 100%;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--brand);
  border: none;
  border-radius: 12px;
  padding: 15px 20px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.calc-btn:hover { background: var(--brand-deep); }
.calc-btn:active { transform: scale(0.99); }

/* ---- Results ---- */
.results-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 8px 24px var(--shadow);
}
.results-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.results-head-text { min-width: 0; }
.results-head .field-label { margin: 0; }
.results-dist {
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-soft);
}
.share-actions {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
}
.share-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-deep);
  background: var(--brand-tint);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.share-btn:hover { background: var(--brand); color: #fff; }
.share-btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.share-x-btn {
  color: #fff;
  background: #000;
}
.share-x-btn:hover { background: #262626; color: #fff; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--paper);
  font-size: 13.5px;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: 0 8px 24px var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity 0.01ms; transform: translate(-50%, 0); }
}
/* 結果の各項目は「項目名と値」の対応が機械可読になるよう dl/dt/dd で組む。
   dl・dd のブラウザ既定マージンは打ち消す。 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin: 0;
}
.stat-grid dd { margin: 0; }
.stat-grid .stat:first-child { grid-column: 1 / -1; }
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
  .stat-grid .stat:first-child { grid-column: auto; }
}
.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}
.stat.accent { background: var(--brand-tint); border-color: transparent; }
.stat-label {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-faint);
  margin-bottom: 8px;
}
.stat.accent .stat-label { color: var(--brand-deep); }
.stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.stat-value .unit {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-faint);
  margin-left: 2px;
}

/* ---- Other distances at the same pace ---- */
.other-times {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.other-times-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.ot-tab-btn {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-faint);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.ot-tab-btn:hover { border-color: var(--brand); color: var(--ink); }
.ot-tab-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.ot-tab-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.other-times-list { display: none; }
.other-times-list.active { display: block; }
.ot-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.other-time-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-size: 12.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.other-time-item:last-child {
  padding-bottom: 0;
  border-bottom: none;
}
.other-time-item .ot-dist {
  font-family: var(--font-mono);
  color: var(--ink-faint);
}
.other-time-item .ot-time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--ink-soft);
}

/* ---- Deviation (full marathon percentile) card ---- */
.dev-card {
  display: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 8px 24px var(--shadow);
  margin-top: 24px;
}
.dev-card.active { display: block; }
@media (max-width: 480px) {
  .dev-card { padding: 20px 16px; border-radius: 14px; }
}
.dev-card .field-label { margin-bottom: 4px; }
.dev-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.dev-head .field-label { margin: 0 0 4px; }
.sex-tabs { display: flex; gap: 6px; }
.sex-btn {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-faint);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.sex-btn:hover { border-color: var(--brand); color: var(--ink); }
.sex-btn.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.sex-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.dev-sub {
  font-size: 12.5px;
  color: var(--ink-faint);
  margin: 8px 0 16px;
}
/* 偏差値・順位の目安を横並びにする（.stat-grid .stat:first-child のフル幅指定を打ち消す） */
.dev-card .stat-grid .stat:first-child { grid-column: auto; }

/* ---- Distribution histogram ---- */
.hist-wrap { margin-top: 18px; }
.hist-svg { width: 100%; height: auto; display: block; overflow: visible; }
.hist-caption {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
  text-align: center;
}

footer {
  text-align: center;
  font-size: 12px;
  color: var(--ink-faint);
  margin-top: 30px;
}
footer a {
  color: var(--ink-soft);
  text-decoration: none;
}
footer a:hover { color: var(--brand); text-decoration: underline; }

/* ---- Page nav (ホーム・サブXページへのリンク) ---- */
.page-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 24px;
}
.page-nav + .page-nav {
  margin-top: 8px;
}
.page-nav a,
.page-nav .page-nav-current {
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  text-decoration: none;
}
.page-nav a {
  color: var(--ink-soft);
  background: var(--paper);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.page-nav a:hover { border-color: var(--brand); color: var(--ink); }
.page-nav a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.page-nav .page-nav-current {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

/* ---- データ根拠ページ ---- */
.doc-card h2 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 10px;
}
.doc-card h2:not(:first-child) {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.doc-card p,
.doc-card li {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.75;
}
.doc-card ul {
  margin: 8px 0 0;
  padding-left: 20px;
}
.doc-card a {
  color: var(--brand);
  text-decoration: none;
}
.doc-card a:hover { text-decoration: underline; }
.doc-table-wrap { overflow-x: auto; margin: 12px 0 0; }
.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 12px 0 0;
}
.doc-table th,
.doc-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px 8px 0;
  text-align: left;
  color: var(--ink-soft);
}
.doc-table th {
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
}
.doc-table td:last-child,
.doc-table th:last-child {
  text-align: right;
  padding-right: 0;
  font-family: var(--font-mono);
  white-space: nowrap;
}
.doc-table th:last-child { font-family: var(--font-body); }
.doc-formula {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0 0;
  overflow-x: auto;
  color: var(--ink);
}
