/* 漢字テストメーカー — 画面のデザイン（モバイル優先）。用紙そのものは paper.css */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-alt: #f6f7f4; /* 入力欄・補助ブロック */
  --ink: #1a1a1a;
  --muted: #5c5c58;
  --faint: #6f6f6a;
  --line: #d9dbd4;
  --line-strong: #1a1a1a;
  --field: var(--surface-alt);
  --black: var(--ink);
  --primary: #4f7a3a;
  --primary-hover: #3f6530;
  --primary-soft: #e8f0e1;
  /* 見本の解答の字だけ。印刷用紙の赤字は paper.css。画面のボタンや案内には使わない */
  --paper-red: #d9381e;
  --accent: var(--primary);
  --accent-soft: var(--primary-soft);
  --accent-ink: var(--ink);
  --danger: #b42318;
  --ok: #4f7a3a;
  --ok-soft: var(--primary-soft);
  --r-lg: 6px; /* カード・パネル・ダイアログ */
  --r-md: 6px;
  --r-sm: 4px; /* ボタン・入力・チップ */
  --shadow: none;
  --shadow-float: 0 2px 8px rgba(0, 0, 0, 0.08); /* ダイアログと通知だけ */
  --font-ui: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", "Noto Sans JP", "Noto Sans CJK JP", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Geist Mono", Menlo, Consolas, monospace;
  --topbar-h: 64px;
  --tabbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background-color 0.15s, color 0.15s, transform 0.1s; }
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, summary:focus-visible, .sheet-viewport:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  font-size: 16px; /* iOS のズーム防止 */
  background: var(--field);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  background: #fff;
  border-color: var(--primary);
  box-shadow: none;
}
textarea { resize: vertical; min-height: 92px; line-height: 1.6; }
input[readonly], textarea[readonly] { color: var(--muted); }
select { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236b7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; padding-right: 40px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden, [hidden] { display: none !important; }

/* ---------- 共通部品 ---------- */

.primary-btn, .soft-btn, .ghost-btn, .pill-btn, .view-btn, .inline-action {
  min-height: 48px;
  padding: 10px 20px;
  border-radius: 4px;
  font-weight: 700;
}
.primary-btn { background: var(--primary); color: #fff; }
.primary-btn:hover { background: var(--primary-hover); }
.soft-btn { background: var(--field); color: var(--ink); }
.soft-btn:hover { background: #e4e7df; }
.ghost-btn { background: transparent; color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.ghost-btn:hover { background: var(--field); }

.full-width { width: 100%; }
.align-end { align-self: end; }
.field-label {
  display: block;
  margin: 0 0 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
}
label { display: block; }
.mt-12, .field-label.mt-12 { margin-top: 16px; }
.grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  font-size: 0.92rem;
  cursor: pointer;
}
.check-row input { width: 22px; height: 22px; flex: none; margin: 0; accent-color: var(--primary); }
.check-stack { display: flex; flex-direction: column; }

.hint { margin: 6px 0 10px; font-size: 0.86rem; color: var(--muted); line-height: 1.65; }
.size-hint { margin-top: 10px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 26px 0 20px; }
.sub-title { margin: 0 0 8px; font-size: 1.05rem; font-weight: 800; letter-spacing: -0.01em; }

.status-box {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  background: var(--field);
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.6;
}
.status-box.is-busy { background: var(--surface-alt); color: var(--ink); }
.status-box.is-ok { background: var(--field); color: var(--ink); }
.status-box.is-warn { background: var(--primary-soft); color: var(--ink); }
.status-box.is-error { background: #fdecea; color: var(--danger); }

.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
#countPills { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
#countPills .pill-btn { min-width: 0; width: 100%; padding-inline: 2px; white-space: nowrap; font-size: clamp(0.72rem, 2.8vw, 0.95rem); }
.pill-btn { background: var(--surface); border: 1px solid var(--line); box-shadow: none; min-width: 64px; padding-inline: 16px; font-weight: 600; }
.pill-btn:hover { border-color: var(--ink); }
.pill-btn.is-active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); box-shadow: none; }

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 4px;
  background: var(--field);
  color: #2b2f36;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.chip.src { background: transparent; color: var(--muted); font-weight: 500; padding-inline: 2px; }

/* ---------- 全体のレイアウト ---------- */

.app-shell { max-width: 1440px; margin: 0 auto; }

/* 上端に張り付く平らなバー（下に細い線） */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 56px;
  margin: 0;
  padding: 6px 16px;
  background: var(--surface);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
}
.brand-block { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  position: relative;
  flex: none;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  font-size: 1.15rem;
  overflow: hidden;
}
/* 用紙のマスと同じ、十字の補助線（田字格） */
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; background: var(--faint); opacity: 0.55; }
.brand-mark::before { left: 50%; top: 0; bottom: 0; width: 1px; }
.brand-mark::after { top: 50%; left: 0; right: 0; height: 1px; }
.brand-mark span { position: relative; z-index: 1; }
.brand-name { margin: 0; font-size: 1.02rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.2; white-space: nowrap; }
.brand-sub { display: none; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.save-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 4px;
  background: var(--field);
  color: var(--muted);
  font-family: var(--font-ui);
  font-weight: 650;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.save-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.save-state.is-error { color: var(--danger); font-weight: 700; }
.save-state.is-error::before { background: var(--danger); }
.save-state-mobile { display: none; }

.workspace { padding: 6px 12px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom, 0px)); }
.pane { min-width: 0; }

