/* テストプリントメーカー スタイル。
   CSSは外部ファイル（public配下）に置くことで、Astroの<style>バンドルを通さず、
   印刷用の @page ルールをそのまま有効にしている（otayori と同じ方式）。
   シート内ブロックのスタイルは、画面プレビューの .tm-sheet と高さ計測用の .tm-measure の
   どちらの配下でも同じ見た目になるよう、両方に効く指定にしている（計測精度の担保）。 */

:root {
  --tm-ink: #1a1a1a;
  --tm-answer: #c0392b;
}

/* ===== 画面用 ===== */
.tm-desc {
  max-width: 1120px;
  margin: 0 auto 12px;
  padding: 0 4px;
  line-height: 1.8;
  color: #333;
}

.tm-layout {
  display: flex;
  gap: 28px;
  max-width: 1180px;
  margin: 24px auto 40px;
  padding: 0 4px;
  align-items: flex-start;
}

/* --- フォーム --- */
.tm-form {
  width: 400px;
  flex-shrink: 0;
  text-align: left;
}

.tm-form .fs-title {
  font-size: 15px;
  font-weight: 700;
  color: #333;
  margin: 22px 0 8px;
  padding-bottom: 5px;
  border-bottom: 2px solid var(--accent, #2a9d8f);
}

.tm-form .fs-title:first-child {
  margin-top: 0;
}

.tm-form label.fld-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #555;
  margin: 10px 0 4px;
}

.tm-form input[type='text'],
.tm-form textarea {
  width: 100%;
  box-sizing: border-box;
  font-size: 14px;
  color: #333;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  font-family: inherit;
}

.tm-form textarea {
  resize: vertical;
  line-height: 1.6;
}

.tm-form .radio-col {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 6px;
}

.tm-form .radio-col label {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 0;
  font-size: 13.5px;
  font-weight: normal;
  color: #333;
  cursor: pointer;
  line-height: 1.5;
}

.tm-form .radio-col input {
  width: auto;
  margin-top: 3px;
  flex-shrink: 0;
}

.tm-check-line {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin-top: 10px;
  font-size: 13.5px;
  color: #333;
  cursor: pointer;
  line-height: 1.5;
}

.tm-check-line input {
  margin-top: 2px;
  width: auto;
  flex-shrink: 0;
}

.tm-form .field-hint {
  font-size: 11.5px;
  color: #888;
  margin: 6px 0 0;
  line-height: 1.65;
}

.tm-md-help code,
.tool-guide code {
  background: #f1f3f5;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.92em;
  color: #c0392b;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.tm-btn-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 8px;
}

.tm-reset-line {
  margin-top: 24px;
}

.tm-sub-btn {
  padding: 7px 14px;
  font-size: 12.5px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  color: #555;
  cursor: pointer;
}

