/* =========================================================================
   原稿用紙エディタ  単一HTML版  v2.0.0
   - 縦書き組版の正統化（英数字の縦中横・拗促音・句読点位置）
   - 禁則処理の強化（行頭禁則 + 行末禁則 + 分離禁止 + ぶら下げ常時ON）
   - 印刷ベース（@page）PDF に一本化（html2canvas/jsPDF は不使用）
   全クラスは .gke- プレフィックスでスコープ化
   ========================================================================= */

.gke-root {
  --gke-navy: #1e3a5f;
  --gke-gold: #d4af37;
  --gke-accent-dark: #b8941f;
  --gke-bg: #fafafa;
  --gke-text: #2c3e50;
  --gke-paper: #fffefa;
  --gke-line: #c8a428;
  --gke-line-strong: #c8a428;
  --gke-panel-width: 320px;
  --gke-furigana-w: 7px;
  --gke-paper-border-width: 1px;
  --gke-paper-padding: 0px;
  color: var(--gke-text);
  font-family: "BIZ UDPGothic", "M PLUS Rounded 1c", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  height: calc(100vh - 24px);
  line-height: 1.6;
  margin: 12px auto;
  max-height: 900px;
  max-width: min(1280px, calc(100vw - 24px));
  overflow: hidden;
}

.gke-root * { box-sizing: border-box; }

