:root {
    --bg: #0f1a36; --bg2: #0a1226; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #eef3ff; --muted: #a9b9dd; --accent: #7aa7ff; --accent-ink: #0a1838; --field: rgba(255,255,255,.08);
    --good: #4ade80; --good-bg: rgba(74,222,128,.12); --bad: #fda4af; --bad-bg: rgba(251,113,133,.16);
    --paper: #ffffff; --check: #e6e9f2;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f3f6fe; --bg2: #e6edfc; --card: #fff; --line: #d3dcf3; --ink: #121a33; --muted: #4c5a7d;
            --accent: #1d4ed8; --accent-ink: #fff; --field: #f4f7ff; --good: #15803d; --good-bg: #ecfdf3; --bad: #be123c; --bad-bg: #fff1f2;
            color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f3f6fe; --bg2: #e6edfc; --card: #fff; --line: #d3dcf3; --ink: #121a33; --muted: #4c5a7d;
            --accent: #1d4ed8; --accent-ink: #fff; --field: #f4f7ff; --good: #15803d; --good-bg: #ecfdf3; --bad: #be123c; --bad-bg: #fff1f2;
            color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #0f1a36; --bg2: #0a1226; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #eef3ff; --muted: #a9b9dd; --accent: #7aa7ff; --accent-ink: #0a1838; --field: rgba(255,255,255,.08);
    --good: #4ade80; --good-bg: rgba(74,222,128,.12); --bad: #fda4af; --bad-bg: rgba(251,113,133,.16);
    color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding: clamp(1rem,4vw,2.5rem) 1rem 4rem; display: flex; justify-content: center;
       font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
       background: var(--bg2) linear-gradient(180deg, var(--bg), var(--bg2) 900px) no-repeat; touch-action: manipulation; }
.app { width: min(560px, 100%); min-width: 0; display: flex; flex-direction: column; }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: 1.85rem; line-height: 1.2; letter-spacing: -.02em; }
.sub { margin: .4rem 0 0; color: var(--muted); font-size: 1rem; }
h2 { display: flex; align-items: center; gap: .5rem; margin: 0 0 .8rem; font-size: 1.15rem; }
.step { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 1.7rem; height: 1.7rem; border-radius: 50%;
        background: var(--accent); color: var(--accent-ink); font-size: .95rem; font-weight: 800; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); }
label.first { margin-top: 0; }
input[type=text], select { width: 100%; min-width: 0; min-height: 48px; padding: .6rem .8rem; font: inherit; font-size: 1.05rem; color: var(--ink);
       background: var(--field); border: 1px solid var(--line); border-radius: 12px; }
select { padding-right: .4rem; }
input[aria-invalid=true] { color: var(--bad); }
.money:has(input[aria-invalid=true]) { border-color: var(--bad); }
select option { color: #111; background: #fff; }
input:focus-visible, button:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
::placeholder { color: var(--muted); opacity: .75; }
.hint { margin: .55rem 0 0; color: var(--muted); font-size: .88rem; }
.hint b { color: var(--ink); }
[hidden] { display: none !important; }
.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; }

/* buttons */
.primary, .secondary, .danger { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; padding: .5rem .8rem; border-radius: 12px;
       font: inherit; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.secondary { border: 1px solid var(--line); background: var(--field); color: var(--ink); font-weight: 600; }
.secondary:disabled { opacity: .45; cursor: default; }
.danger { border: 1px solid var(--bad); background: transparent; color: var(--bad); font-weight: 600; margin-top: 1rem; }
.link { display: block; min-height: 44px; margin-top: .4rem; padding: 0 .1rem; border: 0; background: none; color: var(--accent); font: inherit; font-size: .95rem; font-weight: 600; text-align: left; cursor: pointer; }
.link.small { min-height: 40px; margin-top: .3rem; font-size: .92rem; }
.row-btns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: .7rem; }
.row-btns.three { grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); }
.msg { margin: .5rem 0 0; color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
.msg:empty { margin: 0; }
.msg button { min-height: 40px; margin-left: .4rem; padding: 0 .8rem; border: 1px solid var(--accent); border-radius: 10px; background: none; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; }
.msg.bad { color: var(--bad); font-weight: 600; }

/* tabs */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: .9rem; border: 1px solid var(--line); border-radius: 14px; background: var(--field); }
.tabs button { min-height: 44px; padding: .3rem .5rem; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font: inherit; font-weight: 700; font-size: .95rem; cursor: pointer; line-height: 1.2; }
.tabs button[aria-selected=true] { background: var(--accent); color: var(--accent-ink); }