/* 下端に固定する切り替え。浮いたカプセルにはしない */
.view-tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  transform: none;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  width: 100%;
  padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: var(--surface);
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
}
.kb-open .view-tabs { display: none; }
.site-footer { text-align: center; padding: 18px 16px calc(96px + env(safe-area-inset-bottom, 0px)); }
.site-footer a { color: var(--faint); font-size: 0.8rem; text-decoration: none; }
.site-footer a:hover { color: var(--muted); text-decoration: underline; }
.sponsor-line { margin: 0 0 8px; color: var(--faint); font-size: 0.8rem; line-height: 1.6; }
.sponsor-line a { color: var(--muted); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
.is-native [data-sponsor] { display: none !important; }
.support-screen { max-width: 420px; margin: 0 auto 18px; padding: 0 16px; text-align: center; }
.support-tiers { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.support-tiers .soft-btn { white-space: nowrap; }
@media (min-width: 1000px) { .site-footer { padding-bottom: 24px; } }
.view-btn {
  background: transparent;
  color: var(--muted);
  min-height: 48px;
  padding: 8px 8px;
  border-radius: 0;
  border-top: 2px solid transparent;
}
.view-btn.is-active {
  background: var(--primary-soft);
  color: var(--primary);
  border-top-color: var(--primary);
}
.tab-count { font-weight: 500; font-size: 0.86em; opacity: 0.8; }

/* モバイル・タブレット：1カラムで「編集／プレビュー／解答」を切り替え */
@media (max-width: 999px) {
  html { scroll-padding-bottom: calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom, 0px)); }
  .workspace { padding-bottom: calc(var(--tabbar-h) + 56px + env(safe-area-inset-bottom, 0px)); }
  .workspace[data-view="edit"] .pane-preview { display: none; }
  .workspace:not([data-view="edit"]) .pane-edit { display: none; }
  .save-state-mobile { display: inline-flex; }
  .topbar .save-state { display: none; }
}

/* デスクトップ：左に「つくる」、右にプレビュー */
@media (min-width: 1000px) {
  .view-tabs { display: none; }
  .workspace {
    display: grid;
    grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
    gap: 16px;
    padding: 8px 12px 14px;
    height: calc(100vh - var(--topbar-h));
  }
  .pane { overflow: auto; height: 100%; padding: 2px 4px 40px 2px; }
  .pane-preview { display: flex; flex-direction: column; overflow: hidden; padding: 2px 0 0; }
  .sheet-viewport { flex: 1; min-height: 0; overflow: auto; }
  #printBtn { display: none; } /* 右のプレビューバーに同じボタンがある */
  /* 用紙の大きさはプレビューの横に常に出す。どの欄を開いていても、ここから変えられる */
}

/* ---------- 「つくる」ペイン ---------- */

.hero { display: grid; grid-template-columns: minmax(0, 1fr) 78px; gap: 10px 16px; align-items: start; padding: 20px 4px 2px; }
.hero-copy { min-width: 0; }
.eyebrow { margin: 0 0 8px; color: var(--primary); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; }
.hero h2 {
  margin: 0 0 10px;
  font-size: clamp(1.2rem, 1.1rem + 1.1vw, 1.7rem);
  font-weight: 800;
  line-height: 1.28;
  letter-spacing: -0.03em;
  font-feature-settings: "palt";
  text-wrap: balance;
}
/* 広い画面の左カラムは最大400px。見本の横で、見出しの1行は約292px。
   全角12字（「縦書きの漢字テストを、」）が1行に残る大きさにする。
   字幅が狭いフォントだと 1.7rem でも収まるが、全角ゴシックだと折り返して hero-wrap になる。 */
@media (min-width: 1000px) {
  .hero h2 { font-size: 1.375rem; text-wrap: wrap; }
}
.hero-line { display: block; text-wrap: wrap; }
.hero-sub { margin: 0; color: var(--muted); font-size: 0.92rem; line-height: 1.75; max-width: 34em; }
.hero .save-state { grid-column: 1 / -1; justify-self: start; margin-top: 4px; }

