
    :root {
      --primary: #2563eb;
      --primary-hover: #1d4ed8;
      --primary-light: #eff6ff;
      --surface: #ffffff;
      --bg-workspace: #f1f5f9;
      --border: #e2e8f0;
      --border-focus: #cbd5e1;
      --text-main: #0f172a;
      --text-muted: #64748b;
      --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
      --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
      --shadow-lg: 0 10px 25px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
      --radius-sm: 6px;
      --radius-md: 10px;
      --radius-lg: 16px;
    }

    /* UIフォントは端末標準(システムフォント)のみ。Webフォントは読み込まない(通信・キャッシュ 0KB)。
       言語ごとに先頭の書体を切り替え、字形(日本語/中国語/韓国語の漢字の違い)を正しく出す */
    :root { --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK JP", Roboto, "Helvetica Neue", Arial, sans-serif; }
    :root:lang(ko) { --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK KR", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
    :root:lang(zh-Hans), :root:lang(zh-CN) { --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Segoe UI", Roboto, Arial, sans-serif; }
    :root:lang(zh-Hant), :root:lang(zh-TW) { --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", "Noto Sans CJK TC", "Segoe UI", Roboto, Arial, sans-serif; }
    * { box-sizing: border-box; margin: 0; padding: 0; font-family: var(--font-ui); }
    html { overscroll-behavior: none; height: 100%; overflow: hidden; }
    body { background: var(--bg-workspace); color: var(--text-main); height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; overscroll-behavior: none; -webkit-font-smoothing: antialiased; }

    /* ヘッダー */
    header {
      background: rgba(255, 255, 255, 0.95);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      height: 52px;
      border-bottom: 1px solid var(--border);
      display: flex; align-items: center; justify-content: space-between; padding: 0 16px; flex-shrink: 0;
      position: sticky; top: 0; z-index: 200;
    }
    .logo-area { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 0.95rem; letter-spacing: -0.02em; color: var(--text-main); }
    .logo-sub { font-size: 11px; font-weight: 700; color: #64748b; margin-left: 2px; align-self: center; white-space: nowrap; }
    @media (max-width: 768px) { .logo-sub { display: none; } }

    /* ヘッダーの作業モード表示バッジ: 書類操作中/スタンプ編集中/連続押印中を一目で分かるようにする */
    .header-status-badge {
      display: inline-flex; align-items: center; gap: 4px;
      font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
      border: 1px solid; margin-left: 8px; white-space: nowrap; transition: all 0.2s ease;
    }
    /* 状態表示はボタンに見えないよう、枠・背景・影なしの小さな文字にする(押せる物と誤解させない) */
    #headerStatusBadge.header-status-badge { background: transparent !important; border: none !important; box-shadow: none !important; padding: 0; border-radius: 0; cursor: default; pointer-events: none; user-select: none; font-weight: 600; }
    .header-status-badge.mode-doc { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }
    .header-status-badge.mode-stamp { background: #f5f3ff; color: #7c3aed; border-color: #c4b5fd; box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.12); }
    .header-status-badge.mode-rapid { background: #eff6ff; color: #2563eb; border-color: #93c5fd; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12); }
    @media (max-width: 600px) {
      .header-status-badge { font-size: 10px; padding: 2px 7px; margin-left: 4px; }
    }
    /* ★小型スマホ(〜430px)でロゴ「Pop-A-Sign」が2〜3行に折れ、保存ボタンが画面外にはみ出す問題の対策:
       ロゴは折り返し禁止、モードバッジは非表示(下部バーとツールバーで状態は分かる)、
       さらに狭い端末(〜360px)ではガイドボタンを❓アイコンのみにして保存ボタンを優先して残す */
    .logo-area, .logo-area > span:first-child { white-space: nowrap; flex-shrink: 0; }
    @media (max-width: 430px) {
      .header-status-badge { display: none; }
    }
    @media (max-width: 360px) {
      #txt-header-guide-label { display: none; }
      .logo-area { font-size: 0.8rem; }
    }
    .logo-badge { background: linear-gradient(135deg, #2563eb, #3b82f6); color: #fff; padding: 2px 5px; border-radius: 4px; font-size: 0.65rem; font-weight: 700; }
    .header-right { display: flex; align-items: center; gap: 8px; }

    /* ★ヘッダー右側(言語セレクター/ガイド/保存・共有)はロゴの視覚的ボリュームに合わせて
       min-height:36pxに揃え、headerのalign-items:centerで縦中央に整列させる(追加指示対応) */
    .lang-select-box { position: relative; display: inline-flex; align-items: center; min-height: 36px; }
    .lang-select-box select {
      appearance: none; -webkit-appearance: none;
      background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius-sm);
      padding: 5px 20px 5px 8px; font-size: 0.75rem; font-weight: 600; color: var(--text-main);
      cursor: pointer; outline: none; height: 36px; box-sizing: border-box;
    }
    .lang-select-box::after {
      content: "▾"; position: absolute; right: 7px; font-size: 0.65rem; color: var(--text-muted); pointer-events: none;
    }

    /* B: ヘッダーの設定ボタン(今の言語を必ず出す「🌐 EN ⚙」)と設定パネル(ポップオーバー)。言語セレクタはパネルの中 */
    .btn-header-settings {
      display: inline-flex; align-items: center; gap: 3px; min-height: 36px; padding: 0 8px; box-sizing: border-box;
      background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius-sm);
      font-size: 0.75rem; font-weight: 700; color: var(--text-main); white-space: nowrap; line-height: 1.15; flex-shrink: 0; box-shadow: none;
    }
    .btn-header-settings:hover { transform: none; }
    #settingsPanel { position: fixed; inset: 0; z-index: 1700; background: transparent; }
    .settings-popover {
      position: absolute; top: 52px; right: 8px; width: min(300px, calc(100vw - 16px)); box-sizing: border-box;
      max-height: calc(100dvh - 60px); overflow-y: auto; padding: 4px 14px 14px;
      background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    }
    .settings-head { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
    .settings-head h2 { font-size: 0.95rem; font-weight: 800; color: var(--text-main); margin: 0; }
    .settings-head .app-close-x { margin-right: -10px; }
    .settings-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; font-size: 0.82rem; font-weight: 700; color: var(--text-main); }
    .settings-row .lang-select-box select { font-size: 0.82rem; padding-left: 12px; min-width: 76px; }
    .settings-seg { display: inline-flex; border: 1px solid var(--border-focus); border-radius: var(--radius-sm); overflow: hidden; }
    .settings-seg button {
      border: none; border-radius: 0; box-shadow: none; padding: 0 9px; min-height: 36px; font-size: 0.74rem; font-weight: 700;
      background: var(--surface); color: var(--text-main); border-right: 1px solid var(--border-focus); transform: none;
    }
    .settings-seg button:last-child { border-right: none; }
    .settings-seg button[aria-checked="true"] { background: var(--primary); color: #fff; }
    .settings-seg button[aria-checked="true"]:hover { background: var(--primary); }
    .settings-share { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; gap: 8px; }
    .settings-share-title { font-size: 0.82rem; font-weight: 800; color: var(--text-main); }
    .settings-qr { width: 148px; height: 148px; padding: 8px; box-sizing: border-box; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; }
    .settings-qr img, .settings-qr canvas { width: 132px; height: 132px; }
    .settings-url { font-size: 0.74rem; color: var(--text-muted); word-break: break-all; text-align: center; user-select: all; }
    .settings-copy { min-height: 36px; padding: 0 14px; font-size: 0.78rem; }

    .btn-header-guide {
      background: #eff6ff; color: var(--primary); border: 1px solid #bfdbfe; border-radius: var(--radius-sm);
      padding: 0 10px; min-height: 36px; font-size: 0.78rem; font-weight: 700; display: inline-flex; align-items: center; gap: 4px;
      cursor: pointer; transition: all 0.15s; white-space: nowrap;
    }
    .btn-header-guide:hover { background: #dbeafe; }

    .btn-header-save {
      background: var(--primary); color: #fff; border: none; border-radius: var(--radius-sm);
      padding: 0 14px; min-height: 36px; font-size: 0.82rem; font-weight: 700; display: flex; align-items: center; gap: 4px;
      cursor: pointer; box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25); white-space: nowrap;
    }
    .btn-header-save:hover { background: var(--primary-hover); }

    /* メインコンテナ */
    .main-container {
      display: flex; flex: none; overflow: hidden; position: relative;
      height: calc(100vh - 52px);
      height: calc(100dvh - 52px); /* モバイルのアドレスバー分を正確に考慮 */
    }

    /* サイドバー (PC用) */
    .sidebar {
      width: 320px; background: var(--surface); border-right: 1px solid var(--border);
      display: flex; flex-direction: column; padding: 16px 14px; gap: 14px; overflow-y: auto; flex-shrink: 0;
      align-self: stretch; height: auto; min-height: 0;
    }
    .section-title { font-size: 0.72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }

    button {
      cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text-main);
      padding: 8px 12px; border-radius: var(--radius-sm); font-size: 0.82rem; font-weight: 600;
      display: flex; align-items: center; justify-content: center; gap: 6px; transition: all 0.15s ease;
      box-shadow: var(--shadow-sm);
    }
    button:hover { background: #f8fafc; border-color: var(--border-focus); transform: translateY(-1px); }
    button:active { transform: translateY(0); }
    button.btn-primary {
      background: var(--primary); color: #fff; border: none; font-weight: 600;
      box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
    }
    button.btn-primary:hover { background: var(--primary-hover); }

    /* カラーピッカー */
    .color-picker-row { display: flex; align-items: center; gap: 6px; }
    .color-circle-btn {
      width: 20px; height: 20px; border-radius: 50%; border: 2px solid #fff;
      box-shadow: 0 0 0 1px var(--border); cursor: pointer; padding: 0; transition: transform 0.15s;
    }
    .color-circle-btn:hover { transform: scale(1.15); }
    .color-circle-btn.active { box-shadow: 0 0 0 2px var(--primary); transform: scale(1.15); }

    /* オプションカード */
    .option-card {
      background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius-md);
      padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
    }
    .opt-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.78rem; }
    .opt-label { font-weight: 600; color: var(--text-muted); min-width: 65px; }
    .segmented-control {
      display: flex; background: #e2e8f0; border-radius: 7px; padding: 2px; flex: 1; justify-content: flex-end;
    }
    .segmented-control label {
      flex: 1; text-align: center; padding: 4px 6px; font-size: 0.72rem; font-weight: 600;
      cursor: pointer; border-radius: 5px; transition: all 0.15s; color: var(--text-muted); user-select: none;
    }
    .segmented-control input[type="radio"] { display: none; }
    .segmented-control input[type="radio"]:checked + span {
      background: #fff; color: var(--text-main); box-shadow: var(--shadow-sm); display: block; border-radius: 5px;
    }
    .segmented-control span { display: block; padding: 1px 0; }

    /* プリセットクイックタグ */
    .preset-chip-group { display: flex; flex-wrap: wrap; gap: 4px; }
    .preset-chip {
      padding: 3px 8px; font-size: 11px; font-weight: 600; border-radius: 12px;
      border: 1px solid var(--border); background: #fff; cursor: pointer; color: var(--text-muted);
    }
    .preset-chip:hover { border-color: var(--primary); color: var(--primary); }

    /* プレビュー表示ラッパー */
    .preview-wrapper {
      flex: 1; display: flex; flex-direction: column; height: 100%; position: relative; overflow: hidden;
    }

    /* 完全固定ツールバー */
    .sticky-toolbar-bar {
      display: none; height: 48px; flex-shrink: 0; z-index: 100;
      background: rgba(255, 255, 255, 0.96);
      backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
      border-bottom: 1px solid var(--border);
      padding: 0 12px; align-items: center; justify-content: center; gap: 6px;
      box-shadow: 0 2px 6px rgba(0,0,0,0.04);
      position: sticky; top: 0;
    }
    /* U7: 画面上部の固定バー(#toolbar-top)。背景の灰色(#f1f5f9)に対して白いバー・薄い縁取り(#e2e8f0)が 1.1〜1.2:1 で境目が見えにくかったので、
       背景・縁取り・影と、中立なボタン(回す・戻す・書類を編集・拡大 −＋)の枠線を、下部バー(U6)と同じ値にする。青(フィット・ページ番号)・赤(全消し)は変えない */
    .sticky-toolbar-bar#toolbar-top { background: rgba(241, 245, 249, 0.96); border-bottom: 1px solid #748399; box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12); }
    #toolbar-top #btn-rotate-doc, #toolbar-top #btn-undo, #toolbar-top #btn-doc-edit,
    #toolbar-top .tb-zoom-capsule > button:not(#btn-fit-doc),
    #toolbar-top #btn-rotate-doc:hover, #toolbar-top #btn-undo:hover, #toolbar-top #btn-doc-edit:hover,
    #toolbar-top .tb-zoom-capsule > button:not(#btn-fit-doc):hover { border-color: #748399; }
    /* overflow:hidden の親があると sticky が親の中でしか効かず、ヘッダー下に52pxの隙間ができていた。
       clip なら「スクロール領域」を作らないので、ヘッダー直下に密着したまま画面固定になる。 */
    @supports (overflow: clip) {
      .main-container, .preview-wrapper { overflow: clip; }
      /* clip はスクロール領域ではないため、幅の最小値が中身(書類)に引っ張られないよう明示する */
      .preview-wrapper { min-width: 0; }
      .sticky-toolbar-bar { top: 52px; }
    }
    .controls-group { display: flex; align-items: center; gap: 4px; }
    /* 折り返し時にバラけないよう、関連ボタンをひとまとまりにする */
    .btn-group { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }

    /* ページ番号タップ時のクイックメニュー(先頭/最終へジャンプ・全ページ一覧) */
    .page-quick-menu {
      /* #propColorPopupと同じ理由でposition:fixed + body直下へ移動して配置する:
         position:absoluteのままだと.preview-wrapper(overflow:clip)の重なり順に巻き込まれ、
         書類プレビューの下に隠れてタップ不能になっていたため */
      display: none; position: fixed; background: #fff; border: 1px solid var(--border);
      border-radius: var(--radius-md); box-shadow: 0 8px 20px rgba(15, 23, 42, 0.18);
      padding: 5px; z-index: 1200; min-width: 190px;
    }
    .page-quick-menu.open { display: flex; flex-direction: column; gap: 2px; }
    .page-quick-menu button {
      display: flex; align-items: center; gap: 8px; justify-content: flex-start; width: 100%;
      padding: 8px 10px; font-size: 0.78rem; font-weight: 700; border: none; box-shadow: none; background: transparent;
      color: var(--text-main); white-space: nowrap;
    }
    .page-quick-menu button:hover { background: #f1f5f9; transform: none; }

    /* ページ番号表示(#page-num-indicator): 単なるラベルではなく「タップできるドロップダウン」
       であることが直感的に伝わるよう、青系のボタンらしい見た目にする */
    #page-num-indicator {
      font-size: 11.5px !important;
      font-weight: 800 !important;
      min-width: 48px !important;
      padding: 5px 8px !important;
      background: #eff6ff !important;
      border: 1px solid #bfdbfe !important;
      border-radius: var(--radius-sm) !important;
      color: #1d4ed8 !important;
      cursor: pointer;
      transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    }
    #page-num-indicator:hover,
    #page-num-indicator:active {
      background: #dbeafe !important;
      border-color: #93c5fd !important;
      color: #1e40af !important;
    }

    /* 全ページサムネイル一覧モーダル */
    .page-grid-body {
      display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px;
      overflow-y: auto; padding: 2px; margin: -2px;
    }
    .page-grid-cell {
      position: relative; display: flex; flex-direction: column; gap: 4px;
      padding: 6px; border: 2px solid var(--border); border-radius: var(--radius-md); background: #f8fafc;
      box-shadow: none;
    }
    .page-grid-cell:hover { border-color: #93c5fd; }
    .page-grid-cell.current { border-color: var(--primary); background: #eff6ff; box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15); }
    .pgc-jump {
      position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
      width: 100%; padding: 0; border: none; background: transparent; box-shadow: none; cursor: pointer;
    }
    .pgc-jump:hover { background: transparent; transform: none; }
    .pgc-thumb-wrap {
      width: 100%; aspect-ratio: 3 / 4; background: #fff; border: 1px solid var(--border); border-radius: 6px;
      overflow: hidden; display: flex; align-items: center; justify-content: center;
    }
    .pgc-thumb-wrap img { width: 100%; height: 100%; object-fit: contain; }
    .pgc-spinner {
      width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid #dbeafe; border-top-color: var(--primary);
      animation: pgc-spin 0.8s linear infinite;
    }
    @keyframes pgc-spin { to { transform: rotate(360deg); } }
    .pgc-num { font-size: 0.72rem; font-weight: 800; color: var(--text-main); }
    .pgc-badge {
      position: absolute; top: 4px; right: 4px; font-size: 0.68rem; background: #fff7ed; color: #c2410c;
      border: 1px solid #fed7aa; border-radius: 999px; padding: 1px 5px; font-weight: 800; line-height: 1.4;
    }
    .pgc-del-btn {
      width: 100%; padding: 5px; font-size: 0.7rem; font-weight: 700; color: #ef4444;
      border: 1px solid #fecaca; background: #fff; box-shadow: none;
    }
    .pgc-del-btn:hover { background: #fef2f2; border-color: #fca5a5; }
    /* ページの並べ替え: PCはサムネイルのドラッグ＆ドロップ、タッチ端末は「← 前へ」「後ろへ →」ボタン */
    .page-grid-hint { font-size: 0.74rem; color: var(--text-muted); margin: -4px 0 8px; line-height: 1.5; }
    .page-grid-cell[draggable="true"] { cursor: grab; }
    .page-grid-cell.pgc-dragging { opacity: 0.4; }
    .page-grid-cell.pgc-drop-before { box-shadow: -5px 0 0 0 var(--primary); }
    .page-grid-cell.pgc-drop-after { box-shadow: 5px 0 0 0 var(--primary); }
    .pgc-move-row { display: flex; gap: 4px; }
    .pgc-move-btn {
      flex: 1 1 0; min-width: 0; min-height: 36px; padding: 4px 2px; font-size: 0.7rem; font-weight: 800; color: var(--primary);
      border: 1px solid #bfdbfe; background: #fff; box-shadow: none; border-radius: 8px; white-space: nowrap;
    }
    .pgc-move-btn:disabled { opacity: 0.35; cursor: default; }
    /* スマホ幅: 1画面に4ページほど見えるよう2列・小さめのサムネイルにし、操作ボタンは
       「←」「🗑」「→」のアイコンだけの1行(高さ40px以上)にまとめる(文言はaria-labelに入れる) */
    @media (max-width: 600px) {
      .page-grid-body { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
      .page-grid-cell { padding: 5px; gap: 4px; }
      .pgc-thumb-wrap { aspect-ratio: auto; height: clamp(80px, 15vh, 118px); }
      .pgc-move-row { gap: 4px; }
      .pgc-move-row .pgc-move-btn, .pgc-move-row .pgc-del-btn { flex: 1 1 0; min-width: 0; min-height: 40px; padding: 0; font-size: 16px; border-radius: 8px; }
      .page-grid-cell > .pgc-del-btn { min-height: 40px; }
    }
    /* 書類編集パネル(z-index:1500)から開いたときも、一覧がパネルの下に隠れないようにする */
    body.doc-edit-mode #pageGridModal { z-index: 1600; }
    .toolbar-divider { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
    /* 「すべて消す」は拡大縮小ボタンの隣に置かず、区切り線を挟んでツールバーの右端へ離す(押し間違い防止) */
    @media (min-width: 769px) {
      #default-top-controls { width: 100%; }
      #tag-screen-tool { margin-left: auto; }
      #tb-clear-divider { margin-left: auto; height: 24px; }
    }

    /* 消去ボタン: 右グループ内にインライン配置(以前は右上絶対配置だったが、
       1段レイアウト圧縮のため通常のツールバーボタンとして行内に統合) */
    .btn-clear-corner {
      min-width: 36px; height: 36px; padding: 0 8px !important; font-size: 13.5px !important; flex-shrink: 0;
      white-space: nowrap;
    }
    @media (max-width: 400px) {
      .btn-clear-corner { width: 32px; padding: 0 !important; }
    }
    /* スタンプ操作中は画面ツール側のボタンなので隠す(消し忘れ修正) */
    .sticky-toolbar-bar.stamp-mode .btn-clear-corner { display: none !important; }

    /* 画面ツール/スタンプツールのラベル(通常フロー内に配置し、はみ出し・重なりを防ぐ) */
    .toolbar-tag {
      display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0;
      font-size: 10.5px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
    }
    .tag-screen { background: #f1f5f9; color: #64748b; }
    .tag-stamp { background: #f5f3ff; color: #7c3aed; }

    /* ボタンを押すと枠が光るギミック */
    @keyframes btnPressFlash {
      0%   { box-shadow: 0 0 0 0 rgba(124, 58, 237, 0.7); }
      100% { box-shadow: 0 0 0 8px rgba(124, 58, 237, 0); }
    }
    .sticky-toolbar-bar button, .mobile-bottom-bar button {
      transition: transform 0.08s ease;
    }
    .sticky-toolbar-bar button:active, .mobile-bottom-bar button:active {
      transform: scale(0.94);
    }
    .btn-press-flash { animation: btnPressFlash 0.5s ease-out; }

    /* スタンプ選択時の操作バー：巨大な四角形を廃止し、連続押印バーと揃えた薄型ピル型カプセルに統一する */
    #stamp-prop-toolbar {
      position: fixed;
      display: none;
      z-index: 150;
      transform: translateX(-50%) !important;
      white-space: nowrap;
      align-items: center;
      gap: 5px;
      background: rgba(241, 245, 249, 0.96);   /* U7: 白い書類の上でも見えるよう、下部バー(U6)と同じ薄い青灰色・濃い縁取り・濃い影にする */
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      border: 1px solid #748399;
      border-radius: 999px;   /* 完全なカプセル形状 */
      padding: 8px 10px;
      box-shadow: 0 6px 20px rgba(15, 23, 42, 0.24);
      max-width: min(96vw, 680px);
      overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
    }
    #stamp-prop-toolbar.on { display: inline-flex; }
    #stamp-prop-toolbar::-webkit-scrollbar { display: none; }
    /* 画面上部の常設ツールバー(#toolbar-top)のボタンサイズ統一(スタンプ用バーは上で独自にスリム化済み) */
    .sticky-toolbar-bar button { padding: 9px 13px; font-size: 12.5px; min-height: 42px; white-space: nowrap; flex: 0 0 auto; }

    /* 内部ボタンをスマホでの誤操作防止のため縦厚ピル型に(高さ40〜42px、横並び比率は維持) */
    #stamp-prop-toolbar button {
      flex-shrink: 0;
      min-height: 40px !important;
      height: 40px !important;
      padding: 0 8px !important;
      font-size: 12px !important;
      font-weight: 700;
      border-radius: 999px !important;
      border: 1px solid transparent;
    }
    #stamp-prop-toolbar .toolbar-tag,
    #stamp-prop-toolbar .prop-break {
      display: none !important;   /* 縦幅を取る不要なタグや改行を排除 */
    }

    /* ボタン個別のアクセント */
    #stamp-prop-toolbar #btn-prop-confirm {
      background: #059669 !important; color: #fff !important; border: none !important; font-weight: 700 !important;
      padding: 0 6px !important;
    }
    #stamp-prop-toolbar #btn-prop-confirm:hover { background: #047857 !important; }
    /* UI1: 左のスタンプツールパネルが常に見える幅(769px以上。シートに変わる境目 768px と同じ。stamp-designer のシート切り替えも 768px)では、
       パネルの「✓ 確定」と重複するので、浮きツールバーの確定は隠す(要素・IDは残す。シート側の幅は今のまま) */
    @media (min-width: 769px) {
      #stamp-prop-toolbar #btn-prop-confirm { display: none !important; }
    }
    #stamp-prop-toolbar #btn-prop-del {
      background: #fef2f2 !important; color: #dc2626 !important; border: 1px solid #fecaca !important;
      padding: 0 6px !important; font-size: 12px !important; font-weight: 700 !important;
    }
    #stamp-prop-toolbar #btn-prop-del:hover,
    #stamp-prop-toolbar #btn-prop-del:active { background: #fecaca !important; border-color: #ef4444 !important; }

    /* サイズ・傾きボタングループ: 薄いグレーの器の中に丸角スクエアボタンを収める。
       こちらもタップしやすいよう縦厚を少し増やす(26px→32px) */
    #stamp-prop-toolbar .rapid-quick-scale,
    #stamp-prop-toolbar .tilt-group {
      display: inline-flex; align-items: center; gap: 2px;
      background: #f1f5f9; border-radius: 999px; padding: 3px 5px;
    }
    /* T3: 倍率(%)の下に、メモだけ「約8.5pt」を小さく出す。空のときは出さない(ほかのスタンプの操作バーは変わらない) */
    #stamp-prop-toolbar .prop-scale-col { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; }
    #stamp-prop-toolbar .prop-scale-pt { display: flex; justify-content: center; width: 0; position: relative; z-index: 3; pointer-events: none; font-size: 8.5px; letter-spacing: -0.2px; font-weight: 700; color: #92400e; white-space: nowrap; }   /* 幅 0 で中央から左右に広げ、操作バーの横幅・並びを変えない。隣の ◀▶ ボタンより手前に出して、320px でも端が隠れない(タップは下のボタンへ通す) */
    #stamp-prop-toolbar .prop-scale-pt:empty { display: none; }
    #stamp-prop-toolbar .rapid-quick-scale button,
    #stamp-prop-toolbar .tilt-group button {
      height: 32px !important; min-height: 32px !important; min-width: 26px !important;
      padding: 0 6px !important; font-size: 11px !important; gap: 2px !important;
      background: #fff !important; border: 1px solid #cbd5e1 !important; border-radius: 8px !important;
    }
    /* U7: うすく・小/大・左右の回転の枠線と文字を、下部バー(U6)のボタンと同じ値(枠 #748399・文字 #334155)にする。ホバーでも薄くならない。
       色の丸・確定(緑)・削除(赤)・倍率や角度の数字は変えない */
    #stamp-prop-toolbar #btn-prop-bg, #stamp-prop-toolbar #btn-prop-bg:hover,
    #stamp-prop-toolbar .rapid-quick-scale button, #stamp-prop-toolbar .rapid-quick-scale button:hover,
    #stamp-prop-toolbar .tilt-group button, #stamp-prop-toolbar .tilt-group button:hover { border-color: #748399 !important; color: #334155; }
    #stamp-prop-toolbar #prop-scale-val,
    #stamp-prop-toolbar #tilt-val {
      font-size: 11.5px; font-weight: 800; color: #334155; min-width: 36px; text-align: center;
    }
    @media (max-width: 768px) {
      #stamp-prop-toolbar { max-width: 94vw; }
      /* 絵文字を廃止したため、狭い画面でもラベル文字は非表示にせず残す
         (色▾ / 透過 / ◀小 100% 大▶ / ↶左 0° 右↷ / 削除 が常に見える状態を保つ)。
         padding・gapは詰めつつも、誤操作防止のため縦の余白は一定以上確保する
         (バー全体の高さがおよそ48〜52pxになるよう調整) */
      #stamp-prop-toolbar { gap: 2px !important; padding: 6px 6px !important; }
      #stamp-prop-toolbar button { padding: 0 5px !important; }
      #stamp-prop-toolbar #btn-prop-confirm,
      #stamp-prop-toolbar #btn-prop-del { padding: 0 5px !important; }
      #stamp-prop-toolbar .rapid-quick-scale,
      #stamp-prop-toolbar .tilt-group { gap: 1px !important; padding: 2px 3px !important; }
      #stamp-prop-toolbar .rapid-quick-scale button,
      #stamp-prop-toolbar .tilt-group button { padding: 0 4px !important; min-width: 20px !important; }
      #stamp-prop-toolbar #prop-scale-val,
      #stamp-prop-toolbar #tilt-val { min-width: 26px !important; font-size: 10.5px !important; }
    }
    /* iPhone SE3級(〜400px): [色▾][透過][◀小 100% 大▶][↶左 0° 右↷][削除] が
       横スクロール無しで画面中央にぴったり収まるよう、さらに切り詰める
       (縦厚=タップしやすさは維持したまま、横方向のpaddingのみ切り詰める) */
    @media (max-width: 400px) {
      /* この幅は横方向の余裕が特に少ないため、既存の横方向サイズはそのまま維持し
         (幅を広げると横スクロールが必須になってしまうため)、縦方向のみわずかに余裕を持たせる */
      #stamp-prop-toolbar { gap: 1px !important; padding: 3px 3px !important; }
      #stamp-prop-toolbar button { padding: 0 3px !important; font-size: 10px !important; }
      #stamp-prop-toolbar #btn-prop-confirm,
      /* ★誤タップ防止: 削除ボタンは他ボタンより優先して押しやすいタップ領域を確保する。
         このブレークポイントでは#btn-prop-confirmを非表示にして横の余裕を作っているため、
         削除ボタンだけmin-widthを広めに取っても横スクロールは発生しない */
      #stamp-prop-toolbar #btn-prop-del {
        min-width: 42px !important;
        padding: 0 6px !important;
        font-size: 11px !important;
        font-weight: 800 !important;
        flex-shrink: 0 !important;
      }
      /* iPhone SE3級(〜400px)は横方向の余裕がほぼ無く、確定ボタンを追加すると横スクロールが
         発生してしまうため、この幅だけは非表示にする。この幅では代わりに下部バーの
         大きな緑色の【確定】ボタン(#btn-mob-confirm、親指で確実に押せる)がその役割を担う */
      #stamp-prop-toolbar #btn-prop-confirm { display: none !important; }
      #btn-prop-color { padding: 0 3px !important; gap: 1px !important; font-size: 10px !important; }
      #stamp-prop-toolbar .rapid-quick-scale,
      #stamp-prop-toolbar .tilt-group { padding: 1px !important; }
      #stamp-prop-toolbar .rapid-quick-scale button,
      #stamp-prop-toolbar .tilt-group button { padding: 0 2px !important; min-width: 14px !important; font-size: 9.5px !important; gap: 0 !important; }
      #stamp-prop-toolbar #prop-scale-val,
      #stamp-prop-toolbar #tilt-val { min-width: 20px !important; font-size: 9.5px !important; }
    }

    /* U4: 操作バーの倍率(押すとプリセット)。幅は変えず、押せることが分かるよう点線の下線だけ付ける */
    #stamp-prop-toolbar #prop-scale-val { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
    #btn-prop-smaller, #btn-prop-larger { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
    /* U5: スマホ幅(〜480px)では、操作バーが1行で画面に収まるよう「◀ 小」「大 ▶」「↶ 左」「右 ↷」を記号だけにする。
       文字は見た目だけ隠し(読み上げ用の名前としては残す)、記号のボタンは押しやすい幅を確保する */
    @media (max-width: 480px) {
      #stamp-prop-toolbar .rapid-quick-scale .btn-label-text,
      #stamp-prop-toolbar .tilt-group .btn-label-text {
        position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important;
        clip: rect(0 0 0 0) !important; clip-path: inset(50%) !important; white-space: nowrap !important; margin: -1px !important; padding: 0 !important; min-width: 0 !important;
      }
      /* 大きさの◀▶は押せる幅40px以上を保つ。傾きの↶↷は今の最小幅(約23px)のまま */
      #stamp-prop-toolbar .rapid-quick-scale button { min-width: 40px !important; justify-content: center; }
      #stamp-prop-toolbar .tilt-group button { min-width: 23px !important; justify-content: center; }
      /* 削除は🗑だけにする(「削除」の文字は読み上げ用に残す)。押せる幅は42px以上のまま */
      #stamp-prop-toolbar #btn-prop-del-label {
        position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important;
        clip: rect(0 0 0 0) !important; clip-path: inset(50%) !important; white-space: nowrap !important; margin: -1px !important; padding: 0 !important; min-width: 0 !important;
      }
      #stamp-prop-toolbar #btn-prop-del { min-width: 42px !important; justify-content: center; }
    }
    /* U5: 320px級(〜359px)は、さらに操作バーの内側の余白とグループの余白を1px詰める */
    @media (max-width: 359px) {
      #stamp-prop-toolbar { padding: 3px 1px !important; }
      #stamp-prop-toolbar .rapid-quick-scale,
      #stamp-prop-toolbar .tilt-group { padding: 1px 0 !important; }
    }
    .prop-scale-popup {
      position: fixed; z-index: 260; display: flex; gap: 4px; padding: 5px;
      background: rgba(255, 255, 255, 0.98); border: 1px solid #cbd5e1; border-radius: 12px;
      box-shadow: 0 10px 24px rgba(15, 23, 42, 0.2);
    }
    .prop-scale-preset {
      min-width: 44px; height: 34px; padding: 0 6px !important; border-radius: 8px;
      border: 1px solid #cbd5e1 !important; background: #fff; color: #334155; font-size: 12px; font-weight: 700; box-shadow: none;
    }
    .prop-scale-preset.current { background: var(--primary); border-color: var(--primary) !important; color: #fff; font-weight: 800; }

    /* ===== スタンプ選択時のフロートガイド: [色▾] スウォッチ ===== */
    .prop-color-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
    #btn-prop-color {
      display: inline-flex !important; align-items: center; gap: 4px;
      background: #fff !important; border: 1px solid #cbd5e1 !important; color: #475569 !important;
      font-size: 11px !important; padding: 0 9px !important;
    }
    .prop-color-dot {
      width: 17px; height: 17px; border-radius: 50%; background: #c92a2a; display: inline-block;
      box-shadow: inset 0 0 0 1.5px rgba(0, 0, 0, 0.22), 0 0 0 1px rgba(0, 0, 0, 0.06);
    }
    .prop-color-popup {
      display: none; position: fixed; transform: translateX(-50%);
      background: rgba(255, 255, 255, 0.98); border: 1px solid #cbd5e1; border-radius: 14px;
      padding: 8px; gap: 6px; box-shadow: 0 10px 24px rgba(15, 23, 42, 0.2); z-index: 260;
    }
    .prop-color-popup.open { display: flex; }
    .prop-color-popup .rapid-quick-color { width: 24px; height: 24px; flex-shrink: 0; }
    @media (max-width: 768px) {
      #btn-prop-color { padding: 0 6px !important; }
    }

    .tilt-group { display: none; align-items: center; gap: 4px; flex-shrink: 0; }
    .tilt-group #tilt-val { min-width: 40px; text-align: center; font-size: 12px; font-weight: 800; color: #475569; }
    .btn-prop-confirm { background: #059669 !important; color: #fff !important; border: none !important; font-weight: 700 !important; }
    .btn-prop-confirm:hover { background: #047857 !important; }
    .btn-prop-del { color: #dc2626 !important; font-weight: 700 !important; }
    .btn-prop-del:hover { background: #fee2e2 !important; border-color: #fca5a5 !important; }

    /* ★スタンプ選択中は書類側の触操作を完全ロックし、誤操作を防ぐ */
    #doc-canvas { transition: filter 0.25s ease; }
    .preview-scroll-area.stamp-lock #doc-canvas { filter: brightness(0.96); }
    .preview-scroll-area.stamp-lock {
      touch-action: none; overflow: hidden; background-color: #e2e8f0;
    }
    .preview-scroll-area {
      flex: 1; overflow-x: auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
      /* ★中央寄せをやめ左上揃えにする: align-items:centerだと#canvas-viewportが
         width:fit-contentの自然サイズ(zoom用transform適用前の等倍サイズ)で幅確保されるため、
         ズームで縮小された書類の見た目とスクロール中心がズレて「フィットすると左に寄って見える」
         不具合の温床になっていた。左上揃えなら中心計算が不要になり、常に書類の左上から
         正確に表示できる */
      display: flex; flex-direction: column; align-items: flex-start;
      padding: 20px 14px 90px 14px; position: relative; width: 100%;
    }
    /* ★保存/コピー実行トリガー時の演出: フラッシュや振動は使わず、書類表示エリア全体が
       完了モーダルのプレビューへ「スッと吸い込まれる」ような軽量な縮小+フェードのみで表現する。
       0.2〜0.25秒の短いワンショットで、一瞬scale(0.96)へ沈み込んでからscale(0.85)+半透明まで
       縮小する。#preview-area自体にはJS側で他のtransformを設定していないため、ズーム操作
       (#canvas-containerのtransform:scale)とは干渉しない。アニメーション終了後は必ずクラスを
       外し、通常のスクロール/ズーム挙動に支障が出ないようにする(JSのplaySaveTriggerAnimation/
       resetSaveTriggerAnimation参照) */
    @keyframes docSaveSuckIn {
      0%   { transform: scale(1);    opacity: 1; }
      35%  { transform: scale(0.96); opacity: 1; }
      100% { transform: scale(0.85); opacity: 0.4; }
    }
    #preview-area.save-trigger-anim {
      animation: docSaveSuckIn 0.22s ease-out both;
      transform-origin: 50% 15%;
    }
    @media (prefers-reduced-motion: reduce) {
      #preview-area.save-trigger-anim { animation-duration: 0.01s; }
    }

    /* スタンプ選択中は書類を薄暗くしてLOCK中と分かるようにする */
    .doc-lock-overlay {
      position: fixed; inset: 0; background: rgba(15, 23, 42, 0); pointer-events: none;
      z-index: 90; transition: background 0.25s ease;
    }
    .doc-lock-overlay.active { background: rgba(15, 23, 42, 0); }   /* 書類・サイドバーは元の色のまま(LOCKは右上のバッジで表示) */
    .lock-badge {
      position: fixed; top: 58px; right: 14px; z-index: 91;
      background: rgba(15, 23, 42, 0.8); color: #fff; font-size: 12px; font-weight: 700;
      padding: 6px 12px; border-radius: 20px; display: flex; align-items: center; gap: 5px;
      opacity: 0; transform: translateY(-4px); transition: all 0.25s ease; pointer-events: none;
    }
    .lock-badge.active { opacity: 1; transform: translateY(0); }

    /* ---- 連続押印モード ---- */
    .rapid-pill {
      border-radius: 999px; min-width: 44px; padding: 8px 14px;
      background: #eff6ff; border: 1.5px solid #93c5fd !important; color: #1d4ed8; font-weight: 800;
    }
    .rapid-pill:hover { background: #dbeafe; }
    .rapid-pill.active, .rapid-pill.active:hover { background: #2563eb; border-color: #2563eb !important; color: #fff; }
    /* 控えめな静的ハイライトのみ(派手なパルスは付けない) */
    .rapid-frame {
      position: fixed; display: none; pointer-events: none; z-index: 89; border-radius: 8px;
      box-shadow: inset 0 0 0 3px rgba(37, 99, 235, 0.55);
    }
    .rapid-frame.on { display: block; }
    .rapid-badge {
      position: fixed; display: none; z-index: 92; transform: translateX(-50%) !important; white-space: nowrap;
      background: #2563eb; color: #fff; border: none; border-radius: 999px; padding: 7px 8px 7px 14px;
      font-size: 12.5px; font-weight: 800; gap: 6px; align-items: center; box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45);
      cursor: pointer; user-select: none;
    }
    .rapid-badge:hover, .rapid-badge:active { background: #1d4ed8; transform: translateX(-50%) !important; }
    .rapid-badge.on { display: flex; }
    /* 連続押印中でもサイドバー/シートを開かずに色・サイズ・角度を変えられる、上部の小さなクイック設定バー。
       スマホでも横スクロールせず必ず1行のカプセルに収まるよう、色は#propColorWrapと同様の
       ポップアップ式(丸ドット+▾)に圧縮し、空いたスペースを角度ステッパーに充てる */
    .rapid-quick-bar {
      position: fixed; display: none; z-index: 92; transform: translateX(-50%) !important; white-space: nowrap;
      background: #fff; border-radius: 14px; padding: 6px 9px; gap: 7px; align-items: center;
      box-shadow: 0 6px 18px rgba(15, 23, 42, 0.22); border: 1px solid #e2e8f0;
    }
    .rapid-quick-bar.on { display: flex; }
    .rapid-quick-bar .prop-color-wrap { display: inline-flex; }
    .rapid-quick-bar #btn-rapid-color {
      display: inline-flex; align-items: center; gap: 3px; cursor: pointer;
      background: #f8fafc; border: 1.5px solid #cbd5e1; color: #475569;
      font-size: 11px; height: 24px; padding: 0 7px; border-radius: 999px;
    }
    .rapid-quick-bar #btn-rapid-color:hover { background: #eff6ff; }
    .rapid-quick-bar .prop-color-dot { width: 13px; height: 13px; }
    .rapid-quick-color {
      width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; padding: 0; cursor: pointer;
      box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
    }
    .rapid-quick-color.active { border-color: #1e293b; }
    .rapid-quick-sep { width: 1px; height: 20px; background: #e2e8f0; }
    .rapid-quick-size { display: flex; gap: 4px; align-items: center; }
    .rapid-quick-size button {
      min-width: 26px; height: 24px; padding: 0 6px; border-radius: 999px; border: 1.5px solid #cbd5e1;
      background: #f8fafc; color: #334155; font-size: 11.5px; font-weight: 800; cursor: pointer;
    }
    .rapid-quick-size button.active { background: #2563eb; border-color: #2563eb; color: #fff; }
    .rapid-quick-scale { display: flex; gap: 4px; align-items: center; }
    .rapid-quick-scale button {
      min-width: 22px; height: 24px; padding: 0 6px; border-radius: 8px; border: 1.5px solid #cbd5e1; background: #f8fafc;
      color: #334155; font-size: 11px; font-weight: 800; cursor: pointer; line-height: 1; white-space: nowrap;
    }
    .rapid-quick-scale span { font-size: 11.5px; font-weight: 700; color: #334155; min-width: 34px; text-align: center; }
    .rapid-quick-bar .tilt-group button {
      min-width: 22px; height: 24px; padding: 0 6px; border-radius: 8px; border: 1.5px solid #cbd5e1; background: #f8fafc;
      color: #334155; font-size: 11px; font-weight: 800; cursor: pointer; line-height: 1;
    }
    #rapid-tilt-val { font-size: 11.5px; font-weight: 800; color: #334155; min-width: 32px; text-align: center; }
    @media (max-width: 480px) {
      .rapid-quick-bar { padding: 5px 6px; gap: 4px; }
      .rapid-quick-bar #btn-rapid-color { padding: 0 5px; font-size: 10px; }
      .rapid-quick-size button, .rapid-quick-scale button, .rapid-quick-bar .tilt-group button { min-width: 18px; padding: 0 4px; font-size: 10px; }
      .rapid-quick-scale span, #rapid-tilt-val { min-width: 26px !important; font-size: 10.5px !important; }
    }
        /* ★連続押印中はブラウザ標準のスクロール/パン・ジェスチャーを無効化し、
           1本指でタップ→即打刻のつもりが誤って書類がスクロールしてしまうのを防ぐ
           (ピンチズームは従来通りJS側で2本指を検知して処理する) */
        .preview-scroll-area.rapid-active,
        .preview-scroll-area.rapid-active #canvas-container,
        .preview-scroll-area.rapid-active #doc-canvas {
          touch-action: none !important; -webkit-user-select: none !important; user-select: none !important;
        }
        .preview-scroll-area.rapid-active { cursor: crosshair; }
    .preview-scroll-area.rapid-active .stamp-element { pointer-events: none; }   /* 既存のスタンプの上でもそのままタップして押せる */
    /* 連続押印: カーソル/指先に追従する半透明の「まだ押されていない」プレビュー */
    .stamp-ghost-preview {
      position: absolute; pointer-events: none; z-index: 95;
      opacity: 0.65; border: 1.5px dashed rgba(37, 99, 235, 0.6); border-radius: 2px;
      box-sizing: border-box; transform-origin: center center; display: none;
      background-size: 100% 100%; background-repeat: no-repeat; background-position: center;
      transition: opacity 0.1s ease;
    }
    .rapid-ripple {
      position: absolute; border-radius: 50%; pointer-events: none; z-index: 96;
      border: 2px solid rgba(37, 99, 235, 0.55);
      background: radial-gradient(circle, rgba(96, 165, 250, 0.35), rgba(96, 165, 250, 0) 70%);
      animation: rapidRipple 0.45s ease-out forwards;
    }
    @keyframes rapidRipple { from { transform: scale(0.3); opacity: 0.9; } to { transform: scale(1.3); opacity: 0; } }
    @media (prefers-reduced-motion: reduce) { .rapid-ripple { animation-duration: 0.01s; } }

    /* ドロップゾーン */
    .drop-zone {
      width: 90%; max-width: 480px; min-height: 320px; border: 2px dashed #cbd5e1; border-radius: var(--radius-lg);
      background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center;
      gap: 12px; padding: 24px; text-align: center; margin-top: 30px; box-shadow: var(--shadow-md);
      transition: all 0.2s;
      /* ★左上揃え化(.preview-scroll-area の align-items: flex-start)の副作用で、このカード自身も
         左寄りになっていたため、このカードだけ独立して水平中央に戻す。親や#canvas-viewport側の
         左上揃えには一切影響しない */
      align-self: center; margin-left: auto; margin-right: auto;
    }
    .drop-zone.dragover { border-color: var(--primary); background: #f8fbff; }

    /* ★書類プレビュー領域(#preview-area)へのドラッグ&ドロップ新規読み込み: 既存の.drop-zone
       (書類未読込時の初期画面)とは別に、書類を開いた後のプレビュー領域自体にもドロップを
       受け付けられるようにする。新規のDOM要素は増やさず、#preview-areaがposition:relativeを
       持つことを利用してinset box-shadowの枠線+背景色の薄い着色だけで表現する
       (.rapid-frameのinset box-shadow手法と同じ考え方)。 */
    #preview-area.doc-drag-over {
      box-shadow: inset 0 0 0 3px var(--primary);
      background-color: rgba(37, 99, 235, 0.06);
    }

    .hero-badge {
      font-size: 10.5px; font-weight: 700; padding: 4px 10px; border-radius: 20px;
      background: #f1f5f9; color: #475569;
    }

    .drop-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 320px; margin-top: 4px; }
    .drop-btn { width: 100%; min-height: 50px; padding: 12px 16px; font-size: 0.95rem; font-weight: 800; border-radius: 12px; justify-content: center; align-items: center; }
    .drop-btn-open { display: flex; background: var(--primary) !important; color: #fff !important; border: none !important; box-shadow: 0 4px 12px rgba(37,99,235,.3); }
    .drop-btn-sample { display: flex; background: #f8fafc; color: var(--text-main); border: 1.5px solid #cbd5e1; }
    .drop-btn.btn-camera-trigger { background: #f8fafc; color: var(--text-main); border: 1.5px solid #cbd5e1; }
    .drop-btn-blank { display: flex; background: #f8fafc; color: var(--text-main); border: 1.5px solid #cbd5e1; }
    .btn-camera-trigger { display: none; }
    @media (max-width: 768px) {
      .btn-camera-trigger { display: inline-flex !important; }
    }

    /* キャンバスラッパー: 書類は中央ではなく左上揃えで表示する(justify-content:flex-start) */
    .canvas-scroll-viewport {
      display: flex; justify-content: flex-start; align-items: flex-start;
      padding: 10px; width: fit-content; min-width: 100%;
    }
    .canvas-container {
      position: relative; box-shadow: var(--shadow-lg); background: #fff;
      /* ★中央寄せから左上揃えへ変更: transform-origin: top center のままだと、layout上は左端に
         配置していてもscale()の縮小・拡大が書類の水平中央を軸に起こるため、見た目上は
         書類が右へずれて表示されてしまう(leftGapが想定より大きくなる)。top leftにすることで、
         ズーム倍率に関わらず書類の左上角が常に固定され、真の左上揃えになる */
      display: none; user-select: none; transform-origin: top left; transition: transform 0.1s ease-out;
      border-radius: 2px;
    }
    #doc-canvas { display: block; }

    /* スタンプ要素 */
    .stamp-element {
      position: absolute; cursor: move; user-select: none; touch-action: none;
      box-sizing: border-box; border: 1.5px solid transparent; transform-origin: center center;
      /* --stamp-rot: 署名・画像スタンプの回転角(dataset.rotationと連動)。作成スタンプの傾きは画像に焼き込み済みで常に0deg */
      transform: rotate(var(--stamp-rot, 0deg));
    }
    /* --- スタンプ当たり判定の最小サイズ保証 & 選択時の視覚化 ---
       極小サイズ(認印・チェック印など)や画面縮小表示でも、指の腹で確実に掴めるよう
       当たり判定(::before)は本体サイズ+30pxと最低56px(マウス)のどちらか大きい方を確保する。
       通常時・確定後は完全透明で書類の見た目を一切邪魔しない。 */
    .stamp-element::before {
      content: ''; position: absolute; top: 50%; left: 50%;
      transform: translate(-50%, -50%);
      width: max(100% + 30px, 56px); height: max(100% + 30px, 56px);
      touch-action: none; pointer-events: auto; border-radius: 8px; box-sizing: border-box;
      background: transparent; border: none;
      transition: background 0.15s ease, border-color 0.15s ease;
    }
    /* 選択中のみ、掴める範囲を淡いブルーの点線枠で可視化(確定後・通常時は完全透明のまま) */
    .stamp-element.selected::before {
      background: rgba(37, 99, 235, 0.04);
      border: 1px dashed rgba(37, 99, 235, 0.35);
    }
    /* 掴んでいる(ドラッグ中)瞬間は枠をわずかに濃くしてフィードバックする */
    .stamp-element.selected:active::before {
      background: rgba(37, 99, 235, 0.08);
      border-color: rgba(37, 99, 235, 0.6);
    }
    /* ★「前回と同じ位置」でスタンバイ配置した直後だけ付く目印。まだ確定(実体化)していないことが
       一目でわかるよう、半透明+エメラルドグリーンの点線グルグル(呼吸するアウトライン)を重ねる。
       確定ボタン押下でconfirmStamp()がこのクラスを外すと、通常のスタンプ表示に戻る。
       GPU負荷の低いoutline-offsetのアニメーションのみを使う(位置・サイズの再計算は発生しない) */
    .stamp-element.stamp-recall-ghost {
      opacity: 0.85;
      outline: 2px dashed #10b981;
      outline-offset: 4px;
      animation: stampDottedSpin 1.2s linear infinite;
      box-shadow: 0 0 12px rgba(16, 185, 129, 0.35);
    }
    @keyframes stampDottedSpin {
      0% { outline-offset: 3px; }
      50% { outline-offset: 6px; }
      100% { outline-offset: 3px; }
    }
    /* 選択中は「つまみ上げて操作中」であることが一目で分かるよう、浮き上がる演出にする(回転角はvar(--stamp-rot)で維持)。
       枠線・発光色は下部バーの「✏️ スタンプを編集」ボタン(.editing-stamp)と同じ--primaryで統一し、
       画面上のハイライトと手元のボタンが同色に光ることで、今どれを編集中か直感的に分かるようにする */
    .stamp-element.selected {
      /* T4: 確定前と確定後で位置・大きさが変わらないようにする。持ち上げる動き(translateY(-4px)・scale(1.02))は使わず、
         浮き上がりは影だけで見せる。枠線の太さも通常(1.5px)と同じにして、中の画像がずれないようにする */
      border: 1.5px dashed var(--primary);
      background: rgba(37, 99, 235, 0.07);
      transform: rotate(var(--stamp-rot, 0deg)) !important;
      box-shadow: 0 16px 32px rgba(15, 23, 42, 0.28), 0 6px 12px rgba(15, 23, 42, 0.15), 0 0 0 4px rgba(37, 99, 235, 0.18) !important;
      z-index: 100 !important;
      transition: box-shadow 0.12s ease;
    }
    .stamp-element.confirmed { cursor: pointer; }
    /* U3: 確定前(選択中)のスタンプは、点線の枠(上の .selected)に加えて枠の左上に小さく「未確定」を出す。
       画面表示だけ(保存するPDF・JPGはスタンプ画像から作るので入らない)。確定すると .selected が外れて消える */
    .stamp-element.selected::after {
      content: attr(data-pending-label); position: absolute; left: -2px; bottom: 100%; margin-bottom: 3px;
      padding: 1px 6px; border-radius: 6px; background: var(--primary); color: #fff;
      font-size: 10px; font-weight: 800; line-height: 1.5; white-space: nowrap; pointer-events: none;
      transform: scale(var(--stamp-label-inv, 1)); transform-origin: left bottom;
    }
    .stamp-element.stamp-recall-ghost::after { background: #10b981; }
    .stamp-element.selected[data-ever-confirmed]::after { content: none; }   /* U3追補: 確定済みを選び直したときは点線の枠だけ */
    /* U3: 最初の1回だけの吹き出し */
    .app-hint {
      position: fixed; z-index: 2100; max-width: min(260px, calc(100vw - 16px)); box-sizing: border-box;
      background: #0f172a; color: #fff; border-radius: 10px; padding: 8px 30px 8px 11px;
      font-size: 12px; font-weight: 700; line-height: 1.45; box-shadow: 0 8px 20px rgba(15, 23, 42, 0.28);
      opacity: 0; transition: opacity 0.18s ease;
    }
    .app-hint.show { opacity: 1; }
    .app-hint-close {
      position: absolute; top: 2px; right: 2px; width: 26px; height: 26px; padding: 0 !important;
      border: none !important; background: transparent; color: #cbd5e1; font-size: 16px; line-height: 1; cursor: pointer; box-shadow: none;
    }
    @media (prefers-reduced-motion: reduce) { .app-hint { transition: none; } }
    .stamp-element img { width: 100%; height: 100%; display: block; pointer-events: none; }

    .resize-handle {
      position: absolute; bottom: -7px; right: -7px; width: 16px; height: 16px;
      background: var(--primary); border: 2px solid #fff; border-radius: 50%;
      cursor: nwse-resize; display: none; z-index: 10; box-shadow: var(--shadow-sm);
      touch-action: none;
    }
    .stamp-element.selected .resize-handle { display: block; }

    /* スマホ(タッチ操作)では指が太い分、当たり判定の最低保証サイズをさらに広げる(最低64px) */
    @media (pointer: coarse) {
      .stamp-element::before {
        width: max(100% + 40px, 64px); height: max(100% + 40px, 64px);
      }
      .resize-handle {
        width: 28px; height: 28px; bottom: -14px; right: -14px;
      }
      /* 連続押印モード撤廃(スマホ/タッチ): 誤タップ防止のため、切り替えボタンや通知UIごと非表示にし、
         単発押印(配置したら即確定)フローに一本化する */
      #sd-rapid-btn, .rapid-badge, #rapidQuickBar { display: none !important; }
    }

    /* スマホ下部バー */
    .mobile-bottom-bar {
      display: none; position: fixed; bottom: 12px; left: 12px; right: 12px;
      background: rgba(241, 245, 249, 0.96); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
      border: 1px solid #748399; border-radius: 20px; padding: 6px; gap: 5px; z-index: 100;
      box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.22);   /* U6: 白い書類の上でも輪郭が見えるよう、背景を薄い青灰色・縁取りと影を濃くした */
      align-items: stretch;
    }
    .mobile-bottom-bar button {
      font-size: 12px; font-weight: 700; border-radius: 13px; white-space: nowrap;
      min-height: 46px;
    }
    /* 開く・撮影は使用頻度が低いため、場所を取らないアイコン専用ボタンに */
    .mob-bar-icon-btn { flex: 0 0 46px; font-size: 17px; padding: 0; }
    /* U6: 開く・スタンプツールの枠線と文字を濃くする(隣の色に対して3:1以上・文字は4.5:1以上)。ホバー(タッチ後に残る)でも薄くならない */
    .mobile-bottom-bar .mob-bar-icon-btn, .mobile-bottom-bar .mob-bar-icon-btn:hover,
    .mobile-bottom-bar .mob-bar-main-btn, .mobile-bottom-bar .mob-bar-main-btn:hover { border-color: #748399; color: #334155; }
    /* 「直前と同じ内容で「同じ位置」」ボタン: 開く・撮影とスタンプツールの間(中央付近)に配置。
       書類モード(未選択・未編集)時、かつ直近に確定したスタンプがある時だけ表示し、
       「同じ位置」ラベルで一目で分かるようにする。
       通常のアイコン専用ボタン(開く/撮影)よりひと回り大きい、角丸ピル型のバッジボタンにして
       淡いオレンジ系の配色でメイン動線として視認性高く誘導する */
    .mobile-bottom-bar .mob-bar-repeat-btn {
      position: relative; flex: 0 0 auto; min-height: 44px;
      background: #fff7ed; border: 1px solid #fb923c !important; border-radius: 999px !important; overflow: visible;
      padding: 6px 14px 6px 6px;
      display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 6px;
      transition: background .12s ease;
    }
    .mob-bar-repeat-btn:hover, .mob-bar-repeat-btn:active { background: #ffedd5; }
    .repeat-icon-wrap { position: relative; width: 24px; height: 24px; flex-shrink: 0; }
    #mob-repeat-icon {
      position: absolute; inset: 0; border-radius: 999px; background-size: contain; background-position: center; background-repeat: no-repeat;
      background-color: #fff; border: 1px solid rgba(251, 146, 60, 0.5);
      /* ★以前の挙動に戻す: 呼び出し内容は都度あらためて描画するため(前回の画像を使い回さない)、
         サムネイルの代わりに固定の再押印アイコンを表示する */
      display: flex; align-items: center; justify-content: center; font-size: 12px;
    }
    .repeat-label { font-size: 12px; font-weight: 800; color: #ea580c; line-height: 1; white-space: nowrap; }
    /* スタンプ・署名系は実際によく押すボタンなので、大きく確実にタップできるように
       通常時は主張しすぎない透明/白背景・控えめな文字色。パネル展開中・スタンプ編集中だけ
       アクセントカラーで目立たせる(下の.active/.editing-stampで上書き) */
    .mob-bar-main-btn {
      flex: 1 1 0; padding: 8px 4px; font-size: 12.5px;
      background: transparent; border-color: var(--border); color: var(--text-muted);
      transition: background .12s ease, border-color .12s ease, color .12s ease, box-shadow .12s ease;
    }
    /* シート(パレット/ドロワー)を開いている間: 薄い青背景＋青文字で「開いている」ことを示す */
    .mob-bar-main-btn.active {
      background: var(--primary-light) !important; border-color: var(--primary) !important; color: var(--primary) !important;
    }
    /* 書類上でスタンプを選択中: 「編集中」であることをパネル展開中の青(.active)とは
       視覚的に区別するため、注意喚起色のアンバーで強調する */
    .mob-bar-main-btn.editing-stamp {
      background: #fffbeb !important; border: 1.5px solid #f59e0b !important; color: #b45309 !important;
      box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.22) !important;
    }

    /* ★スタンプ選択中(編集中)は下部バーを丸ごと「確定 / スタンプを編集」の2分割UIへ切り替える。
       #mobile-barの直接の子はこの2つのグループだけにし、非表示側はdisplay:noneでDOMごと隠す
       (表示中の側だけがflex:1 1 autoで#mobile-barの横幅いっぱいに広がる) */
    .mob-bar-normal-group, .mob-bar-edit-group {
      display: flex; align-items: stretch; gap: 5px; flex: 1 1 auto; min-width: 0;
    }
    .mob-bar-edit-group { display: none; }
    .mob-bar-edit-group.on { display: flex; }
    .mob-bar-normal-group.hide { display: none; }
    /* 【確定】: 親指で即座に押せる主アクション。書類上のフロートバー(#btn-prop-confirm)と
       同じ緑系で統一し、「これを押せば終わる」ことが一目でわかるようにする */
    .btn-mob-confirm {
      background: #059669 !important; border: none !important; color: #fff !important;
      font-weight: 800 !important; flex: 1.2 1 0;
    }
    .btn-mob-confirm:hover, .btn-mob-confirm:active { background: #047857 !important; }
    /* 【スタンプを編集】: 副アクション。主アクション(緑)と混同しないよう、
       #mob-bar-main-btn.editing-stampと同じアンバー系の枠線スタイルに揃える */
    .btn-mob-edit {
      background: #fffbeb !important; border: 1.5px solid #f59e0b !important; color: #b45309 !important;
      font-weight: 700 !important; flex: 1 1 0;
    }
    .btn-mob-edit:hover, .btn-mob-edit:active { background: #fef3c7 !important; }

    /* 操作案内チップ: 下部バーの少し上に控えめに出し、状態変化に合わせてフェードイン/アウトする */
    .app-toast {
      position: fixed; left: 50%; bottom: 82px; transform: translate(-50%, 6px);
      background: rgba(15, 23, 42, 0.88); color: #fff; font-size: 12.5px; font-weight: 700;
      padding: 8px 16px; border-radius: 999px; white-space: nowrap;
      z-index: 250; pointer-events: none;
      opacity: 0; visibility: hidden;
      transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
    }
    .app-toast.show {
      opacity: 1; visibility: visible; transform: translate(-50%, 0);
      transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0s;
    }
    @media (max-width: 768px) { .app-toast { bottom: 78px; } }
    /* 案内通知(showAppToastに表示時間を渡した場合): 長文・改行入りでも画面内で折り返し、モーダルやシートより手前に出す */
    .app-toast.is-notice {
      white-space: pre-line; width: max-content; max-width: calc(100vw - 32px); box-sizing: border-box;
      text-align: center; line-height: 1.45; border-radius: 14px; z-index: 2000;
    }

    /* エラー通知トースト(ファイルサイズ超過など): X等のアプリ内ブラウザではalert()が抑止されることがあるため、
       アプリ内に表示する。シートやモーダルより手前(z-index)・ヘッダー直下に出し、数秒で自動的に消える(タップでも閉じる) */
    .app-error-toast {
      position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 64px); transform: translate(-50%, -6px);
      width: max-content; max-width: calc(100vw - 32px); box-sizing: border-box;
      background: rgba(15, 23, 42, 0.92); color: #fff; font-size: 13px; font-weight: 700; line-height: 1.45;
      padding: 10px 16px; border-radius: 14px; border-left: 4px solid #e11d48;
      box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
      z-index: 2000; text-align: center; cursor: pointer;
      opacity: 0; visibility: hidden;
      transition: opacity 0.25s ease, transform 0.25s ease, visibility 0s linear 0.25s;
    }
    .app-error-toast.show {
      opacity: 1; visibility: visible; transform: translate(-50%, 0);
      transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0s;
    }

    /* ===== 書類編集モード(トリミングなど) ===== */
    .header-status-badge.mode-edit { background: #fff7ed; color: #c2410c; border-color: #fdba74; box-shadow: 0 0 0 2px rgba(234, 88, 12, 0.12); }
    #btn-doc-edit.active { background: #fff7ed; color: #c2410c; border-color: #fdba74; }
    /* 編集中はスタンプの選択・追加をできないようにする(スタンプは表示のみ) */
    body.doc-edit-mode .stamp-element { pointer-events: none !important; }
    body.doc-edit-mode #mobile-bar { display: none !important; }
    body.doc-edit-mode .sidebar { pointer-events: none; }
    body.doc-edit-mode .sidebar > :not(.doc-edit-sidebar-note) { opacity: 0.45; filter: grayscale(0.4); }
    /* 書類編集中だけ、スタンプ欄の上に「なぜ操作できないか」を1行で出す */
    .doc-edit-sidebar-note { display: none; background: #fff7ed; border: 1px solid #fdba74; color: #c2410c; border-radius: 10px; padding: 8px 10px; font-size: 12px; font-weight: 700; line-height: 1.5; }
    body.doc-edit-mode .doc-edit-sidebar-note { display: block; }
    body.doc-edit-mode #btn-clear-all { pointer-events: none; opacity: 0.4; }
    .doc-edit-panel {
      position: fixed; left: 50%; transform: translateX(-50%);
      bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
      width: min(560px, calc(100vw - 16px)); box-sizing: border-box;
      background: #ffffff; border: 1px solid #e2e8f0; border-radius: 16px;
      box-shadow: 0 12px 32px rgba(15, 23, 42, 0.22); padding: 10px 12px 12px;
      z-index: 1500; font-size: 13px; color: #1e293b;
      max-height: calc(100dvh - 140px); overflow-y: auto;
    }
    .dep-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
    .dep-title { font-weight: 800; font-size: 14px; color: #c2410c; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .dep-done { background: #ffffff; color: #2563eb; border: 1.5px solid #2563eb; border-radius: 10px; font-weight: 800; font-size: 13px; padding: 8px 16px; min-height: 38px; cursor: pointer; flex-shrink: 0; }
    .dep-done:hover { background: #eff6ff; }
    .dep-tools { display: flex; flex-wrap: wrap; gap: 6px; }
    .dep-tool { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; min-height: 52px;
      background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; font-size: 12px; font-weight: 700; color: #334155; cursor: pointer; }
    .dep-tool .dep-ic { font-size: 18px; line-height: 1; }
    .dep-tool .dep-lb { white-space: normal; overflow-wrap: anywhere; line-height: 1.2; text-align: center; max-width: 100%; }
    .dep-tool.active { background: #fff7ed; border-color: #fdba74; color: #c2410c; }
    .dep-tool:disabled { opacity: 0.4; cursor: default; }
    .dep-body { margin-top: 10px; }
    .dep-note { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 10px; padding: 8px 10px; font-size: 12px; line-height: 1.5; margin-bottom: 8px; }
    .dep-hint { color: #64748b; font-size: 12px; line-height: 1.5; margin-bottom: 8px; }
    .dep-actions { display: flex; flex-wrap: wrap; gap: 6px; }
    .dep-actions button { flex: 1 1 0; min-width: 0; min-height: 40px; border-radius: 10px; font-weight: 800; font-size: 13px; padding: 6px 8px; cursor: pointer; border: 1px solid #cbd5e1; background: #fff; color: #334155; white-space: normal; line-height: 1.25; }
    .dep-actions .dep-primary { background: #ea580c; border-color: #ea580c; color: #fff; }
    .dep-actions button:disabled { opacity: 0.45; cursor: default; }
    .dep-actions .dep-danger { background: #dc2626; border-color: #dc2626; color: #fff; }
    /* トリミング中だけ: 下部パネルを「ⓘ・適用・キャンセル」の1行に縮め、書類を広く見せる */
    .doc-edit-panel.dep-compact { padding: 8px; }
    .doc-edit-panel.dep-compact .dep-body { margin-top: 0; }
    .doc-edit-panel.dep-compact .dep-actions { flex-wrap: nowrap; }
    .doc-edit-panel.dep-compact .dep-note { margin-bottom: 8px; }
    .doc-edit-panel.dep-compact .dep-note .dep-hint { color: inherit; margin-bottom: 4px; }
    .dep-hintrow { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
    .dep-hintrow .dep-hint { flex: 1 1 auto; min-width: 0; margin-bottom: 0; }
    .dep-hintrow .dep-info { flex: 0 0 36px; width: 36px; height: 36px; padding: 0; border-radius: 50%; font-size: 17px; font-weight: 700; color: #2563eb; border: 1px solid #bfdbfe; background: #eff6ff; cursor: pointer; }
    .dep-hintrow .dep-info[aria-expanded="true"] { background: #2563eb; border-color: #2563eb; color: #fff; }
    .dep-actions .dep-info { flex: 0 0 40px; width: 40px; min-width: 40px; padding: 0; border-radius: 50%; font-size: 18px; font-weight: 700; color: #2563eb; border-color: #bfdbfe; background: #eff6ff; }
    .dep-actions .dep-info[aria-expanded="true"] { background: #2563eb; border-color: #2563eb; color: #fff; }
    /* 傾き補正: 角度スライダーの行と、書類に重ねる方眼(線と文字の行を見比べて合わせる) */
    .dep-straighten { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
    .dep-straighten input[type="range"] { flex: 1 1 auto; min-width: 0; height: 32px; accent-color: #ea580c; }
    .dep-straighten .dep-step { flex: 0 0 auto; min-width: 44px; min-height: 36px; border-radius: 10px; border: 1px solid #cbd5e1; background: #fff; color: #334155; font-weight: 800; font-size: 12px; cursor: pointer; padding: 0 6px; }
    .dep-straighten .dep-deg { flex: 0 0 auto; min-width: 52px; text-align: center; font-weight: 800; font-size: 14px; color: #c2410c; font-variant-numeric: tabular-nums; }
    .straighten-grid { position: absolute; inset: 0; pointer-events: none; z-index: 55; --sg: 40px; --sl: 1px;
      background-image: linear-gradient(to right, rgba(37, 99, 235, 0.5) var(--sl), transparent var(--sl)), linear-gradient(to bottom, rgba(37, 99, 235, 0.5) var(--sl), transparent var(--sl));
      background-size: var(--sg) var(--sg); }
    #doc-canvas.straighten-preview { transform-origin: 50% 50%; background: #fff; }
    /* 枠をドラッグしている間は、パネルを半透明にして触れないようにする(枠の操作を邪魔しない) */
    .doc-edit-panel.dep-dragging { opacity: 0.35; pointer-events: none; }
    .doc-edit-panel.dep-dragging * { pointer-events: none !important; }
    .dep-warn { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 10px; padding: 8px 10px; font-size: 12px; font-weight: 700; line-height: 1.5; margin-bottom: 8px; }
    /* トリミング枠: 書類キャンバス(canvas-container)の上に重ねる。ハンドル類は表示倍率に関係なく
       指で掴める大きさを保つため、--crop-inv(=1/表示倍率)で逆スケールする */
    .crop-layer { position: absolute; inset: 0; overflow: hidden; z-index: 60; touch-action: none; --crop-inv: 1; }
    .crop-rect { position: absolute; box-sizing: border-box; border: calc(2px * var(--crop-inv)) solid #ffffff;
      outline: calc(1px * var(--crop-inv)) dashed #ea580c; box-shadow: 0 0 0 99999px rgba(15, 23, 42, 0.5); cursor: move; touch-action: none; }
    .crop-h { position: absolute; width: calc(22px * var(--crop-inv)); height: calc(22px * var(--crop-inv));
      margin: calc(-11px * var(--crop-inv)) 0 0 calc(-11px * var(--crop-inv)); border-radius: 50%;
      background: #ffffff; border: calc(3px * var(--crop-inv)) solid #ea580c; box-sizing: border-box; touch-action: none; }
    .crop-h::before { content: ""; position: absolute; inset: calc(-10px * var(--crop-inv)); }   /* 指で掴みやすいよう当たり判定を広げる */
    .crop-h[data-h="nw"], .crop-h[data-h="se"] { cursor: nwse-resize; }
    .crop-h[data-h="ne"], .crop-h[data-h="sw"] { cursor: nesw-resize; }
    .crop-h[data-h="n"], .crop-h[data-h="s"] { cursor: ns-resize; }
    .crop-h[data-h="e"], .crop-h[data-h="w"] { cursor: ew-resize; }
    /* スタンプ操作バーの削除ボタン: タッチ端末の案内「🗑で削除」と合わせて🗑を添える(PCは従来どおり文字だけ) */
    .prop-del-icon { display: none; margin-right: 2px; }
    html.is-touch .prop-del-icon { display: inline; }
    /* アイコンだけのボタンに添える短い文字(スマホ幅のみ表示) */
    .tb-cap { display: none; }
    @media (max-width: 768px) {
      #btn-doc-edit { flex-direction: column !important; justify-content: center; line-height: 1; gap: 1px; }
      #btn-doc-edit .tb-cap { display: block; font-size: 9.5px; font-weight: 700; line-height: 1; letter-spacing: -0.2px; }
      #btn-doc-edit { padding: 0 2px !important; }
    }
    @media (max-width: 480px) {
      #btn-rotate-doc, #btn-undo, #btn-clear-all { flex-direction: column !important; justify-content: center; line-height: 1; gap: 1px; }
      #btn-rotate-doc .btn-label-text { display: none !important; }
      #btn-rotate-doc .tb-cap, #btn-undo .tb-cap, #btn-clear-all .tb-cap { display: block; font-size: 9.5px; font-weight: 700; line-height: 1; letter-spacing: -0.2px; }
      #btn-rotate-doc, #btn-undo, #btn-doc-edit { padding: 0 2px !important; min-width: 30px !important; }
      #btn-doc-edit .tb-cap { font-size: 9.5px; letter-spacing: -0.2px; }
      #btn-clear-all .clear-all-icon { width: 14px !important; height: 14px !important; }
      #tb-clear-divider { display: block !important; margin: 0 2px; }
    }
    /* スマホ幅(〜480px)では拡大縮小(－ ％ ＋ フィット)を1つのボタンにまとめ、ツールバーを画面内に収める */
    #btn-zoom-menu { display: none; }
    #zoomQuickMenu.open { flex-direction: row; align-items: center; gap: 4px; min-width: 0; }
    #zoomQuickMenu button { width: auto; min-width: 44px; min-height: 40px; justify-content: center; padding: 0 10px; font-size: 15px; border: 1px solid var(--border); }
    #zoomQuickMenu #zqm-fit { font-size: 0.8rem; color: var(--primary); background: #eff6ff; border-color: #bfdbfe; }
    #zqm-pct { min-width: 44px; text-align: center; font-size: 13px; font-weight: 700; }
    @media (max-width: 480px) {
      .tb-zoom-capsule > button:not(#btn-zoom-menu), .tb-zoom-capsule > #zoom-indicator { display: none !important; }
      #btn-zoom-menu { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; gap: 1px; min-width: 36px; height: 36px; min-height: 36px; padding: 0 2px !important; font-size: 13px; }
      #btn-zoom-menu .tb-cap { display: block; font-size: 9.5px; font-weight: 700; line-height: 1; letter-spacing: -0.2px; }
      #btn-doc-edit { height: 36px; min-height: 36px; }
    }
    /* 320px級では「Clear all / Borrar todo」を2行にして幅を詰める(複数ページのPDFでも1行のツールバーに収める) */
    @media (max-width: 360px) {
      #btn-clear-all .tb-cap { white-space: normal; max-width: 34px; text-align: center; overflow-wrap: anywhere; line-height: 1; }
      #btn-clear-all .clear-all-icon { width: 12px !important; height: 12px !important; }
      #pagination-controls button:not(#page-num-indicator) { min-width: 36px !important; }
      /* ◀▶を36pxにした分の幅を空ける: ページ番号(1/2 ▾)の左右の余白と、ボタン間・区切り線・ツールバー端の余白を詰める */
      #pagination-controls #page-num-indicator { min-width: 0 !important; padding: 0 3px !important; }
      #pagination-controls, #default-top-controls .tb-left-group { gap: 0; }
      #toolbar-top #default-top-controls { gap: 1px; }
      .sticky-toolbar-bar#toolbar-top { padding: 0 2px; }
      #default-top-controls .toolbar-divider { margin: 0 1px; }
      #default-top-controls #btn-doc-edit { padding: 0 2px !important; }
      #default-top-controls #btn-clear-all { padding: 0 1px !important; }
      #default-top-controls .toolbar-divider { flex-shrink: 0; }
    }
    /* スマホ幅では上部ツールバーを広げないよう、書類編集ボタンは「✂️」のアイコンだけにする */
    @media (max-width: 768px) {
      #btn-doc-edit { min-width: 30px; padding: 0 5px !important; }
      #btn-doc-edit .btn-label-text { display: none !important; }
    }
    @media (max-width: 400px) {
      #btn-doc-edit { min-width: 30px; padding: 0 4px; font-size: 13px; height: 36px; min-height: 36px; }
      .dep-tool { font-size: 11px; padding: 6px 2px; }
      /* ツールが5つになったので、狭い画面では3つ＋2つの2段に並べて、名前が単語の途中で切れないようにする */
      .dep-tools { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
      .dep-actions button { font-size: 12px; }
    }

    /* モーダル共通 */
    /* 端末に保存するかの選択(初期値OFF)・保存データの全消去・アプリ内の確認ダイアログ */
    .persist-check { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 700; color: var(--text-main); margin: 8px 0 10px; cursor: pointer; }
    .persist-check input { width: 16px; height: 16px; margin: 0; flex-shrink: 0; }
    .ie-persist-row { padding: 0 16px; margin: 6px 0 2px; }
    .data-wipe-btn { display: block; width: 100%; margin-top: 10px; background: none !important; border: none !important; box-shadow: none !important; color: #b91c1c; font-size: 11px; font-weight: 700; padding: 6px 0 !important; text-decoration: underline; }
    #appDialog { z-index: 4000; }
    .modal-overlay {
      position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(4px);
      z-index: 1000; display: none; align-items: center; justify-content: center; padding: 16px;
    }
    .modal-box {
      background: var(--surface); width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto;
      border-radius: var(--radius-lg); padding: 20px; box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
      position: relative; border: 1px solid var(--border);
    }

    /* ---- 保存完了モーダル: A(保存選択)→C(完了・広告・次のアクション)の2画面構造。
       ★保存フローA-C化: 従来あったB(結果通知のみ)画面は廃止し、保存/コピー実行後は
       このC画面へ直接遷移する。以下の.cm-b-*系クラス名は旧B画面から流用したもので、
       現在はすべてC(#cm-screen-c内)で使われている ---- */
    .cm-box { text-align: center; max-width: 440px; }

    /* 結果通知ヘッダー(アイコン+テキスト)を横並びにして縦スペースを圧縮する */
    .cm-b-head { display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%; margin-bottom: 2px; }
    .cm-b-ic { font-size: 2rem; color: #059669; line-height: 1.1; flex: 0 0 auto; }
    .cm-b-head-text { text-align: left; min-width: 0; }
    .cm-b-head-text h3 { margin: 0 0 2px; font-size: 1.05rem; }
    .cm-b-head-text p { margin: 0; font-size: 0.8rem; color: var(--text-muted); }
    /* 共有ボタン(Web Share APIが使える環境のみ表示): 相互アクション/次のアクションより控えめな
       アウトライン調にし、主従関係をはっきりさせる */
    .cm-b-share {
      width: 100%; padding: 11px; margin-top: 10px; font-size: 0.85rem; font-weight: 700;
      background: #eff6ff; border: 1px solid #bfdbfe !important; color: var(--primary, #2563eb);
      box-shadow: none; transition: background .12s ease;
    }
    .cm-b-share:hover, .cm-b-share:active { background: #dbeafe; }
    /* コピー実行時のみ出す「端末に原本を保存」救済導線。保存(PDF/画像)実行時は常に非表示 */
    .cm-backup-box {
      margin: 8px 0 0; text-align: left; background: #f8fafc; border: 1px solid var(--border);
      border-radius: var(--radius-sm); padding: 7px 10px; width: 100%; box-sizing: border-box;
    }
    .cm-backup-label { display: block; font-size: 0.72rem; font-weight: 700; color: var(--text-muted); line-height: 1.4; }
    /* 「画像をコピー」実行時のみ表示するステータスバッジ(クリップボードへのコピー完了を示す緑系) */
    .cm-copied-badge {
      display: none; font-size: 0.7rem; font-weight: 800; color: #047857; background: #ecfdf5;
      border: 1px solid #a7f3d0; border-radius: 999px; padding: 3px 9px; margin: 0 0 5px; white-space: nowrap;
    }

    /* 画面C上部のミニロゴ＆タイトル: 上部の寂しさを解消しつつ、縦幅を極力取らない超薄型ヘッダー(全高32px以内) */
    .cm-c-header { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin-bottom: 8px; line-height: 1; }
    .cm-c-logo { font-size: 0.82rem; font-weight: 800; color: var(--text, #0f172a); }
    .cm-c-sub { font-size: 0.68rem; font-weight: 700; color: var(--text-muted); }

    .cm-left { display: flex; flex-direction: column; gap: 7px; }
    .cm-next { width: 100%; padding: 12px; }
    .cm-row { display: flex; gap: 8px; }
    .cm-row button { flex: 1 1 0; min-width: 0; padding: 10px 6px; font-size: 0.82rem; }
    /* 相互アクションボタン: Aで「コピー」した人には💾保存、Aで「保存」した人には📋コピーを促す誘導導線。
       別の書類を処理する(青)/編集に戻る(グレー)とはひと目で区別できるよう、淡いオレンジ系にする */
    .cm-reciprocal {
      width: 100%; padding: 11px; font-weight: 700; font-size: 0.85rem;
      background: #fff7ed; border: 1px solid #fb923c !important; color: #ea580c;
      box-shadow: none; transition: background .12s ease;
    }
    .cm-reciprocal:hover, .cm-reciprocal:active { background: #ffedd5; }
    /* 主要2択(別の書類を処理する/編集に戻る): 誤操作防止のため間隔を少し広めに取り、
       色をはっきり分ける(次へ進む=鮮やかな青 / 戻る=落ち着いたスレートグレー) */
    .cm-row-primary { gap: 10px; }
    .cm-row-primary .cm-next, .cm-row-primary .cm-back { flex: 1 1 0; min-width: 0; padding: 12px 6px; }
    /* 「編集に戻る」: 隣の「＋別の書類を処理する」(鮮やかな青の主導線)とはっきり区別できるよう、
       枠線＋落ち着いたグレー背景のサブボタンにする(サブ導線であることが一目でわかるように) */
    .cm-back {
      width: 100%; border: 1px solid #cbd5e1 !important; color: #475569; background: #f8fafc;
      font-weight: 600; box-shadow: none; transition: background .12s ease;
    }
    .cm-back:hover, .cm-back:active { background: #f1f5f9; }
    .qr-pop { max-width: 300px; text-align: center; padding: 22px 20px 20px; }
    .qr-pop-x { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; padding: 0; border: none; background: transparent; box-shadow: none; color: var(--text-muted); font-size: 1rem; cursor: pointer; }
    .qr-pop-title { font-weight: 800; font-size: 0.95rem; margin: 0 20px 12px; }
    .qr-pop-qr { display: flex; justify-content: center; margin-bottom: 12px; }
    .qr-pop-sub { font-size: 0.75rem; color: var(--text-muted); line-height: 1.5; }
    /* ★AdSense審査対策(誤クリック誘発防止): 広告枠と操作ボタン群との距離を安全側に拡大 */
    .cm-right { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
    .cm-ad-label { font-size: 0.62rem; color: var(--text-muted); letter-spacing: 0.05em; margin-bottom: 6px; }
    .cm-ad { width: 300px; max-width: 100%; height: 250px; min-height: 250px; margin: 0 auto 14px; box-sizing: border-box; background: #f1f5f9; border: 1px dashed var(--border); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 0.72rem; overflow: hidden; flex-shrink: 0; }
    /* シェア(QR)・応援リンク(Buy Me a Coffee): 補助導線として広告の下に小さく横並びでまとめる */
    .cm-secondary-links { display: flex; gap: 8px; margin-top: 14px; }
    .cm-secondary-links button, .cm-secondary-links a {
      flex: 1 1 0; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 5px;
      padding: 9px 8px; border-radius: 999px; box-sizing: border-box;
      font-weight: 700; font-size: 0.72rem; text-decoration: none;
      transition: transform 0.15s ease, box-shadow 0.15s ease, background .12s ease;
    }
    #btn-complete-share { background: #f1f5f9; border: 1px solid var(--border) !important; color: var(--text-muted); }
    #btn-complete-share:hover { background: #e2e8f0; }
    .cm-support-btn {
      background: #FFDD00; color: #1a1a1a; box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    }
    .cm-support-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
    .cm-support-btn:active { transform: translateY(0); box-shadow: 0 2px 4px rgba(0,0,0,0.15); }
    @media (max-width: 768px) {   /* スマホ: 余白を詰めて、縦長でも収まりやすく(広告300×250のサイズ自体は変えない) */
      .cm-box { padding: 12px 14px 14px; }
      .cm-b-ic { font-size: 2.2rem; }
      .cm-left { gap: 6px; }
      .cm-next { padding: 10px; }
      .cm-row button { padding: 8px 6px; }
      .cm-row-primary .cm-next, .cm-row-primary .cm-back { padding: 10px 6px; }
      /* ★AdSense審査対策(誤クリック誘発防止): スマホでも広告枠周辺の距離を安全側に拡大 */
      .cm-right { margin-top: 16px; padding-top: 14px; }
      .cm-ad-label { margin-bottom: 4px; }
      .cm-ad { margin-bottom: 12px; }
      .cm-secondary-links button, .cm-secondary-links a { padding: 8px; font-size: 0.68rem; }
    }
    @media (min-width: 769px) {
      /* PC/スマホ共通の単一カラムに統一(広告は画面中央に集約配置)。ここでは横幅・余白のみ調整する */
      .cm-box { max-width: 460px; padding: 20px 28px 22px; }
      .cm-b-ic { font-size: 2.6rem; }
      .cm-left { justify-content: center; gap: 10px; }
    }

    /* ---- 縦の短いスマホ(iPhone SEなど)向けの調整 ----
       方針: 「全部を1画面に収める」ことは目的にしない。通常サイズのスマホの見やすさ・
       ボタン/文字の大きさは一切変えず、必須操作(書類操作・スタンプ/サイン・チェック・
       戻す・完了・保存/共有・モーダルを閉じる)が確実に押せることだけを優先する。
       広告枠・投げ銭・補足説明など非必須コンテンツは、画面が足りなければ下に隠れて
       (スクロールすれば辿り着ける状態で)構わない — ここでは、その非必須コンテンツが
       占める縦スペースを削って、必須ボタン側の余白を少しでも確保するだけに留める。
       画面Aのプレビュー枠は既に専用のmax-height:700px調整(.save-preview-wrap img)を持つ。 */
    @media (max-height: 700px) {
      /* モーダル全体: 外周パディングを少し詰めて中身の実効高さを稼ぐ(文字サイズは変えない) */
      .modal-box { padding: 10px; }

      .cm-b-ic { font-size: 1.7rem; }
      .cm-b-head { margin-bottom: 0; gap: 8px; }
      .cm-b-head-text h3 { font-size: 0.95rem; }
      .cm-b-share { padding: 9px; margin-top: 8px; }
      .cm-c-header { margin-bottom: 2px; }
      .cm-left { gap: 4px; }
      .cm-right { margin-top: 4px; padding-top: 4px; }
      /* ★広告枠(300x250)は必須の厳守サイズのため、短い画面でも高さを縮めない。
         その分、周囲の非必須な余白(ラベル下マージン・セクション間ギャップ)を切り詰めて
         下のボタン群がなるべく画面内に収まるよう補う。それでも収まらない場合は
         .modal-box の overflow-y: auto によりスクロールで到達可能(こちらは許容範囲)。 */
      .cm-ad-label { margin-bottom: 1px; }
      .cm-secondary-links button, .cm-secondary-links a { padding: 6px; font-size: 0.64rem; }
      .cm-secondary-links { gap: 5px; margin-top: 5px; }
    }

    .guide-step {
      display: flex; gap: 12px; align-items: flex-start; margin-bottom: 10px;
      background: #f8fafc; padding: 12px; border-radius: var(--radius-md); border: 1px solid var(--border);
    }
    .guide-num {
      background: var(--primary); color: #fff; font-size: 0.75rem; font-weight: 700;
      width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    }

    .camera-frame-mockup {
      width: 180px; height: 130px; margin: 12px auto; border: 2px dashed var(--primary);
      border-radius: 8px; background: #eff6ff; display: flex; flex-direction: column;
      align-items: center; justify-content: center; gap: 4px; color: var(--primary); font-size: 0.75rem; font-weight: 700;
    }

    /* 手書き署名パッド。
       ★実際に書類へスタンプされる縦横比のプレビューにする: 保存済みサインが無い状態での
       既定配置比率(140:65、useSavedSignature()等のフォールバックと同じ比率)に固定し、
       描画中の見た目と最終的にスタンプされた見た目の縦横比が一致するようにする。
       実寸(書類上での小さな見た目)より少し広めに描けるよう、幅は最大560pxまで確保する */
    .pad-wrapper {
      position: relative;
      border: 1px solid var(--border); border-radius: 8px; background: #fff;
      margin: 12px auto; touch-action: none;
      width: 100%; max-width: 560px; aspect-ratio: 140 / 65;
    }
    #signature-pad-canvas { width: 100%; height: 100%; display: block; }
    /* 枠(あり/なし)がONの時、実際に合成される枠線の内側の安全マージンをガイド表示し、
       署名のストロークが枠にかからないようにする(装飾のみ・描画やタップの邪魔はしない) */
    .sign-border-guide {
      position: absolute; inset: 7%; border: 1px dashed var(--sign-guide-color, #94a3b8);
      border-radius: 4px; pointer-events: none; display: none;
    }
    .pad-wrapper.show-border-guide .sign-border-guide { display: block; }

    /* スマホでは署名パッドをフルスクリーン化し、書くスペースを最大限確保する */
    @media (max-width: 768px) {
      /* ★ブラウザ標準の「引っ張って更新」やバウンス動作をここでも明示的に防止 */
      #signModal .modal-box {
        position: fixed; inset: 0; max-width: none; width: 100%; height: 100%;
        border-radius: 0; display: flex; flex-direction: column;
        overscroll-behavior: none; touch-action: none;
      }
      /* ★縦横比は固定(140:65)のまま、横幅いっぱいを使って少し広めに描けるようにする */
      #signModal .pad-wrapper {
        flex: 0 0 auto; margin: 10px auto; width: 94%; max-width: 480px;
        aspect-ratio: 140 / 65; height: auto; max-height: none; min-height: 0;
      }
    }
    /* 横画面の時は、縦方向にも余裕があるので少し大きめに表示する(比率は変えない) */
    @media (max-width: 768px) and (orientation: landscape) {
      #signModal .pad-wrapper { flex: none; width: 70%; max-width: 600px; height: auto; max-height: none; }
    }

    .color-swatch-btn {
      width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff;
      box-shadow: 0 0 0 1px var(--border); padding: 0; cursor: pointer;
      transition: transform 0.12s ease, box-shadow 0.12s ease;
    }
    /* 選択中は二重リング+拡大でひと目で分かるようにする(自由選択ピッカーは廃止し、
       ビジネスサイン用の主要4色スウォッチのワンタップ切替に統一) */
    .color-swatch-btn.active {
      transform: scale(1.15);
      box-shadow: 0 0 0 2px #fff, 0 0 0 4px #2563eb !important;
    }

    /* モーダル右上の閉じるボタン(モバイルで下部ボタンが隠れる対策) */
    .modal-close-x {
      position: absolute; top: 10px; right: 10px; width: 28px; height: 28px;
      border-radius: 50%; border: 1px solid var(--border); background: #fff;
      color: var(--text-muted); font-size: 14px; font-weight: 700; padding: 0;
      display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-sm);
      z-index: 5;
    }
    .modal-close-x:hover { background: #f1f5f9; color: var(--text-main); }
    /* ⑥: 確認ダイアログ・保存画面・完了画面の右上の「×」(押せる範囲 44×44px) */
    .app-close-x {
      width: 44px; height: 44px; min-width: 44px; padding: 0 !important; border: none !important; border-radius: 50%;
      background: transparent; color: var(--text-muted); font-size: 17px; font-weight: 700; line-height: 1;
      display: inline-flex; align-items: center; justify-content: center; box-shadow: none; cursor: pointer; flex-shrink: 0;
    }
    .app-close-x:hover, .app-close-x:focus-visible { background: #f1f5f9; color: var(--text-main); }
    #appDialogX { position: absolute; top: 4px; right: 4px; }
    .save-head-row { display: flex; align-items: center; gap: 4px; margin-bottom: 6px; }
    .save-head-row .save-fmt-seg { flex: 1; min-width: 0; margin-bottom: 0; }
    #btn-save-close-x { margin: -6px -8px -6px 0; }
    .cm-c-header { position: relative; }
    #btn-complete-close-x { position: absolute; right: -10px; top: 50%; transform: translateY(-50%); }

    /* ---- 保存モーダル: フォーマット切替セグメント / インフォバッジ / 広告枠+画像コピー枠 / スケルトン(背景透過)ギミック ----
       縦スクロール解消のため、通常のモーダルよりpaddingや行間を詰めた専用レイアウト(高さ660px前後のスマホでも1画面に収まる想定) */
    .save-modal-box { padding: 14px; }
    .save-fmt-seg { display: flex; gap: 6px; background: #f1f5f9; border-radius: 10px; padding: 3px; margin-bottom: 6px; }
    .save-fmt-btn {
      flex: 1; border: none; background: transparent; color: var(--text-muted); font-size: 0.8rem; font-weight: 800;
      padding: 6px 4px; border-radius: 8px; cursor: pointer; transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
      box-shadow: none; min-height: 0;
    }
    .save-fmt-btn.fmt-pdf.active { background: #fff; color: #1d4ed8; box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2); }
    .save-fmt-btn.fmt-jpg.active { background: #fff; color: #c2410c; box-shadow: 0 2px 6px rgba(234, 88, 12, 0.2); }

    /* インフォバッジ: PDF=青 / JPEG=オレンジ でフォーマットと連動する */
    .save-info-badge {
      display: flex; align-items: center; gap: 6px; border-radius: 999px; padding: 4px 12px; font-size: 0.7rem;
      font-weight: 700; margin-bottom: 6px; line-height: 1.25; width: fit-content;
      background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe;
    }
    .save-info-badge.fmt-jpg { background: #fff7ed; color: #c2410c; border-color: #fed7aa; }

    /* ★保存フローA-C化: 保存前プレビュー(A画面用)。旧B画面の.cm-result-preview-wrapと
       ほぼ同じ見た目を踏襲するが、縦スペースを取りすぎないよう保存モーダル用に少し控えめにする */
    .save-preview-wrap { margin: 0 0 8px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; }
    .save-preview-wrap img {
      max-width: 100%; max-height: 190px; width: auto; height: auto;
      border-radius: var(--radius-sm); border: 1px solid var(--border);
      box-shadow: 0 4px 10px rgba(15, 23, 42, 0.12); object-fit: contain; background: #fff;
      cursor: zoom-in;   /* ★タップで拡大できることを示すカーソル(PC) */
    }
    @media (max-height: 700px) {
      .save-preview-wrap img { max-height: 120px; }
    }
    /* ★プレビュータップで拡大表示できることを伝える小さなヒント文言 */
    .save-preview-hint { font-size: 0.68rem; color: var(--text-muted); }
    /* ★プレビュー拡大表示用のライトボックス。qrPopup同様の全画面オーバーレイに
       画像1枚だけを大きく表示し、どこをタップしても閉じるシンプルな挙動にする */
    #previewZoomOverlay {
      display: none; position: fixed; inset: 0; z-index: 1200;
      background: rgba(15, 23, 42, 0.82); align-items: center; justify-content: center;
      padding: 24px; cursor: zoom-out;
    }
    #previewZoomOverlay img {
      max-width: 92vw; max-height: 88vh; width: auto; height: auto;
      border-radius: var(--radius-sm); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5); background: #fff;
    }
    #previewZoomOverlay .pz-close {
      position: absolute; top: 14px; right: 16px; width: 40px; height: 40px; border-radius: 999px;
      border: none; background: rgba(255, 255, 255, 0.16); color: #fff; font-size: 1.1rem; cursor: pointer;
    }
    #previewZoomOverlay .pz-close:hover, #previewZoomOverlay .pz-close:active { background: rgba(255, 255, 255, 0.28); }

    .save-filename-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
    .save-filename-row input {
      flex: 1; min-width: 0; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 0.8rem;
    }
    #save-filename-ext { font-size: 0.8rem; font-weight: 800; flex-shrink: 0; color: #1d4ed8; }
    #save-filename-ext.fmt-jpg { color: #c2410c; }

    .copy-section { display: flex; flex-direction: column; gap: 5px; margin-bottom: 0; }
    /* 画像コピー枠本体: 常に白背景+影付きで手前に浮かせる(スケルトン透過の対象から除外)。
       見出しは「📋 画像コピー」のみとし、「保存なし」等の否定的な補足は置かない */
    .copy-card {
      background: #fff !important; border: 1px solid var(--border); border-radius: var(--radius-md);
      box-shadow: 0 4px 10px rgba(15, 23, 42, 0.08); padding: 6px 10px; display: flex; flex-direction: column;
      gap: 4px; position: relative; z-index: 2;
    }
    .copy-card-head { font-size: 0.74rem; font-weight: 800; color: var(--text-main); line-height: 1.2; }
    .copy-page-nav { display: flex; align-items: center; justify-content: center; gap: 10px; }
    .copy-page-nav button { padding: 3px 10px; font-size: 0.8rem; font-weight: 800; flex: 0 0 auto; min-height: 0; }
    .copy-page-nav button:disabled { opacity: 0.35; cursor: default; }
    .copy-page-nav span { font-size: 0.78rem; font-weight: 700; color: var(--text-main); }
    #btn-save-copy { padding: 7px; font-size: 0.8rem; min-height: 0; }
    #btn-save-copy:disabled { opacity: 0.7; cursor: default; }

    .save-actions { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
    .save-main-btn { padding: 10px; font-size: 0.86rem; font-weight: 800; border: none; color: #fff; border-radius: var(--radius-md); cursor: pointer; min-height: 0; box-shadow: none; }
    .save-main-btn.fmt-pdf { background: #2563eb; box-shadow: 0 3px 10px rgba(37, 99, 235, 0.3); }
    .save-main-btn.fmt-pdf:hover { background: #1d4ed8; }
    .save-main-btn.fmt-jpg { background: #ea580c; box-shadow: 0 3px 10px rgba(234, 88, 12, 0.3); }
    .save-main-btn.fmt-jpg:hover { background: #c2410c; }
    .save-cancel-btn { border: none; color: var(--text-muted); box-shadow: none; padding: 5px; margin-top: 0; background: transparent; min-height: 0; }

    /* フッターSEOエリア */
    .seo-footer-content {
      background: #fff; border-top: 1px solid var(--border); padding: 40px 20px 80px 20px;
      color: var(--text-muted); line-height: 1.6; font-size: 0.82rem; width: 100%;
    }
    .seo-container { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }
    .seo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
    .seo-card { background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; }
    .seo-card h4 { color: var(--text-main); margin-bottom: 6px; font-size: 0.9rem; font-weight: 700; }
    .footer-links { display: flex; gap: 16px; font-size: 0.75rem; justify-content: center; margin-top: 10px; }
    .footer-links a { color: var(--text-muted); text-decoration: none; }
    .footer-links a:hover { text-decoration: underline; }

    /* スマホ最適化 */
    @media (max-width: 768px) {
      .sidebar { display: none; }
      .mobile-bottom-bar { display: flex; }
      .preview-scroll-area { padding: 12px 8px 80px 8px; }
      .seo-grid { grid-template-columns: 1fr; }

      header { padding: 0 10px; height: 48px; }
      .sticky-toolbar-bar { top: 48px !important; }
      .logo-area { font-size: 0.85rem; }
      /* 「❓ ガイド」のように絵文字とテキストが混在すると、絵文字フォントの行送りに
         line-height:normalが引きずられてボタンだけ縦に間延びすることがあるため、
         line-heightを明示して1行の高さを固定し、折り返し禁止・余白も詰める */
      .btn-header-guide, .btn-header-save {
        white-space: nowrap; line-height: 1.15; padding: 4px 8px; font-size: 0.8rem; flex-shrink: 0;
      }

      /* 上部ツールバーを高さ40px(タップ領域34px前後)・1段固定に超薄型化。折り返しは一切許可しない。
         横スクロールは万一のための保険としてのみ残すが、下の寸法調整で
         スマホの実用幅(320〜430px)では発生しない前提で組む(横スクロールに頼らない設計を最優先)。
         連続モードは下部スタンプパレット側に一本化したため、上部からは撤去し軽量化。 */
      /* ★タップ領域拡大要望により40px→44pxへ(高さのみ拡大。横スクロールに頼らない設計は維持) */
      .sticky-toolbar-bar {
        height: 44px;
        min-height: 44px;
        padding: 0 6px;
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 3px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
      }
      .sticky-toolbar-bar::-webkit-scrollbar { display: none; }
      #default-top-controls {
        flex-wrap: nowrap; width: max-content; margin: 0 auto; gap: 3px;
      }
      #default-top-controls button {
        padding: 6px 7px; min-height: 34px; font-size: 12px; flex-shrink: 0;
      }
      .tb-left-group, .tb-zoom-capsule, .tb-right-group { flex-shrink: 0; gap: 2px; }
      .toolbar-divider { height: 24px; margin: 0 2px; }
      /* 短縮ラベル: あふれた分は ... で切って1行を死守(スペイン語対策) */
      #default-top-controls .btn-label-text {
        display: inline-block; white-space: nowrap; overflow: hidden;
        text-overflow: ellipsis; max-width: 44px; vertical-align: middle;
      }
      .tag-screen { display: none; } /* 狭い画面ではラベルバッジも省略 */
      #zoom-indicator { font-size: 13px !important; min-width: 32px !important; }

      #stamp-prop-toolbar {
        padding: 6px 10px; gap: 8px;
      }
    }

    /* 絵文字を全廃したため、401〜768px幅は上のellipsis省略ルールに任せてラベルを残す
       (絵文字が無いのでラベルを丸ごと隠すと空白ボタンになってしまうため)。
       iPhone SE3級(〜400px)は下のルールで各要素の寸法を個別に厳密指定し、
       横スクロール無しの1段固定に収める。 */
    @media (max-width: 480px) {
      #toolbar-top { padding: 0 4px; height: 44px; }
      #default-top-controls { gap: 2px; }
      .btn-group { gap: 2px; }

      /* ★タップサイズ拡大要望(iPhone SE3等): ↻90°・↩戻す・ズームカプセル(－/＋)・Fit・
         全消去(ゴミ箱)を、375px幅でも横スクロール・折り返しなしのまま親指で押しやすい
         高さ36pxへ揃える(横方向の幅は既存の詰め方をそのまま維持し、1行固定を死守する) */
      #btn-rotate-doc { padding: 0 5px; font-size: 11.5px; height: 36px; min-height: 36px; }

      #btn-undo { min-width: 28px; padding: 0; font-size: 13px; height: 36px; min-height: 36px; }
      #btn-undo .btn-label-text { display: none !important; }

      .tb-zoom-capsule button { min-width: 26px; height: 36px; min-height: 36px; padding: 0; font-size: 13px; }
      #zoom-indicator { min-width: 32px !important; font-size: 11.5px !important; }
      #btn-fit-doc { height: 36px; min-height: 36px; padding: 0 10px !important; font-size: 12px; font-weight: 800; }
      #tb-fit-label { max-width: none !important; overflow: visible !important; }

      #btn-clear-all .btn-label-text { display: none; }
      #btn-clear-all .clear-all-icon { display: inline-block !important; width: 16px !important; height: 16px !important; }
      #btn-clear-all { width: auto !important; min-width: 38px !important; height: 36px !important; min-height: 36px !important; padding: 0 3px !important; justify-content: center; }

      #page-num-indicator { min-width: 42px !important; padding: 5px 4px !important; font-size: 11px !important; }
      #pagination-controls button:not(#page-num-indicator) { min-width: 36px; height: 36px; min-height: 36px; padding: 0; font-size: 13px; }
      #page-num-indicator { height: 36px; min-height: 36px; }
      /* 375px幅では合計370px以内を死守するため、区切り線は非表示にして幅を節約する */
      .toolbar-divider { display: none; }
      #btn-rotate-doc { gap: 2px; }
    }

    /* =====================================================
       スタンプデザイナー (StampLab 統合パネル)
       ※ 既存アプリの button{...} 等に影響されないよう、すべて .sd-panel 配下 + sd- 接頭辞でスコープ
       ===================================================== */
    .sidebar { width: 330px; }
    .sidebar { padding: 12px 12px 16px; gap: 10px; }
    .sb-doc-row { display: grid; grid-template-columns: 1.15fr 0.85fr 0.85fr; gap: 6px; }
    .sb-doc-row button { padding: 7px 6px; font-size: 0.76rem; white-space: nowrap; }
    .sb-doc-row .sb-sample { background: #f8fafc; color: var(--primary); border-color: #dbeafe; }
    .sb-doc-row .sb-blank { background: #f8fafc; color: var(--text-main); border-color: #cbd5e1; }
    #btn-pc-delete-sign { color: #dc2626; flex: 0 0 auto; padding: 7px 10px !important; }

    .sd-panel {
      --sd-primary: #c92a2a; --sd-border: #e2e8f0; --sd-border-strong: #cbd5e1;
      --sd-muted: #64748b; --sd-ink: #0f172a; --sd-accent: #e8a26b; --sd-accent-dark: #9a4a1c; --sd-accent-soft: #fdf6ee;
      background: #fff; border: 1px solid var(--sd-border-strong); border-radius: 14px;
      padding: 10px; display: flex; flex-direction: column; gap: 7px;
      box-shadow: 0 4px 16px -6px rgba(15, 23, 42, 0.10);
    }
    .sd-panel button {
      box-shadow: none; transform: none; padding: 0; gap: 0; font-family: inherit;
    }
    .sd-panel button:hover { transform: none; }
    .sd-panel input[type="text"] { font-family: inherit; }

    .sd-sticky {
      position: sticky; top: -12px; z-index: 20; background: #fff;
      margin: -10px -10px 0; padding: 10px 10px 8px;
      border-radius: 14px 14px 0 0; border-bottom: 1px solid var(--sd-border);
      display: flex; flex-direction: column; gap: 6px;
    }
    /* プレビューと操作ボタンを横並びにするレイアウト(Gemini試作案の採用箇所)。
       プレビュー側に日付印等の横長スタンプが見切れず収まるよう、やや幅広に配分する */
    .sd-compact-head { display: grid; grid-template-columns: 1.25fr 1fr; gap: 8px; align-items: stretch; }
    .sd-compact-head .sd-stage-wrap { height: 116px; }
    /* ★不具合修正: .sd-action-rowの子は常に(新規押印ボタン)と(.sd-sub-actionsラッパー)の2つだけにし、
       .sd-compact-headのgrid(2列)側に3つ目の子要素が増えて自動的に2行目へ折り返されることのないようにする */
    .sd-compact-head .sd-action-row { display: flex; flex-direction: column; gap: 6px; height: 116px; }
    .sd-compact-head .sd-place-btn { flex: 1.1 1 0; width: 100%; }
    /* 下段ボタングループ(PC版: 「前回と同じ位置」「連続押印」の2分割) */
    .sd-sub-actions { display: flex; gap: 6px; flex: 1 1 0; width: 100%; }
    .sd-sub-actions .sd-recall-btn,
    .sd-sub-actions .sd-rapid-btn {
      flex: 1 1 0; min-width: 0; height: 100%; font-size: 11.5px;
      padding: 0 4px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    /* ★PC版とスマホ版の設計を明確に分離: 「前回位置」(スロット別記憶)はPC専用機能とし、
       スマホ版のスタンプ選択シートからは撤廃する(以前のシンプルな1ボタン構成に戻す)。
       再押印はシートを開かなくても使える独立ボタンとして、書類画面下部バー(#btn-mob-repeat)側に
       別途用意する。連続押印は(既存の@media (pointer: coarse)ルールに加えて)ここでも明示的に隠す */
    @media (max-width: 768px), (pointer: coarse) {
      #sd-rapid-btn { display: none !important; }
      .sd-recall-btn { display: none !important; }
      .sd-sub-actions { display: none !important; }
    }

    /* ★スマホ版・保存モーダルの動線一本化: メイン保存ボタン(#btn-save-download)に
       「共有・保存」を一本化する代わりに、別動作の画像コピー枠(.copy-section)と、
       完了画面(#completeModal)の共有ボタン/相互アクション/そのフォーマット切替は
       スマホでは非表示にし、「＋別の書類を処理する」「⮌編集に戻る」の2択へ導線を絞る。
       PC版はこのメディアクエリの対象外のため、レイアウト・挙動とも完全に従来のまま */
    @media (max-width: 768px), (pointer: coarse) {
      .copy-section { display: none !important; }
      #btn-cm-share { display: none !important; }
      #btn-complete-reciprocal { display: none !important; }
      #cm-fmt-seg { display: none !important; }
      /* 画像コピー枠が非表示になり空いた分、iPhone SE等の狭い画面でも視認しやすいよう
         唯一の実行ボタンを一回り大きくする(PC版のサイズには一切影響しない) */
      #btn-save-download.save-main-btn { padding: 14px; font-size: 1rem; }
    }

    .sd-stage-wrap { position: relative; }
    .sd-stage {
      background-color: #fff;
      background-image:
        linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
        linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
        linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
      background-size: 14px 14px; background-position: 0 0, 0 7px, 7px -7px, -7px 0;
      border: 1px solid var(--sd-border-strong); border-radius: 10px;
      height: 108px; display: flex; align-items: center; justify-content: center; overflow: hidden;
    }
    .sd-compact-head .sd-stage { height: 100%; }
    /* #sd-canvas(500×500固定)は実際の押印書き出しにも使う「内部マスター」なので常に非表示にし、
       見た目には lastBBox でトリミングした #sd-canvas-preview だけを表示する。
       このpreview側は内容(円形の実印/横長の日付印など)に合わせて描画時にwidth/height属性を
       動的に設定しているため、CSSはwidth/height:autoで実寸比率のまま縮小するだけでよい
       (以前はcanvasが常に500×500固定で、CSS側でwidth/heightを個別%指定していたため
       正円/正方形スタンプが楕円・長方形に潰れて見える不具合があった。今はcanvas自体の
       解像度が内容の実際の縦横比を反映するため、aspect-ratio固定は不要かつ逆効果になる) */
    #sd-canvas { display: none; }
    .sd-stage canvas { max-width: 96px; max-height: 96px; width: auto; height: auto; filter: drop-shadow(0 3px 6px rgba(0,0,0,0.08)); }
    .sd-compact-head .sd-stage canvas { max-width: 100%; max-height: 88%; width: auto; height: auto; }
    /* U2追補: メモのプレビューを10px以上の文字で描いたときは、枠の中だけ縦にスクロールする */
    .sd-stage.sd-stage-memo-scroll { overflow-x: hidden; overflow-y: auto; align-items: flex-start; padding: 4px 0; box-sizing: border-box; -webkit-overflow-scrolling: touch; }
    .sd-stage.sd-stage-memo-scroll canvas#sd-canvas-preview { max-width: 100%; max-height: none; flex: 0 0 auto; margin: auto 0; }
    .sd-edit-badge {
      position: absolute; left: 6px; top: 6px; background: #3f9c7a; color: #fff;
      font-size: 10px; font-weight: 800; padding: 3px 8px; border-radius: 20px; display: none;
      box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    }
    /* ★ご要望により非表示化: スタンプパネルのプレビュー上に出る「✎ 押印済みを編集中」バッジが
       邪魔とのことで廃止。表示切替のJS(editingOn時にclassList.toggle('on', ...))はそのまま
       残しているが、CSS側で常にdisplay:noneにすることで無害化している。 */
    .sd-edit-badge.on { display: none; }
    .sd-panel.sd-editing .sd-edit-badge { font-size: 11px; padding: 4px 10px; }

    .sd-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #f1f5f9; border-radius: 11px; padding: 3px; }
    .sd-seg-btn {
      height: 34px; border: none !important; border-radius: 9px; background: transparent; color: #64748b; cursor: pointer;
      font-size: 12px; font-weight: 800; padding: 0 4px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
      transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
    }
    .sd-seg-new.active { background: #c92a2a; color: #fff; box-shadow: 0 3px 8px rgba(201, 42, 42, 0.35); }
    .sd-seg-edit.active { background: #f59e0b; color: #fff; box-shadow: 0 3px 8px rgba(245, 158, 11, 0.4); }
    .sd-seg-btn.flash { background: #fee2e2; color: #b91c1c; }
    .sd-panel.sd-editing .sd-place-btn { background: #3f9c7a; box-shadow: 0 3px 8px rgba(63, 156, 122, 0.28); }
    /* チェックモード専用の押印ボタン配色(青=連続打刻の"開始"を示す)は廃止。
       PC/スマホを問わず他モード(通常・認印など)と全く同じボタンデザイン(赤系)に統一する */
    .sd-panel.sd-editing .sd-stage { border-color: #3f9c7a; box-shadow: 0 0 0 3px rgba(63, 156, 122, 0.18); }
    .sd-action-row { display: flex; gap: 6px; }
    .sd-place-btn {
      flex: 1; height: 42px; border: none !important; border-radius: 9px; background: var(--sd-primary);
      color: #fff; font-size: 13px; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 5px;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 6px;
    }
    .sd-place-btn:active { transform: scale(0.98) !important; }
    /* 確定直後にマウス・指がボタン上に残っていても、共通のhover(薄い灰色)で白文字が見えなくならないようにする */
    .sd-place-btn:hover { background: var(--sd-primary); color: #fff; filter: brightness(0.95); }
    .sd-panel.sd-editing .sd-place-btn:hover { background: #3f9c7a; }
    .sd-icon-btn {
      width: 36px; height: 36px; border-radius: 9px; background: #f8fafc; border: 1px solid var(--sd-border-strong) !important;
      font-size: 15px; display: flex; align-items: center; justify-content: center; color: var(--sd-ink);
    }
    .sd-icon-btn:hover { background: #f1f5f9; }
    .sd-stage-tools { position: absolute; right: 6px; top: 6px; display: flex; gap: 6px; }
    .sd-stage-tools .sd-icon-btn { background: rgba(255,255,255,0.92); box-shadow: 0 1px 3px rgba(0,0,0,0.15); }
    /* 連続押印ボタン(サイドバー/ボトムシート): 通常押印ボタンと同じ高さで2分割 */
    .sd-rapid-btn {
      flex: 1; height: 42px; border-radius: 9px; background: #fff; color: #2563eb; font-size: 13px; font-weight: 800;
      border: 1.5px solid #2563eb !important; display: flex; align-items: center; justify-content: center; gap: 5px; box-shadow: none;
    }
    .sd-rapid-btn:hover { background: #eff6ff; }
    /* 連続押印モード中(rapidMode===true)は#sd-rapid-btnを塗りつぶし+パルス発光させ、作業中であることを強調する */
    @keyframes rapidGlowPulse {
      0% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.6); }
      70% { box-shadow: 0 0 0 6px rgba(37, 99, 235, 0); }
      100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
    }
    .sd-rapid-btn.active {
      background: var(--primary, #2563eb) !important;
      color: #ffffff !important;
      border-color: #2563eb !important;
      font-weight: 900;
      animation: rapidGlowPulse 1.8s infinite;
    }
    /* 「前回と同じ位置」ボタン(PC/デスクトップ側)。ゴースト表示と同じエメラルドグリーンで統一し、
       連続押印(青)・新規押印(赤)とは違う機能であることが一目でわかるようにする */
    .sd-recall-btn {
      width: 100%; height: 38px; border-radius: 9px; background: #ecfdf5; color: #047857; font-size: 12.5px; font-weight: 800;
      border: 1.5px solid #10b981 !important; display: flex; align-items: center; justify-content: center; gap: 5px; box-shadow: none;
    }
    .sd-recall-btn:hover { background: #d1fae5; }

    /* Gemini案: 6モードを等幅グリッドのフラットなセグメントボタンに統一(スパン分けを廃止)
       → 6モード(標準/日付/印影/チェック/サイン or 画像/メモ)を3列×2行に再編。
       縦幅が過大にならないよう、1行あたりの min-height を抑えてコンパクトに保つ(iPhone SE等) */
    .sd-mode-grid {
      display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: #f1f5f9;
      border: none; padding: 3px; border-radius: 12px; margin-bottom: 4px;
    }
    /* 各タブが「独立したピル/カード」に見えるよう、非アクティブ時も白背景+薄い枠+わずかな影を
       持たせる(以前は透明背景で、周囲の.sd-mode-grid背景と同化してベタッと一体化して見えていた)。
       サイドバー幅320〜330px付近でも「✓チェック」「✍サイン」等が折り返されて潰れないよう、
       font-sizeを縮小+letter-spacingを詰め、paddingを極小化して絶対に1行に収める。
       3列×2行化に伴い、min-heightを縮小して2行になっても全体の縦幅が過大にならないようにする */
    /* U1: 選ばれているタブを「濃い青の塗りつぶし＋白の太字」、選ばれていないタブを「透明＋薄い枠＋
       濃いグレーの普通の太さ」にして、色だけでなく形と太さでも見分けられるようにする。
       押せる高さは44px以上、タブ同士のすき間は6px。
       コントラスト比: 白 #fff / #1d4ed8 = 6.70:1、#334155 / #f1f5f9 = 9.4:1、#334155 / #fff = 10.4:1 */
    .sd-mode-btn {
      grid-column: auto; min-height: 44px; border: 1px solid #cbd5e1 !important;
      background: transparent; padding: 6px 2px !important;
      font-size: 14px; letter-spacing: -0.03em; font-weight: 700; color: #334155; border-radius: 999px; text-align: center;   /* U2: ラベルを 10px/600 → 13px/700 に(選ばれているタブは 800 のまま)。E1: 13px → 14px */
      display: flex; align-items: center; justify-content: center;
      white-space: nowrap; overflow: hidden; text-overflow: clip;
      box-shadow: none;
      transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease, transform .12s ease;
    }
    .sd-mode-btn:active { transform: scale(0.96); }
    .sd-mode-btn.active { background: #1d4ed8; border-color: #1d4ed8 !important; color: #fff; font-weight: 800; box-shadow: 0 2px 5px rgba(29, 78, 216, 0.3); }
    @media (prefers-reduced-motion: reduce) { .sd-mode-btn { transition: none; } .sd-mode-btn:active { transform: none; } }

    /* Gemini案: タブ切替をやめ「基本・文字」を常時表示 + 「形状・質感」はスライドドロワーに変更 */
    /* overflow:hidden で、閉じたドロワー(translateYで下に逃がしている分)がパネル下部に
       はみ出してスクロール領域に残ってしまう(=同じ設定が下の方に二重に見える)のを防ぐ */
    .sd-body-container { position: relative; width: 100%; min-height: 400px; overflow: hidden; }
    .sd-pane { display: flex; flex-direction: column; gap: 8px; }
    .sd-btn-details-trigger {
      width: 100%; min-height: 42px; background: #eff6ff; border: 1.5px solid #bfdbfe !important;
      border-radius: 8px; font-size: 12px; font-weight: 900; color: #1d4ed8;
      display: flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; margin-top: 4px;
    }
    .sd-btn-details-trigger:hover { background: #dbeafe; }
    /* --sd-primaryはスタンプのインク色(赤)用の変数なので、メイン押印ボタンと紛らわしくならないよう
       ここでは直接プライマリブルーを指定する(誤ってvar(--sd-primary)を使うと赤になってしまうため注意) */
    .sd-btn-details-trigger.sd-details-done { background: #2563eb; color: #fff; border-color: #2563eb !important; margin-top: 8px; }

    .sd-slide-drawer {
      position: absolute; left: 0; right: 0; bottom: 0; top: 0;
      background: rgba(255, 255, 255, 0.99); backdrop-filter: blur(12px);
      border: 1.5px solid var(--sd-border-strong); border-radius: 12px; padding: 10px;
      display: flex; flex-direction: column; gap: 8px; z-index: 50; overflow-y: auto;
      transform: translateY(105%); transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
      box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.16);
    }
    .sd-slide-drawer.open { transform: translateY(0); }
    .sd-drawer-head {
      display: flex; justify-content: space-between; align-items: center;
      border-bottom: 1.5px solid var(--sd-border); padding-bottom: 6px; flex-shrink: 0;
    }
    .sd-drawer-title { font-size: 12px; font-weight: 900; color: var(--sd-ink); }
    .sd-drawer-close {
      background: #eff6ff; color: #1d4ed8; border: 1.5px solid #bfdbfe !important; border-radius: 6px;
      padding: 2px 10px; font-size: 11px; font-weight: 800; cursor: pointer;
    }
    .sd-reroll-inline { font-size: 10px !important; padding: 0 !important; }
    .sd-reroll-inline[aria-disabled="true"] { cursor: not-allowed; }
    #check-wear-reroll[hidden] { display: none !important; }   /* K4: 擦れがオフのときは 🎲 を出さない */
    #check-wear-reroll { font-size: 15px !important; line-height: 1; margin-left: auto; margin-right: 2px; cursor: pointer; }
    /* 傾き・透過はスタンプ選択後、書類上のハンドル/バッジで直接操作する方式に移行したため、
       設定パネル側からは項目自体を非表示にしてスリム化する(内部ロジック・JSバインドはそのまま保持) */
    #sd-tilt-wrap, #sd-bg-wrap { display: none !important; }
    .sd-label {
      font-size: 10px; font-weight: 800; color: var(--sd-muted); letter-spacing: 0.3px;
      display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px;
    }
    .sd-config-btn {
      width: 100%; height: 32px; background: #eff6ff; border: 1px solid #bfdbfe !important; color: #1d4ed8;
      border-radius: 7px; font-size: 11.5px; font-weight: 800; display: flex; align-items: center; justify-content: center; gap: 5px;
    }
    .sd-config-btn:hover { background: #dbeafe; }

    .sd-color-box {
      background: #f8fafc; border: 1px solid var(--sd-border); border-radius: 8px; padding: 6px 10px;
      display: flex; align-items: center; justify-content: space-between;
    }
    .sd-color-row { display: flex; gap: 8px; }
    .sd-color {
      width: 22px; height: 22px; border-radius: 50%; cursor: pointer; border: 2px solid #fff !important;
      box-shadow: 0 0 0 1px var(--sd-border-strong) !important; transition: transform 0.15s;
    }
    .sd-color.active { transform: scale(1.15) !important; box-shadow: 0 0 0 2px #e8a26b, 0 2px 5px rgba(0,0,0,0.2) !important; }

    /* ★文字入力欄とインク色パレットの1行統合(縦スペース捻出用)。
       text-color-unified-rowは既存の.sd-input-rowに追加するクラスなので、
       .sd-input(flex:1)の挙動はそのまま、右側にパレットドット列を横並びで追加するだけで済む */
    .text-color-unified-row { align-items: center; }
    .text-color-unified-row .palette-dots {
      display: flex; align-items: center; gap: 5px; flex: 0 0 auto; padding-left: 2px;
    }

    .sd-preset-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
    .sd-preset {
      min-height: 34px; background: #f8fafc; border: 1px solid var(--sd-border) !important; border-radius: 8px; color: #334155;
      font-size: 10.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 3px !important;
      display: flex; align-items: center; justify-content: center;
    }
    .sd-preset.active { background: var(--sd-accent-soft); border-color: #e8a26b !important; color: var(--sd-accent-dark); font-weight: 800; }
    .sd-preset.empty { color: #94a3b8; border-style: dashed !important; }

    /* 認印・角印: 8枠ではなく実用2枠＋空2枠の計4枠を1行で。長い社名等が省略され過ぎないよう
       高さを確保して折り返し表示にする(横幅は4等分のままだが、行数を1行増やして視認性を上げる) */
    .sd-preset-grid.sd-preset-grid-wide {
      grid-template-columns: repeat(4, 1fr); gap: 6px;
    }
    /* ★通常スタンプ(standard)モード: 8枠(4列×2行)から、スロット6=自由文字(添え書き)枠を含む
       計6枠の均等グリッド(3列×2行)に再編。スロット自体のスタイルは通常の.sd-presetを共用する */
    .sd-preset-grid.sd-preset-grid-3x2 {
      grid-template-columns: repeat(3, 1fr);
    }
    .sd-preset-grid-wide .sd-preset {
      height: 40px; white-space: normal; line-height: 1.2; font-size: 11px;
      display: flex; align-items: center; justify-content: center; text-align: center;
      overflow: hidden; text-overflow: clip; word-break: break-word; padding: 2px 4px !important;
    }

    /* ★英語向け定型スタンプ(APPROVED/PAID/RECEIVED)の常設クイックボタン行 */
    .sd-en-stamps-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
    .sd-en-stamps-label { font-size: 10px; color: #64748b; font-weight: 700; flex: none; white-space: nowrap; }
    .sd-en-stamps-btns { display: flex; gap: 4px; flex: 1 1 auto; min-width: 0; }
    .sd-en-stamps-btns .sd-en-stamp-btn { flex: 1 1 0; min-height: 30px; font-size: 9.5px; letter-spacing: 0.02em; }

    .sd-input-row { display: flex; gap: 5px; }
    .sd-input {
      flex: 1; min-width: 0; height: 32px; background: #f8fafc; border: 1px solid var(--sd-border-strong); border-radius: 6px;
      padding: 0 8px; font-size: 13px; font-weight: 700; color: var(--sd-ink); outline: none;
    }
    .sd-input:focus { background: #fff; border-color: #2563eb; }
    .sd-today-btn {
      height: 32px; padding: 0 10px !important; background: #f1f5f9; border: 1px solid var(--sd-border-strong) !important;
      border-radius: 6px; color: var(--sd-ink); font-size: 11px; font-weight: 700; white-space: nowrap; display: block;
    }

    .sd-stepper {
      display: flex; align-items: center; background: #f8fafc; border: 1px solid var(--sd-border-strong);
      border-radius: 6px; height: 32px; overflow: hidden;
    }
    .sd-step {
      width: 38px; height: 100%; background: #f1f5f9; border: none !important; color: var(--sd-ink); font-size: 13px; font-weight: 800;
      display: flex; align-items: center; justify-content: center; border-radius: 0 !important;
    }
    .sd-step:hover { background: #e2e8f0; }
    /* T3b: メモの文字サイズ「− 11 pt ＋」。見た目は ◀ 値 ▶ (.sd-stepper)にそろえ、真ん中は数字を入力できる欄＋「pt」。端(6・36)のボタンは押せない見た目 */
    .sd-memo-stepper { height: 32px; }
    .sd-memo-stepper .sd-step { width: 44px; font-size: 18px; line-height: 1; }
    .sd-step:disabled { opacity: 0.38; cursor: not-allowed; }
    .sd-memo-size-val { display: flex; align-items: center; justify-content: center; gap: 3px; }
    .sd-memo-size-val input { width: 2.2em; min-width: 0; height: 26px; padding: 0 !important; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--sd-ink); font: inherit; font-size: 14px; font-weight: 800; text-align: center; box-shadow: none; outline: none; -moz-appearance: textfield; }
    .sd-memo-size-val input:focus { border-color: #2563eb; background: #fff; }
    .sd-memo-size-unit { font-size: 12px; font-weight: 800; color: var(--sd-muted); }
    .sd-step:active { background: #cbd5e1; }
    .sd-step-val { flex: 1; text-align: center; font-size: 11.5px; font-weight: 800; color: var(--sd-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

    /* ドロワー内でスクロール無しに収まるよう、文字サイズ・文字の太さを横並びにする省スペース行 */
    .sd-row-2col { display: flex; gap: 8px; }
    .sd-row-2col > div { flex: 1; min-width: 0; }
    .sd-row-2col > div.sd-hidden { display: none !important; flex: 0; }

    .sd-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
    .sd-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
    .sd-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
    .sd-grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }   /* T3: メモの文字サイズ(pt)の5つ(T3b で数字の箱に替えたあとも、ほかで使うかもしれないので残す) */
    .sd-tap {
      height: 30px; background: #f8fafc; border: 1px solid var(--sd-border) !important; color: #334155; font-size: 11px; font-weight: 700;
      border-radius: 6px; display: flex; align-items: center; justify-content: center; padding: 0 4px !important;
      white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .sd-tap.active { background: #fbe8d5; color: #7c3a12; border-color: #e8a26b !important; }
    .sd-hidden { display: none !important; }
    #sd-open-preset {
      display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 14px !important; border-radius: 16px;
      background: #eef2ff; border: 1px solid #c7d2fe !important; color: #3730a3; font-size: 12px; font-weight: 800; cursor: pointer;
    }
    #sd-open-preset:hover { background: #e0e7ff; text-decoration: none; }
    @media (max-width: 768px) { #sd-open-preset { min-height: 38px; padding: 0 18px !important; font-size: 13px; } }
    .sd-link-btn { background: none; border: none !important; color: #1d4ed8; font-size: 10.5px; font-weight: 800; padding: 0 !important; display: inline; }
    .sd-link-btn:hover { text-decoration: underline; }
    .sd-file-btn {
      width: 100%; height: 40px; background: #eff6ff; border: 1.5px dashed #93c5fd !important; color: #1d4ed8;
      border-radius: 8px; font-size: 12.5px; font-weight: 800; display: flex; align-items: center; justify-content: center;
    }
    .sd-file-btn:hover { background: #dbeafe; }
    .sd-file-name { font-size: 10.5px; color: var(--sd-muted); word-break: break-all; margin-top: -4px; }
    .sd-check { display: flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 700; color: #334155; cursor: pointer; user-select: none; }
    .sd-check input { accent-color: #2563eb; width: 15px; height: 15px; cursor: pointer; }
    .sd-sign-wrap { display: none; flex-direction: column; gap: 8px; }
    .sd-panel.sd-signmode .sd-sign-wrap { display: flex; }
    /* Imageモード用パネル: サインモードと同じ縦積みレイアウト(ラベル行→プレビュー枠→ボタン行→トグル) */
    #sd-image-wrap:not(.sd-hidden) { display: flex; flex-direction: column; gap: 8px; }
    .sd-panel.sd-signmode .sd-body-container { display: none !important; }

    /* チェックモード: 書体・枠・質感などは出さないが、押印の操作感(設定を選んでから押印ボタンを押す)は
       他のモードと完全に揃える。「押印」ボタンだけ、押すと連続打刻を開始/終了するトグルとして働く */
    .sd-check-wrap { display: none; flex-direction: column; gap: 10px; }
    .sd-panel.sd-checkmode .sd-check-wrap { display: flex; }
    .sd-panel.sd-checkmode .sd-body-container { display: none !important; }

    /* 💬 メモ(テキスト注記)モード: 自由記入のコメント欄＋色/サイズ/背景・枠トグルのみのシンプル構成 */
    .sd-memo-wrap { display: none; flex-direction: column; gap: 8px; }
    .sd-panel.sd-memomode .sd-memo-wrap { display: flex; }
    .sd-panel.sd-memomode .sd-body-container { display: none !important; }
    .sd-memo-textarea {
      width: 100%; min-height: 44px; max-height: 110px; resize: vertical; box-sizing: border-box;
      border: 1.5px solid #c3d5f3; border-radius: 10px; padding: 8px 10px; font-size: 14px;
      font-family: inherit; line-height: 1.4; color: #1e293b;
    }
    .sd-memo-quick-row { display: flex; flex-wrap: wrap; gap: 6px; }
    .sd-memo-wrap .sd-memo-quick-label { margin: 0 0 -4px; }   /* U2: 挿入ボタン群の見出し(ボタンのすぐ上に寄せる) */
    .sd-memo-quick-row .sd-tap { padding: 5px 9px; font-size: 11.5px; width: auto; flex: 0 0 auto; }
    /* 🔁連続押印ボタンはチェックモードでも他モードと同様に表示する(単発押印/連続押印を選べるようにする) */
    .sd-check-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
    .sd-check-tile {
      aspect-ratio: 1 / 1; border: 1.5px solid #c3d5f3 !important; background: #fff; border-radius: 10px;
      font-size: 22px; font-weight: 800; color: #1d4ed8; display: flex; align-items: center; justify-content: center;
      cursor: pointer; padding: 0;
    }
    .sd-check-tile.active {
      background: #2563eb !important;
      color: #ffffff !important;
      border-color: #2563eb !important;
      box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
    }
    /* K2: 英単語の定型(Paid・Done・Pagado・Listo・Pago・Feito)は、正方形のタイルに収まるよう小さめの文字にする */
    /* K3a: ✓マークタブの「PNG枠」(好きな PNG 画像を登録して押せる)。登録済みはサムネイル・未登録は「＋」。選択中は青い枠 */
    .sd-png-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
    .sd-png-tile {
      aspect-ratio: 1 / 1; min-height: 40px; border: 1.5px dashed #cbd5e1 !important; background: #f8fafc; border-radius: 10px;
      font-size: 22px; font-weight: 800; color: #94a3b8; display: flex; align-items: center; justify-content: center;
      cursor: pointer; padding: 0; overflow: hidden;
    }
    .sd-png-tile.filled { border: 1.5px solid #c3d5f3 !important; background: #fff; }
    .sd-png-tile.filled img { max-width: 84%; max-height: 84%; object-fit: contain; pointer-events: none; }
    .sd-png-tile.active { border: 2px solid #2563eb !important; box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35); }
    .sd-png-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
    .sd-png-reserve-toggle { min-height: 44px; padding: 0 8px; border: none; background: transparent; color: #1d4ed8; font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap; }
    .sd-png-reserve { margin-top: 2px; }
    .sd-png-actions { display: flex; gap: 8px; }
    .sd-sign-delete-btn.sd-png-delete-btn { flex: 1 1 0; min-width: 0; min-height: 44px; font-size: 13px; }   /* 選んでいる画像の削除・入れ替え: 押しやすい 44px 以上 */
    .sd-png-swap-btn { flex: 1 1 0; min-width: 0; min-height: 44px; font-size: 13px; font-weight: 700; color: #1d4ed8; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px; cursor: pointer; white-space: nowrap; }
    .sd-png-swap-btn.active { background: #1d4ed8; color: #fff; border-color: #1d4ed8; }
    .sd-png-tile.swapping { border-style: dashed !important; border-color: #f59e0b !important; }   /* 入れ替え元に選んだ枠: 破線・オレンジの枠 */
    .sd-check-tile.sd-check-tile-word { font-size: 12px; letter-spacing: -0.02em; overflow: hidden; }
    .sd-hint { font-size: 10.5px; color: var(--sd-muted); line-height: 1.5; }
    /* 汎用トグルスイッチ(日付ON/OFF・背景透過ON/OFFで共用)。タップ領域は縦44px以上を維持しつつ、
       見た目のトラック/つまみは一回り小さくして省スペース化(視認性・操作性は変えない) */
    .sd-toggle-row {
      display: flex; align-items: center; justify-content: space-between; gap: 10px;
      min-height: 44px; padding: 2px; margin-bottom: 4px;
    }
    .sd-switch { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; cursor: pointer; flex: none; }
    .sd-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
    .sd-switch-track {
      position: relative; width: 36px; height: 20px; border-radius: 999px; background: #cbd5e1; transition: background 0.15s ease; display: block;
    }
    .sd-switch-thumb {
      position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
      box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: transform 0.15s ease;
    }
    .sd-switch input:checked + .sd-switch-track { background: #2563eb; }
    .sd-switch input:checked + .sd-switch-track .sd-switch-thumb { transform: translateX(16px); }
    .sd-switch input:focus-visible + .sd-switch-track { outline: 2px solid #2563eb; outline-offset: 2px; }
    /* 「透過」「枠を追加」など、2つのトグルを1行にまとめてコンパクトにする並び。
       各グループのタップ領域(ラベル+スイッチ)は引き続き44px以上を確保する */
    .sd-toggle-row-pair { display: flex; align-items: stretch; gap: 6px; margin-bottom: 4px; }
    .sd-toggle-row-pair .sd-toggle-group {
      flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 6px;
      min-height: 44px; padding: 2px 8px; background: #f8fafc; border: 1px solid var(--sd-border); border-radius: 8px;
    }
    .sd-toggle-row-pair .sd-toggle-group .sd-label { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    /* 「画面に手書きで登録」「データから読み込む」を横並びにしてコンパクトにする */
    .sd-file-btn-row { display: flex; gap: 6px; }
    .sd-file-btn-row .sd-file-btn { flex: 1; min-width: 0; height: 44px; padding: 0 4px !important; font-size: 11.5px; line-height: 1.25; white-space: normal; }
    /* 「今日」ボタンの右にトグルを並べる省スペース版レイアウト。入力欄+今日ボタンは
       #sd-date-disable-targetでまとめ、トグル(#sd-showdate-toggle-wrap)だけは
       日付OFF時のグレーアウト対象から外す(OFFにした後も自分でON/OFFを切り替えられるようにするため) */
    #sd-date-wrap .sd-input-row { align-items: center; gap: 8px; }
    .sd-input-row-fields { display: flex; gap: 5px; flex: 1; min-width: 0; }
    /* トグルの左に「表示/非表示」の状態テキストを添えて、何を切り替えているか一目でわかるようにする */
    .sd-switch-labeled { display: flex; align-items: center; gap: 5px; flex: none; }
    .sd-switch-state-text {
      font-size: 10.5px; font-weight: 800; white-space: nowrap; min-width: 30px; text-align: right;
      color: #94a3b8; transition: color 0.15s ease;
    }
    .sd-switch-state-text.is-on { color: #2563eb; }
    /* 日付OFF時は日付入力欄一式(見出し・入力欄・今日ボタン・日付形式)をグレーアウト+操作不可にする。
       トグル自身(#sd-showdate-toggle-wrap)は対象外にして常に操作できるようにする */
    #sd-date-wrap.sd-date-disabled > .sd-label,
    #sd-date-wrap.sd-date-disabled #sd-date-disable-target,
    #sd-date-wrap.sd-date-disabled #sd-datefmt-wrap, #sd-datefmt-wrap.sd-date-disabled {
      opacity: 0.4; pointer-events: none;
    }
    #sd-date-wrap { margin-top: 2px; }
    /* マイサイン枠のラベル行: 右側に明示的な削除ボタンを配置(タップ領域は余白込みで44px以上) */
    .sd-sign-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
    .sd-sign-delete-btn {
      display: flex; align-items: center; justify-content: center; gap: 4px; flex: none;
      min-height: 30px; padding: 10px 10px; font-size: 11px; font-weight: 700; white-space: nowrap;
      color: #dc2626; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; cursor: pointer;
    }
    .sd-sign-delete-btn:hover, .sd-sign-delete-btn:active { background: #fee2e2; }
    .sd-stage.sd-drag { outline: 2px dashed #2563eb; outline-offset: -3px; background-color: #eff6ff; }


    /* 画像を編集(取り込み画像のエディタ) */
    .sd-edit-img-btn {
      width: 100%; min-height: 48px; color: #fff; border: none !important; border-radius: 12px; cursor: pointer;
      background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
      font-size: 14px; font-weight: 800; letter-spacing: 0.02em; display: flex; align-items: center; justify-content: center; gap: 6px;
      transition: transform 0.12s ease, box-shadow 0.12s ease;
    }
    .sd-edit-img-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(99, 102, 241, 0.45); }
    .sd-edit-img-btn:disabled { opacity: 0.4; cursor: default; box-shadow: none; background: #94a3b8; }
    /* 保存スロット(画像・サイン) */
    .sd-my-slot { position: relative; height: 84px; border: 2px dashed var(--sd-border-strong, #cbd5e1); border-radius: 12px; background: #f8fafc; display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: 12px; font-weight: 700; cursor: pointer; }
    .sd-my-slot.filled { border-style: solid; border-color: #e8a26b; background: #fff; cursor: default; }
    .sd-my-slot img { max-width: 92%; max-height: 74px; object-fit: contain; pointer-events: none; }
    .sd-my-slot .sd-slot-del { position: absolute; top: 4px; right: 4px; }
    .sd-slot-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
    .sd-slot {
      position: relative; aspect-ratio: 1; border-radius: 12px; border: 1.5px dashed #cbd5e1; background: #f8fafc; cursor: pointer;
      display: flex; align-items: center; justify-content: center; color: #94a3b8; font-size: 20px; font-weight: 800; overflow: hidden;
      transition: border-color 0.12s ease, transform 0.12s ease;
    }
    .sd-slot:hover { border-color: #6366f1; transform: translateY(-1px); }
    .sd-slot.filled { border-style: solid; border-color: #e2e8f0; color: inherit;
      background-color: #fff;
      background-image: linear-gradient(45deg, #eef2f7 25%, transparent 25%, transparent 75%, #eef2f7 75%), linear-gradient(45deg, #eef2f7 25%, transparent 25%, transparent 75%, #eef2f7 75%);
      background-size: 10px 10px; background-position: 0 0, 5px 5px; }
    .sd-slot.active { border-color: #e8a26b; box-shadow: 0 0 0 2.5px rgba(232, 162, 107, 0.35); }
    .sd-slot:hover { border-color: #94a3b8; }
    .sd-slot img { width: 100%; height: 100%; object-fit: contain; padding: 4px; box-sizing: border-box; pointer-events: none; }
    .sd-slot-del {
      position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; padding: 0 !important; min-height: 0 !important;
      border: none !important; background: rgba(15, 23, 42, 0.65); color: #fff; font-size: 9px; line-height: 18px; cursor: pointer; opacity: 0;
      display: flex; align-items: center; justify-content: center;
    }
    .sd-slot:hover .sd-slot-del, .sd-slot.active .sd-slot-del { opacity: 1; }
    @media (hover: none) { .sd-slot-del { opacity: 1; } }
    .ie-overlay {
      position: fixed; inset: 0; z-index: 1400; background: rgba(15, 23, 42, 0.55); display: none;
      align-items: center; justify-content: center; padding: 14px;
    }
    .ie-overlay.open { display: flex; }
    .ie-card {
      background: #fff; border-radius: 18px; width: 100%; max-width: 460px; max-height: 100%;
      display: flex; flex-direction: column; box-shadow: 0 24px 60px rgba(15, 23, 42, 0.45); overflow: hidden;
    }
    .ie-head { display: flex; align-items: flex-start; gap: 8px; padding: 14px 16px 8px; }
    .ie-title { font-size: 16px; font-weight: 900; color: #0f172a; }
    .ie-sub { font-size: 11px; color: #64748b; margin-top: 2px; line-height: 1.4; }
    .ie-close { margin-left: auto; width: 30px; height: 30px; border-radius: 50%; border: none !important; background: #f1f5f9; color: #475569; font-size: 15px; cursor: pointer; flex: none; }
    .ie-body { padding: 0 16px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
    .ie-stage {
      background: #0f172a; border-radius: 12px; padding: 10px; display: flex; align-items: center; justify-content: center; flex: none;
    }
    .ie-wrap { position: relative; display: inline-block; line-height: 0; cursor: crosshair; touch-action: none; user-select: none; -webkit-user-select: none;
      background-color: #fff;
      background-image: linear-gradient(45deg, #cbd5e1 25%, transparent 25%, transparent 75%, #cbd5e1 75%), linear-gradient(45deg, #cbd5e1 25%, transparent 25%, transparent 75%, #cbd5e1 75%);
      background-size: 16px 16px; background-position: 0 0, 8px 8px; }
    .ie-wrap canvas { max-width: 100%; max-height: 34vh; width: auto; height: auto; display: block; }
    .ie-crop { position: absolute; display: none; border: 2px solid #38bdf8; box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.55); pointer-events: none; box-sizing: border-box; }
    .ie-sec { display: flex; flex-direction: column; gap: 6px; }
    .ie-sec-head { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; font-weight: 800; color: #0f172a; }
    .ie-sec-head b { color: #2563eb; font-variant-numeric: tabular-nums; margin-left: 6px; }
    .ie-reset { background: none; border: none !important; color: #1d4ed8; font-size: 11px; font-weight: 800; cursor: pointer; padding: 2px 0 !important; }
    .ie-reset:hover { text-decoration: underline; }
    .ie-btn-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .ie-btn-row button { height: 34px; border-radius: 8px; border: 1px solid #e2e8f0 !important; background: #f8fafc; font-size: 11.5px; font-weight: 800; color: #334155; cursor: pointer; padding: 0 2px !important; white-space: nowrap; }
    .ie-btn-row button:hover { background: #e2e8f0; }
    .ie-sec input[type=range] { width: 100%; accent-color: #2563eb; }
    .ie-tint-row { display: flex; gap: 8px; align-items: center; }
    .ie-tint { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff !important; box-shadow: 0 0 0 1px #cbd5e1; cursor: pointer; padding: 0 !important; }
    .ie-tint.active { box-shadow: 0 0 0 2.5px #0f172a; }
    .ie-tint.ie-tint-orig { width: auto; border-radius: 13px; padding: 0 10px !important; font-size: 11px; font-weight: 800; background: #f1f5f9; color: #334155; }
    .ie-foot { display: flex; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid #f1f5f9; background: #fff; }
    .ie-foot button { height: 44px; border-radius: 10px; font-size: 13.5px; font-weight: 800; cursor: pointer; border: none !important; }
    .ie-foot .ie-cancel { flex: 1; background: #f1f5f9; color: #475569; }
    .ie-foot .ie-apply { flex: 2; background: #2563eb; color: #fff; }

    /* スロット編集モーダル (パネルの外・body直下に置く) */
    .sd-modal-backdrop {
      position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(2px);
      z-index: 1300; display: none; align-items: center; justify-content: center; padding: 12px;
    }
    .sd-modal-backdrop.open { display: flex; }
    .sd-modal-card {
      width: 100%; max-width: 360px; background: #fff; border-radius: 14px; padding: 14px;
      box-shadow: 0 10px 25px -5px rgba(0,0,0,0.2); display: flex; flex-direction: column; gap: 8px;
      max-height: 85vh; overflow-y: auto;
    }
    .sd-modal-card button { box-shadow: none; transform: none; }
    .sd-modal-title { font-size: 13px; font-weight: 800; color: #0f172a; border-bottom: 1px solid #e2e8f0; padding-bottom: 6px; }
    .sd-modal-slot { display: flex; align-items: center; gap: 6px; }
    .sd-modal-slot-label { font-size: 10px; font-weight: 800; color: #64748b; width: 42px; flex-shrink: 0; }
    /* ★スロット編集: 名前欄の横に置く「ユーザーの覚書」欄。押印内容には影響しないことが一目で
       わかるよう、名前欄より控えめ(斜体・薄い色・点線罫)にし、幅も名前欄よりやや狭くする */
    .sd-modal-slot .sd-modal-name-input { flex: 1.15; min-width: 0; }
    .sd-modal-slot .sd-modal-memo-input {
      flex: 0.85; min-width: 0; font-style: italic; color: #64748b; background: #f8fafc;
      border-style: dashed !important;
    }
    .sd-modal-slot .sd-modal-memo-input:focus { font-style: normal; color: inherit; }
    /* ★行クリア(✕)ボタン: このスロットの文字・メモを即座に空にする小さな丸ボタン */
    .sd-modal-row-clear {
      flex: 0 0 auto; width: 22px; height: 22px; min-height: 0; border-radius: 50%;
      background: #f1f5f9; border: 1px solid #cbd5e1 !important; color: #64748b;
      font-size: 11px; font-weight: 800; line-height: 1; padding: 0 !important;
      display: flex; align-items: center; justify-content: center; cursor: pointer;
    }
    .sd-modal-row-clear:hover, .sd-modal-row-clear:active { background: #fee2e2; border-color: #fca5a5 !important; color: #b91c1c; }
    .sd-modal-save-current {
      background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8; width: 100%; height: 32px;
      font-size: 11.5px; font-weight: 800; border-radius: 6px;
    }
    .sd-modal-actions { display: flex; gap: 5px; margin-top: 6px; border-top: 1px solid #e2e8f0; padding-top: 8px; }
    .sd-modal-actions button { height: 32px; border-radius: 6px; font-size: 11px; font-weight: 700; border: 1px solid #cbd5e1; padding: 0 10px; }
    .sd-modal-reset { background: #f8fafc; color: #c92a2a; flex: 1; }
    .sd-modal-cancel { background: #f1f5f9; color: #475569; }
    .sd-modal-save { background: #0f172a; color: #fff; flex: 1.2; border: none !important; }

    /* スマホ用ボトムシート (同じパネルをここへ移動して使い回す) */
    .sd-sheet {
      position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100; display: none;
      flex-direction: column; background: #f8fafc; border-radius: 18px 18px 0 0;
      box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.25); height: calc(100vh - 54px); height: calc(100dvh - 54px);
      padding-bottom: env(safe-area-inset-bottom);
    }
    .sd-sheet.open { display: flex; }
    .sd-sheet-backdrop {
      position: fixed; inset: 0; z-index: 1090; background: rgba(15, 23, 42, 0.28); display: none;
    }
    .sd-sheet-backdrop.open { display: block; }
    .sd-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 6px; }
    .sd-sheet-title-wrap { display: inline-flex; align-items: center; gap: 6px; }
    .sd-sheet-title { font-weight: 800; font-size: 0.9rem; }
    /* 編集中だけ見出しの横に添える小さなピルバッジ(タイトル自体は「スタンプツール」に統一) */
    .badge-editing {
      display: none; font-size: 10.5px; font-weight: 700; color: #7c3aed;
      background: #f5f3ff; border: 1px solid #c4b5fd; border-radius: 999px; padding: 2px 8px;
    }
    .badge-editing.on { display: inline-block; }
    .sd-sheet-close { padding: 5px 14px; font-size: 0.8rem; border-radius: 16px; }
    .sd-sheet-body { overflow-y: auto; padding: 0 10px 14px; -webkit-overflow-scrolling: touch; }
    .sd-sheet-body .sd-panel { box-shadow: none; }
    .sd-sheet-body .sd-sticky { top: 0; }

    /* ---- スタンプツールシート: 縦の短い端末(iPhone SEなど)向けの圧縮 ----
       このスタイルブロックは<style>内で他のsd-*定義より後に置くことで、
       CSSの詳細度が同じでもソース順で確実に上書きされるようにしている
       (同じ@media (max-height:700px)を上のほうに置くと、後で定義される
       同一クラスの通常ルールに負けて無効化されてしまうため、ここに集約する)。
       見た目の情報量・機能は変えず、余白/高さだけを詰めて1画面に収める狙い */
    @media (max-height: 700px) {
      .sd-sheet-head { padding: 6px 14px 4px; }
      .sd-sticky { padding: 8px 10px 6px; gap: 5px; }
      .sd-compact-head .sd-stage-wrap, .sd-compact-head .sd-action-row { height: 100px; }
      .sd-panel { gap: 6px; }
      .sd-sheet-body { padding: 0 10px 5px; }
      .sd-body-container { min-height: 260px; }
      .sd-mode-grid { padding: 2px; margin-bottom: 2px; gap: 6px; }
      .sd-mode-btn { min-height: 44px; padding: 2px 2px !important; font-size: 12px; }   /* U2: 高さの低い画面は 9px → 11px。E1: 11px → 12px */
      .sd-pane { gap: 3px; }
      .sd-label { margin-bottom: 2px; }
      .sd-preset-grid { gap: 2px; }
      .sd-preset { min-height: 24px; font-size: 9.5px; }
      .sd-preset-grid-wide .sd-preset { height: 32px; }
      .sd-input, .sd-today-btn { height: 28px; }
      .sd-color-box { padding: 2px 10px; }
      .text-color-unified-row { height: 28px; }
      .sd-color { width: 20px; height: 20px; }
      #sd-datefmt-wrap { margin-top: 2px; }
      .sd-grid-2, .sd-grid-4, .sd-grid-5 { gap: 2px; }
      .sd-tap { height: 22px; font-size: 10px; }
      .sd-memo-stepper { height: 22px; }   /* T3b: 高さの低い画面は、今までの5つのボタン(.sd-tap)と同じ高さ 22px(1画面に収める) */
      .sd-memo-stepper .sd-step { font-size: 15px; }
      .sd-memo-size-val input { height: 18px; font-size: 12px; }
      .sd-memo-size-unit { font-size: 11px; }
      .sd-btn-details-trigger { min-height: 32px; margin-top: 0; }
      .sd-file-btn { height: 34px; }
      /* U2追補: 英語・スペイン語は挿入ボタンが2段になるため、メモ画面の部品の間の余白だけ詰めて
         一番下の注意書きまでスクロールなしで見せる(ボタン・入力欄の大きさと日本語の表示は変えない) */
      html:not([lang="ja"]) .sd-sheet-body .sd-memo-wrap { gap: 5px; }
    }

    /* ---- スタンプツールの詳細設定ドロワー(.sd-slide-drawer)がスマホ実機で画面の
       半分ほどで高さが止まってしまう不具合の修正 ----
       原因: ドロワーは position:absolute; inset:0 で親の .sd-body-container を基準に
       広がる仕様だが、.sd-body-container自体の高さは中の(絶対配置ではない)通常コンテンツの
       自然な高さ(またはmin-height)で決まるため、ドロワーもその低い高さに閉じ込められてしまう。
       → ボトムシート(.sd-sheet-body)内に配置されている時だけ、ドロワーをposition:fixedに切り替えて
       .sd-sheetの可視領域いっぱいに独立して広がるようにする(PCサイドバー側の.sd-slide-drawerは
       従来通りの挙動を維持するため、.sd-sheet-body配下にのみ限定して適用)。
       ★topの値は固定pxではなく、JS側(positionDrawerBelowSticky)がプレビュー+押印ボタンの
       エリア(.sd-sticky)の実際の下端に毎回動的に合わせて設定する。これにより、ドロワー展開中も
       プレビューと新規/連続押印ボタンが隠れず常に見えたままになる(--sd-drawer-topは保険用の初期値)。 */
    .sd-sheet-body .sd-slide-drawer.open {
      position: fixed;
      left: 0; right: 0; top: var(--sd-drawer-top, 54px); bottom: 0;
      max-height: calc(100vh - var(--sd-drawer-top, 54px)); max-height: calc(100dvh - var(--sd-drawer-top, 54px));
      border-radius: 12px 12px 0 0;
      padding-bottom: calc(10px + env(safe-area-inset-bottom));
      z-index: 45;   /* .sd-sticky(z-index:20)より上、シート自体(1100)より下でよい(fixedなので視覚的には常に手前) */
    }
    @media (max-height: 700px) {
      .sd-sheet-body .sd-slide-drawer.open { --sd-drawer-top: 46px; }
    }

    /* ---- 書類撮影・台形歪み補正機能(PasScanner) ----
       既存の.modal-overlay/.modal-boxパターンを流用しつつ、写真確認モーダルと
       4隅ピン補正モーダル専用のスタイルのみ追加する。新規クラスは pas- 接頭辞で統一し、
       既存スタイルとの衝突を避ける。 */
    .pas-tip-text {
      text-align: left; font-size: 0.78rem; color: var(--text-main); line-height: 1.6;
      margin-bottom: 14px; background: #f8fafc; padding: 10px 12px; border-radius: 8px;
      border: 1px solid var(--border);
    }
    .pas-preview-container {
      width: 100%; max-height: 50vh; overflow: hidden; border-radius: var(--radius-md);
      border: 1px solid var(--border); background: #111; display: flex;
      align-items: center; justify-content: center; margin-bottom: 14px;
    }
    .pas-preview-container img { max-width: 100%; max-height: 50vh; display: block; }
    .pas-confirm-actions { display: flex; flex-direction: column; gap: 8px; }
    .pas-btn {
      width: 100%; padding: 12px; font-size: 0.9rem; border-radius: var(--radius-md);
      cursor: pointer; font-weight: 700; box-sizing: border-box;
    }
    .pas-btn-primary { background: var(--primary); color: #fff; border: none; }
    .pas-btn-secondary { background: #eff6ff; color: var(--primary); border: 1px solid #bfdbfe; }
    .pas-btn-ghost { background: transparent; color: var(--text-muted); border: none; box-shadow: none; }

    .pas-crop-card { max-width: 480px; width: 100%; padding: 14px; }
    .pas-crop-toolbar {
      display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px;
    }
    .pas-crop-toolbar .pas-btn { width: auto; flex: 1; padding: 10px 8px; font-size: 0.82rem; }
    .pas-crop-wrapper { position: relative; width: 100%; }
    .pas-crop-viewport {
      position: relative; width: 100%; background: #0f172a; border-radius: var(--radius-md);
      overflow: hidden; touch-action: none; user-select: none;
    }
    #pas-crop-canvas { display: block; width: 100%; height: auto; touch-action: none; }
    #pas-loupe {
      position: absolute; width: 120px; height: 120px; border-radius: 50%;   /* S2: 96px→120px、枠は青い線 */
      border: 3px solid #2563eb; box-shadow: 0 2px 10px rgba(0,0,0,0.4);
      pointer-events: none; display: none; z-index: 10; overflow: hidden;
    }
    #pas-loupe canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }   /* S2: 枠いっぱいに表示 */
  
    /* ---- A1 全ページモード ---- */
    /* スタンプツールの切替(2ページ以上のときだけ出る)。連続押印ボタンと同じ青の枠・ONで塗りつぶし */
    .sd-allpages-row { display: flex; padding: 0 2px; }
    .sd-allpages-btn {
      flex: 1; min-width: 0; height: 34px; border-radius: 9px; background: #fff; color: #0f766e; font-size: 12.5px; font-weight: 800;
      border: 1.5px solid #0f766e !important; display: flex; align-items: center; justify-content: center; gap: 5px; box-shadow: none;
      padding: 0 6px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .sd-allpages-btn:hover { background: #f0fdfa; }
    .sd-allpages-btn.active { background: #0f766e !important; color: #fff !important; border-color: #0f766e !important; font-weight: 900; }
    /* 書類の上の「📄 全ページ ON」表示。連続押印の ⚡ バッジ(.rapid-badge)と同じ作り・置き場所(書類エリアの上の中央)。
       連続押印と違い、スマホ(タッチ)でも出す。狭い画面でも画面の外へはみ出さないよう、幅を収めて折り返す */
    .allpages-badge {
      position: fixed; display: none; z-index: 92; transform: translateX(-50%) !important; box-sizing: border-box;
      width: max-content; max-width: calc(100vw - 16px); text-align: left; line-height: 1.3;
      background: #0f766e; color: #fff; border: none; border-radius: 999px; padding: 7px 14px;
      font-size: 12.5px; font-weight: 800; gap: 6px; align-items: center; box-shadow: 0 4px 14px rgba(15, 118, 110, 0.45);
      cursor: pointer; user-select: none;
    }
    .allpages-badge:hover, .allpages-badge:active { background: #115e59; transform: translateX(-50%) !important; }
    .allpages-badge.on { display: flex; }
    /* 全ページスタンプの札(画面だけ。保存する PDF・JPG はスタンプのデータから作るので入らない)。「未確定」の札(左上)と重ならないよう、スタンプの左下に出す */
    .stamp-element .stamp-all-label {
      position: absolute; left: -2px; top: 100%; margin-top: 3px; padding: 1px 6px; border-radius: 6px;
      background: #0f766e; color: #fff; font-size: 10px; font-weight: 800; line-height: 1.5; white-space: nowrap; pointer-events: none;
      transform: scale(var(--stamp-label-inv, 1)); transform-origin: left top;
    }


/* =====================================================================
   B: ダークテーマ(アプリの枠だけ)。<html data-theme="dark"> のときに効く(最初の描画の前に js/i18n-preload.js が付ける)。
   書類のキャンバス・書類そのもの・ページのサムネイル・スタンプ/サインの色・書き出し結果には、一切かけない。
   ===================================================================== */
html[data-theme="dark"] {
  color-scheme: dark;
  --primary-light: #172a4a; --surface: #1e293b; --bg-workspace: #0f172a; --border: #334155; --border-focus: #475569;
  --text-main: #e2e8f0; --text-muted: #94a3b8;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4); --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.45); --shadow-lg: 0 10px 25px -3px rgb(0 0 0 / 0.55);
}
html[data-theme="dark"] body { background: var(--bg-workspace); color: var(--text-main); }
html[data-theme="dark"] .btn-header-settings { background: #182235; }
html[data-theme="dark"] header { background:rgba(30,41,59,0.96) }
html[data-theme="dark"] .header-status-badge.mode-doc { background:#243044; color:#b4c0d0; border-color:var(--border-focus) }
html[data-theme="dark"] .header-status-badge.mode-stamp { background:#2a2347; color:#c4b5fd }
html[data-theme="dark"] .header-status-badge.mode-rapid { background:#172a4a; color:#7aa7f7; border-color:#3b6bb5 }
html[data-theme="dark"] .lang-select-box select { background:#182235 }
html[data-theme="dark"] .btn-header-settings { background:#182235 }
html[data-theme="dark"] .btn-header-guide { background:#172a4a; color:#93c5fd; border:1px solid #2b4a7a }
html[data-theme="dark"] .btn-header-guide:hover { background:#1e3a66 }
html[data-theme="dark"] button:hover { background:#182235 }
html[data-theme="dark"] .option-card { background:#182235 }
html[data-theme="dark"] .segmented-control { background:#334155 }
html[data-theme="dark"] .segmented-control input[type="radio"]:checked + span { background:var(--surface) }
html[data-theme="dark"] .preset-chip { background:var(--surface) }
html[data-theme="dark"] .preset-chip:hover { color:#93c5fd }
html[data-theme="dark"] .sticky-toolbar-bar { background:rgba(30,41,59,0.96) }
html[data-theme="dark"] .page-quick-menu { background:var(--surface) }
html[data-theme="dark"] .page-quick-menu button:hover { background:#243044 }
html[data-theme="dark"] #page-num-indicator { background:#172a4a !important; border:1px solid #2b4a7a !important; color:#93c5fd !important }
html[data-theme="dark"] #page-num-indicator:hover,
html[data-theme="dark"] #page-num-indicator:active { background:#1e3a66 !important; border-color:#3b6bb5 !important; color:#bfdbfe !important }
html[data-theme="dark"] .page-grid-cell { background:#182235 }
html[data-theme="dark"] .page-grid-cell:hover { border-color:#3b6bb5 }
html[data-theme="dark"] .page-grid-cell.current { background:#172a4a }
html[data-theme="dark"] .pgc-badge { background:#33210f; color:#fdba74 }
html[data-theme="dark"] .pgc-del-btn { border:1px solid #7f1d1d; background:var(--surface) }
html[data-theme="dark"] .pgc-del-btn:hover { background:#3a1a1d; border-color:#7f1d1d }
html[data-theme="dark"] .pgc-move-btn { color:#93c5fd; border:1px solid #2b4a7a; background:var(--surface) }
html[data-theme="dark"] .tag-screen { background:#243044 }
html[data-theme="dark"] .tag-stamp { background:#2a2347; color:#c4b5fd }
html[data-theme="dark"] #stamp-prop-toolbar #btn-prop-del { background:#3a1a1d !important; color:#fca5a5 !important; border:1px solid #7f1d1d !important }
html[data-theme="dark"] #stamp-prop-toolbar .rapid-quick-scale,
html[data-theme="dark"] #stamp-prop-toolbar .tilt-group { background:#243044 }
html[data-theme="dark"] #stamp-prop-toolbar .prop-scale-pt { color:#fcd34d }
html[data-theme="dark"] #stamp-prop-toolbar .rapid-quick-scale button,
html[data-theme="dark"] #stamp-prop-toolbar .tilt-group button { background:var(--surface) !important; border:1px solid var(--border-focus) !important }
html[data-theme="dark"] #stamp-prop-toolbar #btn-prop-bg,
html[data-theme="dark"] #stamp-prop-toolbar #btn-prop-bg:hover,
html[data-theme="dark"] #stamp-prop-toolbar .rapid-quick-scale button,
html[data-theme="dark"] #stamp-prop-toolbar .rapid-quick-scale button:hover,
html[data-theme="dark"] #stamp-prop-toolbar .tilt-group button,
html[data-theme="dark"] #stamp-prop-toolbar .tilt-group button:hover { color:#cbd5e1 }
html[data-theme="dark"] #stamp-prop-toolbar #prop-scale-val,
html[data-theme="dark"] #stamp-prop-toolbar #tilt-val { color:#cbd5e1 }
html[data-theme="dark"] .prop-scale-popup { background:rgba(30,41,59,0.96); border:1px solid var(--border-focus) }
html[data-theme="dark"] .prop-scale-preset { border:1px solid var(--border-focus) !important; background:var(--surface); color:#cbd5e1 }
html[data-theme="dark"] #btn-prop-color { background:var(--surface) !important; border:1px solid var(--border-focus) !important; color:#b4c0d0 !important }
html[data-theme="dark"] .prop-color-popup { background:rgba(30,41,59,0.96); border:1px solid var(--border-focus) }
html[data-theme="dark"] .tilt-group #tilt-val { color:#b4c0d0 }
html[data-theme="dark"] .btn-prop-del { color:#fca5a5 !important }
html[data-theme="dark"] .btn-prop-del:hover { background:#4a1f22 !important; border-color:#7f1d1d !important }
html[data-theme="dark"] .preview-scroll-area.stamp-lock { background-color:#334155 }
html[data-theme="dark"] .rapid-pill { background:#172a4a; border:1.5px solid #3b6bb5 !important; color:#93c5fd }
html[data-theme="dark"] .rapid-pill:hover { background:#1e3a66 }
html[data-theme="dark"] .rapid-quick-bar { background:var(--surface); border:1px solid var(--border) }
html[data-theme="dark"] .rapid-quick-bar #btn-rapid-color { background:#182235; border:1.5px solid var(--border-focus); color:#b4c0d0 }
html[data-theme="dark"] .rapid-quick-bar #btn-rapid-color:hover { background:#172a4a }
html[data-theme="dark"] .rapid-quick-sep { background:#334155 }
html[data-theme="dark"] .rapid-quick-size button { border:1.5px solid var(--border-focus); background:#182235; color:#cbd5e1 }
html[data-theme="dark"] .rapid-quick-scale button { border:1.5px solid var(--border-focus); background:#182235; color:#cbd5e1 }
html[data-theme="dark"] .rapid-quick-scale span { color:#cbd5e1 }
html[data-theme="dark"] .rapid-quick-bar .tilt-group button { border:1.5px solid var(--border-focus); background:#182235; color:#cbd5e1 }
html[data-theme="dark"] #rapid-tilt-val { color:#cbd5e1 }
html[data-theme="dark"] .drop-zone { border:2px dashed var(--border-focus) }
html[data-theme="dark"] .hero-badge { background:#243044; color:#b4c0d0 }
html[data-theme="dark"] .drop-btn-sample { background:#182235; border:1.5px solid var(--border-focus) }
html[data-theme="dark"] .drop-btn.btn-camera-trigger { background:#182235; border:1.5px solid var(--border-focus) }
html[data-theme="dark"] .drop-btn-blank { background:#182235; border:1.5px solid var(--border-focus) }
html[data-theme="dark"] .mobile-bottom-bar .mob-bar-icon-btn,
html[data-theme="dark"] .mobile-bottom-bar .mob-bar-icon-btn:hover,
html[data-theme="dark"] .mobile-bottom-bar .mob-bar-main-btn,
html[data-theme="dark"] .mobile-bottom-bar .mob-bar-main-btn:hover { color:#cbd5e1 }
html[data-theme="dark"] .mobile-bottom-bar .mob-bar-repeat-btn { background:#33210f }
html[data-theme="dark"] #mob-repeat-icon { background-color:var(--surface) }
html[data-theme="dark"] .repeat-label { color:#fb923c }
html[data-theme="dark"] .mob-bar-main-btn.active { color:#93c5fd !important }
html[data-theme="dark"] .mob-bar-main-btn.editing-stamp { background:#33290f !important }
html[data-theme="dark"] .btn-mob-edit { background:#33290f !important }
html[data-theme="dark"] .header-status-badge.mode-edit { background:#33210f; color:#fdba74; border-color:#7c3a15 }
html[data-theme="dark"] #btn-doc-edit.active { background:#33210f; color:#fdba74; border-color:#7c3a15 }
html[data-theme="dark"] .doc-edit-sidebar-note { background:#33210f; border:1px solid #7c3a15; color:#fdba74 }
html[data-theme="dark"] .doc-edit-panel { background:var(--surface); border:1px solid var(--border) }
html[data-theme="dark"] .dep-title { color:#fdba74 }
html[data-theme="dark"] .dep-done { background:var(--surface); color:#7aa7f7 }
html[data-theme="dark"] .dep-done:hover { background:#172a4a }
html[data-theme="dark"] .dep-tool { background:#182235; border:1px solid var(--border); color:#cbd5e1 }
html[data-theme="dark"] .dep-tool.active { background:#33210f; border-color:#7c3a15; color:#fdba74 }
html[data-theme="dark"] .dep-note { background:#33290f; color:#fcd34d }
html[data-theme="dark"] .dep-actions button { border:1px solid var(--border-focus); background:var(--surface); color:#cbd5e1 }
html[data-theme="dark"] .dep-hintrow .dep-info { color:#7aa7f7; border:1px solid #2b4a7a; background:#172a4a }
html[data-theme="dark"] .dep-actions .dep-info { color:#7aa7f7; border-color:#2b4a7a; background:#172a4a }
html[data-theme="dark"] .dep-straighten .dep-step { border:1px solid var(--border-focus); background:var(--surface); color:#cbd5e1 }
html[data-theme="dark"] .dep-straighten .dep-deg { color:#fdba74 }
html[data-theme="dark"] .dep-warn { background:#3a1a1d; border:1px solid #7f1d1d; color:#fca5a5 }
html[data-theme="dark"] .crop-h { background:var(--surface) }
html[data-theme="dark"] #zoomQuickMenu #zqm-fit { color:#93c5fd; background:#172a4a; border-color:#2b4a7a }
html[data-theme="dark"] .data-wipe-btn { color:#fca5a5 }
html[data-theme="dark"] .cm-b-ic { color:#6ee7b7 }
html[data-theme="dark"] .cm-b-share { background:#172a4a; border:1px solid #2b4a7a !important }
html[data-theme="dark"] .cm-b-share:hover,
html[data-theme="dark"] .cm-b-share:active { background:#1e3a66 }
html[data-theme="dark"] .cm-backup-box { background:#182235 }
html[data-theme="dark"] .cm-copied-badge { color:#6ee7b7 }
html[data-theme="dark"] .cm-reciprocal { background:#33210f; color:#fb923c }
html[data-theme="dark"] .cm-back { border:1px solid var(--border-focus) !important; color:#b4c0d0; background:#182235 }
html[data-theme="dark"] .cm-back:hover,
html[data-theme="dark"] .cm-back:active { background:#243044 }
html[data-theme="dark"] .cm-ad { background:#243044 }
html[data-theme="dark"] #btn-complete-share { background:#243044 }
html[data-theme="dark"] #btn-complete-share:hover { background:#334155 }
html[data-theme="dark"] .guide-step { background:#182235 }
html[data-theme="dark"] .camera-frame-mockup { background:#172a4a; color:#93c5fd }
html[data-theme="dark"] .modal-close-x { background:var(--surface) }
html[data-theme="dark"] .modal-close-x:hover { background:#243044 }
html[data-theme="dark"] .app-close-x:hover,
html[data-theme="dark"] .app-close-x:focus-visible { background:#243044 }
html[data-theme="dark"] .save-fmt-seg { background:#243044 }
html[data-theme="dark"] .save-fmt-btn.fmt-pdf.active { background:var(--surface); color:#93c5fd }
html[data-theme="dark"] .save-fmt-btn.fmt-jpg.active { background:var(--surface); color:#fdba74 }
html[data-theme="dark"] .save-info-badge { background:#172a4a; color:#93c5fd; border:1px solid #2b4a7a }
html[data-theme="dark"] .save-info-badge.fmt-jpg { background:#33210f; color:#fdba74 }
html[data-theme="dark"] .save-preview-wrap img { background:var(--surface) }
html[data-theme="dark"] #previewZoomOverlay img { background:var(--surface) }
html[data-theme="dark"] #save-filename-ext { color:#93c5fd }
html[data-theme="dark"] #save-filename-ext.fmt-jpg { color:#fdba74 }
html[data-theme="dark"] .copy-card { background:var(--surface) !important }
html[data-theme="dark"] .seo-footer-content { background:var(--surface) }
html[data-theme="dark"] .seo-card { background:#182235 }
html[data-theme="dark"] .sb-doc-row .sb-sample { background:#182235; color:#93c5fd }
html[data-theme="dark"] .sb-doc-row .sb-blank { background:#182235; border-color:var(--border-focus) }
html[data-theme="dark"] #btn-pc-delete-sign { color:#fca5a5 }
html[data-theme="dark"] .sd-panel { background:var(--surface) }
html[data-theme="dark"] .sd-sticky { background:var(--surface) }
html[data-theme="dark"] .sd-seg { background:#243044 }
html[data-theme="dark"] .sd-seg-btn.flash { background:#4a1f22; color:#fca5a5 }
html[data-theme="dark"] .sd-icon-btn { background:#182235 }
html[data-theme="dark"] .sd-icon-btn:hover { background:#243044 }
html[data-theme="dark"] .sd-rapid-btn { background:var(--surface); color:#7aa7f7 }
html[data-theme="dark"] .sd-rapid-btn:hover { background:#172a4a }
html[data-theme="dark"] .sd-recall-btn { color:#6ee7b7 }
html[data-theme="dark"] .sd-mode-grid { background:#243044 }
html[data-theme="dark"] .sd-mode-btn { border:1px solid var(--border-focus) !important; color:#cbd5e1 }
html[data-theme="dark"] .sd-btn-details-trigger { background:#172a4a; border:1.5px solid #2b4a7a !important; color:#93c5fd }
html[data-theme="dark"] .sd-btn-details-trigger:hover { background:#1e3a66 }
html[data-theme="dark"] .sd-slide-drawer { background:rgba(30,41,59,0.96) }
html[data-theme="dark"] .sd-drawer-close { background:#172a4a; color:#93c5fd; border:1.5px solid #2b4a7a !important }
html[data-theme="dark"] .sd-config-btn { background:#172a4a; border:1px solid #2b4a7a !important; color:#93c5fd }
html[data-theme="dark"] .sd-config-btn:hover { background:#1e3a66 }
html[data-theme="dark"] .sd-color-box { background:#182235 }
html[data-theme="dark"] .sd-preset { background:#182235; color:#cbd5e1 }
html[data-theme="dark"] .sd-input { background:#182235 }
html[data-theme="dark"] .sd-input:focus { background:var(--surface) }
html[data-theme="dark"] .sd-today-btn { background:#243044 }
html[data-theme="dark"] .sd-stepper { background:#182235 }
html[data-theme="dark"] .sd-step { background:#243044 }
html[data-theme="dark"] .sd-step:hover { background:#334155 }
html[data-theme="dark"] .sd-step:active { background:#475569 }
html[data-theme="dark"] .sd-tap { background:#182235; color:#cbd5e1 }
html[data-theme="dark"] .sd-link-btn { color:#93c5fd }
html[data-theme="dark"] .sd-file-btn { background:#172a4a; border:1.5px dashed #3b6bb5 !important; color:#93c5fd }
html[data-theme="dark"] .sd-file-btn:hover { background:#1e3a66 }
html[data-theme="dark"] .sd-check { color:#cbd5e1 }
html[data-theme="dark"] .sd-memo-textarea { border:1.5px solid #2b4a7a }
html[data-theme="dark"] .sd-check-tile { border:1.5px solid #2b4a7a !important; background:var(--surface); color:#93c5fd }
html[data-theme="dark"] .sd-png-tile { border:1.5px dashed var(--border-focus) !important; background:#182235 }
html[data-theme="dark"] .sd-png-tile.filled { border:1.5px solid #2b4a7a !important; background:var(--surface) }
html[data-theme="dark"] .sd-png-reserve-toggle { color:#93c5fd }
html[data-theme="dark"] .sd-png-swap-btn { color:#93c5fd; background:#172a4a; border:1px solid #2b4a7a }
html[data-theme="dark"] .sd-switch-track { background:#475569 }
html[data-theme="dark"] .sd-toggle-row-pair .sd-toggle-group { background:#182235 }
html[data-theme="dark"] .sd-switch-state-text.is-on { color:#7aa7f7 }
html[data-theme="dark"] .sd-sign-delete-btn { color:#fca5a5; background:#3a1a1d; border:1px solid #7f1d1d }
html[data-theme="dark"] .sd-sign-delete-btn:hover,
html[data-theme="dark"] .sd-sign-delete-btn:active { background:#4a1f22 }
html[data-theme="dark"] .sd-my-slot { border:2px dashed var(--sd-border-strong, var(--border-focus)); background:#182235 }
html[data-theme="dark"] .sd-my-slot.filled { background:var(--surface) }
html[data-theme="dark"] .sd-slot { border:1.5px dashed var(--border-focus); background:#182235 }
html[data-theme="dark"] .sd-slot.filled { border-color:var(--border); background-color:var(--surface) }
html[data-theme="dark"] .ie-card { background:var(--surface) }
html[data-theme="dark"] .ie-title { color:var(--text-main) }
html[data-theme="dark"] .ie-close { background:#243044; color:#b4c0d0 }
html[data-theme="dark"] .ie-wrap { background-color:var(--surface) }
html[data-theme="dark"] .ie-sec-head { color:var(--text-main) }
html[data-theme="dark"] .ie-sec-head b { color:#7aa7f7 }
html[data-theme="dark"] .ie-reset { color:#93c5fd }
html[data-theme="dark"] .ie-btn-row button { border:1px solid var(--border) !important; background:#182235; color:#cbd5e1 }
html[data-theme="dark"] .ie-btn-row button:hover { background:#334155 }
html[data-theme="dark"] .ie-tint.ie-tint-orig { background:#243044; color:#cbd5e1 }
html[data-theme="dark"] .ie-foot { border-top:1px solid #2a3547; background:var(--surface) }
html[data-theme="dark"] .ie-foot .ie-cancel { background:#243044; color:#b4c0d0 }
html[data-theme="dark"] .sd-modal-card { background:var(--surface) }
html[data-theme="dark"] .sd-modal-title { color:var(--text-main); border-bottom:1px solid var(--border) }
html[data-theme="dark"] .sd-modal-slot .sd-modal-memo-input { background:#182235 }
html[data-theme="dark"] .sd-modal-row-clear { background:#243044; border:1px solid var(--border-focus) !important }
html[data-theme="dark"] .sd-modal-row-clear:hover,
html[data-theme="dark"] .sd-modal-row-clear:active { background:#4a1f22; border-color:#7f1d1d !important; color:#fca5a5 }
html[data-theme="dark"] .sd-modal-save-current { background:#172a4a; border:1px solid #2b4a7a; color:#93c5fd }
html[data-theme="dark"] .sd-modal-actions { border-top:1px solid var(--border) }
html[data-theme="dark"] .sd-modal-actions button { border:1px solid var(--border-focus) }
html[data-theme="dark"] .sd-modal-reset { background:#182235; color:#f87171 }
html[data-theme="dark"] .sd-modal-cancel { background:#243044; color:#b4c0d0 }
html[data-theme="dark"] .sd-sheet { background:#182235 }
html[data-theme="dark"] .badge-editing { color:#c4b5fd; background:#2a2347 }
html[data-theme="dark"] .pas-tip-text { background:#182235 }
html[data-theme="dark"] .pas-btn-secondary { background:#172a4a; color:#93c5fd; border:1px solid #2b4a7a }
html[data-theme="dark"] .sd-allpages-btn { background:var(--surface); color:#5eead4 }


/* --- 生成だけでは足りない所(インラインの色指定・変数・グラデーション)の手当て --- */
html[data-theme="dark"] .sd-panel { --sd-border: #334155; --sd-border-strong: #475569; --sd-muted: #94a3b8; --sd-ink: #e2e8f0; --sd-accent-dark: #f0b98a; --sd-accent-soft: #2c2118; }
html[data-theme="dark"] .btn-header-guide { color: #93c5fd; }
html[data-theme="dark"] .sticky-toolbar-bar#toolbar-top { background: rgba(15, 23, 42, 0.96); border-bottom-color: #475569; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); }
html[data-theme="dark"] .mobile-bottom-bar { background: rgba(30, 41, 59, 0.98); border-color: var(--border-focus); }
html[data-theme="dark"] #btn-fit-doc { background: #172a4a !important; color: #93c5fd !important; border-color: #2b4a7a !important; }
html[data-theme="dark"] #zoom-indicator { color: var(--text-main); }
html[data-theme="dark"] #sd-open-preset { background: #232a52; border-color: #4a54a0 !important; color: #c7d2fe; }
html[data-theme="dark"] #sd-open-preset:hover { background: #2d3566; }
html[data-theme="dark"] .tag-screen { color: var(--text-muted); }
html[data-theme="dark"] { --text: #e2e8f0; }
/* app.html のインライン指定(style="…")の色 */
html[data-theme="dark"] [style*="background:#f8fafc"] { background: #182235 !important; }
html[data-theme="dark"] button[style*="background:#fff"] { background: var(--surface) !important; }
html[data-theme="dark"] [style*="background:#fffbeb"] { background: #33290f !important; border-color: #6b5314 !important; }
html[data-theme="dark"] [style*="color:#92400e"] { color: #fcd34d !important; }
html[data-theme="dark"] [style*="background:#eff6ff"] { background: #172a4a !important; border-color: #2b4a7a !important; }

/* =====================================================================
   E3: ダークモードのスタンプツールのパネルで、ボタンの境目(枠)をパネルの背景から 3:1 以上離す(WCAG 1.4.11)。
   未選択は「パネルより一段明るい塗り＋明るい枠」、選択中は「濃い青(温かい色のものは暗いオレンジ)の塗り＋明るい枠」。文字と塗りは 4.5:1 以上。
   色はここの変数にまとめ、html[data-theme="dark"] の中だけで指定する(ライトは変えない)。書類・サムネイル・スタンプの色・書き出しには触れない。
   ===================================================================== */
html[data-theme="dark"] .sd-panel {
  --sd-d-fill: #2c3a52;        /* 未選択のボタンの塗り(パネル #1e293b・#243044 より一段明るい) */
  --sd-d-edge: #8493ab;        /* 未選択のボタンの枠(パネルの背景との差 3:1 以上) */
  --sd-d-ink: #e2e8f0;
  --sd-d-sel-fill: #1d4ed8;    /* 選択中の塗り(今の濃い青) */
  --sd-d-sel-edge: #93c5fd;    /* 選択中の枠(明るい青) */
  --sd-d-warm-fill: #4a3220;   /* 選択中(温かい色のスロット・XS/S/M/L など)の塗り */
  --sd-d-warm-edge: #e8a26b;
  --sd-d-warm-ink: #fde8cf;
  --sd-d-blue-fill: #1c3358;   /* 青系のボタン(詳細設定・サイン読み込みなど)の塗りと枠 */
  --sd-d-blue-edge: #7c9fe6;
  --sd-d-blue-ink: #c7dcff;
}
html[data-theme="dark"] .sd-panel .sd-mode-btn,
html[data-theme="dark"] .sd-panel .sd-preset,
html[data-theme="dark"] .sd-panel .sd-tap,
html[data-theme="dark"] .sd-panel .sd-check-tile,
html[data-theme="dark"] .sd-panel .sd-png-tile,
html[data-theme="dark"] .sd-panel .sd-png-tile.filled,
html[data-theme="dark"] .sd-panel .sd-today-btn,
html[data-theme="dark"] .sd-panel .sd-step { background: var(--sd-d-fill); border-color: var(--sd-d-edge) !important; color: var(--sd-d-ink); }
html[data-theme="dark"] .sd-panel .sd-stepper { border-color: var(--sd-d-edge); }   /* ◀ ▶ の枠(ボタン単体には枠が無い) */
html[data-theme="dark"] .sd-panel #sd-open-preset { background: var(--sd-d-blue-fill); border-color: var(--sd-d-blue-edge) !important; color: var(--sd-d-blue-ink); }
html[data-theme="dark"] .sd-panel .sd-png-tile { border-color: var(--sd-d-edge) !important; }
html[data-theme="dark"] .sd-panel .sd-png-tile.filled { border-style: solid !important; }
html[data-theme="dark"] .sd-panel .sd-mode-btn.active,
html[data-theme="dark"] .sd-panel .sd-check-tile.active { background: var(--sd-d-sel-fill) !important; border-color: var(--sd-d-sel-edge) !important; color: #fff !important; }
html[data-theme="dark"] .sd-panel .sd-check-tile.active { background: #2563eb !important; }
html[data-theme="dark"] .sd-panel .sd-png-tile.active { border-color: var(--sd-d-sel-edge) !important; background: var(--sd-d-fill); }
html[data-theme="dark"] .sd-panel .sd-preset.active,
html[data-theme="dark"] .sd-panel .sd-tap.active { background: var(--sd-d-warm-fill); border-color: var(--sd-d-warm-edge) !important; color: var(--sd-d-warm-ink); }
html[data-theme="dark"] .sd-panel .sd-link-btn,
html[data-theme="dark"] .sd-panel .sd-btn-details-trigger,
html[data-theme="dark"] .sd-panel .sd-drawer-close,
html[data-theme="dark"] .sd-panel .sd-file-btn { background: var(--sd-d-blue-fill); border-color: var(--sd-d-blue-edge) !important; color: var(--sd-d-blue-ink); }
html[data-theme="dark"] .sd-panel .sd-link-btn.sd-reroll-inline { background: transparent; border-color: transparent !important; }
html[data-theme="dark"] .sd-panel .sd-toggle-row-pair .sd-toggle-group { background: var(--sd-d-fill); border-color: var(--sd-d-edge); }
html[data-theme="dark"] .sd-panel .sd-switch-track { background: var(--sd-d-edge); }
html[data-theme="dark"] .sd-panel .sd-switch input:checked + .sd-switch-track { background: #3b82f6; }
html[data-theme="dark"] .sd-panel .sd-memo-size-val input:focus { background: var(--sd-d-fill); border-color: var(--sd-d-sel-edge); }


/* ダークのメモのコメント入力欄: 文字色が #1e293b のままで背景が暗く読めなかった(1.31:1)ので、明るい文字・暗い塗りにする(ライトは変えない) */
html[data-theme="dark"] .sd-panel .sd-memo-textarea { background: #182235; color: #e2e8f0; border-color: #7c9fe6; caret-color: #e2e8f0; }
html[data-theme="dark"] .sd-panel .sd-memo-textarea::placeholder { color: #94a3b8; opacity: 1; }
html[data-theme="dark"] .sd-panel .sd-memo-textarea:focus { border-color: #93c5fd; outline: none; }

/* ダークの保存画面(と完了画面の形式切替): 切替・ヒント・キャンセル・ファイル名の欄を、E3 のスタンプツールのタブと同じ見え方にそろえる(ライトは変えない)。
   未選択=一段明るい塗り+はっきりした枠+白に近い文字 / 選択中=青の塗り+明るい枠+白文字。色は E3 の変数と同じ値 */
html[data-theme="dark"] .save-fmt-seg .save-fmt-btn { background: #2c3a52; border: 1px solid #8493ab; color: #e2e8f0; box-shadow: none; }
html[data-theme="dark"] .save-fmt-seg .save-fmt-btn.fmt-pdf.active,
html[data-theme="dark"] .save-fmt-seg .save-fmt-btn.fmt-jpg.active { background: #1d4ed8; border-color: #93c5fd; color: #fff; box-shadow: none; }
html[data-theme="dark"] .save-preview-hint { color: #b9c4d4; }
html[data-theme="dark"] .save-cancel-btn { color: #cbd5e1; }
html[data-theme="dark"] .save-filename-row input { background: #2c3a52; border-color: #8493ab; color: #e2e8f0; caret-color: #e2e8f0; }
html[data-theme="dark"] .save-filename-row input::placeholder { color: #94a3b8; opacity: 1; }
html[data-theme="dark"] .save-filename-row input:focus { border-color: #93c5fd; outline: none; }

/* ダークの保存完了画面: 保存画面と同じ見え方にそろえる。二次ボタン(編集に戻る・シェア(QR)・共有)は一段明るい塗り+はっきりした枠+白に近い文字、
   主ボタン(別の書類を処理する)は青の塗り+明るい枠+白文字。薄いグレーだった説明・「広告」・サブタイトルは持ち上げる(ライトは変えない) */
html[data-theme="dark"] #completeModal #btn-complete-back,
html[data-theme="dark"] #completeModal #btn-complete-share,
html[data-theme="dark"] #completeModal #btn-cm-share { background: #2c3a52; border: 1px solid #8493ab !important; color: #e2e8f0; box-shadow: none; }
html[data-theme="dark"] #completeModal #btn-complete-next { background: #1d4ed8; border: 1px solid #93c5fd !important; color: #fff; }
html[data-theme="dark"] #completeModal .cm-b-head-text p,
html[data-theme="dark"] #completeModal .cm-c-sub,
html[data-theme="dark"] #completeModal .cm-ad-label,
html[data-theme="dark"] #completeModal .cm-backup-label { color: #b9c4d4; }
