/* ===========================
   制度の計算機 — yorozu-craft 共通の和紙風の配色（ハブと各計算機のページで共有）
   色はトークン（--bg / --card / --text / --muted / --accent / --border）だけを使う。
   ダークモードは端末の設定に自動で合わせる（prefers-color-scheme。手動切替は付けない）
   =========================== */
:root {
  color-scheme: light dark;
  --bg: #f0ebe0;
  --bg-2: #e6dfd0;
  --card: #faf6ee;
  --text: #3a3025;
  --muted: #6e604f;
  --accent: #8b4513;
  --accent-soft: #f3e6d8;
  --border: #cfc0a0;
  --shadow: rgba(58, 48, 37, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1814;
    --bg-2: #25201a;
    --card: #2b251e;
    --text: #ece4d6;
    --muted: #b9ab96;
    --accent: #e0a066;
    --accent-soft: #3a2e22;
    --border: #4a3f33;
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  /* README「ツールを追加するとき」9: 端末のフォント。Web フォントは読まない */
  font-family: "Noto Sans JP", "Noto Sans CJK JP", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

a { color: var(--accent); }

/* ヘッダー */
.app-header {
  text-align: center;
  padding: 1.4rem 1rem 1.1rem;
  background: var(--bg-2);
  border-bottom: 2px solid var(--border);
}
.app-header h1 { font-size: 1.45rem; color: var(--accent); line-height: 1.4; }
.app-header .subtitle { font-size: 0.88rem; color: var(--muted); margin-top: 0.3rem; }

/* レイアウト */
.app-main { max-width: 680px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.2rem;
  margin-bottom: 1rem;
  box-shadow: 0 2px 8px var(--shadow);
}
.card h2 {
  font-size: 1.02rem;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
  margin-bottom: 0.9rem;
}

/* 入力 */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; font-size: 0.95rem; margin-bottom: 0.25rem; }
.field .hint { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; }
.field input[type="number"], .field input[type="text"], .field select {
  width: 100%;
  max-width: 16rem;
  padding: 0.45rem 0.5rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
}

.btn {
  display: inline-block;
  padding: 0.5rem 1.1rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--card);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 読みもの（guide.html） */
.content h3 { font-size: 0.95rem; margin: 1rem 0 0.3rem; }
.content p, .content li { font-size: 0.9rem; }
.content p + p { margin-top: 0.5rem; }
.content ul, .content ol { padding-left: 1.3rem; margin: 0.3rem 0; }
.faq dt { font-weight: 600; margin-top: 0.9rem; font-size: 0.92rem; }
.faq dt::before { content: 'Q. '; color: var(--accent); }
.faq dd { font-size: 0.88rem; color: var(--muted); padding: 0.2rem 0 0.5rem 1.2rem; border-bottom: 1px solid var(--border); }
.info-list { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.2rem; font-size: 0.9rem; }
.info-list dt { font-weight: 600; }
.info-list dd { color: var(--muted); }
.small { font-size: 0.8rem; color: var(--muted); margin-top: 0.4rem; }

/* フッター */
.app-footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}
.footer-nav ul { list-style: none; display: flex; justify-content: center; flex-wrap: wrap; gap: 0.4rem 1.1rem; margin-bottom: 0.6rem; }
.footer-nav a { color: var(--muted); text-decoration: none; }
.footer-nav a:hover, .footer-nav a[aria-current="page"] { color: var(--accent); }

@media (max-width: 480px) {
  .app-header h1 { font-size: 1.2rem; }
}

/* ===== 制度の計算機 共通 ===== */
/* 結果などを app.js で描くので、描き終わるまで本体を見えなくしてレイアウトのずれ（CLS）を防ぐ。3 秒たったら必ず見せる */
.js-loading .app-main { visibility: hidden; }
:root { --error: #b3261e; --ok: #2e6b30; --warn-bg: #fff4d6; --warn-border: #d9a520; }
@media (prefers-color-scheme: dark) {
  :root { --error: #ff8a80; --ok: #9fd49a; --warn-bg: #3a3020; --warn-border: #a88420; }
}
.badge { text-align: center; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.8rem; }
.badge.is-stale { color: var(--error); }
.msg { border-radius: 6px; padding: 0.6rem 0.8rem; margin-bottom: 0.8rem; font-size: 0.88rem; }
.msg-warn { background: var(--warn-bg); border: 1px solid var(--warn-border); }
.msg p + p { margin-top: 0.3rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.2rem 0 0.4rem; }
.btn-sub { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--border); padding: 0.4rem 0.8rem; font-size: 0.88rem; }
h3.sub { font-size: 0.92rem; margin: 1rem 0 0.4rem; }

/* 入力 */
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0 1rem; }
.money { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.money input { max-width: 11rem !important; text-align: right; }
.money .unit { font-size: 0.9rem; }
.money .yomi { font-size: 0.8rem; color: var(--muted); min-width: 5em; }
fieldset.field { border: none; }
fieldset.field legend { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.3rem; }
label.inline { display: flex; align-items: center; gap: 0.4rem; font-weight: normal !important; font-size: 0.92rem; margin: 0.2rem 0; }
label.inline input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); flex: none; }
.sub-block { border-left: 3px solid var(--border); padding-left: 0.8rem; margin-top: 0.4rem; }