/* できあがりの見本：縦書きの1問（用紙と同じ、方格・読み・赤字） */
.hero-sample {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  width: 78px;
  min-height: 118px;
  padding: 10px 6px 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: none;
  font-family: "YuKyokasho", "UD Digi Kyokasho N-R", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
}
.hs-no { display: inline-grid; place-items: center; width: 22px; height: 22px; border: 1.5px solid var(--ink); border-radius: 50%; font-size: 0.72rem; font-weight: 700; }
.hs-text { writing-mode: vertical-rl; font-size: 1.05rem; line-height: 1.45; letter-spacing: 0.04em; max-height: 7.2em; overflow: hidden; }
.hs-box { display: inline-block; width: 1.25em; height: 1.25em; border: 1.5px solid var(--ink); text-align: center; line-height: 1.2em; color: var(--paper-red); font-weight: 700; writing-mode: horizontal-tb; }
.hero-sample rt { font-size: 0.5em; color: var(--muted); }
.hs-cap { font-family: var(--font-ui); font-size: 0.72rem; color: var(--faint); letter-spacing: 0.04em; }

/* つくり方をえらぶ（3つ） */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 22px 0 12px;
}
.tile {
  min-height: 96px;
  padding: 13px 13px 12px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: none;
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px;
}
.tile:hover { border-color: var(--ink); }
.tile .glyph {
  position: relative;
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  font-size: 0.95rem; font-weight: 800;
  overflow: hidden;
}
.tile .glyph::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--faint); opacity: 0.5; }
.tile .glyph::after { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--faint); opacity: 0.5; }
.tile strong { font-size: 1rem; line-height: 1.3; letter-spacing: -0.01em; }
.tile .sub { font-size: 0.74rem; line-height: 1.45; color: var(--muted); font-weight: 400; }
.tile.is-active { background: var(--primary-soft); border-color: var(--primary); box-shadow: none; }
.tile.is-active .glyph { background: #fff; color: var(--primary); border-color: var(--primary); }
.tile.is-active strong { color: var(--ink); }
.tile.is-active .sub { color: var(--muted); }
.tile-preview { display: none; }

/* 筆順練習プリント（上の3つとは別物だと分かるように、区切り線＋幅いっぱい＋緑の下地） */
.quick-stroke { margin: 0 0 12px; }
.qs-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 0 8px;
  font-size: 0.72rem; letter-spacing: 0.06em; color: var(--faint);
}
.qs-divider::before, .qs-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.tile.tile-stroke {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 12px; row-gap: 2px;
  width: 100%;
  min-height: 0;
  padding: 12px 14px;
  background: var(--primary-soft);
  border: 1px solid var(--line);
  box-shadow: none;
}
.tile.tile-stroke .glyph { grid-row: 1 / 3; align-self: center; border-color: var(--primary); color: var(--primary); }
.tile.tile-stroke strong { align-self: end; }
.tile.tile-stroke .sub { align-self: start; color: var(--ink); }
.tile.tile-stroke:hover { border-color: var(--primary); }
.tile.tile-stroke.is-active { background: var(--primary-soft); border-color: var(--primary); box-shadow: none; }
.tile.tile-stroke.is-active .glyph { background: #fff; color: var(--primary); border-color: var(--primary); }
.tile.tile-stroke.is-active strong { color: var(--ink); }
.tile.tile-stroke.is-active .sub { color: var(--muted); }

details.tool {
  margin: 0 0 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: none;
  overflow: hidden;
  overflow: clip; /* clip は「中の sticky ボタン」を邪魔しない */
}
details.tool > summary { display: none; } /* 開閉は上の3つの選択で行う */
details.tool:not([open]) { display: none; }
.tool-body { padding: 22px 18px 22px; }

.layout-settings > summary, .mini-details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 8px 4px;
  font-weight: 700;
}
.layout-settings > summary::-webkit-details-marker, .mini-details > summary::-webkit-details-marker { display: none; }
.layout-settings > summary::after, .mini-details > summary::after {
  content: "＋"; color: var(--muted); font-weight: 400; font-size: 1.1rem;
}
.layout-settings[open] > summary::after, .mini-details[open] > summary::after { content: "−"; }

.mini-details { margin-top: 10px; }
.mini-details > summary { min-height: 48px; font-weight: 600; font-size: 0.86rem; color: var(--muted); }

.ocr-thumb { display: block; max-width: 100%; max-height: 160px; margin-top: 12px; border-radius: var(--r-sm); border: 1px solid var(--line); }
.format-sample {
  margin: 0 0 10px; padding: 12px 14px; overflow-x: auto;
  background: var(--field); border-radius: var(--r-sm);
  font-size: 0.84rem; line-height: 1.7; font-family: var(--font-mono);
}

