:root {
    --bg: #131809; --bg2: #0c1005; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f4f8ec; --muted: #b9c6a5; --accent: #a3e635; --accent-ink: #1a2e05; --field: rgba(255,255,255,.08);
    --good: #4ade80; --good-bg: rgba(74,222,128,.12); --warn: #fbbf24; --warn-bg: rgba(251,191,36,.12); --bad: #fda4af; --bad-bg: rgba(251,113,133,.16);
    --stage: #0a0d05;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f6f9ef; --bg2: #ecf2df; --card: #fff; --line: #d8e3c4; --ink: #1b240e; --muted: #56653f;
            --accent: #4d7c0f; --accent-ink: #fff; --field: #f4f8ec; --good: #15803d; --good-bg: #ecfdf3; --warn: #a16207; --warn-bg: #fff8e6; --bad: #be123c; --bad-bg: #fff1f2;
            --stage: #e3ead6; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f6f9ef; --bg2: #ecf2df; --card: #fff; --line: #d8e3c4; --ink: #1b240e; --muted: #56653f;
            --accent: #4d7c0f; --accent-ink: #fff; --field: #f4f8ec; --good: #15803d; --good-bg: #ecfdf3; --warn: #a16207; --warn-bg: #fff8e6; --bad: #be123c; --bad-bg: #fff1f2;
            --stage: #e3ead6; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #131809; --bg2: #0c1005; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f4f8ec; --muted: #b9c6a5; --accent: #a3e635; --accent-ink: #1a2e05; --field: rgba(255,255,255,.08);
    --good: #4ade80; --good-bg: rgba(74,222,128,.12); --warn: #fbbf24; --warn-bg: rgba(251,191,36,.12); --bad: #fda4af; --bad-bg: rgba(251,113,133,.16);
    --stage: #0a0d05;
    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; }
.col-main, .col-side { min-width: 0; }
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 { margin: 0 0 .7rem; font-size: 1.15rem; }
h3 { margin: 1rem 0 .5rem; font-size: .95rem; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label, legend { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); }
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 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: .45rem 0 0; color: var(--muted); font-size: .88rem; }
.lead { margin: 0 0 .9rem; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: 0; }
.file-input { display: none; }

/* buttons */
.primary, .secondary, .danger, .ghost { display: flex; align-items: center; justify-content: center; gap: .45rem; width: 100%; min-height: 48px; padding: .5rem .8rem; border-radius: 12px;
       font: inherit; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; margin: 0; color: inherit; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.primary:disabled { opacity: .5; cursor: default; }
.secondary { border: 1px solid var(--line); background: var(--field); color: var(--ink); font-weight: 600; }
.secondary:disabled { opacity: .45; cursor: default; }
.ghost { border: 1px dashed var(--accent); background: transparent; color: var(--ink); font-weight: 600; margin-top: .8rem; }
.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: .3rem; padding: 0 .1rem; border: 0; background: none; color: var(--accent); font: inherit; font-size: .95rem; font-weight: 600; text-align: left; cursor: pointer; }
.two-btn { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: .8rem; }
.add-btns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }
.add-btns button { min-height: 56px; font-size: 1.02rem; }
.drop-hint { display: none; }
.add-card.over { outline: 3px dashed var(--accent); outline-offset: 2px; }

.money { display: flex; align-items: center; min-height: 48px; background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 0 .8rem; min-width: 0; }
.money:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.money span { color: var(--muted); font-weight: 600; white-space: nowrap; flex: none; margin-left: .35rem; }
.money input { border: 0; background: transparent; padding: .6rem 0; outline: none; min-height: 46px; }
.money input:focus-visible { outline: none; }

.err { margin: .6rem 0 0; color: var(--bad); font-weight: 600; }
.err:empty { margin: 0; }
.msg { margin: .6rem 0 0; color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
.msg:empty { margin: 0; }
.msg.bad { color: var(--bad); font-weight: 600; }
.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; }

