/* ===== かな造くん(画面の見た目は漢造くんとそろえる) ===== */
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #2b2622;
  --muted: #7a7068;
  --line: #e4ddd3;
  --accent: #c2410c;
  --accent-soft: #fdeee4;
  --warn: #9a5b00;
  --warn-bg: #fff4dc;
  --radius: 12px;
  --kyokasho: "UD デジタル 教科書体 N-R", "UD Digital Kyokasho N-R", "UD デジタル 教科書体 NK-R",
    "UD Digital Kyokasho NK-R", "游教科書体", "YuKyokasho", "Klee One", serif;
  --ui: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--ui); font-size: 15px; line-height: 1.6; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }

/* ---- 上部バー ---- */
.appbar { background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 20px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 48px; height: 48px; display: block; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .05em; }
.brand p { margin: 0; font-size: 12.5px; color: var(--muted); }

/* ---- 2カラム ---- */
.layout { display: grid; grid-template-columns: 360px 1fr; gap: 20px; padding: 20px; align-items: start; }
.panel {
  position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 18px 18px;
}
.step { padding: 14px 0; border-bottom: 1px dashed var(--line); }
.step h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.step h2 .n { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; }
.step h2 .opt { font-weight: normal; font-size: 12px; color: var(--muted); margin-left: auto; }

.seg { display: grid; gap: 8px; }
.grid2 { grid-template-columns: repeat(2, 1fr); }
.seg button {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 10px;
  padding: 9px 4px; min-height: 44px; line-height: 1.25; transition: border-color .15s, background .15s;
}
.seg button:hover { border-color: var(--accent); }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.seg button small { display: block; font-size: 11px; color: var(--muted); font-weight: normal; margin-top: 2px; }

/* 字をえらぶ */
.picked-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.picked { font-family: var(--kyokasho); font-size: 18px; letter-spacing: .08em; color: var(--accent); min-height: 1.5em; }
.picked.none { font-family: var(--ui); font-size: 13px; color: var(--muted); letter-spacing: 0; }
.mini { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 4px 10px; font-size: 12.5px; flex: none; }
.kana-h { font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
.kana-h:first-child { margin-top: 0; }
.kana-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.kana-grid.yoon { grid-template-columns: repeat(3, 1fr); }
.kana-grid button, .kana-grid span {
  font-family: var(--kyokasho); font-size: 21px; line-height: 1;
  height: 40px; border: 1.5px solid var(--line); border-radius: 8px; background: var(--surface);
}
.kana-grid span { border: 0; background: transparent; }
.kana-grid button:hover:not(:disabled) { border-color: var(--accent); }
.kana-grid button.on { border-color: var(--accent); background: var(--accent); color: #fff; }
.kana-grid button:disabled { color: #cfc7bf; background: #faf8f5; cursor: not-allowed; }

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; margin-top: 2px; }
.range-help { font-size: 12.5px; color: var(--muted); margin: 0 0 8px; }
.warn { font-size: 13px; color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 8px 12px; margin: 0 0 10px; }
.disclaimer { font-size: 11.5px; color: var(--muted); margin: 10px 0 0; line-height: 1.5; }
input[type="text"] {
  width: 100%; font: inherit; font-size: 15px;
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface); color: var(--ink);
}
input[type="text"]:focus { outline: none; border-color: var(--accent); }

/* ---- できあがり ---- */
.preview { min-width: 0; }
.toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; position: sticky; top: 20px; z-index: 5;
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1.5px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 10px 16px; min-height: 46px; font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; padding: 10px 26px; font-size: 16px; }
.btn.primary:hover { filter: brightness(1.08); }
.hint { font-size: 12.5px; color: var(--muted); margin: 10px 4px; }
.swap-icon { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; }