/* 取り込みプレビュー */
.import-preview:empty { display: none; }
.import-preview { margin-top: 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; }
.ip-summary { padding: 10px 14px; font-size: 0.84rem; border-bottom: 1px solid var(--line); background: var(--field); border-radius: var(--r-sm) var(--r-sm) 0 0; }
.ip-summary.is-error { color: var(--danger); background: #fdecea; border-bottom: 0; border-radius: var(--r-sm); }
.ip-note { color: var(--muted); margin-left: 6px; font-size: 0.78rem; }
.ip-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow: auto; }
.ip-item label { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-height: 48px; padding: 6px 14px; cursor: pointer; }
.ip-item + .ip-item, .ip-skip { border-top: 1px solid var(--line); }
.ip-item input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--primary); }
.ip-item.is-off { opacity: 0.5; }
.ip-main { font-weight: 700; }
.ip-sentence { color: var(--muted); font-size: 0.88rem; }
.ip-warn { flex-basis: 100%; padding-left: 30px; color: var(--ink); font-size: 0.78rem; }
.ip-auto { flex-basis: 100%; padding-left: 30px; color: var(--muted); font-size: 0.78rem; }
.ip-skip { padding: 10px 14px; font-size: 0.8rem; color: var(--muted); }

.sticky-action { margin-top: 20px; }
.sticky-action .primary-btn { min-height: 54px; font-size: 1.02rem; }

