:root {
  color-scheme: light;
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #262321;
  --muted: #6b645e;
  --line: #e4ded6;
  --accent: #b23a2f;
  --accent-soft: #fbeeec;
  --hl: #fff6d6;
  --on-accent: #ffffff;
}
/* Dark tokens: system preference unless the visitor picked light, or an explicit dark choice */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1a1817;
    --surface: #24211f;
    --text: #ece7e1;
    --muted: #a39b93;
    --line: #3a3532;
    --accent: #e8735f;
    --accent-soft: #3a2420;
    --hl: #3b331c;
    --on-accent: #1a1817;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1817;
  --surface: #24211f;
  --text: #ece7e1;
  --muted: #a39b93;
  --line: #3a3532;
  --accent: #e8735f;
  --accent-soft: #3a2420;
  --hl: #3b331c;
  --on-accent: #1a1817;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.75 system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Noto Sans KR", "Noto Sans SC", "Noto Sans Thai", Meiryo, sans-serif;
}
a { color: var(--accent); }
.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }

.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 24px; padding-top: 10px; padding-bottom: 6px; }
.logo { font-weight: 700; font-size: 1.25rem; text-decoration: none; color: var(--text); }
.logo span { display: block; font-size: .72rem; font-weight: 400; color: var(--muted); line-height: 1.2; }
.controls { order: 2; margin-left: auto; display: flex; gap: 6px; align-items: center; }
.theme-btn, .langs summary { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); font-size: .8rem; font-weight: 400; cursor: pointer; line-height: 1; }
.langs { position: relative; }
.langs summary { list-style: none; }
.langs summary::-webkit-details-marker { display: none; }
.langs ul { position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; margin: 0; padding: 6px; list-style: none; min-width: 140px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 24px rgba(0, 0, 0, .15); }
.langs li a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: .9rem; }
.langs li a:hover, .langs li a[aria-current] { background: var(--accent-soft); }
.langs li a[aria-current] { font-weight: 700; }
.sub { display: block; font-size: .6em; font-weight: 400; color: var(--muted); margin-top: 2px; }
.nav { order: 1; display: flex; gap: 2px 14px; overflow-x: auto; white-space: nowrap; font-size: .92rem; padding-bottom: 4px; }
.nav a { text-decoration: none; color: var(--text); padding: 2px 0; }
.nav a[aria-current] { color: var(--accent); font-weight: 700; border-bottom: 2px solid var(--accent); }

.crumbs { font-size: .8rem; color: var(--muted); margin-top: 14px; }
.crumbs a { color: var(--muted); }
h1 { font-size: 1.6rem; line-height: 1.4; margin: 16px 0 12px; }
h2 { font-size: 1.25rem; margin: 36px 0 12px; padding-left: 10px; border-left: 4px solid var(--accent); }
h3 { font-size: 1.05rem; margin: 24px 0 8px; }
.lead { color: var(--muted); margin-top: 0; }

.tool { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin: 16px 0; }
.tool h2 { margin-top: 0; border: 0; padding: 0; font-size: 1.1rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
select, input, button { font: inherit; font-size: 16px; }
select, input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); }
button { padding: 8px 20px; border: 0; border-radius: 6px; background: var(--accent); color: var(--on-accent); font-weight: 700; cursor: pointer; }
.result { margin-top: 14px; }
.result:empty { display: none; }
.big { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.note { font-size: .85rem; color: var(--muted); }

.table-wrap { overflow-x: auto; margin: 12px 0; }
table { border-collapse: collapse; width: 100%; background: var(--surface); font-size: .92rem; }
th, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; white-space: nowrap; }
th { background: var(--accent-soft); font-weight: 700; }
tr.hl td { background: var(--hl); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 16px 0; }
.card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; text-decoration: none; color: var(--text); }
.card strong { display: block; color: var(--accent); font-size: 1.05rem; }
.card span { font-size: .85rem; color: var(--muted); }

.today { background: var(--accent-soft); border-radius: 10px; padding: 14px 16px; margin: 12px 0; }
.year-links { display: flex; flex-wrap: wrap; gap: 6px; padding: 0; list-style: none; }
.year-links a { display: inline-block; padding: 2px 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); text-decoration: none; font-size: .9rem; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 12px 0; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.fact b { display: block; font-size: .8rem; color: var(--muted); font-weight: 400; }
.fact span { font-size: 1.2rem; font-weight: 700; }

.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 8px 0; }
.faq summary { font-weight: 700; cursor: pointer; }
.faq p { margin: 8px 0 0; }

.pager { display: flex; justify-content: space-between; margin: 28px 0; }

.site-footer { margin-top: 48px; border-top: 1px solid var(--line); background: var(--surface); font-size: .85rem; color: var(--muted); }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 4px 16px; padding-top: 12px; }
.site-footer a { color: var(--muted); }
.nav, main, .tool, .row > select { min-width: 0; max-width: 100%; }
.site-footer a { display: inline-block; padding: 6px 0; }
.site-footer .wrap { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.12rem; }
  .facts { grid-template-columns: 1fr 1fr; }
  .fact span { font-size: 1rem; }
  .row select:first-child { flex: 1 1 100%; }
  .row button { flex: 1 1 auto; }
  /* Menu wraps into a grid instead of hiding items off-screen */
  .site-header .wrap { display: flex; }
  .controls { order: 1; }
  .nav { order: 2; flex-basis: 100%; }
  .nav { flex-wrap: wrap; gap: 0 16px; overflow: visible; margin-top: 4px; }
  .nav a { padding: 6px 0; }
  .tool { padding: 14px 12px; }
  table { font-size: .85rem; }
  th, td { padding: 6px 8px; white-space: normal; word-break: keep-all; overflow-wrap: anywhere; }
}
