/* ===========================
   学校の計算機（gakko-keisan）— 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; }
}

/* ===========================
   画面の骨組み（yorozu-plans の docs/SCREEN.md。README「ツールを追加するとき」25）
   必須の入力（fieldset.req）→ 結果（.result-card）→ くわしく入れる（details.opt）、上端の固定バー、PC の 2 カラム
   seido-keisan/nenmatsu と gakushu-print の試験（2026-09-24）から取り出したもの
   =========================== */
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; }

/* 結果: 大きな数字 1 つ＋ 1 行。内訳は details.rels */
.result-card { scroll-margin-top: 56px; }   /* 固定バー（44px）で見出しが隠れないように */
.result-card:focus { outline: none; }
.result-big { font-size: 1.8rem; font-weight: 700; color: var(--accent); line-height: 1.3; }
.result-sub { font-size: 0.9rem; color: var(--muted); }
details.rels > summary { cursor: pointer; min-height: 44px; padding: 0.55rem 0; list-style: none; color: var(--accent); font-size: 0.92rem; }
details.rels > summary::-webkit-details-marker { display: none; }
details.rels > summary::before { content: '▸'; margin-right: 0.4rem; }
details.rels[open] > summary::before { content: '▾'; }

/* くわしく入れる（1 グループ 1 つの details）。summary の .opt-state に今の状態を出す（screen.js の detailsSummary） */
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 > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.opt-state { color: var(--text); font-weight: normal; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0.6rem 0; }   /* ボタンの間隔（SCREEN.md 5 章。4 章の上下 12px 以上は margin で） */
.btn-row .btn { min-height: 44px; }

/* 固定バー（SCREEN.md 0 章の 3・D59）: 上端に 1 行、高さ 44px。下端は AdSense のアンカー広告が使う。
   読み込み時は hidden（screen.js が出し入れする。fixed なのでレイアウトはずれない） */
.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, .fixbar button {
  display: block; width: 100%; 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: inherit; font-weight: 700;
  color: var(--accent); background: none; border: none; text-decoration: none; cursor: pointer;
}
.fixbar a:focus-visible, .fixbar button:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

/* PC（900px 以上）の 2 カラム（D63: 制度の計算機だけ）。<main class="app-main layout-2col"> にすると、
   左に入力・右に結果（sticky）。結果が常に見えるので、固定バーに fixbar-narrow も付けて PC では出さない */
@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 > *, .layout-2col > form > * { grid-column: 1; }
  .layout-2col > form { display: contents; }
  .layout-2col .result-card { grid-column: 2; grid-row: 1 / span 30; position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
}

/* ===========================
   学校の計算機で共通の部品（ハブの一覧・確認日の帯・表・評定のタイル・行を足す入力）
   =========================== */
.badge { text-align: center; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.8rem; }
.badge.is-stale { color: var(--accent); font-weight: 700; }
.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; }

.steps { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.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.total th, .steps tr.total td { font-weight: 700; color: var(--accent); }
.steps .rule { display: block; font-size: 0.74rem; color: var(--muted); font-weight: normal; }
.table-wrap { overflow-x: auto; margin: 0.4rem 0; }
.result-card .note:empty { display: none; }
.result-big.is-over { color: var(--text); }

.field .row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.field .row input[type="number"] { max-width: 9rem; text-align: right; }
.field .unit { font-size: 0.9rem; }
.field.is-missing input, .field.is-missing select { border-color: var(--accent); background: var(--accent-soft); }
label.inline { display: flex; align-items: center; gap: 0.5rem; font-weight: normal; font-size: 0.93rem; min-height: 44px; }
label.inline input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); flex: none; }
textarea { width: 100%; font: inherit; font-size: 1rem; padding: 0.45rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text); }
.btn-sub { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--border); }

/* 評定のタイル（教科ごとに 1〜5 を 1 タップで選ぶ）。入れ子の fieldset は選択肢だけなので measure_fold は 1 つと数える */
fieldset.grades { border: none; min-width: 0; margin: 0 0 0.6rem; }
fieldset.grades .hint { font-size: 0.8rem; color: var(--muted); margin-top: 0.2rem; }
fieldset.grades > legend { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.3rem; }
.grade-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.15rem 0; }
.grade-row + .grade-row { border-top: 1px dashed var(--border); }
.grade-row .subj { flex: 0 0 5.2em; font-size: 0.92rem; }
.grade-row .subj small { display: block; font-size: 0.7rem; color: var(--muted); line-height: 1.2; }
.tiles { display: flex; gap: 0.3rem; }
.tiles label { position: relative; }
.tiles input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tiles span {
  display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--card); font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer;
}
.tiles input:checked + span { background: var(--accent); color: var(--card); border-color: var(--accent); }
.tiles input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.grades.is-missing .grade-row.is-empty .subj { color: var(--accent); font-weight: 700; }
@media (max-width: 360px) { .tiles span { width: 40px; } .grade-row .subj { flex-basis: 4.4em; } }

/* 行を足す入力（科目の一覧） */
.rows { display: grid; gap: 0.5rem; margin: 0.4rem 0; }
.rows .r { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr) 44px; gap: 0.3rem; align-items: end; }
.rows .r label { font-size: 0.72rem; color: var(--muted); display: block; }
.rows .r input { width: 100%; padding: 0.4rem; font-size: 1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text); }
.rows .r button { height: 42px; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--muted); cursor: pointer; }

.content .steps td { white-space: normal; text-align: left; }
.five th, .five td { text-align: center; padding: 0.3rem 0.15rem; }
.five input { width: 4.2em; padding: 0.35rem 0.2rem; font-size: 1rem; text-align: right; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--text); }
.five td:last-child { font-weight: 700; color: var(--accent); }

@media print {
  .fixbar, .no-print { display: none !important; }
  /* 印刷では折りたたみの中も出す（途中の計算・入れた値を紙に残す） */
  main details::details-content { content-visibility: visible; display: block; }
  main details > summary::before { content: none; }
  .layout-2col { display: block; }
  .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; }
}