.type-counts { margin-top: 12px; padding: 14px; background: var(--field); border-radius: var(--r-md); }
.tc-title { font-size: 0.78rem; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.tc-grid { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.tc-item { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; }
.tc-item input[type="number"] { width: 76px; min-height: 44px; padding: 6px 8px; text-align: center; background: #fff; }
.tc-total { margin-top: 8px; font-size: 0.86rem; color: var(--muted); }
.tc-total strong { color: var(--ink); font-size: 1.05rem; }

/* ---------- 問題一覧 ---------- */

.panel {
  padding: 22px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: none;
}
.list-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.list-head h2 { margin: 0; font-size: 1.25rem; font-weight: 800; letter-spacing: -0.02em; }
.count-badge { display: inline-block; min-width: 30px; margin-left: 6px; padding: 1px 10px; border-radius: 4px; background: var(--ink); color: #fff; text-align: center; font-family: var(--font-mono); font-size: 0.8rem; vertical-align: 3px; }
.list-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.bulk-type { display: block; margin: 0 0 12px; }
.bulk-type select:disabled { color: var(--muted); cursor: default; }
.bulk-type-note {
  margin: 8px 0 0;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  background: var(--primary-soft);
  color: var(--ink);
  font-size: 0.84rem;
  line-height: 1.55;
  box-shadow: none;
}

.inline-action {
  min-width: 48px;
  padding: 6px 14px;
  background: var(--field);
  font-size: 0.84rem;
}
.inline-action:hover { background: #e4e7df; }
.inline-action.danger { color: var(--danger); }

.question-list { display: flex; flex-direction: column; gap: 10px; }
.empty-note { padding: 26px 8px; text-align: center; color: var(--muted); font-size: 0.9rem; line-height: 1.7; }

.question-item { padding: 14px 16px; background: var(--surface-alt); border: 1px solid var(--line); border-radius: var(--r-md); }
.question-item.is-open { background: #fff; border-color: var(--line-strong); }
.qi-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.qi-no { display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 6px; border-radius: 4px; background: var(--ink); color: #fff; font-family: var(--font-mono); font-weight: 700; font-size: 0.78rem; }
.qi-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin: 0; }
.qi-fields > div { min-width: 0; }
.qi-fields .wide { grid-column: 1 / -1; }
.qi-fields dt { font-size: 0.74rem; color: var(--faint); font-weight: 700; }
.qi-fields dd { margin: 0; overflow-wrap: anywhere; font-size: 0.94rem; }
.qi-kanji { font-size: 1.3rem !important; font-weight: 800; }
.qi-warn { margin-top: 8px; padding: 7px 10px; border-radius: 4px; background: var(--primary-soft); color: var(--ink); font-size: 0.78rem; }
.qi-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.qi-editor { display: grid; gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }

.list-notice { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 12px; padding: 12px 14px; border-radius: var(--r-sm); background: var(--primary-soft); color: var(--ink); font-size: 0.84rem; line-height: 1.65; }

.saved-sets { margin-top: 18px; }
.set-save { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0; }
.set-save .text-input { flex: 1 1 10em; min-width: 0; }
.set-save #saveSetBtn { flex: 0 0 auto; align-self: center; white-space: nowrap; min-width: 5em; }
.storage-usage { margin: 0 0 10px; font-size: 0.78rem; color: var(--muted); }
.set-list { display: grid; gap: 8px; }
.set-item { display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: #fff; }
.set-info { min-width: 0; display: flex; flex-direction: column; font-size: 0.88rem; }
.set-info strong { overflow-wrap: anywhere; }
.set-info span { color: var(--muted); font-size: 0.76rem; }
.set-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; width: 100%; }
.set-actions-main, .set-actions-more { display: flex; flex-wrap: wrap; justify-content: flex-start; align-items: center; gap: 6px; width: 100%; }
.set-actions button { flex: 0 0 auto; white-space: nowrap; }
.set-actions .danger { margin-left: 8px; }
.set-rename { flex: 1 1 100%; display: flex; gap: 6px; }
.set-rename .text-input { flex: 1 1 auto; min-width: 0; }
.set-file { margin-top: 12px; }
@media (max-width: 520px) {
  .saved-sets .grid-two { grid-template-columns: 1fr; }
}
.backup { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 6px; }
.update-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 8px 12px 0;
  padding: 10px 14px;
  border-radius: var(--r-sm);
  background: var(--primary-soft);
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.5;
}
.update-notice[hidden] { display: none !important; }
.update-notice .soft-btn { min-height: 40px; background: #fff; }
/* 将来、広告やお知らせを足すときは、フッターの直前に全幅で1段置く。
   下の固定ナビや、この保存した一覧とは重ねない。いまは何も置かない。 */

/* ---------- プレビューのペイン ---------- */

.preview-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: none;
}
.fit-short { display: none; }
@media (min-width: 1000px) {
  .preview-bar { flex-wrap: nowrap; border-radius: 4px; gap: 4px; padding: 3px; }
  .preview-bar > * { flex: 0 0 auto; }
  .preview-bar .sheet-seg { flex: 0 0 auto; min-width: 0; }
  .preview-bar .sheet-seg button { min-height: 34px; padding: 2px 8px; font-size: 0.74rem; white-space: nowrap; }
  .preview-bar .bar-field { flex: 0 0 auto; min-width: 0; gap: 4px; }
  .preview-bar .bar-label { font-size: 0.7rem; }
  .preview-bar .bar-field select { min-height: 34px; min-width: 0; width: auto; max-width: none; font-size: 0.74rem; padding: 2px 22px 2px 8px; background-position: right 8px center; }
  .preview-bar .zoom-group { flex: 0 0 auto; gap: 2px; }
  .preview-bar .zoom-group .ghost-btn { min-width: 28px; min-height: 34px; padding: 2px 6px; }
  .preview-bar .zoom-group .fit-btn { padding-inline: 8px; font-size: 0.74rem; }
  .preview-bar .zoom-label { min-width: 34px; font-size: 0.7rem; }
  .preview-bar .print-btn { flex: 0 0 auto; margin-left: auto; white-space: nowrap; min-height: 34px; padding: 4px 10px; font-size: 0.76rem; gap: 6px; }
  .preview-bar .print-sub { font-family: var(--font-ui); }
}
@media (min-width: 1000px) and (max-width: 1279px) {
  .preview-bar .bar-label { display: none; }
  .preview-bar .print-sub { display: none; }
  .preview-bar .fit-long { display: none; }
  .preview-bar .fit-short { display: inline; }
}
@media (min-width: 1280px) {
  .preview-bar { gap: 6px; padding: 4px; }
  .preview-bar .sheet-seg button { padding: 4px 12px; font-size: 0.8rem; min-height: 36px; }
  .preview-bar .print-btn { min-height: 36px; padding: 6px 12px; font-size: 0.82rem; }
}
.seg { display: inline-flex; padding: 3px; border-radius: 4px; background: var(--field); }
.seg button { min-height: 42px; padding: 6px 15px; border-radius: 4px; background: transparent; font-weight: 700; color: var(--muted); }
.seg button.is-active { background: var(--primary-soft); color: var(--primary); }
.bar-field { width: auto; }
.bar-field select { width: auto; min-width: 100px; border-radius: 4px; min-height: 48px; }
.zoom-group { display: inline-flex; align-items: center; gap: 4px; }
.zoom-group .ghost-btn { min-width: 46px; padding: 6px 10px; }
.zoom-group .fit-btn { padding-inline: 12px; font-size: 0.84rem; white-space: nowrap; }
.zoom-label { min-width: 42px; text-align: center; font-family: var(--font-mono); font-size: 0.78rem; font-weight: 700; color: var(--muted); }
.preview-bar .primary-btn { margin-left: auto; }
.preview-bar .bar-field { display: inline-flex; align-items: center; gap: 6px; }
.bar-label { font-size: 0.75rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.lang-switch { display: inline-flex; align-items: center; padding: 3px; border-radius: 4px; background: var(--field); gap: 2px; }
.lang-switch button { min-height: 40px; padding: 0 10px; border-radius: 4px; background: transparent; color: var(--muted); font-size: 0.75rem; font-weight: 800; white-space: nowrap; }
.lang-switch button:hover,
.lang-switch button:focus { background: transparent; color: var(--ink); }
.lang-switch button.is-active,
.lang-switch button.is-active:hover,
.lang-switch button.is-active:focus,
.lang-switch button[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); }
.print-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; line-height: 1.2; padding-block: 6px; }
.print-btn .print-sub { padding: 2px 9px; border-radius: 4px; background: rgba(255, 255, 255, 0.16); font-family: var(--font-mono); font-size: 0.64rem; font-weight: 500; }
/* 下のバーは「編集／プレビュー／解答」の3つなので、用紙が3種類（問題用紙・解答用紙・筆順練習）
   ある今は、画面が狭いときもこの切り替えを出す。はみ出すときは折り返す */
@media (max-width: 999px) {
  #printBtn2 { display: none; }
  .preview-bar { border-radius: 4px; }
  .sheet-seg { flex-wrap: wrap; }
  .sheet-seg button { padding-inline: 12px; font-size: 0.86rem; }
}

.layout-settings { margin-bottom: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 0 12px; }
.layout-settings > summary { min-height: 50px; font-size: 0.92rem; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px 16px; padding: 6px 4px 8px; }
.settings-grid .check-stack { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr; column-gap: 20px; }
@media (min-width: 700px) { .settings-grid .check-stack { grid-template-columns: 1fr 1fr; } }
/* デスクトップでは、設定は用紙の上に重ねて出す（開いても用紙が小さくならない） */
@media (min-width: 1000px) {
  .layout-settings { position: relative; z-index: 8; }
  .layout-settings[open] .settings-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0; right: 0;
    max-height: 58vh;
    overflow: auto;
    padding: 6px 16px 8px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    box-shadow: none;
  }
}
.layout-settings .hint { padding: 0 4px 12px; margin: 0; }

.sheet-info { margin-bottom: 10px; padding: 10px 14px; border-radius: var(--r-sm); background: var(--field); color: var(--muted); font-size: 0.82rem; line-height: 1.65; }
.sheet-info.is-warn { background: var(--primary-soft); color: var(--ink); }
.print-hint { margin: 0 0 10px; font-size: 0.8rem; color: var(--muted); line-height: 1.6; }

.sheet-viewport {
  padding: 18px;
  background: var(--surface-alt);
  border-radius: var(--r-lg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.paper-preview { display: inline-block; min-width: 100%; }
.sheet-scaler { position: relative; margin: 0 auto; box-shadow: none; border: 1px solid var(--line-strong); background: #fff; }
.paper-wrap { transform-origin: 0 0; width: max-content; }
.paper-empty .soft-btn { margin-top: 16px; }

/* ---------- 通知 ---------- */

.toast {
  position: relative;
  z-index: 25;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  width: fit-content;
  max-width: min(640px, calc(100% - 24px));
  margin: 8px 12px 0;
  padding: 10px 16px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 0.88rem;
  line-height: 1.5;
  box-shadow: var(--shadow-float);
  cursor: pointer;
}
.toast[hidden] { display: none !important; }
.toast.is-warn-legacy { }
.toast-action {
  margin-left: 10px;
  min-height: 44px;
  padding: 4px 14px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
  font-weight: 700;
  white-space: nowrap;
}
.toast.is-warn .toast-action { background: rgba(0, 0, 0, 0.1); }
.inline-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--field);
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.5;
}
.inline-notice[hidden] { display: none !important; }
.inline-notice.is-warn { background: var(--primary-soft); color: var(--ink); }
.inline-notice .soft-btn { min-height: 40px; }
@media (min-width: 1000px) {
  /* 広い画面では浮かぶ案内を出さない。左の文章に重なるため */
  #toast { display: none !important; }
}

/* ---------- 印刷前の確認（画面内のダイアログ） ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80; /* 通知（60）や下の切り替え（40）より上 */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px calc(16px + env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
}
.modal-back { position: absolute; inset: 0; background: rgba(20, 17, 15, 0.46); }
.modal-card {
  position: relative;
  width: min(100%, 520px);
  max-height: min(84vh, 640px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 22px 22px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-float);
}
.modal-title { margin: 0 0 14px; font-size: 1.05rem; line-height: 1.5; }
.modal-warn {
  display: block;
  margin-bottom: 10px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  background: var(--primary-soft);
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1.7;
}
.modal-warn b { display: block; margin-bottom: 2px; font-size: 0.92rem; }
.modal-actions { display: flex; flex-direction: column; align-items: stretch; gap: 6px; margin-top: 16px; }
.modal-main { width: 100%; font-size: 1rem; }
.modal-sub {
  min-height: 44px;
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.modal-sub:hover { color: var(--ink); }

/* ---------- 小さい画面の調整 ---------- */

@media (max-width: 520px) { .stack-sm { grid-template-columns: 1fr; } }

@media (max-width: 520px) {
  .hero { padding-top: 10px; }
  .quick-actions { margin: 10px 0 8px; }
  .tool-body { padding-top: 12px; }
  .size-hint { margin-top: 6px; margin-bottom: 4px; }
}

@media (max-width: 720px) {
  .topbar { gap: 6px; padding-right: 6px; }
  .header-actions { flex: none; gap: 6px; }
  .brand-block { flex: 1 1 auto; min-width: 0; overflow: hidden; }
  .brand-name { overflow: hidden; text-overflow: ellipsis; }
  .lang-switch { flex: none; }
  .lang-switch button { white-space: nowrap; min-height: 36px; padding: 0 8px; }
  #printBtn { min-height: 36px; padding: 6px 10px; font-size: 0.78rem; }
  #printBtn .print-sub { display: none; }
}
@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; border-radius: 0; row-gap: 6px; }
  .brand-block { flex: 1 1 100%; overflow: visible; }
  .brand-name { overflow: visible; text-overflow: clip; }
  .header-actions { flex: 1 1 auto; width: 100%; justify-content: flex-end; }
}
@media (max-width: 420px) {
  .topbar { margin-inline: 0; padding-left: 10px; }
  .brand-name { font-size: 0.92rem; }
  .hero-sub { display: none; }
  .hero-sample { padding: 10px 6px 6px; }
  .hs-text { font-size: 1.05rem; }
  .hs-cap { display: none; }
  .workspace { padding-inline: 8px; }
  .tool-body, .panel { padding-inline: 14px; }
  .tile { min-height: 88px; padding: 11px 11px 9px; }
  .tile .sub { font-size: 0.66rem; }
  .tile strong { font-size: 0.96rem; }
  .grid-two { gap: 8px; }
  .preview-bar .primary-btn { margin-left: 0; flex: 1 0 100%; }
}

/* ---------- 印刷 ---------- */

#printArea { display: none; }

@media print {
  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
  }
  .app-shell, .toast, .site-footer, [data-sponsor], #supportScreen { display: none !important; }
  #printArea { display: block; margin: 0; padding: 0; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-sheet {
    overflow: hidden;
    width: var(--W);
    height: calc(var(--H) - var(--slack, 1.2mm));
    break-after: page;
    page-break-after: always;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  /* avoid は Safari が最後に空白ページを足すのを防ぐ。auto だと足すことがある */
  .print-sheet:last-child { break-after: avoid; page-break-after: avoid; }
  .paper { margin: 0 !important; box-shadow: none !important; }
}

.notice-fix { min-height: 44px; padding: 6px 16px; border-radius: 4px; background: var(--primary); color: #fff; font-weight: 700; white-space: nowrap; }
.toast.is-warn { background: var(--primary-soft); color: var(--ink); }

/* ---------- 問題の種類：用紙に出る形の絵で選ぶ ---------- */

.block-label { display: block; }
.type-cards, #typePills.pill-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.type-card {
  display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 4px;
  min-height: 0; min-width: 0; padding: 8px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: none;
  color: var(--ink); font-weight: 600; text-align: left;
  cursor: pointer;
}
.type-card:hover { border-color: var(--ink); }
.type-card.is-active, .pill-btn.type-card.is-active {
  background: var(--primary-soft); color: var(--ink);
  border-color: var(--primary);
  box-shadow: none;
}
.tc-name { font-size: 0.82rem; font-weight: 700; line-height: 1.35; word-break: keep-all; }
.tc-desc { font-size: 0.74rem; font-weight: 500; color: var(--muted); line-height: 1.4; }
.tc-change { margin-left: auto; align-self: center; font-size: 0.8rem; font-weight: 700; color: var(--primary); text-decoration: underline; }

.type-fold > summary.type-now {
  list-style: none; cursor: pointer;
  display: grid; grid-template-columns: 64px 1fr auto; grid-template-rows: auto auto; column-gap: 12px; align-items: center;
  padding: 8px 12px 8px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); box-shadow: none;
  min-height: 48px;
}
.type-fold > summary.type-now::-webkit-details-marker { display: none; }
.type-fold > summary .tv { grid-row: 1 / 3; }
.type-fold > summary .tc-name { align-self: end; }
.type-fold > summary .tc-desc { align-self: start; }
.type-fold > summary .tc-change { grid-column: 3; grid-row: 1 / 3; }
.type-fold[open] > summary.type-now { margin-bottom: 8px; }

/* 小さな見本（縦書き） */
.tv {
  display: flex; flex-direction: row-reverse; align-items: center; justify-content: center; gap: 3px;
  height: 66px; padding: 4px; border-radius: 4px; background: var(--field);
  overflow: hidden; box-sizing: border-box;
}
.type-fold > summary .tv { width: 64px; }
.tv-t {
  writing-mode: vertical-rl; font-family: "YuKyokasho", "UD Digi Kyokasho N-R", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  font-size: 12px; line-height: 1.05; font-weight: 700; color: var(--ink); white-space: nowrap;
  max-height: 100%; overflow: hidden;
}
.tv-t rt { font-size: 6px; font-weight: 600; }
.tv-u { font-style: normal; border-right: 1.5px solid var(--ink); }
.tv-b {
  display: inline-block; box-sizing: border-box; width: 13px; height: 13px;
  border: 1px solid var(--ink); background: #fff; font-style: normal;
}
.tv > .tv-b { display: block; }
.tv-t > .tv-b { vertical-align: top; }
.tv-m, .tv-g { font-size: 10px; line-height: 11px; text-align: center; font-weight: 700; color: var(--ink); }
.tv-g { color: #c9c4bb; }
.tv-word { align-self: center; font-size: 14px; font-weight: 700; color: var(--ink); writing-mode: vertical-rl; letter-spacing: 0.1em; }
.tv-dash { padding: 4px 3px; border: 1.5px dashed var(--muted); border-radius: 4px; }
.pill-btn.type-card { position: relative; }
.pill-btn.type-card.is-active::after {
  content: "✓"; position: absolute; top: 12px; right: 14px; font-size: 0.95rem; font-weight: 800; color: var(--primary);
}

/* 学年から作るときの種類は、最初の画面で「作る」ボタンを押し下げないよう、横並びの小さなカードにする */
#typePills.pill-group { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
#typePills .type-card {
  flex-direction: row; align-items: center; gap: 8px; min-height: 52px; padding: 4px 22px 4px 4px;
  overflow: hidden;
}
#typePills .type-card .tv { flex: none; width: 44px; height: 44px; padding: 3px 2px; }
#typePills .type-card .tv-t { font-size: 11px; }
#typePills .type-card .tc-desc { font-size: 0.64rem; line-height: 1.3; }
#typePills .type-card .tc-name { font-size: 0.74rem; }
#typePills .pill-btn.type-card.is-active::after {
  top: 3px; right: 3px; width: 16px; height: 16px; border-radius: 2px;
  display: grid; place-items: center; font-size: 0.62rem; line-height: 1; background: var(--primary); color: #fff;
}

