:root {
  --ink: #2b2b28; --ink-soft: #63655f; --line: #d9dfd6; --paper: #fff; --bg: #f3f6f2;
  --accent: #2f6243; --accent-strong: #24503a; --accent-soft: #e6efe8; --red: #c8312a;
  --kyokasho: "UD デジタル 教科書体 N", "UD Digi Kyokasho N", "UD デジタル 教科書体 N-R", "UD Digi Kyokasho N-R", "UD デジタル 教科書体 NK", "UD Digi Kyokasho NK", "YuKyokasho", "BIZ UDMincho", "Yu Mincho", serif; /* Windows の名前は N（R・B は太さ）。2026-10-18 このPCの一覧で確かめた */
}
html { background: var(--bg); }
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); line-height: 1.7; font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif; }
button { font: inherit; cursor: pointer; }

.top { max-width: 1400px; margin: 0 auto; padding: .8rem 16px 0; display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.brand { font-weight: 800; color: var(--accent-strong); text-decoration: none; }
.crumb { color: var(--ink-soft); }
.crumb::before { content: "／"; margin-right: .6rem; color: #b7bdb4; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 8px 16px 24px; display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 20px; align-items: start; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: .9rem; padding: 1rem 1.1rem; position: sticky; top: 8px; max-height: calc(100vh - 16px); overflow: auto; }
.panel h1 { margin: 0; font-size: 1.35rem; color: var(--accent-strong); }
.lead { margin: .2rem 0 .4rem; color: var(--ink-soft); font-size: .92rem; }
.step { border-top: 1px solid var(--line); padding: .7rem 0 .5rem; }
.step h2 { margin: 0 0 .4rem; font-size: 1rem; display: flex; align-items: center; gap: .45rem; }
.step h2 small { font-weight: 400; color: var(--ink-soft); font-size: .85rem; }
.n { display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--accent); color: #fff; font-size: .85rem; }
.hint { margin: .2rem 0 .5rem; font-size: .82rem; color: var(--ink-soft); }
.row { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .5rem; }
.seg { display: flex; gap: .3rem; flex-wrap: wrap; }
.seg button, .row button.sub, button.sub { border: 1px solid var(--line); background: #f7f9f6; border-radius: .55rem; padding: .3rem .75rem; min-height: 2.4rem; }
.seg button[aria-pressed="true"], button.sub[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.field { display: grid; grid-template-columns: 3.2rem 1fr; gap: .5rem; align-items: center; margin: .35rem 0; }
.field > span { font-size: .85rem; color: var(--ink-soft); }
.field input:not([type]) , .field input[id="title"] { border: 1px solid var(--line); border-radius: .5rem; padding: .45rem .6rem; font: inherit; width: 100%; }
.checks { display: flex; flex-direction: column; gap: .15rem; font-size: .92rem; }
.checks input { width: 1.1rem; height: 1.1rem; vertical-align: -2px; }
.kgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.5rem, 1fr)); gap: .25rem; }
.kgrid button { font-family: var(--kyokasho); font-size: 1.3rem; aspect-ratio: 1; border: 1px solid var(--line); border-radius: .45rem; background: #fff; color: #9aa09a; padding: 0; }
.kgrid button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 700; }
.kgrid button:disabled { opacity: .35; cursor: default; }
button.main { width: 100%; border: none; border-radius: .7rem; background: var(--accent); color: #fff; font-weight: 800; padding: .7rem; font-size: 1.05rem; margin-bottom: .4rem; }
button.main.print { background: #8a5a12; }
.msg { color: var(--red); font-size: .9rem; margin: .3rem 0 0; min-height: 1em; }

.preview { min-width: 0; }
#sheets { display: flex; flex-direction: column; gap: 18px; align-items: center; }
.empty { color: var(--ink-soft); }

/* ---- A4 の紙 ---- */
.sheet { width: 210mm; height: 297mm; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12); padding: 12mm 12mm 10mm; display: flex; flex-direction: column; overflow: hidden; color: #111; font-family: var(--kyokasho); position: relative; }
.sh-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 6mm; border-bottom: .5mm solid #333; padding-bottom: 2.5mm; }
.sh-title { font-size: 7mm; font-weight: 700; white-space: nowrap; }
.sh-title small { font-size: 4.2mm; margin-left: 3mm; font-weight: 400; }
.sh-name { display: flex; gap: 2mm; font-size: 3.8mm; }
.sh-name span { border-bottom: .3mm solid #555; min-width: 12mm; text-align: right; padding: 0 1mm; }
.sh-name .nm { min-width: 48mm; text-align: left; }
.sh-name .pt { min-width: 16mm; }
.sh-lead { margin: 2.5mm 0 1mm; font-size: 4mm; }
.answer .sh-title { color: var(--red); }

.items { list-style: none; margin: 0; padding: 0; flex: 1; min-height: 0; }
.item { position: relative; }
.no { font-family: "Yu Gothic UI", "Meiryo", sans-serif; }
.box { display: inline-grid; place-items: center; border: .35mm solid #222; background: #fff; vertical-align: middle; }
.box + .box { margin-block-start: -.35mm; }
.box b { color: var(--red); font-weight: 400; }
.q rt { font-size: 3.4mm; letter-spacing: .05em; }
.q.yomi { position: relative; }
.q.yomi .paren { position: absolute; white-space: pre; line-height: 1; } /* pre＝全角の空白を詰めない（たて書きで（　）が縮んだ） */
.q.yomi .paren b { color: var(--red); font-weight: 400; }
.answer .q.kaki rt { color: #888; }

/* たて書き：右から左へ1問1列 */
.sheet.tate .items { writing-mode: vertical-rl; display: flex; flex-direction: column; flex-wrap: wrap; gap: 0; margin-top: 3mm; }
.sheet.tate .item { inline-size: 100%; block-size: calc((186mm) / 10); padding-block: 0; padding-inline: 2mm 0; border-inline-start: none; font-size: 7mm; line-height: 1.5; border-block-end: .2mm dashed #ccc; }
.sheet.tate .no { font-size: 4.2mm; margin-block-end: 2mm; display: inline-block; text-combine-upright: none; }
.sheet.tate .q.yomi .word { border-right: .35mm solid #222; padding-right: .4mm; }
/* （　）は子どもが書ける大きさ：3年から6mm・1、2年は7mm（下の低学年の所） */
.sheet.tate .q.yomi .paren { right: -7.6mm; top: -.3em; font-size: 6mm; }
.sheet.tate .item.has-yomi { padding-block-start: 7.4mm; }
.sheet.tate .box { inline-size: 12mm; block-size: 12mm; font-size: 9mm; }
.sheet.tate .q rt { font-size: 3.4mm; }

/* 横書き：上から1問1行 */
.sheet.yoko .items { display: flex; flex-direction: column; margin-top: 3mm; }
.sheet.yoko .item { flex: 1; display: flex; align-items: center; gap: 3mm; font-size: 6.5mm; line-height: 2.2; border-bottom: .2mm dashed #ccc; }
.sheet.yoko .no { font-size: 4.2mm; width: 7mm; }
.sheet.yoko .q.yomi .word { border-bottom: .35mm solid #222; }
.sheet.yoko .q.yomi .paren { left: -.3em; top: -6.6mm; font-size: 5.8mm; }
.sheet.yoko .item.has-yomi { line-height: 3; }
.sheet.yoko .box { width: 12mm; height: 12mm; font-size: 9mm; }
.sheet.yoko .box + .box { margin: 0 0 0 -.35mm; }

/* 低学年は字を大きく */
.sheet.g1 .item, .sheet.g2 .item { font-size: 8mm; }
.sheet.g1 .box, .sheet.g2 .box { inline-size: 14mm; block-size: 14mm; width: 14mm; height: 14mm; font-size: 10.5mm; }
.sheet.tate.g1 .q.yomi .paren, .sheet.tate.g2 .q.yomi .paren { right: -8.6mm; font-size: 7mm; }
.sheet.tate.g1 .item.has-yomi, .sheet.tate.g2 .item.has-yomi { padding-block-start: 8.4mm; }
.sheet.yoko.g1 .q.yomi .paren, .sheet.yoko.g2 .q.yomi .paren { top: -7.6mm; font-size: 6.6mm; }

/* 入れかえ・書きかえ（画面だけ） */
.item .tools { position: absolute; display: none; gap: 1mm; z-index: 2; writing-mode: horizontal-tb; }
/* ⇄✎ は問題の頭（番号の横）に横向きで出す（列の下端だと画面の外で見つからない・アイコンが回る＝2026-10-18 使う人の役） */
.sheet.tate .item .tools { top: 0; left: 50%; transform: translate(-50%, -110%); flex-direction: row; }
.sheet.yoko .item .tools { right: 1mm; top: 50%; transform: translateY(-50%); }
.item:hover .tools, .item:focus-within .tools, .item.on .tools { display: flex; }
.item .tools button { border: 1px solid var(--accent); background: #fff; color: var(--accent-strong); border-radius: .4rem; width: 2.1rem; height: 2.1rem; font-size: 1rem; padding: 0; }
.item:hover { background: #f6faf6; }

/* 練習のマス：1列1字（お手本・なぞり2・空き4） */
.pcols { list-style: none; margin: 4mm 0 0; padding: 0; display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 1.5mm; flex: 1; }
.pcols li { display: flex; flex-direction: column; }
.cell { width: 22mm; height: 22mm; border: .35mm solid #333; margin-top: -.35mm; display: grid; place-items: center; font-size: 17mm; line-height: 1; position: relative;
  background-image: linear-gradient(#bbb, #bbb), linear-gradient(#bbb, #bbb); background-size: 100% .2mm, .2mm 100%; background-position: center; background-repeat: no-repeat; }
.cell.model { font-weight: 400; }
.cell.model small { position: absolute; right: .6mm; bottom: .2mm; font-size: 2.8mm; color: #555; font-family: "Yu Gothic UI", sans-serif; }
.cell.trace { color: #c9c9c9; }

dialog { border: none; border-radius: .9rem; padding: 1rem 1.2rem; max-width: 30rem; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog label { display: block; font-size: .9rem; margin: .4rem 0; }
dialog input { display: block; width: 100%; font: inherit; font-size: 1.1rem; border: 1px solid var(--line); border-radius: .5rem; padding: .45rem .6rem; margin-top: .15rem; font-family: var(--kyokasho); }
dialog .row button { flex: 1; }

.foot { max-width: 1400px; margin: 0 auto; padding: 0 16px 32px; font-size: .8rem; color: var(--ink-soft); }
.sister h2 { font-size: .9rem; margin: 1rem 0 .3rem; }
.sister ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .1rem 1rem; }
.sister a { color: var(--accent-strong); font-weight: 700; margin-right: .5rem; }
.credits summary { cursor: pointer; padding-block: .35rem; }

/* 画面がせまい時：紙を縮めて見せる（印刷は原寸） */
@media (max-width: 1100px) { .wrap { grid-template-columns: 1fr; } .panel { position: static; max-height: none; } }
@media screen and (max-width: 860px) { #sheets { zoom: .62; } }
@media screen and (max-width: 520px) { #sheets { zoom: .43; } }

@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff; }
  .no-print, .panel, .top, .foot, #edit-hint { display: none !important; }
  .wrap { display: block; padding: 0; max-width: none; }
  #sheets { display: block; zoom: 1; }
  .sheet { box-shadow: none; break-after: page; page-break-after: always; }
  .item:hover { background: none; }
}

#grades { display: grid; grid-template-columns: repeat(6, 1fr); }
#grades button { padding-inline: 0; }
