/* Fill & Sign PDF. Handwriting and seal fonts are declared here but only downloaded when text in
   that family is drawn (the Type tab's style buttons, a Japanese name, the hanko dialog). */
@font-face { font-family: "Caveat"; src: url("/static/vendor/fonts-sign/Caveat-Regular.woff2?v=1") format("woff2"); font-display: swap; }
@font-face { font-family: "MH Hand Script"; src: url("/static/vendor/fonts-sign/MHHandScript-Regular.woff2?v=1") format("woff2"); font-display: swap; }
@font-face { font-family: "Kalam"; src: url("/static/vendor/fonts-sign/Kalam-Regular.woff2?v=1") format("woff2"); font-display: swap; }
@font-face { font-family: "Yuji Syuku"; src: url("/static/vendor/fonts-sign/YujiSyuku-Regular.woff2?v=1") format("woff2"); font-display: swap; }
@font-face { font-family: "Noto Serif JP"; font-weight: 700; src: url("/static/vendor/fonts-sign/NotoSerifJP-Bold.woff2?v=1") format("woff2"); font-display: swap; }

.sg-wrap { max-width: 1100px; margin: 0 auto; padding: 96px 16px 48px; color: var(--text-primary); box-sizing: border-box;
  --sg-accent: var(--color-primary, #6366f1); --sg-warn: var(--color-warning, #f59e0b); --sg-ok: #4ade80;
  --sg-req: #f43f5e; }
:root[data-theme="light"] .sg-wrap { --sg-accent: #4f46e5; --sg-warn: #b45309; --sg-ok: #15803d; --sg-req: #e11d48; }
.sg-wrap *, .sg-wrap *::before, .sg-wrap *::after, .sg-dlg *, .sg-dlg *::before, .sg-dlg *::after { box-sizing: border-box; }
.sg-wrap [hidden], .sg-dlg [hidden] { display: none !important; }
.sg-intro h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); margin: 0 0 8px; }
.sg-intro p { color: var(--text-secondary); margin: 0 0 16px; max-width: 70ch; }
.sg-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.sg-card { background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 12px; padding: 18px 16px; display: grid; gap: 12px; min-width: 0; }
.sg-card h2 { font-size: 1.15rem; margin: 0; }

/* empty state */
.sg-open { justify-items: center; text-align: center; border: 2px dashed var(--border-color); padding: 32px 16px; transition: border-color .15s, background .15s; }
.sg-open.is-over { border-color: var(--sg-accent); background: color-mix(in srgb, var(--sg-accent) 10%, var(--bg-secondary)); }
.sg-drop-title { font-weight: 700; margin: 0; font-size: 1.1rem; }
@media (hover: none) { .sg-drop-title { display: none; } }
.sg-privacy, .sg-honesty { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 0.9rem; border: 1px solid var(--border-color); background: var(--bg-primary);
  color: var(--text-secondary); display: flex; gap: 8px; align-items: flex-start; text-align: left; max-width: 60ch; }
.sg-privacy::before { content: "\2713"; flex: 0 0 auto; color: var(--sg-ok); font-weight: 800; }
.sg-honesty::before { content: "i"; flex: 0 0 auto; width: 1.2em; height: 1.2em; border-radius: 50%; border: 1.5px solid currentColor; display: inline-grid; place-items: center;
  font-size: 0.75em; font-weight: 800; font-style: italic; margin-top: 2px; }

/* open state */
.sg-work { display: grid; gap: 12px; min-width: 0; }
.sg-work > .sg-msg { margin: 0; }
.sg-filebar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; min-width: 0; }
.sg-name { font-size: 1.05rem; margin: 0; overflow-wrap: anywhere; min-width: 0; }
.sg-bar { position: sticky; top: 72px; z-index: 5; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: 12px; padding: 8px; display: grid; gap: 6px; min-width: 0;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); }
.sg-tools { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.sg-tool { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-color); background: var(--bg-primary); color: var(--text-primary);
  border-radius: 10px; padding: 6px 12px; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; min-width: 44px; justify-content: center; }
