* { box-sizing: border-box; }
html, body { margin: 0; }

:root {
  --sheet-w: 210mm;
  --sheet-h: 297mm;
  --page-w: 190mm;
  --page-h: 276mm;
}

body {
  font-family: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Hiragino Sans", "Meiryo", sans-serif;
  background: #e8eaed;
  color: #202124;
}

#app { display: flex; height: 100vh; }

#sidebar {
  width: 486px;
  flex: none;
  background: #fff;
  border-right: 1px solid #dadce0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px 48px;
}

#preview { flex: 1; overflow: auto; padding: 20px; }

h1 { font-size: 17.5px; margin: 4px 0 4px; color: #0f766e; }
.subtitle { font-size: 11.5px; color: #5f6368; margin: 0 0 10px; line-height: 1.45; }

h2 {
  font-size: 13.5px;
  margin: 15px 0 8px;
  padding-left: 8px;
  border-left: 4px solid #0d9488;
}

button {
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  padding: 4px 8px;
}
button:hover { background: #f1f5f9; }

button.primary {
  background: #0d9488;
  border-color: #0d9488;
  color: #fff;
  font-weight: bold;
  padding: 6px 12px;
}
button.primary:hover { background: #0f766e; }

button.btn-issue {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  font-weight: bold;
}
button.btn-issue:hover { background: #1d4ed8; }

button.btn-print {
  background: #1e293b;
  border-color: #1e293b;
  color: #fff;
  font-weight: bold;
}
button.btn-print:hover { background: #0f172a; }

button.btn-save-stock {
  background: #fffbeb;
  border-color: #f59e0b;
  color: #92400e;
  font-weight: bold;
}
button.btn-save-stock:hover { background: #fef3c7; }

input[type=text], input[type=date], select, textarea {
  font: inherit;
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
}
#catalog-filter { width: 100%; margin-bottom: 6px; }

#stage-filter {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 8px;
}
#stage-filter button {
  font-size: 11px;
  padding: 5px 3px;
  line-height: 1.25;
  text-align: center;
}

.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; font-size: 12px; }
.muted { color: #5f6368; font-size: 11.2px; line-height: 1.4; }
.status { font-size: 12px; color: #0f766e; min-height: 1.4em; font-weight: bold; margin-top: 4px; }

.catalog-group summary { cursor: pointer; font-weight: bold; font-size: 12.8px; padding: 4px 0; color: #1e293b; }
.catalog-item-wrap { padding: 4px 6px; border-radius: 6px; }
.catalog-item-wrap:hover { background: #f8fafc; }
.catalog-item { display: flex; align-items: center; gap: 5px; font-size: 12.5px; }
.catalog-item .name { flex: 1; line-height: 1.35; }
.catalog-item .last { color: #64748b; font-size: 10.5px; width: 4.2em; text-align: right; }
.catalog-item.done .name { color: #94a3b8; text-decoration: line-through; }
.catalog-goal { font-size: 10.8px; color: #64748b; margin: 2px 0 0 28px; line-height: 1.35; }

.badge { display: inline-block; font-size: 10px; font-weight: bold; padding: 1px 5px; border-radius: 4px; flex: none; }
.badge-基礎 { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.badge-標準 { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.badge-発展 { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge-issued { background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; }
.badge-saved { background: #f3e8ff; color: #6b21a8; border: 1px solid #e9d5ff; }

.set-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 5px 6px;
  margin-bottom: 5px;
  background: #fff;
  font-size: 12px;
}
.set-item.dragging { opacity: 0.4; }
.set-item .handle { cursor: grab; color: #94a3b8; padding: 0 4px; }
.set-item .name { flex: 1; }
.set-item input[type=number] { width: 42px; text-align: center; font: inherit; }

.action-bar-box {
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 8px;
}
.action-grid-four {
  display: grid;
  grid-template-columns: 1.1fr 0.95fr 0.95fr 0.9fr;
  gap: 5px;
}
.action-grid-four button {
  padding: 7px 4px;
  font-size: 11.5px;
  text-align: center;
}

.panel-box {
  margin-top: 12px;
  border: 1px solid #dadce0;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fafafa;
  font-size: 12px;
}
.panel-box summary {
  cursor: pointer;
  font-weight: bold;
  color: #334155;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-body { margin-top: 8px; padding-top: 8px; border-top: 1px solid #e2e8f0; }

.archive-entry {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 7px 8px;
  margin-bottom: 6px;
}
.archive-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 3px; }
.archive-titles { font-size: 11.5px; color: #1e293b; margin-bottom: 5px; line-height: 1.35; }
.archive-actions { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.archive-actions button { font-size: 10.8px; padding: 2px 6px; }
.archive-transfer-row {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 5px;
  padding-top: 4px;
  border-top: 1px dashed #e2e8f0;
  font-size: 11px;
}
.archive-transfer-row select { font-size: 11px; padding: 2px 4px; }

/* 4人の学習者バー */
.learner-bar {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 7px 8px;
  margin-bottom: 10px;
}
.learner-bar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  font-weight: bold;
  color: #334155;
  margin-bottom: 5px;
}
.learner-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}
.learner-tabs button {
  font-size: 12px;
  padding: 5px 2px;
  border-radius: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.learner-tabs button.active-learner {
  background: #0f766e;
  border-color: #0f766e;
  color: #fff;
  font-weight: bold;
}
.learner-edit-panel {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #cbd5e1;
  font-size: 11.5px;
}
.learner-edit-row {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 5px;
  align-items: center;
  margin-bottom: 4px;
}

.smart-recommend-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
}
.smart-rec-head {
  font-size: 12px;
  font-weight: bold;
  color: #166534;
  margin-bottom: 6px;
}
.smart-rec-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}
.smart-rec-grid button {
  font-size: 11.5px;
  padding: 5px 3px;
  font-weight: bold;
}

.remedy-tree-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 8px;
  margin-top: 6px;
}
.remedy-cp-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 4px 0;
  border-bottom: 1px dashed #f3e8d2;
  font-size: 11.8px;
  line-height: 1.35;
}
.remedy-cp-item:last-child { border-bottom: none; }
.remedy-layer-tag {
  display: inline-block;
  font-size: 10px;
  background: #dcfce7;
  color: #166534;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
}

/* ---------- A4用紙プレビュー＆印刷完全一致レイアウト ---------- */
.sheet {
  width: var(--sheet-w);
  height: var(--sheet-h);
  padding: 10mm;
  margin: 0 auto 18px;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.page {
  width: var(--page-w);
  height: var(--page-h);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: #000;
}

body.font-maru .page {
  font-family: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Hiragino Sans", "Meiryo", sans-serif;
}
body.font-kyokasho .page {
  font-family: "UD デジタル 教科書体 NK-R", "UD Digi Kyokasho NK-R", "YuKyokasho Yoko", "Klee", "Hiragino Sans", sans-serif;
}
body.font-gothic .page {
  font-family: "BIZ UDPGothic", "BIZ UDPゴシック", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
}

.page-meta {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  font-size: 10pt;
  margin-bottom: 1.5mm;
}
.page-meta .meta-serial { color: #555; font-size: 8.5pt; font-family: monospace; }
.page-meta .meta-name { margin-left: auto; }
.page-meta .name-line {
  display: inline-block;
  width: 48mm;
  border-bottom: 1px solid #000;
  margin-left: 2mm;
}

.page-title {
  font-size: 16pt;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  border-bottom: 2px solid #0f766e;
  padding-bottom: 1.2mm;
  margin-bottom: 1.8mm;
}

.page-instruction {
  font-size: 9.4pt;
  line-height: 1.4;
  color: #1e293b;
  margin-bottom: 2.5mm;
}

.problems {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  row-gap: 4mm;
}

.item {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 2mm;
  border-bottom: 1px dashed #cbd5e1;
}
.item:last-child { border-bottom: none; }

.item-body {
  display: flex;
  align-items: flex-start;
  gap: 0.55em;
}

.qno {
  flex: none;
  font-weight: bold;
  line-height: 1.85;
}

.expr {
  flex: 1;
  min-width: 0;
  line-height: 1.92; /* ルビが重ならないゆとりの行間 */
  white-space: normal;
}

ruby { ruby-align: center; }
rt { font-size: 0.54em; color: #334155; line-height: 1; }

/* 広大な自由お絵かき・思考スペース（クロッキー帳感覚！） */
.thinking-workspace {
  flex: 1;
  min-height: 22mm;
  margin-top: 2mm;
  position: relative;
}
.workspace-watermark {
  position: absolute;
  right: 1.5mm;
  bottom: 0.5mm;
  font-size: 8pt;
  color: #cbd5e1;
  pointer-events: none;
}

/* カスタム導入イラスト（問題ページにONしたときのみ表示） */
.custom-prob-visual {
  margin-top: 2.5mm;
  max-width: 112mm;
  max-height: 58mm;
  overflow: hidden;
}
.custom-prob-visual svg,
.custom-prob-visual img {
  max-width: 100%;
  max-height: 55mm;
  width: auto;
  height: auto;
  display: block;
}

/* 解答・お手本お絵かきカード */
.ans-main {
  font-size: 1.06em;
  margin-bottom: 1.5mm;
}
.vis-card {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 5px 8px;
  margin: 2px 0;
  max-width: 100%;
}
.vis-caption {
  font-size: 0.85em;
  color: #1e293b;
  margin-bottom: 3px;
  line-height: 1.48;
}
.vis-svg-holder {
  margin: 2px 0;
}
.vis-svg-holder img {
  max-width: 115mm;
  max-height: 62mm;
  height: auto;
  display: block;
}
.vis-legend {
  font-size: 0.83em;
  color: #0f172a;
  line-height: 1.5;
  margin-top: 3px;
  line-break: strict;
  overflow-wrap: anywhere;
}
.parent-watch-memo {
  font-size: 0.77em;
  line-height: 1.42;
  color: #334155;
  background: #f0fdf4;
  border-left: 3px solid #16a34a;
  padding: 1.2mm 2.5mm;
  margin-top: 1.5mm;
  border-radius: 2px;
}
.ans-self-check {
  font-size: 0.74em;
  color: #475569;
  margin-top: 1.2mm;
  padding-top: 1mm;
  border-top: 1px dotted #cbd5e1;
}

.thinking-compass-box {
  margin-top: 4px;
  padding: 3px 7px;
  background: #f0fdfa;
  border-left: 3px solid #0d9488;
  border-radius: 3px;
  font-size: 0.84em;
  color: #115e59;
  line-height: 1.45;
}
.thinking-tag-pill {
  display: inline-block;
  background: #ccfbf1;
  color: #115e59;
  font-weight: bold;
  font-size: 0.84em;
  padding: 0.5px 5px;
  border-radius: 3px;
  margin-right: 4px;
}

/* ★画面専用（印刷時は完全非表示）：AIプロンプトコピー＆カスタムSVG/画像スタジオバー */
.screen-only-ai-bar {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
  margin: 3px 0 2px;
  padding: 3px 6px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 5px;
  font-size: 10.5px;
  font-family: "Hiragino Sans", sans-serif;
}
.screen-only-ai-bar button {
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 4px;
}
.ai-studio-drawer {
  margin: 4px 0;
  padding: 8px;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  font-size: 11px;
  font-family: "Hiragino Sans", sans-serif;
}
.ai-studio-drawer textarea {
  width: 100%;
  font-family: monospace;
  font-size: 11px;
  margin: 4px 0;
}

.diagram-svg { flex-shrink: 0; }

@media print {
  body { background: #fff; }
  #sidebar,
  .screen-only-ai-bar,
  .ai-studio-drawer {
    display: none !important;
  }
  #app { display: block; height: auto; }
  #preview { padding: 0; overflow: visible; }
  .workspace-watermark { color: #d0d5dc; }

  .sheet {
    width: auto;
    height: auto;
    padding: 0;
    margin: 0;
    box-shadow: none;
    overflow: visible;
    break-after: page;
    page-break-after: always;
  }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
}

/* トースト通知 ＆ AIセットアップモーダル（画面専用・印刷時は完全非表示） */
#toast-notice {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 9998;
  max-width: 440px;
  padding: 11px 16px;
  border-radius: 8px;
  background: #0f172a;
  color: #ffffff;
  font-size: 12.5px;
  line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  display: none;
}
#toast-notice.toast-error {
  background: #991b1b;
  border: 1px solid #fca5a5;
}
#toast-notice.toast-ok {
  background: #0f766e;
}

#ai-setup-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.ai-modal-card {
  background: #ffffff;
  width: 100%;
  max-width: 520px;
  border-radius: 12px;
  padding: 18px 22px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.3);
  font-size: 13px;
  line-height: 1.55;
}
.ai-modal-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: #0f766e;
}
.ai-step-list {
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 8px 0 12px;
  font-size: 12px;
}
.ai-step-list ol {
  margin: 4px 0 0;
  padding-left: 18px;
}

@media print {
  #toast-notice,
  #ai-setup-modal {
    display: none !important;
  }
}

/* カスタム・AI導入イラスト＆解説絵図のセンタリング・サイズ3段階切替 */
.custom-prob-visual {
  margin: 4mm auto 2mm !important;
  max-width: 100% !important;
  max-height: none !important;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.custom-prob-visual svg,
.custom-prob-visual img {
  display: block;
  margin: 0 auto;
  width: 100% !important;
  height: auto !important;
  border-radius: 8px;
}

/* サイズ段階：sm(控えめ95mm), lg(標準ワイド148mm), xl(直接描き込める特大178mm) */
.custom-prob-visual.vis-size-sm svg,
.custom-prob-visual.vis-size-sm img {
  max-width: 96mm !important;
  max-height: 48mm !important;
}
.custom-prob-visual.vis-size-lg svg,
.custom-prob-visual.vis-size-lg img {
  max-width: 150mm !important;
  max-height: 82mm !important;
}
.custom-prob-visual.vis-size-xl svg,
.custom-prob-visual.vis-size-xl img {
  max-width: 180mm !important;
  max-height: 118mm !important;
}

/* 解答ページ側も中央に大きくクッキリ表示 */
.ans-ai-svg-holder {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 2.5mm auto;
  width: 100%;
}
.ans-ai-svg-holder svg,
.ans-ai-svg-holder img {
  display: block;
  margin: 0 auto;
  width: 100% !important;
  max-width: 166mm !important;
  max-height: 108mm !important;
  height: auto !important;
  border-radius: 6px;
}

/* カスタム・AI導入イラスト＆解説絵図のセンタリング・サイズ3段階切替 */
.custom-prob-visual {
  margin: 4mm auto 2mm !important;
  max-width: 100% !important;
  max-height: none !important;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.custom-prob-visual svg,
.custom-prob-visual img {
  display: block;
  margin: 0 auto;
  width: 100% !important;
  height: auto !important;
  border-radius: 8px;
}

/* サイズ段階：sm(控えめ95mm), lg(標準ワイド148mm), xl(直接描き込める特大178mm) */
.custom-prob-visual.vis-size-sm svg,
.custom-prob-visual.vis-size-sm img {
  max-width: 96mm !important;
  max-height: 48mm !important;
}
.custom-prob-visual.vis-size-lg svg,
.custom-prob-visual.vis-size-lg img {
  max-width: 150mm !important;
  max-height: 82mm !important;
}
.custom-prob-visual.vis-size-xl svg,
.custom-prob-visual.vis-size-xl img {
  max-width: 180mm !important;
  max-height: 118mm !important;
}

/* 解答ページ側も中央に大きくクッキリ表示 */
.ans-ai-svg-holder {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 2.5mm auto;
  width: 100%;
}
.ans-ai-svg-holder svg,
.ans-ai-svg-holder img {
  display: block;
  margin: 0 auto;
  width: 100% !important;
  max-width: 166mm !important;
  max-height: 108mm !important;
  height: auto !important;
  border-radius: 6px;
}