/* the corner editor */
.editor { border-color: var(--accent); }
.ed-hint { margin: -.3rem 0 .7rem; }
.stage-wrap { display: flex; justify-content: center; background: var(--stage); border-radius: 12px; padding: 12px; }
.stage { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; max-width: 100%; }
.stage canvas#ed-photo { display: block; max-width: 100%; border-radius: 4px; }
#ed-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#ed-shade { fill: rgba(0,0,0,.5); }
#ed-quad { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.handle { position: absolute; width: 44px; height: 44px; margin: -22px 0 0 -22px; padding: 0; border: 0; background: transparent; cursor: grab; touch-action: none; }
.handle::before { content: ""; position: absolute; inset: 9px; border-radius: 50%; border: 3px solid var(--accent); background: rgba(0,0,0,.25); box-shadow: 0 0 0 2px rgba(0,0,0,.45); }
.handle::after { content: ""; position: absolute; left: 20px; top: 20px; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); }
.handle:focus-visible { outline: none; }
.handle:focus-visible::before { border-width: 4px; box-shadow: 0 0 0 3px #fff; }
.loupe { position: absolute; left: 6px; top: 6px; width: 110px; height: 110px; border-radius: 50%; border: 3px solid var(--accent); background: #000; pointer-events: none; box-shadow: 0 4px 14px rgba(0,0,0,.5); }
.loupe.right { left: auto; right: 6px; }
.looks { border: 0; margin: .4rem 0 0; padding: 0; min-width: 0; }
.looks legend { padding: 0; }
.look { display: flex; align-items: center; gap: .7rem; margin: .4rem 0 0; padding: .5rem .75rem; border: 1px solid var(--line); border-radius: 12px; background: var(--field); color: var(--ink); cursor: pointer; min-height: 48px; }
.look:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.look input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.look span { min-width: 0; }
.look b { display: block; font-size: .98rem; }
.look small { display: block; color: var(--muted); font-weight: 400; font-size: .85rem; }
.prev-h { margin-top: .9rem; }
.turns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; }
.preview { display: flex; justify-content: center; align-items: center; margin-top: .6rem; padding: 12px; min-height: 120px; background: var(--stage); border-radius: 12px; }
.preview canvas { display: block; max-width: 100%; max-height: 420px; box-shadow: 0 2px 10px rgba(0,0,0,.35); background: #fff; }
#ed-done { margin-top: 1rem; }

/* the list of pages: each page in its own bordered box */
.count { color: var(--muted); font-weight: 500; font-size: 1rem; }
.top-hint { margin: -.4rem 0 .8rem; }
.pages { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.page { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: .8rem; align-items: start; padding: .65rem; border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 12px; background: var(--field); min-width: 0; }
.page.editing { outline: 3px solid var(--accent); outline-offset: 1px; }
.thumb { display: flex; align-items: center; justify-content: center; width: 88px; height: 112px; border-radius: 6px; background: var(--stage); overflow: hidden; }
.thumb img { display: block; max-width: 100%; max-height: 100%; background: #fff; }
.p-info { min-width: 0; }
.p-title { margin: 0; font-weight: 700; font-size: 1.05rem; }
.p-sub { margin: .1rem 0 .5rem; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.p-btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
.p-btns button { min-height: 40px; padding: 0 .5rem; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--ink); font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; }
.p-btns button:disabled { opacity: .4; cursor: default; }
.p-btns .p-edit { border-color: var(--accent); color: var(--accent); }
.page.gone { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; border-left-color: var(--line); color: var(--muted); }
.page.gone button { min-height: 40px; padding: 0 1rem; border-radius: 10px; border: 1px solid var(--accent); background: transparent; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; }

/* the PDF */
.ready { margin: -.2rem 0 0; font-weight: 600; }
.pdf-card label:first-of-type { margin-top: .9rem; }
.make { margin-top: 1.1rem; }
.result { margin-top: 1rem; padding: 1rem; border-radius: 12px; border: 1px solid var(--line); border-left: 5px solid var(--good); background: var(--field); }
.result.over { border-left-color: var(--bad); }
.res-label { margin: 0; color: var(--muted); font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
.big { margin: 0; font-size: clamp(2.2rem, 11vw, 2.9rem); font-weight: 800; letter-spacing: -.02em; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.15; }
.verdict { margin: .2rem 0 0; font-weight: 700; color: var(--good); }
.result.over .verdict { color: var(--bad); }
.res-detail { margin: .3rem 0 0; color: var(--muted); font-size: .92rem; white-space: pre-line; }
#privacy { 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); }
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) {
    .add-btns, .two-btn, .turns { grid-template-columns: minmax(0, 1fr); }
    .page { grid-template-columns: 64px minmax(0, 1fr); gap: .6rem; }
    .thumb { width: 64px; height: 84px; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
}
@media (hover: hover) and (pointer: fine) { .drop-hint { display: block; } }

/* laptops and desktops: pages on the left, the PDF on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); column-gap: 1.5rem; align-items: start; }
    .app > * { grid-column: 1 / -1; }
    .app > .col-main { grid-column: 1; grid-row: 3; }
    .app > .col-side { grid-column: 2; grid-row: 3; }
    .app > .faq { grid-row: 4; }
    .app > footer { grid-row: 5; }
    .app > .faq, .app > footer { width: min(760px, 100%); justify-self: center; }
    header h1 { font-size: 2.3rem; }
    .pages { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
    .editor .stage-wrap { padding: 16px; }
    .ed-body { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1.2rem; }
    .big { font-size: 3rem; }
}
