:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  --frame: #1e1e1e;
  --footer: #121212;
  --workspace: #808080;
  --ink: #f3f6f9;
  --accent: #9ce0d4;
  --action: #148f2b;
  --sheet-top: 21.5px;
  --side: clamp(14px, 4.93vw, 22px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: #101923; color: var(--ink); }
button { font: inherit; cursor: pointer; }
button:focus-visible, .scroll:focus-visible { outline: 2px solid #fff; outline-offset: -3px; }
button:disabled { opacity: .58; cursor: wait; }

.shell {
  width: min(100%, 56rem);
  height: 100dvh;
  margin-inline: auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.top {
  --top-inset: max(44px, env(safe-area-inset-top));
  min-height: calc(54px + var(--top-inset));
  padding: calc(var(--top-inset) + 8px) 48px 0;
  position: relative;
  display: grid;
  place-items: center;
  background: var(--frame);
}

.top h1 { margin: 0; text-align: center; font: 650 clamp(.84rem, 4.35vw, 1.0625rem)/1.25 -apple-system, system-ui, sans-serif; }
.back {
  position: absolute;
  left: 1px;
  bottom: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
}
.back img { display: block; width: 18px; height: auto; }

.stage { position: relative; min-height: 0; background: var(--workspace); }
.scroll { height: 100%; overflow: auto; overscroll-behavior: contain; touch-action: manipulation; scrollbar-color: #3a4651 transparent; }
.pages { display: grid; justify-items: center; align-content: start; gap: 14px; padding: var(--sheet-top) var(--side) 26px; }
.page { width: min(100%, 46rem); display: grid; overflow: hidden; background: #fff; }
.page canvas { display: block; width: 100%; align-self: start; }
.page-error { color: #2e3b46; display: grid; place-items: center; padding: 1rem; text-align: center; }
.count {
  position: absolute;
  inset: 20px auto auto var(--side);
  z-index: 1;
  background: #152431;
  color: #f9fbfc;
  padding: 6px 11px;
  border: 1px solid #425a6c;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 650;
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;
}
.count.visible { opacity: 1; }

.welcome {
  position: absolute;
  inset: var(--sheet-top) var(--side) 0;
  width: min(calc(100% - 2 * var(--side)), 46rem);
  margin-inline: auto;
  display: grid;
  place-items: center;
  background: #000;
}
.drop-target {
  width: 100%;
  height: 100%;
  padding: 14px;
  min-height: 44px;
  color: #e6eaed;
  background: transparent;
  border: 0;
  font-weight: 500;
}
.stage.dragging { outline: 2px dashed var(--accent); outline-offset: -5px; }
.photo {
  display: block;
  width: min(100%, 46rem);
  height: auto;
  background: #000;
}

.status {
  position: absolute;
  inset: auto var(--side) 12px;
  z-index: 2;
  margin: 0 auto;
  width: fit-content;
  max-width: calc(100% - 2 * var(--side));
  padding: 9px 13px;
  background: var(--frame);
  border: 1px solid #526775;
  border-radius: 9px;
  color: var(--ink);
  line-height: 1.35;
}
.actions {
  --action-side: clamp(14px, 4.07vw, 22px);
  padding: 16px max(var(--action-side), env(safe-area-inset-right))
    max(50px, calc(env(safe-area-inset-bottom) + 10px))
    max(var(--action-side), env(safe-area-inset-left));
  background: var(--footer);
}
.primary {
  display: grid;
  place-items: center;
  width: min(100%, 46rem);
  min-height: 52px;
  margin-inline: auto;
  padding: 9px 16px;
  border: 0;
  border-radius: 17px;
  background: var(--action);
  color: #fff;
  text-align: center;
  font: 500 1rem/1.25 -apple-system, system-ui, sans-serif;
  letter-spacing: 0.1px;
}
.primary:active { filter: brightness(.9); }
@media (prefers-contrast: more) { .primary { background: #117723; } }
.text-button { min-height: 44px; padding: 0 8px; border: 0; background: transparent; color: var(--accent); font-weight: 600; }
dialog { width: min(calc(100% - 2 * var(--side)), 24rem); color: var(--ink); background: var(--frame); border: 1px solid #536674; border-radius: 16px; padding: 18px; }
dialog::backdrop { background: #08111ab8; }
dialog h2 { margin: 4px 0 12px; font-size: 1.125rem; }
.dialog-action { display: block; width: 100%; min-height: 44px; margin-bottom: 8px; border: 0; border-radius: 9px; background: #293d4d; color: var(--ink); text-align: left; padding-inline: 12px; }
@media (prefers-reduced-motion: reduce) { .count { transition: none; } }
