:root {
  --paper: #f4f1ea;
  --card: #fffdf8;
  --ink: #1d1b16;
  --muted: #6f685b;
  --line: #e4ded1;
  --accent: #1f6f78;
  --accent-ink: #12454b;
  --edge: #c0392b;      /* perforated-edge swatch (matches overlay) */
  --design: #2f6fd0;    /* printed-design swatch (matches overlay) */
  --ok: #3f7d4e;
  --warn: #9a6a12;
  --shadow: 0 1px 2px rgba(40,34,20,.06), 0 6px 24px rgba(40,34,20,.08);
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --display: "Fraunces", Georgia, serif;
}
:root:not([data-theme="light"]) {
  @media (prefers-color-scheme: dark) {
    --paper: #15140f;
    --card: #1f1d17;
    --ink: #f1ece1;
    --muted: #a69c88;
    --line: #322e25;
    --accent: #57bcc6;
    --accent-ink: #bfeaee;
    --edge: #e0674f;
    --design: #6fa2e8;
    --ok: #74b487;
    --warn: #d0a24a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 30px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --paper: #15140f; --card: #1f1d17; --ink: #f1ece1; --muted: #a69c88;
  --line: #322e25; --accent: #57bcc6; --accent-ink: #bfeaee; --edge: #e0674f;
  --design: #6fa2e8; --ok: #74b487; --warn: #d0a24a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 30px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 40rem; margin: 0 auto; padding: 0 1.15rem 3rem; }
a { color: var(--accent-ink); }
em { font-style: italic; }

/* ---- top bar ---- */
.topbar {
  max-width: 40rem; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.15rem .75rem;
}
.wordmark { font-family: var(--display); font-weight: 600; font-size: 1.25rem; letter-spacing: -.01em; }
.wordmark .perf {
  padding: .05em .3em; border-radius: 4px;
  background: var(--accent); color: #fff;
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 3px var(--accent);
}
.engine {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em;
}
.engine .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.engine[data-state="ready"] .dot { background: var(--ok); }
.engine[data-state="boot"] .dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }

/* ---- capture ---- */
h1 {
  font-family: var(--display); font-weight: 600;
  font-size: clamp(2rem, 7vw, 2.9rem); line-height: 1.05; letter-spacing: -.02em;
  margin: 1rem 0 .6rem; text-wrap: balance;
}
h1 em { color: var(--accent); font-style: italic; }
.lede { color: var(--muted); font-size: 1.02rem; margin: 0 0 1.5rem; max-width: 34rem; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .5rem; text-align: center;
  padding: 2.2rem 1.25rem;
  background: var(--card);
  border: 1.5px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 16px;
  cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
  box-shadow: var(--shadow);
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); }
.dropzone:active { transform: scale(.995); }
.dropzone .cam { width: 40px; height: 40px; color: var(--accent); }
.dz-title { font-weight: 600; font-size: 1.05rem; }
.dz-sub { color: var(--muted); font-size: .85rem; }

.example-line { text-align: center; color: var(--muted); font-size: .9rem; margin: .9rem 0 0; }
.linkbtn {
  font: inherit; font-weight: 600; color: var(--accent-ink); background: none; border: none;
  padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.linkbtn:hover { filter: brightness(1.1); }
.linkbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 3px; }

.tips { list-style: none; padding: 0; margin: 1.4rem 0 0; display: grid; gap: .5rem; }
.tips li { position: relative; padding-left: 1.4rem; color: var(--muted); font-size: .9rem; }
.tips li::before {
  content: ""; position: absolute; left: .1rem; top: .55em;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}

/* ---- working ---- */
.working { text-align: center; padding: 3.5rem 1rem; color: var(--muted); }
.spinner {
  width: 38px; height: 38px; margin: 0 auto 1rem;
  border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- result ---- */
.result { animation: rise .3s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.overlay-fig { margin: 0 0 1.25rem; }
.overlay-fig img {
  width: 100%; max-height: 62vh; object-fit: contain;
  border-radius: 14px; background: #000; box-shadow: var(--shadow);
}
.overlay-fig figcaption {
  display: flex; flex-wrap: wrap; gap: .3rem 1rem; align-items: center;
  margin-top: .6rem; font-size: .82rem; color: var(--muted);
}
.key { display: inline-flex; align-items: center; gap: .4rem; }
.sw { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
.sw-edge { background: var(--edge); }
.sw-design { background: var(--design); }
.cap { margin-left: auto; font-style: italic; }

.score-wrap { display: flex; align-items: center; gap: 1.25rem; margin: 0 0 1.25rem; }
.score-ring {
  --v: 0;
  flex: 0 0 auto; width: 108px; height: 108px; border-radius: 50%;
  display: grid; place-content: center; text-align: center;
  background:
    radial-gradient(closest-side, var(--card) 79%, transparent 80% 100%),
    conic-gradient(var(--accent) calc(var(--v) * 1%), var(--line) 0);
  box-shadow: var(--shadow);
}
.score-num { font-family: var(--display); font-weight: 600; font-size: 2.1rem; line-height: 1; }
.score-of { font-size: .72rem; color: var(--muted); }
.score-side { min-width: 0; }
.score-label { text-transform: uppercase; letter-spacing: .08em; font-size: .72rem; color: var(--muted); }
.reading { font-family: var(--display); font-size: 1.35rem; font-weight: 500; margin: .1rem 0 .25rem; }
.not-grade { font-size: .8rem; color: var(--muted); }

.margins {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
  margin: 0 0 1.25rem;
}
.m-cell {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: .6rem .3rem; text-align: center;
}
.m-cell .m-side { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.m-cell .m-val { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1.15rem; font-weight: 600; }
.m-cell .m-unit { font-size: .66rem; color: var(--muted); }

.confidence { border-radius: 12px; padding: .85rem 1rem; margin: 0 0 1.5rem; font-size: .9rem; }
.confidence.ok { background: color-mix(in srgb, var(--ok) 12%, var(--card)); border: 1px solid color-mix(in srgb, var(--ok) 35%, var(--line)); }
.confidence.low { background: color-mix(in srgb, var(--warn) 14%, var(--card)); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line)); }
.confidence h3 { margin: 0 0 .3rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.confidence ul { margin: .35rem 0 0; padding-left: 1.1rem; }
.confidence li { margin: .15rem 0; }
.tag { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; padding: .05em .4em; border-radius: 4px; margin-left: .35rem; }
.tag.capture { background: color-mix(in srgb, var(--design) 22%, transparent); color: var(--accent-ink); }
.tag.subject { background: color-mix(in srgb, var(--muted) 22%, transparent); color: var(--muted); }

/* ---- buttons ---- */
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: .7rem 1.15rem; border-radius: 10px; border: 1px solid transparent;
  background: var(--accent); color: #fff;
  transition: filter .12s, transform .1s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- refused ---- */
.refused { text-align: center; padding: 2.5rem 1rem; }
.refused-icon {
  width: 56px; height: 56px; margin: 0 auto 1rem; border-radius: 50%;
  display: grid; place-content: center; font-size: 1.8rem; color: var(--muted);
  border: 2px solid var(--line);
}
.refused h2 { font-family: var(--display); font-weight: 600; margin: 0 0 .4rem; }
.refused p { color: var(--muted); max-width: 30rem; margin: 0 auto 1.4rem; }

/* ---- footer ---- */
.foot { max-width: 40rem; margin: 0 auto; padding: 1.5rem 1.15rem 2.5rem; color: var(--muted); font-size: .82rem; border-top: 1px solid var(--line); }
.foot p { margin: .2rem 0; }

@media (min-width: 34rem) {
  .margins { gap: .75rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
