:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #5d6675;
  --line: #dde1e7;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --accent-soft: #e8f0fc;
  --good: #1a7f4b;
  --warn-bg: #fff6df;
  --warn-line: #e8c76a;
  --panel-w: 340px;
  --topbar-h: 48px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --text: #e6e9ee;
    --muted: #a0a8b5;
    --line: #333a45;
    --accent: #5c9bf0;
    --accent-text: #0c1320;
    --accent-soft: #22324a;
    --good: #5fd39a;
    --warn-bg: #3a3220;
    --warn-line: #8c7536;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

button, input, select { font: inherit; color: inherit; }

/* ---------- 上部バー ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.title { margin: 0; font-size: 17px; white-space: nowrap; }
.title-btn { background: none; border: 0; padding: 0; font-weight: 700; cursor: pointer; }
.progress { margin: 0 0 0 auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress .sep { color: var(--muted); margin: 0 4px; }
.progress + .link-btn { margin-left: 0; }
.topbar > .link-btn { margin-left: auto; white-space: nowrap; }
.progress:not([hidden]) + .link-btn { margin-left: 8px; }

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: 14px;
}

/* ---------- レイアウト ---------- */
.layout {
  display: flex;
  height: calc(100% - var(--topbar-h));
}
.map { flex: 1; min-width: 0; height: 100%; background: #dfe6ec; }
.panel {
  width: var(--panel-w);
  flex: none;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px 16px 24px;
}

h2 { font-size: 19px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 20px 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.lead-title { font-size: 20px; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .link-btn:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.actions { margin: 16px 0 8px; }
.actions .btn { width: 100%; font-size: 17px; }
.action-bar { margin: 16px 0 8px; display: flex; gap: 8px; }
.action-bar .btn { flex: 1; }

/* ---------- スタート画面 ---------- */
.count { margin-top: 4px; }
.count strong { font-variant-numeric: tabular-nums; }
.note {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}
.best { color: var(--good); font-weight: 600; }

.settings { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.settings summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.presets button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 13px;
}
.presets button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.form fieldset { border: 0; padding: 0; margin: 0 0 12px; }
.form legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 4px; }
.range { display: flex; align-items: center; gap: 6px; }
.range input, .range select {
  width: 96px;
  min-height: 36px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}
.choices { display: flex; gap: 14px; }
.checks label { display: block; margin-bottom: 4px; }

/* 期間の切り替え（スタート画面） */
.period { margin: 14px 0 0; }
.period-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
  background: var(--bg);
}
.segmented label { flex: 1; position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 14px;
  text-align: center;
  color: var(--muted);
}
.segmented input:checked + span { background: var(--panel); color: var(--accent); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* 対象年の2つのつまみのスライダー */
.year-label { margin: 0 0 2px; font-weight: 600; font-variant-numeric: tabular-nums; }
.dual-range { position: relative; height: 40px; }
.dr-track {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 18px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}
.dr-fill { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--accent); }
.dual-range input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 40px;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
  z-index: 2;
}
.dual-range input[type="range"]::-webkit-slider-runnable-track { height: 40px; background: none; border: 0; }
.dual-range input[type="range"]::-moz-range-track { height: 40px; background: none; border: 0; }
.dual-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 28px;
  height: 28px;
  margin-top: 6px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--panel);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
  cursor: grab;
}
.dual-range input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--panel);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
  cursor: grab;
}
.dual-range input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.dual-range input[type="range"]:focus { outline: none; }
.dr-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: -2px; }
.steppers { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; }
.stepper { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.step-btn {
  width: 36px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.step-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- 出題・答え合わせ ---------- */
.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0 0 12px;
}
.facts dt { color: var(--muted); font-size: 13px; padding-top: 2px; }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.instruct { font-size: 14px; }
.quit { margin-top: 8px; }

.result-head {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}
.result-head p {
  flex: 1;
  margin: 0;
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 8px 10px;
}
.result-head .label { display: block; font-size: 12px; color: var(--muted); }
.result-head strong { font-size: 24px; font-variant-numeric: tabular-nums; }

/* ---------- 結果 ---------- */
.total strong { font-size: 32px; font-variant-numeric: tabular-nums; }
.rounds { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.rounds th, .rounds td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.rounds th { color: var(--muted); font-weight: 500; }
.rounds .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rounds tbody tr { cursor: pointer; }
.rounds tbody tr:hover, .rounds tbody tr:focus-visible { background: var(--accent-soft); outline: none; }

/* ---------- 地図の部品 ---------- */
.legend {
  background: rgba(255, 255, 255, .92);
  color: #1d2330;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
.legend .row { display: flex; align-items: center; gap: 6px; }
.legend .dot { width: 11px; height: 11px; border-radius: 50%; border: 1px solid #333; display: inline-block; }
.legend .ttl { font-weight: 600; margin-bottom: 2px; }
.legend .row.off { opacity: .35; }
.legend.old .ttl { max-width: 9em; line-height: 1.3; }

.epi-icon {
  position: relative;
}
.epi-icon::before, .epi-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 6px;
  margin: -3px 0 0 -13px;
  background: #e0001b;
  border: 1.5px solid #fff;
  border-radius: 2px;
  box-shadow: 0 0 2px rgba(0, 0, 0, .6);
}
.epi-icon::before { transform: rotate(45deg); }
.epi-icon::after { transform: rotate(-45deg); }

.leaflet-container { font-family: inherit; }
.leaflet-tooltip.epi-label { font-weight: 700; }

/* ---------- このサイトについて ---------- */
.about {
  max-width: 560px;
  width: calc(100% - 32px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 20px 20px 16px;
}
.about::backdrop { background: rgba(0, 0, 0, .4); }
.about-close { text-align: right; margin: -6px 0 0; }
.about ul { padding-left: 20px; margin: 0 0 10px; }
.about a { color: var(--accent); word-break: break-all; }

/* ---------- スマートフォン ---------- */
@media (max-width: 767px) {
  :root { --topbar-h: 44px; }
  html, body { height: auto; }
  .topbar { position: sticky; top: 0; z-index: 1000; gap: 8px; padding: 0 12px; }
  .title { font-size: 15px; }
  .progress { font-size: 13px; }
  .topbar > .link-btn { font-size: 12px; }
  .layout { flex-direction: column; height: auto; }
  .map { flex: none; height: 56vh; min-height: 300px; }
  .panel { width: 100%; height: auto; border-left: 0; border-top: 1px solid var(--line); padding: 14px 16px 88px; overflow: visible; }
  .action-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: var(--panel);
    border-top: 1px solid var(--line);
    z-index: 1000;
  }
  .screen[hidden] .action-bar { display: none; }
  .legend { font-size: 10px; line-height: 1.35; padding: 4px 6px; display: grid; grid-template-columns: auto auto; column-gap: 8px; }
  .legend .ttl { grid-column: 1 / -1; margin-bottom: 0; }
  .legend .dot { width: 9px; height: 9px; }
}
