:root {
  --paper: #eef0ec;      /* travertine grey */
  --sheet: #fbfcfa;
  --ink: #1d2733;
  --muted: #5d6971;
  --rule: #c9d0ca;
  --stamp: #2e6a55;      /* ministerial green ink */
  --stamp-soft: #dbe7e0;
  --alert: #9e3a2b;
  --focus: #2e6a55;
  --serif: 'Spectral', Georgia, serif;
  --sans: 'Public Sans', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #151b20; --sheet: #1c242a; --ink: #e5e9e4; --muted: #9aa6a2;
    --rule: #33403b; --stamp: #74b59b; --stamp-soft: #22342d; --alert: #e08b78; --focus: #74b59b;
  }
}
:root[data-theme="dark"] {
  --paper: #151b20; --sheet: #1c242a; --ink: #e5e9e4; --muted: #9aa6a2;
  --rule: #33403b; --stamp: #74b59b; --stamp-soft: #22342d; --alert: #e08b78; --focus: #74b59b;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1 { font: 500 1.75rem/1.15 var(--serif); margin: 0; letter-spacing: -0.01em; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

/* the revenue-stamp mark: perforated square, IT over EN */
.stamp {
  --size: 64px;
  width: var(--size); height: calc(var(--size) * 1.18);
  display: grid; grid-template-rows: 1fr 1fr; place-items: center;
  background: var(--stamp); color: var(--sheet);
  font: 500 calc(var(--size) * 0.28)/1 var(--serif);
  -webkit-mask: radial-gradient(circle at 50% 50%, #000 62%, transparent 64%) 0 0 / 8px 8px round,
    linear-gradient(#000, #000) center / calc(100% - 6px) calc(100% - 6px) no-repeat;
  -webkit-mask-composite: source-over;
  mask: radial-gradient(circle at 50% 50%, #000 62%, transparent 64%) 0 0 / 8px 8px round,
    linear-gradient(#000, #000) center / calc(100% - 6px) calc(100% - 6px) no-repeat;
  mask-composite: add;
  padding: 6px;
}
.stamp span:first-child { border-bottom: 1px solid color-mix(in srgb, var(--sheet) 45%, transparent); width: 70%; text-align: center; padding-bottom: 4px; }
.stamp span:last-child { font-style: italic; }
.stamp.small { --size: 40px; padding: 4px; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%);
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 4px;
  padding: 36px 32px 32px; display: grid; gap: 10px;
}
.login-card .stamp { margin-bottom: 12px; }
.lede { margin: 0 0 14px; color: var(--muted); font-family: var(--serif); font-size: 1.05rem; line-height: 1.55; }
label { font-weight: 500; font-size: 0.92rem; }
input[type=password], textarea {
  width: 100%; border: 1px solid var(--rule); background: var(--paper);
  border-radius: 3px; padding: 10px 12px;
}
textarea { resize: vertical; min-height: 76px; }

.primary, .secondary {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 3px; padding: 11px 18px; font-weight: 600; font-size: 0.95rem;
  cursor: pointer; text-decoration: none; border: 1px solid var(--stamp);
}
.primary { background: var(--stamp); color: var(--sheet); }
.secondary { background: transparent; color: var(--stamp); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.primary:not(:disabled):hover { filter: brightness(1.08); }
.error { color: var(--alert); margin: 4px 0 0; font-size: 0.93rem; }

/* ---------- app */
.top {
  max-width: 1180px; margin: 0 auto; padding: 22px 24px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand h1 { font-size: 1.45rem; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }
.signout { color: var(--muted); font-size: 0.92rem; }

.work { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }
.intake { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 40px; align-items: start; }

/* the drop target is a sheet of A4 */
.sheet {
  position: relative; display: block; aspect-ratio: 210 / 297; cursor: pointer;
  background: var(--sheet); border: 1px solid var(--rule); border-radius: 2px;
  box-shadow: 0 1px 0 var(--rule), 0 14px 30px -22px rgba(29, 39, 51, 0.45);
  transition: transform 160ms ease, border-color 160ms ease;
  overflow: hidden;
}
.sheet-lines {
  position: absolute; inset: 14% 12% 12%;
  background: repeating-linear-gradient(to bottom, transparent 0 17px, var(--rule) 17px 18px);
  opacity: 0.55;
}
.sheet::before { /* margin rule like carta uso bollo */
  content: ''; position: absolute; top: 0; bottom: 0; left: 9%; width: 1px; background: var(--rule);
}
.sheet-body {
  position: absolute; left: 12%; right: 12%; top: 50%; transform: translateY(-50%);
  display: grid; gap: 8px; background: var(--sheet); padding: 14px 4px;
}
.sheet-body strong { font: 500 1.3rem/1.25 var(--serif); }
.sheet-body span { color: var(--muted); font-size: 0.9rem; }
.sheet.over, .sheet:hover { border-color: var(--stamp); transform: translateY(-2px); }
.sheet.has-file .sheet-lines { opacity: 0.9; }
.sheet.has-file strong { color: var(--stamp); word-break: break-word; }

.controls { display: grid; gap: 10px; max-width: 520px; padding-top: 6px; }
.opt { color: var(--muted); font-weight: 400; margin-left: 6px; }
.hint { margin: -2px 0 8px; color: var(--muted); font-size: 0.86rem; }
.controls .primary { justify-self: start; }

.status { margin-top: 10px; }
.bar { height: 4px; background: var(--stamp-soft); border-radius: 2px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--stamp); transition: width 300ms ease; }
.status p { margin: 8px 0 0; color: var(--muted); font-size: 0.92rem; }

.result { margin-top: 40px; border-top: 1px solid var(--rule); padding-top: 22px; }
.result-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.tabs { display: inline-flex; border: 1px solid var(--rule); border-radius: 3px; overflow: hidden; }
.tabs button {
  background: transparent; border: 0; padding: 8px 14px; cursor: pointer; color: var(--muted); font-weight: 500;
}
.tabs button + button { border-left: 1px solid var(--rule); }
.tabs button[aria-selected="true"] { background: var(--stamp-soft); color: var(--ink); }
.downloads { display: flex; gap: 10px; flex-wrap: wrap; }
.notes { margin: 0 0 14px; padding: 10px 14px 10px 30px; background: var(--stamp-soft); border-radius: 3px; font-size: 0.9rem; }
.viewer {
  height: 82vh; overflow: auto; border: 1px solid var(--rule); border-radius: 2px;
  background: color-mix(in srgb, var(--paper) 70%, var(--rule)); padding: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.viewer canvas { width: 100%; height: auto; background: #fff; box-shadow: 0 1px 0 var(--rule), 0 10px 24px -18px rgba(29, 39, 51, 0.5); }
.viewer.single canvas { max-width: 860px; }

@media (max-width: 760px) {
  .intake { grid-template-columns: 1fr; gap: 24px; }
  .sheet { max-width: 260px; margin: 0 auto; width: 100%; }
  .top { padding: 16px; }
  .work { padding: 20px 16px 48px; }
  .viewer { height: 70vh; padding: 10px; gap: 10px; }
  .downloads a { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .sheet, .bar span { transition: none; }
}