.tc-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.type-fold > summary.type-now { grid-template-columns: 64px 1fr auto; grid-template-rows: auto; }
.type-fold > summary .tv { grid-row: auto; }
.type-fold > summary .tc-name, .type-fold > summary .tc-desc { align-self: auto; }
.type-fold > summary .tc-change { grid-column: auto; grid-row: auto; }
.tv-tall { height: 26px; }
@media (max-width: 520px) { .qi-types { grid-template-columns: 1fr; } }

/* 答えを書く場所（かっこ・線）の小さな絵 */
.tv-k { position: relative; display: block; width: 13px; height: 22px; }
.tv-k::before, .tv-k::after { content: ""; position: absolute; left: 0; right: 0; height: 7px; border: 1px solid var(--ink); }
.tv-k::before { top: 0; border-bottom: 0; border-radius: 6px 6px 0 0; }
.tv-k::after { bottom: 0; border-top: 0; border-radius: 0 0 6px 6px; }
.tv-ln { display: block; width: 0; height: 22px; border-left: 1.5px solid var(--ink); margin: 0 5px; }
.tv-k.tv-tk, .tv-ln.tv-tk { height: 34px; }

/* ---------- 筆順練習プリント（設定画面） ---------- */

.s-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 232px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  -webkit-overflow-scrolling: touch;
}
.s-chip {
  min-width: 42px; min-height: 42px; padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  box-shadow: none;
  color: var(--ink);
  font-size: 1.12rem; font-weight: 600; line-height: 1.1;
  cursor: pointer;
}
.s-chip:hover { border-color: var(--ink); }
.s-chip.is-on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); box-shadow: none; }

/* 筆順練習プリントは複数ページになる。用紙の枠をたてに並べる */
.sheet-scaler + .sheet-scaler { margin-top: 18px; }

/* 出典の表示（KANJIDIC2 は表示する画面ごとの記載が許諾条件。消さないこと） */
.data-credit { margin: 14px auto 0; max-width: 640px; text-align: left; }
.data-credit p { margin: 0 0 8px; color: var(--faint); font-size: 0.7rem; line-height: 1.7; word-break: break-word; }
.data-credit a { color: var(--faint); font-size: inherit; text-decoration: underline; }
.data-credit a:hover { color: var(--muted); }