.gke-root .gke-app {
  background: var(--gke-bg);
  border: 1px solid #e9edf2;
  border-radius: 22px;
  box-shadow: 0 18px 40px rgba(30, 58, 95, 0.1);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.gke-root .gke-topbar {
  align-items: center;
  border-bottom: 1px solid #e9edf2;
  display: flex;
  flex: 0 0 auto;
  gap: 18px;
  justify-content: space-between;
  min-height: 72px;
  padding: 12px 20px;
}

.gke-root .gke-brand { min-width: 0; }

.gke-root .gke-kicker {
  color: var(--gke-gold);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0 0 2px;
}

.gke-root .gke-title {
  color: var(--gke-navy);
  font-size: clamp(1.24rem, 2.4vw, 1.75rem);
  line-height: 1.2;
  margin: 0;
}

.gke-root .gke-topbar-status {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  gap: 14px;
}

.gke-root .gke-page-label,
.gke-root .gke-print-page-label {
  color: var(--gke-navy);
  font-size: 1.05rem;
  font-weight: 800;
  white-space: nowrap;
}

.gke-root .gke-print-page-label {
  display: none;
  margin-bottom: 8px;
}

.gke-root .gke-button {
  appearance: none;
  background: #fff;
  border: 2px solid var(--gke-navy);
  border-radius: 999px;
  color: var(--gke-navy);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
  min-height: 42px;
  padding: 10px 16px;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.gke-root .gke-button:hover,
.gke-root .gke-button:focus-visible {
  background: var(--gke-navy);
  color: #fff;
  outline: none;
  transform: translateY(-1px);
}

.gke-root .gke-button:disabled {
  background: #eef1f5;
  border-color: #b6c0ca;
  color: #7d8793;
  cursor: not-allowed;
  transform: none;
}

.gke-root .gke-panel-open-button,
.gke-root .gke-print-button {
  background: var(--gke-navy);
  color: #fff;
}

.gke-root .gke-clear-button {
  background: #fff6f4;
  border-color: #d9544f;
  color: #b42318;
  grid-column: 1 / -1;
}

.gke-root .gke-clear-button:hover,
.gke-root .gke-clear-button:focus-visible {
  background: #b42318;
  border-color: #b42318;
  color: #fff;
}

.gke-root .gke-shell {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.gke-root .gke-stage {
  align-items: center;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 14px;
  justify-content: center;
  min-width: 0;
  overflow: hidden;
  padding: 16px 18px;
  transition: padding-right 0.24s ease;
}

.gke-root.is-panel-open .gke-stage {
  padding-right: calc(var(--gke-panel-width) + 18px);
}

.gke-root .gke-print-area {
  align-items: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 100%;
}

.gke-root .gke-paper-frame {
  align-items: center;
  background: #ffffff;          /* 用紙の周りの余白を白で明示 */
  border: 1px solid #e4e9ef;
  border-radius: 14px;
  box-shadow: 0 16px 36px rgba(44, 62, 80, 0.14);
  cursor: text;
  display: flex;
  justify-content: center;
  max-width: 100%;
  padding: 34px;                /* 原稿用紙の周りの余白（広め） */
  position: relative;
}

.gke-root .gke-paper {
  aspect-ratio: 1123 / 794; /* A4横比率 */
  background-color: var(--gke-paper);
  border: var(--gke-paper-border-width) solid var(--gke-line-strong);
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr)) calc(16px + var(--gke-furigana-w)) repeat(10, minmax(0, 1fr)); /* 11番目=中央余白(16px)＋ふりがな欄 */
  grid-template-rows: repeat(20, minmax(0, 1fr));
  height: auto;
  overflow: visible; /* 枠外ぶら下げ文字を下の余白に表示するため */
  padding: var(--gke-paper-padding);
  max-height: calc(100vh - 200px);
  position: relative;
  transition: width 0.24s ease;
  width: min(56vw, 700px);
}

.gke-root.is-paper-input-active .gke-paper-frame {
  box-shadow:
    0 0 0 3px rgba(30, 58, 95, 0.16),
    0 16px 36px rgba(44, 62, 80, 0.14);
}

.gke-root .gke-ghost-input {
  background: transparent;
  border: 0;
  caret-color: var(--gke-navy);
  color: transparent;
  font: inherit;
  height: auto;
  inset: calc(34px + var(--gke-paper-border-width));
  margin: 0;
  outline: none;
  overflow: hidden;
  padding: 0;
  pointer-events: none;
  position: absolute;
  resize: none;
  width: auto;
  z-index: 6;
}

.gke-root .gke-ghost-input::selection {
  background: rgba(30, 58, 95, 0.18);
}

/* 中央綴じ線：非表示（中央の空白マスはグリッド列としてそのまま残す） */
.gke-root .gke-paper::before {
  display: none;
}

.gke-root .gke-cell {
  color: #222;
  display: flex;
  flex-direction: row; /* 文字マス＋ふりがなマスを横並び */
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif CJK JP", "BIZ UDPMincho", serif;
  font-size: clamp(12px, 1.7vw, 20px);
  font-weight: 600;
  line-height: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.gke-root .gke-cell::after {
  border-top: 0.5px solid var(--gke-line);
  border-bottom: 0.5px solid var(--gke-line);
  border-left: 1.5px solid var(--gke-line-strong);
  border-right: 1.5px solid var(--gke-line-strong);
  content: "";
  inset: 0;
  pointer-events: none;
  position: absolute;
  z-index: 2;
}

/* 右端列のふりがな欄も枠内に表示する（全列でふりがな欄あり・マスの大きさは統一） */

/* 中央列（11列目）のふりがな欄：16pxの空白を保ったまま、左側にふりがな欄の帯を追加 */
.gke-root .gke-center-furigana {
  background: var(--gke-paper);
  border-left: 0.5px solid var(--gke-line);
  height: 100%;
  margin-right: 16px;          /* 中央の空白(16px)はそのまま維持 */
  pointer-events: none;
  width: var(--gke-furigana-w);
  z-index: 1;
}

.gke-root .gke-furigana {
  background: var(--gke-paper);
  border-left: 0.5px solid var(--gke-line);
  border-top: none;
  border-bottom: none;
  flex: 0 0 var(--gke-furigana-w);
  height: 100%;
  position: relative;
  z-index: 3;
}

.gke-root .gke-char {
  align-items: center;
  display: flex;
  flex: 1 1 0;
  height: 100%;
  justify-content: center;
  line-height: 0.95;
  padding: 2px 1px;
  position: relative;
  text-orientation: upright;
  white-space: pre;
  writing-mode: vertical-rl; /* 縦書き：右→左、上→下 */
  z-index: 3;
}

/* ===== 縦書き字形補正（構造Y：マスを保ったまま字形だけ補正） ===== */

/* 半角英数字：縦中横で正立。1〜2文字を1マスに重ねる */
.gke-root .gke-cell--alnum .gke-char {
  writing-mode: vertical-rl;
  text-orientation: upright;
}
.gke-root .gke-cell--alnum .gke-char .gke-tcy {
  text-combine-upright: all;        /* 縦中横：数字を横に並べて正立 */
  -webkit-text-combine: horizontal; /* 旧WebKit向け */
  letter-spacing: 0;
}

/* 拗促音（ゃゅょっ等）：マス内で少し小さく右上に寄せる */
.gke-root .gke-cell--small .gke-char {
  align-items: flex-start;
  justify-content: flex-start;
  font-size: 0.92em;
  padding-top: 1px;
  padding-right: 1px;
}

/* 句読点・閉じ括弧：マス内の右上へ寄せる */
.gke-root .gke-cell--punct .gke-char {
  align-items: flex-start;
  justify-content: flex-start;
  padding-top: 1px;
  padding-right: 1px;
}

/* 句読点＋閉じ括弧の組（。」など）：2文字をほぼ通常の大きさで、マスの右上に縦に並べる */
.gke-root .gke-cell--punct-combo .gke-char {
  align-items: flex-start;     /* 縦書きで上（＝書き始め側）に寄せる */
  font-size: 0.92em;
  justify-content: flex-start; /* 右寄せ（縦書きの行頭側） */
  letter-spacing: -0.02em;
  line-height: 0.9;
  padding: 1px 1px 0 0;
}

/* ダッシュ・三点リーダなどの連結文字：マスいっぱいに伸ばす */
.gke-root .gke-cell--dash .gke-char {
  font-size: 1.05em;
}

/* 選択中マス（カーソル位置）：ふりがな欄を含まない文字マスだけを赤枠に。
   線の太さは原稿用紙のマス線と同じ（上下0.5px／左右1.5px）。 */
.gke-root .gke-cell--cursor .gke-char::before {
  border-top: 0.5px solid #e23b3b;
  border-bottom: 0.5px solid #e23b3b;
  border-left: 1.5px solid #e23b3b;
  border-right: 1.5px solid #e23b3b;
  content: "";
  inset: 0;
  pointer-events: none;
  position: absolute;
  z-index: 5;
}

/* 枠外ぶら下げ文字（Word式）：最終マスの外側＝下の余白へぶら下げる */
.gke-root .gke-hang {
  align-items: flex-start;
  bottom: 0;
  display: none;
  height: 0;
  justify-content: center;
  pointer-events: none;
  position: absolute;
  right: 0;
  left: 0;
  text-orientation: upright;
  writing-mode: vertical-rl;
  z-index: 4;
}
.gke-root .gke-cell--has-hang .gke-hang {
  bottom: calc(-1 * var(--gke-hang-size, 0.9em));
  display: flex;
  font-size: 0.9em;
}
/* ぶら下げ文字を表示するため、最終行マスのはみ出しを許可 */
.gke-root .gke-cell--has-hang {
  overflow: visible;
}

.gke-root .gke-pager {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  justify-content: center;
}

/* ヘッダー内のページ送りボタンは小さめに */
.gke-root .gke-topbar-status .gke-pager .gke-button {
  font-size: 0.9rem;
  min-height: 38px;
  padding: 8px 14px;
}

.gke-root .gke-panel-backdrop {
  background: rgba(12, 24, 38, 0.18);
  border: 0;
  cursor: pointer;
  inset: 0;
  opacity: 0;
  padding: 0;
  pointer-events: none;
  position: absolute;
  transition: opacity 0.24s ease;
  z-index: 4;
}

.gke-root.is-panel-open .gke-panel-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.gke-root .gke-side-panel {
  background: #fff;
  border-left: 1px solid #e3e8ee;
  box-shadow: -18px 0 36px rgba(30, 58, 95, 0.12);
  display: flex;
  flex: 0 0 var(--gke-panel-width);
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  position: absolute;
  right: 0;
  top: 0;
  transform: translateX(100%);
  transition: transform 0.24s ease;
  width: var(--gke-panel-width);
  z-index: 5;
}

.gke-root.is-panel-open .gke-side-panel {
  transform: translateX(0);
}

.gke-root .gke-panel-header {
  align-items: center;
  border-bottom: 1px solid #e9edf2;
  display: flex;
  flex: 0 0 auto;
  gap: 12px;
  justify-content: space-between;
  min-height: 72px;
  padding: 12px 16px;
}

.gke-root .gke-panel-title {
  color: var(--gke-navy);
  font-size: 1.08rem;
  margin: 0;
}

.gke-root .gke-panel-close-button {
  min-height: 38px;
  padding: 8px 12px;
}

.gke-root .gke-panel-content {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.gke-root .gke-panel-section { flex: 0 0 auto; }

.gke-root .gke-input-label,
.gke-root .gke-panel-group-title {
  color: var(--gke-navy);
  display: block;
  font-weight: 800;
  margin: 0 0 8px;
}

.gke-root .gke-panel-group-title { font-size: 0.9rem; }

.gke-root .gke-text-input {
  border: 2px solid #cbd5df;
  border-radius: 14px;
  color: var(--gke-text);
  display: block;
  font: inherit;
  height: 220px;
  max-height: 26vh;
  min-height: 130px;
  overflow: auto;
  padding: 12px;
  resize: none;
  width: 100%;
}

.gke-root .gke-text-input:focus {
  border-color: var(--gke-navy);
  box-shadow: 0 0 0 4px rgba(30, 58, 95, 0.12);
  outline: none;
}

.gke-root .gke-meta {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.gke-root .gke-meta span {
  background: #f2f5f8;
  border-radius: 12px;
  color: var(--gke-navy);
  font-weight: 700;
  padding: 6px 10px;
}

.gke-root .gke-panel-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.gke-root .gke-panel-actions .gke-panel-group-title { grid-column: 1 / -1; }

/* 確認モーダル（confirm 代替・iOS WKWebView 対応） */
.gke-root .gke-confirm-modal {
  align-items: center;
  background: rgba(12, 24, 38, 0.48);
  display: flex;
  inset: 0;
  justify-content: center;
  position: absolute;
  z-index: 20;
}

.gke-root .gke-confirm-modal[hidden] { display: none !important; }

.gke-root .gke-confirm-box {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(12, 24, 38, 0.35);
  max-width: 420px;
  padding: 22px 22px 18px;
  width: calc(100% - 48px);
}

.gke-root .gke-confirm-message {
  color: var(--gke-text);
  font-size: 1.02rem;
  font-weight: 700;
  margin: 0 0 16px;
  white-space: pre-line;
}

.gke-root .gke-confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.gke-root .gke-confirm-ok {
  background: var(--gke-navy);
  color: #fff;
}

/* ===== レスポンシブ ===== */
@media (max-width: 920px) {
  .gke-root.is-panel-open .gke-stage { padding-right: 18px; }
  .gke-root .gke-side-panel {
    border-left: 0;
    border-top: 1px solid #e3e8ee;
    bottom: 0;
    flex: none;
    height: 68vh;
    left: 0;
    right: 0;
    top: auto;
    transform: translateY(100%);
    width: 100%;
  }
  .gke-root.is-panel-open .gke-side-panel { transform: translateY(0); }
  .gke-root .gke-paper { width: min(82vw, 720px); }
}

@media (max-width: 480px) {
  .gke-root .gke-topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .gke-root .gke-topbar-status {
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
    width: 100%;
  }
  .gke-root .gke-panel-actions { grid-template-columns: 1fr; }
  .gke-root .gke-topbar-status .gke-pager { flex: 1 1 auto; }
}

/* ===== 印刷（@page）ベースのPDF ===== */
@page {
  size: A4 landscape;
  margin: 0; /* 印刷ダイアログの余白設定（なし/最小等）に左右されないよう、
                ページ自体の余白はゼロにして、用紙側にmm単位の余白を持たせる */
}

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

  body * { visibility: hidden !important; }

  .gke-root,
  .gke-root .gke-shell,
  .gke-root .gke-stage,
  .gke-root .gke-print-area,
  .gke-root .gke-print-area * { visibility: visible !important; }

  .gke-root {
    display: block !important;
    height: auto !important;
    margin: 0 !important;
    max-height: none !important;
    max-width: none !important;
    overflow: visible !important;
    width: auto !important;
  }

  .gke-root .gke-app {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  .gke-root .gke-topbar,
  .gke-root .gke-pager,
  .gke-root .gke-panel-backdrop,
  .gke-root .gke-side-panel,
  .gke-root .gke-confirm-modal,
  .gke-root .gke-ghost-input { display: none !important; }

  .gke-root .gke-shell {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  .gke-root .gke-stage {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  /* 静的フロー（絶対配置をやめてページ内に正しく流す）。
     縦方向は中央揃えにして、中身の実際の高さに関わらず
     上下の余白が自動的に均等になるようにする（mm決め打ちの計算ズレを避ける）。 */
  .gke-root .gke-print-area {
    align-items: center !important;
    box-sizing: border-box;
    display: flex !important;
    flex-direction: column !important;
    height: 210mm !important;   /* A4横の全体サイズ */
    justify-content: center !important;
    left: auto !important;
    margin: 0 !important;
    padding: 10mm !important;   /* ページ端からの最低限の余白（上下左右） */
    position: static !important;
    top: auto !important;
    transform: none !important;
    width: 297mm !important;
  }

  .gke-root .gke-paper-frame {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;  /* 画面表示用の影を印刷時は完全に打ち消す */
    display: block !important;
    flex: 0 0 auto;
    margin: 0 auto !important;
    padding: 0 !important;
  }

  .gke-root .gke-print-page-label {
    display: none !important; /* 印刷時はページ表記を出さない */
  }

  .gke-root .gke-paper {
    aspect-ratio: 1123 / 794 !important; /* 画面表示と同じ比率を維持して高さを自動計算 */
    box-shadow: none !important;
    break-inside: avoid;
    height: auto !important;
    margin: 0 auto !important;
    max-height: none !important;
    overflow: visible !important;
    page-break-inside: avoid;
    width: 250mm !important;
  }

  .gke-root .gke-char { color: #000 !important; }
}