/* signing box: always white paper, like the file it makes */
.pad-wrap { position: relative; width: 100%; aspect-ratio: 2.3 / 1; min-height: 150px; border-radius: 14px; overflow: hidden; background: var(--paper);
            border: 2px solid var(--accent); }
#pad { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; z-index: 1; }
.pad-line { position: absolute; left: 7%; right: 7%; bottom: 24%; border-bottom: 2px solid #c5cde0; pointer-events: none; }
.pad-line span { position: absolute; left: -.2rem; bottom: .1rem; color: #8c97b3; font-size: 1.5rem; line-height: 1; }
.pad-hint { position: absolute; left: 0; right: 0; top: 34%; margin: 0; text-align: center; color: #9aa4bd; font-size: 1.15rem; font-weight: 600; pointer-events: none; }
.pad-wrap.signed .pad-hint { display: none; }

/* segmented choices */
.seg-field { border: 0; margin: .9rem 0 0; padding: 0; min-width: 0; }
.seg-field legend { padding: 0; margin-bottom: .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); }
.seg { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 14px; background: var(--field); }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.seg label { flex: 1 1 0; min-width: 0; display: flex; align-items: center; justify-content: center; gap: .4rem; margin: 0; min-height: 42px; padding: .25rem .4rem;
             border-radius: 10px; color: var(--ink); font-size: .95rem; font-weight: 600; text-align: center; cursor: pointer; line-height: 1.15; }
.seg.two-lines label { flex-direction: column; gap: 0; min-height: 50px; }
.seg label small { font-size: .78rem; font-weight: 500; color: var(--muted); }
.seg input:checked + label { background: var(--accent); color: var(--accent-ink); }
.seg input:checked + label small { color: inherit; opacity: .85; }
.seg input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; }
.dot { display: inline-block; width: .9rem; height: .9rem; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); flex: none; }

/* photo */
.file-input { position: absolute; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
#photo-pick { position: relative; }
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem; min-height: 150px; margin: 0; padding: 1rem;
        border: 2px dashed var(--accent); border-radius: 14px; background: var(--field); color: var(--accent); text-align: center; cursor: pointer; }
.drop b { font-size: 1.1rem; color: var(--ink); }
.drop-sub { color: var(--muted); font-weight: 500; }
.drop:hover, .drop.over { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.file-input:focus-visible + .drop { outline: 3px solid var(--accent); outline-offset: 3px; }
#photo-view { display: block; width: 100%; height: auto; max-height: 360px; object-fit: contain; border-radius: 12px; border: 2px solid var(--accent); background: var(--paper); touch-action: none; cursor: crosshair; }
#clean-row { margin-top: .8rem; }
input[type=range] { width: 100%; min-height: 36px; accent-color: var(--accent); margin: 0; }
.range-ends { display: flex; justify-content: space-between; gap: .5rem; color: var(--muted); font-size: .82rem; }

/* size */
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .6rem; }
.money { display: flex; align-items: center; min-height: 48px; background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 0 .7rem; min-width: 0; }
.money:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.money input { border: 0; background: transparent; padding: .6rem 0; outline: none; min-height: 46px; }
.money input:focus-visible { outline: none; }
.money .suffix { margin-left: .3rem; color: var(--muted); font-weight: 600; flex: none; font-size: .95rem; }
.two.kb { margin-top: .2rem; }
.err { margin: .5rem 0 0; color: var(--bad); font-weight: 600; font-size: .92rem; }
.err:empty { margin: 0; }

/* result */
.empty { margin: 0; padding: 1rem; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); font-size: .95rem; }
.preview { display: flex; align-items: center; justify-content: center; padding: .6rem; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); min-height: 110px; }
.preview.see-through { background-color: #fff; background-image: linear-gradient(45deg, var(--check) 25%, transparent 25%, transparent 75%, var(--check) 75%), linear-gradient(45deg, var(--check) 25%, transparent 25%, transparent 75%, var(--check) 75%);
                       background-size: 18px 18px; background-position: 0 0, 9px 9px; }