.rel { border-top: 1px dashed var(--border); padding: 0.7rem 0 0.5rem; }
.rel-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-weight: 600; font-size: 0.92rem; margin-bottom: 0.3rem; }
.rel-body { display: flex; flex-wrap: wrap; gap: 0.5rem 0.8rem; align-items: flex-end; }
.mini { display: flex; flex-direction: column; font-size: 0.75rem; color: var(--muted); gap: 0.15rem; }
.mini input, .mini select, .rel select {
  padding: 0.35rem 0.4rem; font-size: 1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text); font-family: inherit;
}
.rel-body > .mini { flex: 1 1 9rem; min-width: 0; max-width: 100%; }
.mini input, .mini select { width: 100%; max-width: 100%; }
.mini input { text-align: right; }
#sp-block select, .field select { max-width: 100%; }
.rel-note { font-size: 0.78rem; color: var(--accent); margin-top: 0.3rem; }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--accent); cursor: pointer; font-size: 0.82rem; padding: 0.2rem 0.6rem; font-family: inherit; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 結果 */
.result-main { text-align: center; background: var(--accent-soft); border-radius: 8px; padding: 0.9rem 0.6rem; margin-bottom: 0.8rem; }
.result-main .lead { font-size: 0.9rem; color: var(--muted); }
.result-main .big { font-size: clamp(1.35rem, 6.4vw, 2rem); font-weight: 700; line-height: 1.3; color: var(--accent); }
.result-main.is-refund .big { color: var(--ok); }
.result-main.is-short .big { color: var(--error); }
.result-main .detail { font-size: 0.82rem; color: var(--muted); margin-top: 0.2rem; }
.steps { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.steps th, .steps td { border-bottom: 1px solid var(--border); padding: 0.4rem 0.3rem; vertical-align: top; text-align: left; }
.steps td { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.steps th { font-weight: 600; }
.steps tr.sub th { font-weight: normal; padding-left: 1rem; }
.steps tr.total th, .steps tr.total td { font-weight: 700; }
.steps .rule { display: block; font-size: 0.74rem; color: var(--muted); font-weight: normal; }
.table-wrap { overflow-x: auto; margin: 0.4rem 0; }
.cmp { border-collapse: collapse; width: 100%; font-size: 0.8rem; }
.cmp th, .cmp td { border-bottom: 1px solid var(--border); padding: 0.35rem 0.3rem; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cmp th:first-child { text-align: left; white-space: normal; }
.cmp thead th { color: var(--muted); font-weight: 600; }
details.rels { margin-top: 0.5rem; font-size: 0.85rem; }
details.rels summary { cursor: pointer; color: var(--accent); }
details.rels ul { padding-left: 1.2rem; margin-top: 0.3rem; }

/* ハブのカード一覧 */
.calc-list { list-style: none; display: grid; gap: 0.8rem; }
.calc-list a { display: block; text-decoration: none; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 0.9rem 1rem; background: var(--accent-soft); }
.calc-list a:hover, .calc-list a:focus-visible { border-color: var(--accent); }
.calc-list .name { display: block; font-weight: 700; color: var(--accent); font-size: 1.02rem; }
.calc-list .desc { display: block; font-size: 0.86rem; color: var(--muted); margin-top: 0.2rem; }

/* 使い方ページの表 */
.tbl { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
.tbl th, .tbl td { border-bottom: 1px solid var(--border); padding: 0.35rem 0.45rem; text-align: left; vertical-align: top; }
.tbl thead th { color: var(--muted); }

@media print {
  .app-header, .app-footer, .no-print { display: none !important; }
}

/* ===========================
   画面の骨組み（yorozu-plans の docs/SCREEN.md 1.1）: 必須の入力 → 結果 → くわしく入れる、上端の固定バー、PC の 2 カラム
   =========================== */
fieldset.card { min-width: 0; }
.req legend {
  float: left; width: 100%;   /* legend を枠の上に載せず、h2 と同じ見た目で枠の中に置く */
  font-size: 1.02rem; font-weight: 700; color: var(--accent);
  border-bottom: 1px solid var(--border); padding-bottom: 0.4rem; margin-bottom: 0.9rem;
}
.req legend + * { clear: both; }
.result-card { scroll-margin-top: 56px; }   /* 固定バー（44px）で見出しが隠れないように */
.result-card details.rels { margin: 0; }
.result-card details.rels > summary { min-height: 44px; padding: 0.55rem 0; }   /* 1.1 の 3: 内訳は折りたたみ。タップしやすい高さ */
.result-card details.rels > summary::before { content: '▸'; margin-right: 0.4rem; }
.result-card details.rels[open] > summary::before { content: '▾'; }
.result-card details.rels > summary { list-style: none; }
.result-card details.rels > summary::-webkit-details-marker { display: none; }
details.card.opt { padding: 0 1.2rem; margin-bottom: 0.6rem; }
details.card.opt > summary {
  cursor: pointer; display: block; min-height: 44px; padding: 0.6rem 0;
  color: var(--accent); font-weight: 600; font-size: 0.95rem; list-style: none;
}
details.card.opt > summary::-webkit-details-marker { display: none; }
details.card.opt > summary::before { content: '▸'; margin-right: 0.4rem; }
details.card.opt[open] > summary::before { content: '▾'; }
details.card.opt[open] { padding-bottom: 0.9rem; }
details.card.opt[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 0.9rem; }
details.card.opt > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.opt-state { color: var(--text); font-weight: normal; }
.opts { margin-bottom: 1rem; }

/* 固定バー（SCREEN.md 0 章の 3・D59）: 上端に 1 行、高さ 44px。下端は AdSense のアンカー広告が使う */
.fixbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50; height: 44px;
  background: var(--card); border-bottom: 2px solid var(--accent); box-shadow: 0 2px 8px var(--shadow);
}
.fixbar a {
  display: block; max-width: 720px; margin: 0 auto; padding: 0 1rem; height: 42px; line-height: 42px; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; color: var(--accent); text-decoration: none;
}
.fixbar a:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

/* PC（900px 以上）: 左に入力、右に結果（sticky）。結果が常に見えるので固定バーは出さない（D63: 制度の計算機だけ） */
@media (min-width: 900px) {
  .fixbar-narrow { display: none !important; }
  .layout-2col { max-width: 1120px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 26rem); column-gap: 1.2rem; align-items: start; }
  .layout-2col > * { grid-column: 1; }
  .layout-2col > .badge { grid-column: 1 / -1; }
  .layout-2col > form { display: contents; }
  .layout-2col > form > * { grid-column: 1; }
  .layout-2col .result-card { grid-column: 2; grid-row: 2 / span 20; position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
}

@media print {
  .fixbar { display: none !important; }
  /* 印刷では折りたたみの中も出す（途中の計算・入れた控除を紙に残す） */
  main details::details-content { content-visibility: visible; display: block; }
  main details > summary::before { content: none; }
  .layout-2col .result-card { position: static; max-height: none; overflow: visible; }
  /* 広告は印刷に出さない（gakushu-print と同じ） */
  ins.adsbygoogle, .google-auto-placed, iframe[id^="aswift"], iframe[id^="google_ads"] { display: none !important; }
}

/* ===========================
   住民税の計算（juminzei）: 均等割・所得割の判定の箱と、納める時期の一覧
   =========================== */
.judge { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-bottom: 0.4rem; }
.judge-box { border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.7rem; background: var(--card); min-height: 7.5rem; }
.judge-title { font-size: 0.82rem; color: var(--muted); }
.judge-tag { font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.judge-box.is-hikazei .judge-tag { color: var(--ok); }
.judge-why { font-size: 0.78rem; color: var(--muted); line-height: 1.55; overflow-wrap: anywhere; }
@media (max-width: 420px) { .judge { grid-template-columns: 1fr; } .judge-box { min-height: 0; } }
.pay { list-style: none; font-size: 0.9rem; }
.pay li { padding: 0.35rem 0; border-bottom: 1px dashed var(--border); }
.pay li:last-child { border-bottom: 0; }
.pay .pay-name { font-weight: 700; display: block; }
.field-label { display: block; font-size: 0.95rem; font-weight: 600; margin-bottom: 0.25rem; }
#nenmatsu-msg:empty { display: none; }

/* ===========================
   育休・産休の計算（ikukyu）: 給付ごとの一覧と、月ごとの表
   =========================== */
.field input[type="date"] {
  width: 100%; max-width: 16rem; padding: 0.4rem 0.5rem; font-size: 1rem; font-family: inherit;
  border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text);
}
.benefits { list-style: none; }
.benefits li { border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.7rem; margin-bottom: 0.5rem; background: var(--card); }
.benefits .b-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; font-weight: 600; font-size: 0.92rem; }
.benefits .b-head strong { color: var(--accent); font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.benefits .b-rule { font-size: 0.8rem; color: var(--text); margin-top: 0.2rem; overflow-wrap: anywhere; }
.benefits .b-src { font-size: 0.74rem; color: var(--muted); margin-top: 0.25rem; }
.sched td:last-child { white-space: normal; text-align: left; min-width: 9rem; }
.sched td:nth-child(2) { white-space: normal; text-align: left; }
.sched tr.has-pay td:last-child { color: var(--accent); font-weight: 600; }
