:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --text: #1a1d21;
  --text-muted: #5b6470;
  --border: #d8dde4;
  --accent: #1b5e9c;
  --accent-soft: #e7f0f9;
  --warn-bg: #fff4e5;
  --warn-border: #e0a250;
  --warn-text: #7a4a06;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-alt: #232830;
    --text: #e6e9ee;
    --text-muted: #9aa4b2;
    --border: #333a45;
    --accent: #6fb3f2;
    --accent-soft: #1d2b3a;
    --warn-bg: #33270f;
    --warn-border: #a8762a;
    --warn-text: #f0cf9a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

.wrap {
  width: min(1180px, 100% - 2rem);
  margin-inline: auto;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.75rem 0 1.5rem;
}

.site-header h1 {
  margin: 0 0 .5rem;
  font-size: clamp(1.25rem, 3.2vw, 1.7rem);
  letter-spacing: .01em;
}

.lede {
  margin: 0 0 1rem;
  color: var(--text-muted);
  max-width: 76ch;
}

.alert {
  margin: 0;
  padding: .85rem 1rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-left-width: 4px;
  border-radius: var(--radius);
  color: var(--warn-text);
  max-width: 88ch;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
  padding: 1.5rem 0 3rem;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

/* 単一カラムを明示しないと auto カラムが中身の幅まで広がり、横スクロールが出る */
.panel-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  min-width: 0;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}

.presets-label {
  color: var(--text-muted);
  font-size: .875rem;
  margin-right: .25rem;
}

.btn {
  font: inherit;
  padding: .4rem .85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  /* リンクをボタンとして使う箇所があるため下線を消す */
  text-decoration: none;
  display: inline-block;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
}

.card > h2,
.card summary h2 {
  margin: 0 0 .75rem;
  font-size: 1rem;
  letter-spacing: .02em;
}

details.card > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .5rem;
}

details.card > summary::-webkit-details-marker { display: none; }

details.card > summary::before {
  content: "▸";
  color: var(--text-muted);
  transition: transform .15s ease;
}

details.card[open] > summary::before { transform: rotate(90deg); }
details.card > summary h2 { margin: 0; }
.details-body { padding-top: .85rem; }

.details-body h3 {
  margin: 1.25rem 0 .4rem;
  font-size: .9rem;
  color: var(--accent);
}

.details-body h3:first-child { margin-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: .85rem 1rem;
}

label {
  display: grid;
  gap: .3rem;
  font-size: .875rem;
  color: var(--text-muted);
  min-width: 0;
}

label small { color: var(--text-muted); font-size: .78rem; line-height: 1.5; }

input[type="text"],
input[type="number"] {
  font: inherit;
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text);
  text-align: right;
}

input[type="text"]:not([data-grouped]) { text-align: left; }

input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

label.checkbox {
  display: flex;
  align-items: start;
  gap: .5rem;
  margin-top: .6rem;
  color: var(--text);
}

label.checkbox input { margin-top: .35rem; flex: none; }

.hint {
  margin: 0 0 .75rem;
  font-size: .82rem;
  color: var(--text-muted);
}

.tag {
  font-size: .7rem;
  padding: .1rem .45rem;
  border-radius: 999px;
  vertical-align: middle;
}

.tag.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}

.table-scroll { overflow-x: auto; margin: .5rem -.25rem; padding: 0 .25rem; }

.input-table { border-collapse: collapse; width: 100%; min-width: 420px; }

.input-table th,
.input-table td {
  padding: .3rem .35rem;
  text-align: right;
  font-size: .82rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.input-table th:first-child,
.input-table td:first-child { text-align: left; }

.input-table input { padding: .35rem .45rem; }
.input-table td:first-child input { min-width: 6.5rem; }
.input-table td input { min-width: 7.5rem; }
.input-table td.months input { min-width: 4rem; }

body:not(.show-adjustments) .adj { display: none; }

.panel-result { position: sticky; top: 1rem; min-width: 0; }

@media (max-width: 900px) {
  .panel-result { position: static; }
}

.result-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
}

.result-inner h2 { margin: 0 0 .25rem; font-size: 1rem; }

.method {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: .15rem .7rem;
  font-size: .8rem;
  margin-bottom: 1rem;
}

.headline { margin: 0 0 1.25rem; }

.headline .value {
  display: block;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  letter-spacing: -.01em;
}

.headline .caption { color: var(--text-muted); font-size: .8rem; }

.kv {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .3rem .75rem;
  margin: 0 0 1rem;
  font-size: .85rem;
}