.sg-tool[aria-pressed="true"] { background: var(--sg-accent); border-color: var(--sg-accent); color: #fff; }
.sg-tool:focus-visible, .sg-chip:focus-visible { outline: 2px solid var(--sg-accent); outline-offset: 2px; }
.sg-ico { font-size: 1.15rem; line-height: 1; font-weight: 800; }
.sg-chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.sg-chips:empty { display: none; }
.sg-chip { flex: 0 0 auto; display: inline-grid; place-items: center; width: 64px; height: 44px; padding: 4px; border-radius: 10px; border: 1px dashed var(--border-color);
  background: #fff; cursor: pointer; }
.sg-chip[aria-pressed="true"] { border: 2px solid var(--sg-accent); }
.sg-chip img { max-width: 100%; max-height: 100%; display: block; }
.sg-bar2 { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; min-width: 0; }
.sg-zoom { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 0.9rem; margin-left: auto; }
.sg-zoom .sg-input { width: auto; min-height: 36px; padding: 4px 8px; }
/* Finish (jump to Download) shows at every width: the pages can be long on any screen */
@media (max-width: 899px) { .sg-zoom { margin-left: 0; } }
.sg-sizes, .sg-seg { display: inline-grid; grid-auto-flow: column; border: 1px solid var(--border-color); border-radius: 10px; overflow: hidden; background: var(--bg-primary); }
.sg-sizes button, .sg-seg button { border: 0; background: transparent; color: var(--text-primary); font: inherit; font-weight: 600; padding: 6px 10px; cursor: pointer; min-height: 36px; white-space: nowrap; }
.sg-sizes button + button, .sg-seg button + button { border-left: 1px solid var(--border-color); }
.sg-sizes button[aria-pressed="true"], .sg-seg button[aria-pressed="true"] { background: var(--sg-accent); color: #fff; }
.sg-place { margin: 0; }
.sg-place:empty { display: none; }
.sg-fieldsbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--sg-accent) 12%, var(--bg-secondary)); border: 1px solid var(--border-color); font-weight: 600; }

