:root {
  --paper: #F7F8FA;
  --surface: #FFFFFF;
  --ink: #17213A;
  --muted: #586078;
  --line: #DCDFE7;
  --stamp: #5436C2;
  --stamp-ink: #FFFFFF;
  --stamp-soft: #ECE7FB;
  --ok: #17754A;
  --ok-soft: #E3F4EB;
  --err: #B42318;
  --err-soft: #FDECEA;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #11141D; --surface: #191D29; --ink: #ECEEF4; --muted: #A2A8BA; --line: #2D3242;
    --stamp: #9E8AF5; --stamp-ink: #14102A; --stamp-soft: #251F42;
    --ok: #5BD198; --ok-soft: #143023; --err: #FF8A80; --err-soft: #3A1A1A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #11141D; --surface: #191D29; --ink: #ECEEF4; --muted: #A2A8BA; --line: #2D3242;
  --stamp: #9E8AF5; --stamp-ink: #14102A; --stamp-soft: #251F42;
  --ok: #5BD198; --ok-soft: #143023; --err: #FF8A80; --err-soft: #3A1A1A;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.55 var(--body); -webkit-font-smoothing: antialiased; }
img, canvas { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--stamp); }
:focus-visible { outline: 3px solid var(--stamp); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px; }
.narrow { max-width: 780px; }

/* header */
.top { border-bottom: 1px solid var(--line); background: var(--surface); }
.top .wrap { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font: 800 1.35rem/1 var(--display); letter-spacing: -0.02em; }
.brand-mark { width: 30px; height: 36px; flex: none; }
.top nav a { color: var(--muted); text-decoration: none; font-weight: 700; font-size: 0.95rem; }
.top nav a:hover { color: var(--ink); }

/* hero */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 40px; align-items: center; padding: 64px 0 40px; }
.hero h1 { font: 800 clamp(2.3rem, 5.4vw, 4rem)/1.02 var(--display); letter-spacing: -0.035em; margin: 0 0 18px; max-width: 13ch; }
.hero p { margin: 0; color: var(--muted); font-size: 1.12rem; max-width: 46ch; }
.stamp { transform: rotate(-9deg); color: var(--stamp); border: 4px solid currentColor; border-radius: 14px; padding: 6px; margin-right: 18px; }
.stamp-inner { border: 1.5px solid currentColor; border-radius: 9px; padding: 16px 24px; text-align: center; }
.stamp-big { font: 800 1.55rem/1.05 var(--display); letter-spacing: 0.06em; text-transform: uppercase; }
.stamp-small { font-size: 0.85rem; font-weight: 700; margin-top: 8px; letter-spacing: 0.02em; }
@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; padding-top: 40px; gap: 28px; }
  .stamp { justify-self: start; margin-left: 6px; }
}

/* tool grid */
.cat { padding: 14px 0 22px; }
.cat h2 { font: 700 1.2rem/1.2 var(--display); margin: 0 0 14px; letter-spacing: -0.01em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile { display: flex; gap: 14px; align-items: flex-start; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; cursor: pointer; text-decoration: none; color: var(--ink); transition: border-color .15s; }
.tile:hover { border-color: var(--stamp); }
.tile-icon { flex: none; width: 40px; height: 40px; border-radius: 10px; background: var(--stamp-soft); color: var(--stamp); display: grid; place-items: center; }
.tile-icon svg { width: 22px; height: 22px; }
.tile strong { display: block; font-size: 1rem; margin-bottom: 2px; color: var(--ink); }
.tile-desc { display: block; color: var(--muted); font-size: 0.9rem; line-height: 1.4; }

/* tool view */
.back { display: inline-flex; align-items: center; gap: 6px; margin: 28px 0 8px; color: var(--muted); text-decoration: none; font-weight: 700; font-size: 0.95rem; }
.back:hover { color: var(--ink); }
.tool-head h1 { font: 800 clamp(2rem, 4.4vw, 2.8rem)/1.05 var(--display); letter-spacing: -0.03em; margin: 0 0 8px; }
.tool-head h1:focus { outline: none; }
.tool-head p { margin: 0 0 24px; color: var(--muted); }

.drop { display: block; border: 2px dashed var(--stamp); border-radius: 16px; background: var(--surface); padding: 36px 20px; text-align: center; cursor: pointer; transition: background .15s; }
.drop.over { background: var(--stamp-soft); }
.drop strong { display: block; font: 700 1.15rem/1.3 var(--display); margin-bottom: 6px; }
.drop #drop-sub { color: var(--muted); font-size: 0.95rem; }
.drop .btn { margin-top: 16px; pointer-events: none; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.files { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.file { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.file-badge { flex: none; width: 34px; height: 40px; border-radius: 5px; border: 1.5px solid var(--line); display: grid; place-items: center; font: 800 0.62rem/1 var(--display); color: var(--stamp); }
.file-main { flex: 1; min-width: 0; }
.file-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { color: var(--muted); font-size: 0.88rem; }
.file-meta.bad { color: var(--err); }
.icon-btn { flex: none; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover:not(:disabled) { color: var(--ink); border-color: var(--muted); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 18px; height: 18px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; margin-top: 20px; }
.panel > h2 { font: 700 1.1rem/1.2 var(--display); margin: 0 0 14px; }
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label, fieldset legend { display: block; font-weight: 700; margin-bottom: 6px; font-size: 0.95rem; padding: 0; }
fieldset { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 16px; }
input[type=text], input[type=number], select { width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; min-height: 44px; }
input[type=text]:focus, input[type=number]:focus, select:focus { border-color: var(--stamp); outline: none; box-shadow: 0 0 0 3px var(--stamp-soft); }
input[type=range] { width: 100%; accent-color: var(--stamp); }
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--stamp); background: var(--stamp-soft); }
.choice input { margin-top: 5px; accent-color: var(--stamp); }
.choice small { display: block; color: var(--muted); font-size: 0.87rem; }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--stamp); }
.hint { color: var(--muted); font-size: 0.88rem; margin: 6px 0 0; }
.note { background: var(--stamp-soft); border-radius: 10px; padding: 12px 14px; font-size: 0.92rem; margin: 0 0 16px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 24px; border-radius: 10px; border: 0; background: var(--stamp); color: var(--stamp-ink); font-weight: 700; cursor: pointer; text-decoration: none; }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 0.92rem; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-top: 22px; }
.actions .status { color: var(--muted); font-size: 0.95rem; }
.error { background: var(--err-soft); color: var(--err); border-radius: 10px; padding: 12px 14px; margin-top: 16px; font-weight: 700; font-size: 0.95rem; }