.preview img { display: block; width: 100%; height: auto; max-height: 260px; object-fit: contain; box-shadow: 0 0 0 1px #c9d1e6; }
.preview.see-through img { box-shadow: 0 0 0 1px rgba(29,78,216,.45); }
.res-info { min-width: 0; margin-top: .8rem; }
.r-size { margin: 0; font-size: 2.1rem; font-weight: 800; line-height: 1.15; letter-spacing: -.02em; color: var(--accent); font-variant-numeric: tabular-nums; }
.r-verdict { margin: .2rem 0 0; font-weight: 700; color: var(--good); overflow-wrap: anywhere; }
.r-verdict.bad { color: var(--bad); }
.r-detail { white-space: pre-line; margin: .25rem 0 0; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.r-detail:empty { display: none; }
.real { display: flex; align-items: center; flex-wrap: wrap; gap: .6rem; margin-top: .6rem; color: var(--muted); font-size: .88rem; }
.real img { display: block; max-width: 100%; height: auto; background: #fff; box-shadow: 0 0 0 1px var(--line); }
.result.busy .preview img, .result.busy .r-size { opacity: .45; }
.result.failed .r-size { color: var(--bad); }
.r-btns { display: flex; gap: .5rem; margin-top: .9rem; }
.r-btns > * { flex: 1 1 0; min-width: 0; }
.r-btns .primary { flex-grow: 1.4; }
.result.failed .r-btns, .result.busy .r-btns .primary { opacity: .45; pointer-events: none; }
.keep { margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.check { display: flex; align-items: center; gap: .6rem; margin: 0; min-height: 44px; color: var(--ink); font-size: 1rem; cursor: pointer; }
.check input { width: 1.3rem; height: 1.3rem; flex: none; accent-color: var(--accent); margin: 0; }
.keep .hint { margin-top: .1rem; }

.faq h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
details { border-top: 1px solid var(--line); padding: .6rem 0; }
summary { cursor: pointer; font-weight: 600; min-height: 32px; }
details p { margin: .4rem 0 0; color: var(--muted); }
details b { color: var(--ink); }
footer { text-align: center; margin-top: 1.5rem; font-size: .9rem; } footer a { color: var(--muted); }

/* back to the list of all apps */
.back { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; margin: 0 0 .5rem; padding: 0 1rem 0 .8rem; border: 1px solid var(--line, rgba(127,127,127,.4)); border-radius: 999px; color: var(--muted, var(--mut, inherit)); font-size: .92rem; font-weight: 600; text-decoration: none; background: transparent; align-self: flex-start; }
.back:hover { color: var(--ink, inherit); border-color: currentColor; }
.back:focus-visible { outline: 3px solid var(--accent, var(--acc, #fff)); outline-offset: 2px; }

/* narrow phones */
@media (max-width: 380px) {
    .card { padding: .95rem; }
    .money { padding: 0 .55rem; }
    .money .suffix { font-size: .85rem; }
    .r-btns { flex-wrap: wrap; }
    .r-btns .primary { flex-basis: 100%; }
    .tabs button { font-size: .9rem; }
    select { font-size: .98rem; padding-left: .6rem; }
}
/* very narrow phones: the light/dark switch shows only its icon so the top bar stays on one line */
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
}

/* laptops and desktops: signing on the left, size and file on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); column-gap: 1.5rem; align-items: start; }
    .app > * { grid-column: 1 / -1; }
    .app > .topbar { grid-row: 1; }
    .app > header { grid-row: 2; }
    .app > .make { grid-column: 1; grid-row: 3 / span 2; }
    .app > .size { grid-column: 2; grid-row: 3; }
    .app > .result { grid-column: 2; grid-row: 4; }
    .app > .faq { grid-row: 5; }
    .app > footer { grid-row: 6; }
    .app > .faq, .app > footer { width: min(760px, 100%); justify-self: center; }
    header h1 { font-size: 2.3rem; }
    .pad-wrap { aspect-ratio: 2 / 1; }
    .pad-hint { font-size: 1.4rem; }
    .card { padding: 1.3rem; }
    .preview { min-height: 0; }
    .preview img { max-height: 170px; }
}