.tm-sub-btn:hover {
  border-color: var(--accent, #2a9d8f);
  color: var(--accent, #2a9d8f);
}

.tm-sub-btn.danger:hover {
  color: #c0392b;
  border-color: #c0392b;
}

.tm-storage-msg {
  font-size: 12px;
  color: #c0392b;
  margin: 8px 0 0;
  line-height: 1.6;
}

/* --- AIへの依頼文（コピー例） --- */
.tm-prompts {
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fafafa;
  padding: 0;
  margin: 10px 0 4px;
  text-align: left;
}

.tm-prompts > summary {
  cursor: pointer;
  padding: 11px 13px;
  font-size: 13.5px;
  font-weight: 600;
  color: #444;
  list-style: revert;
}

.tm-prompts[open] > summary {
  border-bottom: 1px solid #e5e5e5;
}

.tm-prompts-inner {
  padding: 12px 13px 14px;
}

.tm-prompt {
  margin-bottom: 14px;
}

.tm-prompt:last-child {
  margin-bottom: 0;
}

.tm-prompt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.tm-prompt-title {
  font-size: 12.5px;
  font-weight: 700;
  color: #444;
}

.tm-copy-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 12px;
  border: 1px solid var(--accent, #2a9d8f);
  border-radius: 6px;
  background: #fff;
  color: var(--accent, #2a9d8f);
  cursor: pointer;
}

.tm-copy-btn:hover,
.tm-copy-btn.is-copied {
  background: var(--accent, #2a9d8f);
  color: #fff;
}

.tm-prompt-text {
  margin: 0;
  padding: 10px 11px;
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.75;
  color: #333;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
}

/* --- プレビュー側 --- */
.tm-preview {
  flex: 1;
  min-width: 0;
  position: sticky;
  top: 16px;
  align-self: flex-start;
  text-align: center;
}

.tm-print-btn {
  width: 100%;
  background: var(--accent, #2a9d8f);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.tm-print-btn:hover {
  opacity: 0.85;
}

.tm-print-note {
  font-size: 12px;
  color: #888;
  margin: 8px 0 8px;
  line-height: 1.5;
}

.tm-page-count {
  font-size: 12.5px;
  color: #555;
  margin: 0 0 10px;
  font-weight: 600;
}

.tm-sheets {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tm-sheet-box {
  overflow: hidden;
  border-radius: 4px;
}

.tm-preview-caption {
  font-size: 12px;
  color: #888;
  margin-top: 10px;
}

/* 計測専用の隠しコンテナ（画面外に置いてブロックの高さを測る） */
.tm-measure {
  position: absolute;
  left: -99999px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ===== A4シート（プレビュー兼 印刷対象）＋ 計測コンテナの共通基礎 ===== */
.tm-sheet,
.tm-measure {
  width: 210mm;
  background: #fff;
  padding: 14mm;
  box-sizing: border-box;
  /* テスト用紙は事務的な書体が自然（題字用の手書き系フォントは使わない） */
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "YuGothic", "Meiryo", sans-serif;
  font-size: 10.5pt;
  color: var(--tm-ink);
  line-height: 1.7;
  text-align: left;
}

.tm-sheet {
  height: 297mm;
  transform-origin: top left;
  overflow: hidden;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.18);
  position: relative;
}

/* common.cssのレガシーグローバル（* { font-size:14px; color:#313838 } 等）対策 */
.tm-sheet *,
.tm-measure * {
  font-size: inherit;
  color: inherit;
  font-family: inherit;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* --- ヘッダー（タイトル・解答バッジ・名前欄・点数欄） --- */
.tm-head {
  display: flex;
  align-items: flex-end;
  gap: 6mm;
  padding-bottom: 3mm !important;
  border-bottom: 0.5mm solid var(--tm-ink);
  margin-bottom: 4mm;
}

.tm-head-title {
  flex-shrink: 0;
  max-width: 78mm;
}

.tm-test-title {
  font-size: 17pt;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.25;
  word-break: break-word;
}

.tm-test-sub {
  font-size: 9.5pt;
  color: #333;
  margin-top: 1mm;
  line-height: 1.4;
  word-break: break-word;
}

.tm-answer-badge {
  flex-shrink: 0;
  border: 0.5mm solid var(--tm-answer);
  color: var(--tm-answer) !important;
  font-size: 11pt;
  font-weight: 700;
  padding: 1mm 3mm !important;
  letter-spacing: 0.3em;
  line-height: 1.2;
  white-space: nowrap;
}

.tm-head-name {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 2.5mm;
  min-width: 0;
}

.tm-head-label {
  font-size: 9.5pt;
  color: #333;
  white-space: nowrap;
  padding-bottom: 0.5mm !important;
}

.tm-head-line {
  flex: 1;
  height: 9mm;
  border-bottom: 0.3mm solid var(--tm-ink);
}

.tm-head-score {
  flex-shrink: 0;
  width: 30mm;
  height: 14mm;
  border: 0.3mm solid var(--tm-ink);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  padding: 1mm 2mm !important;
}

.tm-score-space {
  flex: 1;
}

.tm-score-label {
  font-size: 9pt;
  color: #333;
}

/* 2枚目以降の見出し */
.tm-cont {
  font-size: 10pt;
  color: #333;
  padding-bottom: 2mm !important;
  border-bottom: 0.3mm solid #999;
  margin-bottom: 4mm;
}

/* --- 本文 --- */
.tm-unit {
  break-inside: avoid;
  page-break-inside: avoid;
}

/* 大問見出し */
.tm-daimon {
  font-size: 12pt;
  font-weight: 700;
  border-left: 1.4mm solid var(--tm-ink);
  padding: 0.4mm 0 0.4mm 2.6mm !important;
  margin: 4mm 0 2.4mm;
  line-height: 1.45;
  word-break: break-word;
}

.tm-unit:first-child .tm-daimon {
  margin-top: 0;
}

/* 説明文（番号にも見出しにも当てはまらない行） */
.tm-note {
  font-size: 10pt;
  line-height: 1.7;
  margin-bottom: 2mm;
  word-break: break-word;
}

/* 問題 */
.tm-q {
  margin-bottom: 2.6mm;
}

.tm-q-row {
  display: flex;
  align-items: flex-start;
  gap: 2mm;
}

.tm-q-no {
  flex-shrink: 0;
  width: 8mm;
  font-size: 11pt;
  line-height: 1.6;
  text-align: right;
}

.tm-q-body {
  flex: 1;
  min-width: 0;
}

.tm-q-text {
  font-size: 11pt;
  line-height: 1.6;
  word-break: break-word;
}

.tm-q-pt {
  font-size: 9pt;
  color: #444;
  white-space: nowrap;
  margin-left: 2mm;
}

/* 解答欄：下線（文章記述用・幅広） */
.tm-line {
  height: 9mm;
  border-bottom: 0.3mm solid var(--tm-ink);
  margin-top: 1mm;
  display: flex;
  align-items: flex-end;
}

/* 解答欄：括弧 */
.tm-paren {
  font-size: 11pt;
  white-space: nowrap;
  margin-left: 2mm;
}

.tm-paren-in {
  display: inline-block;
  min-width: 26mm;
  text-align: center;
  white-space: normal;
}

/* 解答（赤字） */
.tm-a {
  color: var(--tm-answer) !important;
  font-size: 11pt;
  line-height: 1.4;
  word-break: break-word;
}

.tm-line .tm-a {
  padding-left: 2mm !important;
  padding-bottom: 0.5mm !important;
}

.tm-a-inline {
  margin-left: 3mm;
  white-space: nowrap;
}

/* ページ番号 */
.tm-page-mark {
  position: absolute;
  right: 14mm;
  bottom: 6mm;
  text-align: right;
  font-size: 8pt;
  color: #555 !important;
}

/* ===== レスポンシブ ===== */
@media (max-width: 980px) {
  .tm-layout {
    flex-direction: column;
  }

  .tm-form {
    width: 100%;
  }

  .tm-preview {
    position: static;
    width: 100%;
  }
}

/* ===== 印刷用：プレビューのシートだけをA4に ===== */
@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    height: auto !important;
  }

  body > *:not(.container) {
    display: none !important;
  }

  .container {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
    width: auto !important;
  }

  .container > *:not(.tm-layout) {
    display: none !important;
  }

  .tm-layout {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
  }

  .tm-layout > *:not(.tm-preview) {
    display: none !important;
  }

  .tm-preview {
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
  }

  .tm-preview > *:not(.tm-sheets) {
    display: none !important;
  }

  .tm-sheets {
    display: block !important;
    gap: 0 !important;
    margin: 0 !important;
  }

  .tm-sheet-box {
    height: auto !important;
    margin: 0 !important;
    overflow: visible !important;
    border-radius: 0 !important;
  }

  .tm-sheet {
    transform: none !important;
    box-shadow: none !important;
    margin: 0 !important;
    width: 210mm !important;
    height: 296mm !important;
    overflow: hidden !important;
    page-break-after: always;
    break-after: page;
  }

  .tm-sheet-box:last-child .tm-sheet {
    page-break-after: auto;
    break-after: auto;
  }

  /* 背景色・赤字をブラウザの印刷設定に関係なく印刷する */
  .tm-sheet,
  .tm-sheet * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