.result { background: var(--ok-soft); border-radius: 16px; padding: 22px; margin-top: 22px; }
.result h2 { font: 700 1.3rem/1.2 var(--display); margin: 0 0 4px; color: var(--ok); }
.result p { margin: 0; }
.result .actions { margin-top: 16px; }

/* organize */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.pg { border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--paper); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pg-img { height: 150px; display: grid; place-items: center; width: 100%; overflow: hidden; }
.pg-img img { max-height: 130px; max-width: 110px; box-shadow: 0 0 0 1px var(--line); background: #fff; transition: transform .2s; }
.pg-label { font-size: 0.85rem; color: var(--muted); }
.pg-tools { display: flex; gap: 4px; }
.pg-tools .icon-btn { width: 30px; height: 30px; }
.pg-tools .icon-btn svg { width: 15px; height: 15px; }

/* signature */
.sigbox { position: relative; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; overflow: hidden; }
.sigbox canvas { display: block; width: 100%; height: 180px; touch-action: none; cursor: crosshair; }
.sigline { position: absolute; left: 24px; right: 24px; bottom: 46px; border-bottom: 1.5px dashed #C9CCD6; pointer-events: none; }
.sigph { position: absolute; left: 24px; bottom: 18px; color: #8A90A2; font-size: 0.85rem; pointer-events: none; }
.sigbar { display: flex; justify-content: flex-end; margin-top: 8px; }

/* how-to and FAQ sections on tool pages */
.info { margin-top: 48px; padding-top: 8px; border-top: 1px solid var(--line); }
.info h2 { font: 700 1.25rem/1.2 var(--display); margin: 0 0 16px; letter-spacing: -0.01em; }
.info ol { margin: 0; padding-left: 22px; display: grid; gap: 10px; color: var(--ink); }
.info details { border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; margin-bottom: 10px; background: var(--surface); }
.info details[open] { border-color: var(--stamp); }
.info summary { font-weight: 700; cursor: pointer; list-style: none; }
.info summary::-webkit-details-marker { display: none; }
.info summary::before { content: '+'; display: inline-block; width: 1em; color: var(--stamp); font-weight: 800; }
.info details[open] summary::before { content: '\2212'; }
.info details p { margin: 8px 0 0 1em; color: var(--muted); }

/* file and result preview thumbnails */
.file-thumb { flex: none; width: 34px; height: 40px; border-radius: 5px; border: 1.5px solid var(--line); padding: 0; background: var(--surface); cursor: zoom-in; display: grid; place-items: center; overflow: hidden; }
.file-thumb:hover { border-color: var(--stamp); }
.file-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-thumb .file-badge { border: 0; width: auto; height: auto; }
.result-preview { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 14px 0 4px; }
.result-preview .file-thumb { width: 52px; height: 64px; }

/* preview lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(10, 12, 20, 0.86); z-index: 100; display: flex; flex-direction: column; }
.lightbox-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; color: #fff; }
.lightbox-bar span { font-weight: 700; font-family: var(--display); overflow-wrap: anywhere; }
.lightbox-bar .icon-btn { border-color: rgba(255, 255, 255, 0.35); color: #fff; flex: none; }
.lightbox-body { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 0 14px 14px; min-height: 0; }
.lightbox-stage { max-width: 100%; max-height: 100%; overflow: auto; display: flex; align-items: center; justify-content: center; }
.lightbox-stage img { max-width: min(88vw, 900px); max-height: 78vh; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); background: #fff; }
.lightbox-stage pre { max-width: min(88vw, 720px); max-height: 78vh; overflow: auto; background: #fff; color: var(--ink); padding: 20px; border-radius: 10px; white-space: pre-wrap; font: 14px/1.5 ui-monospace, Consolas, monospace; margin: 0; }
.lightbox-nav { flex: none; background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.35); color: #fff; width: 44px; height: 44px; }
.lightbox-nav svg { width: 20px; height: 20px; }
.lightbox-nav:disabled { opacity: 0.25; }
.lightbox-foot { text-align: center; color: rgba(255, 255, 255, 0.75); font-size: 0.88rem; padding-bottom: 14px; }

/* processing progress bar */
.progress-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 40px 32px; text-align: center; }
.progress-title { margin: 0 0 20px; font: 700 1.15rem/1.3 var(--display); }
.progress-track { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; border-radius: 999px; background: var(--stamp); transition: width 0.25s ease; }
.progress-fill.indeterminate { width: 35% !important; animation: progress-slide 1.1s ease-in-out infinite; }
@keyframes progress-slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
.progress-status { margin: 14px 0 0; color: var(--muted); font-size: 0.95rem; min-height: 1.3em; }
@media (prefers-reduced-motion: reduce) { .progress-fill.indeterminate { animation: none; width: 60% !important; margin-left: 20%; } }

footer { border-top: 1px solid var(--line); margin-top: 64px; padding: 28px 0 40px; color: var(--muted); font-size: 0.9rem; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