.pages { display: flex; flex-direction: column; align-items: center; padding-bottom: 40px; }
.sheet-wrap { position: relative; }
.sheet-wrap > .sheet { transform-origin: top left; box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.empty {
  background: var(--surface); border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 60px 20px; text-align: center; color: var(--muted); width: 100%;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #2b2622; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- ダイアログ ---- */
.picker {
  width: min(520px, calc(100vw - 32px)); max-height: min(80vh, 720px);
  border: 0; border-radius: 16px; padding: 0 18px 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25); font-family: var(--ui); color: var(--ink); background: var(--surface);
}
.picker::backdrop { background: rgba(30, 20, 10, .35); }
.pk-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); padding: 14px 0 6px; z-index: 1; }
.pk-head h3 { margin: 0; font-size: 17px; }
.pk-close { border: 0; background: #f1ece5; width: 34px; height: 34px; border-radius: 50%; font-size: 18px; }
.pk-help { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.cf-f { display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; }
.cf-f > span { font-size: 11.5px; color: var(--muted); font-weight: 600; }
#cw-word { font-family: var(--kyokasho); font-size: 22px; }
.cf-msg { font-size: 12.5px; color: var(--warn); margin: 0; min-height: 1.2em; }
.cf-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 12px; border-top: 1px dashed var(--line); }
.bk-list { list-style: none; margin: 0 0 12px; padding: 0; max-height: 50vh; overflow-y: auto; border-top: 1px dashed var(--line); }
.bk-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 2px; border-bottom: 1px dashed var(--line); }
.bk-text { font-family: var(--kyokasho); font-size: 20px; display: flex; align-items: center; gap: 8px; }
.bk-text img { width: 26px; height: 26px; }
.bk-del { border: 1.5px solid #e9c4c4; color: #b42318; background: #fff5f5; border-radius: 8px; padding: 6px 12px; font-weight: 700; flex: none; }
.bk-del:hover { background: #b42318; color: #fff; }
.bk-empty { color: var(--muted); font-size: 14px; justify-content: center !important; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .panel { position: static; max-height: none; }
  .toolbar { top: 0; }
}

/* ===== プリント本体(A4たて・mm基準) ===== */
.sheet {
  --masu: 20mm;
  --line: #333;
  --guide: #9a9a9a;   /* 十字の点線 */
  --trace: #c4c4c4;   /* なぞり書きの薄い字 */
  width: 210mm; height: 297mm; background: #fff; color: #222;
  padding: 12mm 10mm 10mm; display: flex; flex-direction: row-reverse; gap: 6mm;
  font-family: var(--kyokasho); line-height: 1.5;
}
/* 右はしの見出し(縦書き) */
.sheet .head { flex: none; display: flex; flex-direction: row-reverse; gap: 4mm; padding-left: 5mm; border-left: 0.4mm solid var(--line); }
.sheet .hcol { display: flex; flex-direction: column; align-items: center; }
.sheet .v { writing-mode: vertical-rl; white-space: nowrap; }
.sheet .title { font-size: 10.5mm; font-weight: 600; letter-spacing: .12em; }
.sheet .meta { font-size: 7mm; gap: 1.5mm; padding-top: 2mm; }
.sheet .box { width: 14mm; height: 14mm; border: 0.3mm solid var(--line); }
.sheet .space { height: 6mm; }
.sheet .namebox { width: 23mm; flex: 1; border: 0.4mm solid var(--line); margin-top: 1mm; }

/* 本体:縦の帯を右から並べる。帯の中は単語を上から詰める */
.sheet .body { flex: 1; min-width: 0; display: flex; flex-direction: row-reverse; justify-content: space-between; }
.sheet .body.few { justify-content: flex-start; gap: 8mm; }
.sheet .strip { display: flex; flex-direction: column; justify-content: space-between; }
.sheet .strip.few { justify-content: flex-start; gap: 6mm; }

/* 1単語のまとまり=絵+2列(右:なぞる/左:書く) */
.sheet .unit { position: relative; width: calc(var(--masu) * 2); display: flex; flex-direction: column; align-items: center; }
.sheet .pic { height: var(--masu); width: 100%; display: flex; align-items: center; justify-content: center; }
.sheet .pic img { width: calc(var(--masu) * .66); height: calc(var(--masu) * .66); display: block; }
.sheet .pic .emo { font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; font-size: calc(var(--masu) * .6); line-height: 1; }
.sheet .cols { display: flex; flex-direction: row-reverse; }
.sheet .col { display: flex; flex-direction: column; }
.sheet .col + .col { margin-right: -0.3mm; } /* 列の境目の線を1本にする */
.sheet .sq {
  position: relative; width: var(--masu); height: var(--masu); border: 0.3mm solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--masu) * .78); line-height: 1;
}
.sheet .sq + .sq { margin-top: -0.3mm; }
.sheet .sq::before, .sheet .sq::after { content: ""; position: absolute; }
.sheet .sq::before { left: 50%; top: 0; bottom: 0; border-left: 0.25mm dashed var(--guide); }
.sheet .sq::after  { top: 50%; left: 0; right: 0; border-top: 0.25mm dashed var(--guide); }
.sheet .sq span { position: relative; z-index: 1; color: var(--trace); }
/* のばす「ー」は、縦書きではたての棒にする */
.sheet .sq span.bar { writing-mode: vertical-rl; }
/* 小さい字(ゃゅょっ 等)は、十字で分けた4つの部屋のうち「右上の部屋」の真ん中に置く(縦書きの教科書どおり)。
   フォントによって位置がずれないよう、ふつうの大きさの字を小さくして、位置を直接決める */
.sheet .sq span.small {
  position: absolute; left: 50%; top: 0; width: 50%; height: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--masu) * .4); line-height: 1;
}

/* 画面だけのボタン(印刷・PDFには出さない) */
.sheet .tools {
  position: absolute; top: 0; right: 0; width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px solid var(--accent); background: var(--surface); color: var(--accent);
  font-family: var(--ui); font-size: 14px; display: grid; place-items: center; padding: 0;
  transform: scale(var(--inv, 1)); transform-origin: top right; opacity: .75;
}
.sheet .tools:hover { opacity: 1; background: var(--accent); color: #fff; }
.sheet .strip.few .unit.nopic + .unit.nopic { margin-top: 4mm; } /* 絵なしは、ことばの間を広く(合わせて10mm) */
/* 絵なしのときは、書くマス(左の列)の左上に出す */
.sheet .unit.nopic .tools { right: auto; left: 0; transform-origin: top left; }

/* ===== 印刷 ===== */
@page { size: A4 portrait; margin: 0; }
@media print {
  body { background: #fff; }
  .appbar, .panel, .toolbar, .hint, .warn, .toast, .picker, .empty, .sheet .tools { display: none !important; }
  .layout { display: block; padding: 0; }
  .pages { display: block; padding: 0; }
  .sheet-wrap { width: auto !important; height: auto !important; }
  .sheet-wrap > .sheet { transform: none !important; box-shadow: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