/* pages */
.sg-pages { overflow-x: auto; overflow-y: visible; min-width: 0; touch-action: pan-x pan-y; padding: 4px 0; }
.sg-pages-inner { display: grid; justify-items: center; gap: 16px; transform-origin: 0 0; width: max-content; min-width: 100%; }
.sg-page { position: relative; background: #fff; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25); flex: 0 0 auto; }
.sg-page::before { content: attr(data-label); position: absolute; left: 50%; top: 40%; transform: translateX(-50%); color: #9ca3af; font-size: 0.9rem; }
.sg-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.sg-layer { position: absolute; inset: 0; }
.sg-layer.is-armed { cursor: crosshair; }

/* form fields over the page: opaque, so they are the only picture of the field (pdf.js leaves
   widgets off the canvas with ENABLE_FORMS) */
.sg-field { position: absolute; margin: 0; border: 1px solid #a5a8d6; background: #eceefe; color: #111; font-family: Helvetica, Arial, sans-serif;
  border-radius: 2px; padding: 0 3px; min-width: 0; outline: none; resize: none; }
.sg-field:focus { border-color: #4f46e5; box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.35); background: #ffffff; }
.sg-field.is-required { border: 2px solid #e11d48; }
.sg-field[readonly], .sg-field:disabled { background: #efefef; color: #444; cursor: not-allowed; }
input.sg-field[type="checkbox"], input.sg-field[type="radio"] { appearance: none; -webkit-appearance: none; padding: 0; display: grid; place-items: center; cursor: pointer; }
input.sg-field[type="radio"] { border-radius: 50%; }
input.sg-field[type="checkbox"]:checked::after { content: "\2713"; font-weight: 800; color: #111; font-size: 0.9em; line-height: 1; }
input.sg-field[type="radio"]:checked::after { content: ""; width: 50%; height: 50%; border-radius: 50%; background: #111; }
select.sg-field { padding: 0 2px; }

/* placed items */
.sg-item { position: absolute; touch-action: none; cursor: move; outline: none; }
.sg-item.is-selected { outline: 1.5px dashed #4f46e5; outline-offset: 2px; }
.sg-item img, .sg-item svg { display: block; width: 100%; height: 100%; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.sg-item textarea { position: absolute; left: 0; margin: 0; padding: 0; border: 0; background: transparent; color: #000; resize: none; overflow: hidden;
  white-space: pre; font-family: Helvetica, Arial, "Liberation Sans", "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif; outline: none; cursor: text; }
.sg-item:not(.is-selected) textarea { pointer-events: none; }
.sg-item.is-selected textarea { background: rgba(79, 70, 229, 0.06); }
.sg-del, .sg-resize { position: absolute; display: none; }
.sg-item.is-selected .sg-del, .sg-item.is-selected .sg-resize { display: grid; }
.sg-del { top: -30px; right: -14px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: #e11d48; color: #fff; place-items: center; font: 700 16px/1 system-ui, sans-serif;
  cursor: pointer; padding: 0; }
.sg-resize { right: -11px; bottom: -11px; width: 22px; height: 22px; border-radius: 50%; background: #4f46e5; border: 2px solid #fff; cursor: nwse-resize; touch-action: none; }

/* download */
.sg-dl { justify-items: start; }
.sg-check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; min-height: 44px; }
.sg-check input { width: 20px; height: 20px; accent-color: var(--sg-accent); margin: 0; flex: 0 0 auto; }

/* controls */
.sg-label { font-weight: 600; font-size: 0.95rem; }
.sg-input { width: 100%; max-width: 100%; min-width: 0; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border-color);
  background: var(--bg-primary); color: var(--text-primary); font: inherit; min-height: 44px; }
.sg-input--big { font-size: 1.4rem; text-align: center; }
.sg-input:focus-visible, .sg-range:focus-visible { outline: 2px solid var(--sg-accent); outline-offset: 1px; }
.sg-range { width: 100%; accent-color: var(--sg-accent); min-height: 32px; margin: 0; }
.sg-hint { color: var(--text-secondary); font-size: 0.88rem; margin: 0; overflow-wrap: anywhere; }
.sg-msg { margin: 0 0 8px; font-weight: 600; color: var(--sg-warn); overflow-wrap: anywhere; }
.sg-msg:empty { display: none; }
.sg-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border-color); background: var(--bg-primary);
  color: var(--text-primary); border-radius: 10px; padding: 9px 16px; cursor: pointer; font: inherit; font-weight: 600; text-decoration: none; line-height: 1.2; min-height: 44px; }
.sg-btn:hover:not(:disabled) { border-color: var(--sg-accent); }
.sg-btn--primary { background: var(--sg-accent); border-color: var(--sg-accent); color: #fff; }
.sg-btn--primary:hover:not(:disabled) { background: var(--color-primary-active, #4f46e5); color: #fff; }
.sg-btn--quiet { background: transparent; color: var(--text-secondary); }
.sg-btn--small { min-height: 36px; padding: 6px 12px; font-size: 0.92rem; }
.sg-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.sg-btn:focus-visible { outline: 2px solid var(--sg-accent); outline-offset: 2px; }

/* dialogs */
.sg-dlg { width: min(560px, calc(100vw - 24px)); max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow: auto; padding: 18px 16px; border-radius: 14px;
  border: 1px solid var(--border-color); background: var(--bg-secondary); color: var(--text-primary); --sg-accent: var(--color-primary, #6366f1); --sg-warn: var(--color-warning, #f59e0b); }
:root[data-theme="light"] .sg-dlg { --sg-accent: #4f46e5; --sg-warn: #b45309; }
.sg-dlg::backdrop { background: rgba(0, 0, 0, 0.55); }
.sg-dlg h2 { margin: 0 0 12px; font-size: 1.2rem; }
.sg-dlg .sg-msg { margin: 10px 0 0; }
.sg-tabs { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border-color); border-radius: 10px; overflow: hidden; background: var(--bg-primary); margin-bottom: 12px; }
.sg-tabs button { border: 0; background: transparent; color: var(--text-primary); font: inherit; font-weight: 600; padding: 8px 6px; cursor: pointer; min-height: 44px; }
.sg-tabs button + button { border-left: 1px solid var(--border-color); }
.sg-tabs button[aria-selected="true"] { background: var(--sg-accent); color: #fff; }
.sg-panel { display: grid; gap: 10px; min-width: 0; }
.sg-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.sg-pad { width: 100%; height: 200px; display: block; background: #fff; border-radius: 10px; border: 1px solid var(--border-color); touch-action: none; cursor: crosshair;
  background-image: linear-gradient(transparent calc(100% - 52px), #cbd5e1 calc(100% - 52px), #cbd5e1 calc(100% - 50px), transparent calc(100% - 50px)); }
.sg-styles { display: grid; gap: 8px; }
.sg-style { border: 1px solid var(--border-color); background: #fff; color: #111; border-radius: 10px; padding: 6px 12px; font-size: 2rem; min-height: 64px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.sg-style[aria-pressed="true"] { outline: 3px solid var(--sg-accent); outline-offset: 0; }
.sg-style:disabled { opacity: 0.35; cursor: not-allowed; }
.sg-f-caveat { font-family: "Caveat", cursive; }
.sg-f-hand { font-family: "MH Hand Script", cursive; }
.sg-f-kalam { font-family: "Kalam", cursive; }
.sg-f-jp { font-family: "Yuji Syuku", serif; }
.sg-uprow { display: grid; gap: 6px; min-width: 0; }
.sg-upview { border-radius: 10px; padding: 8px; display: grid; place-items: center; background: repeating-conic-gradient(#d9dce3 0% 25%, #f4f5f8 0% 50%) 50% / 16px 16px; }
.sg-uppreview { max-width: 100%; max-height: 180px; display: block; }
.sg-dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.sg-hanko { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 520px) { .sg-hanko { grid-template-columns: 180px minmax(0, 1fr); align-items: start; } }
.sg-hanko-prev { display: grid; place-items: center; background: #fff; border-radius: 10px; border: 1px solid var(--border-color); padding: 10px; }
.sg-hanko-prev canvas { width: 160px; height: 160px; display: block; }

@media (min-width: 900px) {
  .sg-bar { top: 80px; }
}
@media (max-width: 480px) {
  .sg-dl .sg-btn--primary { width: 100%; }
}

.img-foot { text-align: center; padding: 24px 16px; font-size: 0.875rem; }
.img-foot a { color: var(--text-secondary); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
@media print { .sg-bar, .sg-dl, .nav, .img-foot { display: none; } }