.kv dt { color: var(--text-muted); min-width: 0; }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

.result-inner h3 {
  margin: 1.25rem 0 .5rem;
  font-size: .85rem;
  color: var(--accent);
}

table.breakdown {
  width: 100%;
  min-width: 26rem;
  border-collapse: collapse;
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

table.breakdown th,
table.breakdown td {
  padding: .3rem .4rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.breakdown th { color: var(--text-muted); font-weight: 500; }
table.breakdown th:first-child, table.breakdown td:first-child { text-align: left; }
table.breakdown td.negative { color: #c0392b; }

@media (prefers-color-scheme: dark) {
  table.breakdown td.negative { color: #ff8b7a; }
}

.notes {
  margin: 1rem 0 0;
  padding-left: 1.1rem;
  font-size: .78rem;
  color: var(--text-muted);
}

.notes li { margin-bottom: .3rem; }

.error {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  font-size: .85rem;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 1.5rem 0 2.5rem;
  color: var(--text-muted);
  font-size: .8rem;
}

.site-footer p { margin: 0 0 .5rem; max-width: 80ch; }
.site-footer a { color: var(--accent); }

/* 課税時期前５年の実績（事業年度ごとのブロック） */
.year {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  padding: .3rem .9rem .9rem;
  margin: 0 0 .7rem;
  min-width: 0;
}

.year:last-of-type { margin-bottom: 0; }

.year > legend {
  padding: 0 .4rem;
  font-size: .82rem;
  font-weight: 600;
}

.year-months {
  font-weight: 400;
  color: var(--accent);
}

.year-months.is-error { color: var(--warn-text); }

@media (prefers-color-scheme: dark) {
  .year-months.is-error { color: #f0a97a; }
}

.year .grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

input[type="date"] {
  font: inherit;
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

input[type="date"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.year input[type="text"] { background: var(--surface); }

.placeholder {
  margin: 0;
  color: var(--text-muted);
  font-size: .875rem;
}

/* 法人税申告書の参照先などの補足説明 */
details.note {
  margin: .9rem 0 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  font-size: .82rem;
}

details.note > summary {
  cursor: pointer;
  list-style: none;
  padding: .5rem .8rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: .4rem;
}

details.note > summary::-webkit-details-marker { display: none; }

details.note > summary::before {
  content: "▸";
  transition: transform .15s ease;
}

details.note[open] > summary::before { transform: rotate(90deg); }

.note-body {
  padding: 0 .8rem .8rem;
  color: var(--text-muted);
}

.note-body p { margin: 0 0 .6rem; }
.note-body p:last-child { margin-bottom: 0; }
.note-body strong { color: var(--text); }

table.ref {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 .7rem;
  font-variant-numeric: tabular-nums;
}

table.ref th,
table.ref td {
  padding: .28rem .4rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-weight: 400;
}

table.ref thead th {
  font-size: .75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

table.ref td:last-child,
table.ref thead th:last-child { text-align: right; white-space: nowrap; }
table.ref td:nth-child(2) { white-space: nowrap; color: var(--accent); }
table.ref tbody th { color: var(--text); }

table.ref tr.total th,
table.ref tr.total td {
  font-weight: 600;
  color: var(--text);
  border-bottom: none;
  border-top: 2px solid var(--border);
}

.note-caution {
  border-left: 3px solid var(--warn-border);
  padding-left: .6rem;
}

.note-source { font-size: .75rem; opacity: .8; }

.subhead {
  margin: 1.1rem 0 .3rem;
  font-size: .9rem;
  color: var(--accent);
}

.computed {
  margin: .6rem 0 0;
  font-size: .85rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.computed:empty { display: none; }
.computed strong { color: var(--text); font-size: 1rem; }

.computed-note {
  display: block;
  font-size: .75rem;
  opacity: .8;
}

.computed-caution {
  display: block;
  font-size: .75rem;
  color: var(--warn-text);
}

@media (prefers-color-scheme: dark) {
  .computed-caution { color: #f0a97a; }
}

.year .computed { margin-top: .5rem; }

.subhead-minor {
  margin: 1rem 0 .3rem;
  font-size: .82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.subhead .year-months { font-size: .8rem; font-weight: 400; }

/* 利用規約ページ */
.breadcrumb {
  margin: 0 0 .75rem;
  font-size: .82rem;
}

.breadcrumb a,
.site-footer a { color: var(--accent); }

.legal {
  padding: 1.5rem 0 3rem;
  max-width: 78ch;
}

.legal section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.3rem;
  margin-bottom: 1rem;
}

.legal h2 {
  margin: 0 0 .6rem;
  font-size: 1rem;
  color: var(--accent);
}

.legal p { margin: 0 0 .6rem; }
.legal p:last-child { margin-bottom: 0; }

.legal ol {
  margin: 0;
  padding-left: 1.4rem;
}

.legal ol ol {
  margin: .4rem 0 .2rem;
  list-style: none;
  counter-reset: sub;
  padding-left: 1rem;
}

.legal ol ol > li { counter-increment: sub; }

.legal ol ol > li::before {
  content: counter(sub, cjk-ideographic) "　";
  color: var(--text-muted);
}

.legal li { margin-bottom: .45rem; }
.legal li:last-child { margin-bottom: 0; }

.legal-date {
  margin: 0;
  font-size: .82rem;
  color: var(--text-muted);
  text-align: right;
}

/* SNS（控えめに） */
.social {
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  margin: .9rem 0 0;
  font-size: .78rem;
}

.social a {
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.social a:hover,
.social a:focus-visible {
  color: var(--accent);
  border-bottom-color: currentColor;
}

.tagline {
  margin: -.25rem 0 .75rem;
  font-size: .9rem;
  color: var(--text-muted);
}

/* 用語解説ページ */
.toc {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem .5rem;
  margin-top: .9rem;
}

.toc a {
  font-size: .78rem;
  padding: .25rem .7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-muted);
  text-decoration: none;
}

.toc a:hover,
.toc a:focus-visible { border-color: var(--accent); color: var(--accent); }

.glossary dl { margin: 0; }

.glossary dt {
  margin-top: 1rem;
  font-weight: 600;
  color: var(--text);
  scroll-margin-top: 1rem;
}

.glossary dt:first-of-type { margin-top: 0; }

.glossary dd {
  margin: .3rem 0 0;
  color: var(--text-muted);
}

.glossary dd ol {
  margin: .4rem 0 0;
  padding-left: 1.3rem;
}

.glossary dd ol li { margin-bottom: .25rem; }
.glossary section > p { color: var(--text-muted); }
.glossary .tag { margin-left: .4rem; }

.formula,
.inline-formula {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.formula {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .7rem .9rem;
  margin: 0 0 1rem;
  overflow-x: auto;
  white-space: nowrap;
  font-size: .9rem;
}

.inline-formula {
  display: block;
  margin: .35rem 0;
  padding-left: .8rem;
  border-left: 2px solid var(--border);
}

.glossary table.ref td { vertical-align: top; }
.glossary table.ref td small { display: block; font-size: .72rem; opacity: .85; }

/* コラム */
.column-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1rem;
}

.column-list > li { margin: 0; }

.column-list a {
  display: grid;
  gap: .35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.3rem;
  text-decoration: none;
  color: inherit;
}

.column-list a:hover,
.column-list a:focus-visible { border-color: var(--accent); }

.column-no {
  font-size: .72rem;
  letter-spacing: .1em;
  color: var(--accent);
  font-weight: 700;
}

.column-title { font-size: 1.02rem; font-weight: 700; line-height: 1.5; }
.column-summary { font-size: .85rem; color: var(--text-muted); }
.column-list time { font-size: .75rem; color: var(--text-muted); }

.article-meta {
  margin: 0;
  font-size: .8rem;
  color: var(--text-muted);
}

.article h3 {
  margin: 1.1rem 0 .4rem;
  font-size: .92rem;
}

.article ul,
.article ol {
  margin: 0 0 .7rem;
  padding-left: 1.4rem;
  color: var(--text-muted);
}

.article li { margin-bottom: .4rem; }
.article p { line-height: 1.85; }
.article a { color: var(--accent); }

.lead-box {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: .8rem 1rem;
  margin: 0 0 .9rem;
}

.formula-plain {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .7rem .9rem;
  margin: .6rem 0 .9rem;
  font-size: .9rem;
  text-align: center;
}

.next-link {
  margin: 1.1rem 0 0;
  font-size: .88rem;
  font-weight: 600;
}

.faq dt {
  margin-top: 1rem;
  font-weight: 600;
  color: var(--text);
}

.faq dt:first-of-type { margin-top: 0; }
.faq dd { margin: .35rem 0 0; color: var(--text-muted); }
.faq dl { margin: 0; }
/* ===== トップバーと左サイドメニュー ===== */
:root {
  --topbar-h: 52px;
  --sidebar-w: 236px;
}

body { padding-top: var(--topbar-h); }

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

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: 0 .85rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  transition: left .2s ease;
}

.topbar-brand {
  font-weight: 700;
  font-size: .95rem;
  letter-spacing: .01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.topbar-brand:hover { color: var(--accent); }

.topbar-sep {
  color: var(--border);
  font-size: .9rem;
}

.topbar-page {
  font-size: .82rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-toggle {
  flex: none;
  width: 2.1rem;
  height: 2.1rem;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  cursor: pointer;
}

.nav-toggle:hover { background: var(--surface-alt); border-color: var(--border); }
.nav-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ハンバーガー（開くと×になる） */
.nav-toggle-icon,
.nav-toggle-icon::before,
.nav-toggle-icon::after {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
  transition: transform .2s ease, opacity .2s ease;
}

.nav-toggle-icon { position: relative; }

.nav-toggle-icon::before,
.nav-toggle-icon::after {
  content: "";
  position: absolute;
  left: 0;
}

.nav-toggle-icon::before { top: -5px; }
.nav-toggle-icon::after { top: 5px; }

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  z-index: 50;
  width: var(--sidebar-w);
  padding: 1.1rem 1rem 1.2rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform .2s ease;
}

.sidebar-backdrop {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 45;
  background: rgba(0, 0, 0, .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}

.sidebar nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar nav li { margin: 0 0 .15rem; }

.sidebar nav a {
  display: block;
  padding: .42rem .6rem;
  border-radius: 6px;
  font-size: .85rem;
  color: var(--text);
  text-decoration: none;
}

.sidebar nav a:hover { background: var(--surface-alt); color: var(--accent); }

.sidebar nav a[aria-current] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-source {
  margin: 1.2rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: .72rem;
  color: var(--text-muted);
}

.sidebar-source a { color: var(--accent); }
.sidebar-social { margin-top: .7rem; gap: .9rem; }

/* 開いているとき（狭い画面では本文に重ねる） */
:root[data-nav="open"] .sidebar { transform: none; }

:root[data-nav="open"] .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

:root[data-nav="open"] .nav-toggle-icon { background: transparent; }

:root[data-nav="open"] .nav-toggle-icon::before {
  top: 0;
  transform: rotate(45deg);
}

:root[data-nav="open"] .nav-toggle-icon::after {
  top: 0;
  transform: rotate(-45deg);
}

/* 見出しへのアンカー移動がトップバーに隠れないようにする */
[id] { scroll-margin-top: calc(var(--topbar-h) + 1rem); }

/* サイドメニューが全高になる広い画面では、その上端に名前を出す */
.sidebar-brand-slot {
  display: none;
  align-items: center;
  height: var(--topbar-h);
  margin: calc(-1.1rem) -1rem .8rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
  text-decoration: none;
}

.sidebar-brand:hover { color: var(--accent); }

/* 広い画面では既定で開き、本文を右に押し出す */
@media (min-width: 1200px) {
  :root:not([data-nav="closed"]) .sidebar { transform: none; }
  :root:not([data-nav="closed"]) body { padding-left: var(--sidebar-w); }
  :root:not([data-nav="closed"]) .nav-toggle-icon { background: transparent; }

  :root:not([data-nav="closed"]) .nav-toggle-icon::before {
    top: 0;
    transform: rotate(45deg);
  }

  :root:not([data-nav="closed"]) .nav-toggle-icon::after {
    top: 0;
    transform: rotate(-45deg);
  }

  /* サイドメニューが出ているときは、トップバーの幅もそれに合わせる */
  :root:not([data-nav="closed"]) .topbar { left: var(--sidebar-w); }

  /* 名前はサイドメニューの上端に出るので、トップバー側は畳んで
     現在地だけを残す（同じ名前が横並びで二度出るのを避ける） */
  :root:not([data-nav="closed"]) .topbar-brand,
  :root:not([data-nav="closed"]) .topbar-sep { display: none; }

  /* 閉じているあいだは画面外なので、開閉で上端が動かないよう常に全高にする */
  .sidebar { top: 0; }
  .sidebar-brand-slot { display: flex; }

  .sidebar-backdrop { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .nav-toggle,
  .nav-toggle-icon,
  .nav-toggle-icon::before,
  .nav-toggle-icon::after,
  .sidebar-backdrop { transition: none; }
}

/* ===== 将来シミュレーション ===== */
:root {
  /* データビジュアライゼーションの検証済みカテゴリ配色スロット1・2
     （明背景で CVD ΔE 24.7 / 通常視 33.6、暗背景で 26.8 / 31.8。いずれも合格） */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e6e9ee;
}

@media (prefers-color-scheme: dark) {
  :root {
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2b313a;
  }
}

select {
  font: inherit;
  width: 100%;
  padding: .45rem .6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text);
}

select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.chart-section {
  display: grid;
  /* 単一カラムを明示しないと、表の min-width に引きずられて横スクロールが出る */
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  padding-bottom: 3rem;
}

.chart-title {
  margin: 0 0 .5rem;
  font-size: 1rem;
}

#chart,
#table {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.3rem 1.3rem;
}

#chart:empty,
#table:empty { display: none; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem 1.1rem;
  margin: 0 0 .6rem;
  font-size: .8rem;
  color: var(--text-muted);
}

.legend-item { display: inline-flex; align-items: center; gap: .4rem; }

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}

.chart-frame { position: relative; }
.chart-frame svg { display: block; width: 100%; height: auto; }

.grid { stroke: var(--grid); stroke-width: 1; }
.axis { stroke: var(--border); stroke-width: 1; }

.axis-label,
.axis-title {
  fill: var(--text-muted);
  font-size: 11px;
  font-family: inherit;
}

.axis-title { font-size: 10px; }

.series-line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.series-end { stroke: var(--surface); stroke-width: 2; }

.series-tag {
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
}

.crosshair,
.hover-dot { opacity: 0; transition: opacity .12s ease; }
.crosshair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.hover-dot { stroke: var(--surface); stroke-width: 2; }
svg.is-hovering .crosshair,
svg.is-hovering .hover-dot { opacity: 1; }

.chart-tooltip {
  position: absolute;
  top: .3rem;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(16, 24, 40, .12);
  padding: .5rem .7rem;
  font-size: .78rem;
  pointer-events: none;
  white-space: nowrap;
}

.chart-tooltip strong { display: block; margin-bottom: .25rem; }

.tooltip-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  color: var(--text-muted);
}

.tooltip-row b {
  margin-left: auto;
  padding-left: .8rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.table-tall { max-height: 26rem; overflow-y: auto; }

.projection-table { min-width: 42rem; }
.projection-table thead th { position: sticky; top: 0; background: var(--surface); }
.projection-table tbody th { white-space: nowrap; color: var(--text-muted); font-weight: 500; }

@media (prefers-reduced-motion: reduce) {
  .crosshair,
  .hover-dot { transition: none; }
}

/* 狭い画面では吹き出しを浮かせず、グラフの上の読み取り欄にする
   （グラフ幅より吹き出しが広くなり、終端ラベルと重なるため） */
@media (max-width: 640px) {
  .chart-tooltip,
  .chart-tooltip[hidden] {
    display: block;
    position: static;
    transform: none !important;
    left: auto !important;
    margin: 0 0 .6rem;
    white-space: normal;
    box-shadow: none;
    background: var(--surface-alt);
  }
}

/* 試算ツール ⇄ 将来シミュレーションの受け渡し */
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover,
.btn.primary:focus-visible { color: #fff; opacity: .9; }

@media (prefers-color-scheme: dark) {
  .btn.primary { color: #10151c; }
  .btn.primary:hover,
  .btn.primary:focus-visible { color: #10151c; }
}

.handoff {
  margin: 1.1rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: grid;
  gap: .5rem;
  justify-items: start;
}

.handoff-caveat {
  font-size: .75rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.handoff-note {
  margin: 0;
  padding: .55rem .8rem;
  background: var(--accent-soft);
  border-radius: 8px;
  font-size: .8rem;
  color: var(--text-muted);
}

.handoff-note a { color: var(--accent); }
#handoff:empty { display: none; }

/* 系列の色と細かな体裁は、style 属性ではなくクラスで与える
   （CSP の style-src 'self' のもとでは style 属性が適用されないため） */
.series-line.s1 { stroke: var(--series-1); }
.series-line.s2 { stroke: var(--series-2); }
.series-end.s1,
.hover-dot.s1,
.series-tag.s1 { fill: var(--series-1); }
.series-end.s2,
.hover-dot.s2,
.series-tag.s2 { fill: var(--series-2); }
.legend-swatch.s1 { background: var(--series-1); }
.legend-swatch.s2 { background: var(--series-2); }

.kv-spaced { margin-top: .75rem; }
.dd-left { text-align: left; }
.hint-tight { margin: 0 0 .5rem; }
.hint-spaced { margin-top: 1.5rem; }
.notes-flush { margin-top: 0; }
