/* Blot. Violet ink on cool paper. */

:root {
  --paper: #f0eef6;
  --paper-2: #e6e2f0;
  --card: #faf9fd;
  --ink: #1b1726;
  --ink-soft: #5c5570;
  --accent: #5b4a9e;
  --accent-ink: #f5f2ff;
  --line: #d3cde4;
  --high: #a02c1f;
  --high-bg: #f7ddd6;
  --medium: #755a0b;
  --medium-bg: #f3e8c8;
  --low: #5c6b52;
  --low-bg: #e2e8da;
  --ok: #2e6b40;
  --ok-bg: #dcecd9;
  --shadow: 0 2px 14px rgba(27, 23, 38, 0.14);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131118;
    --paper-2: #1b1824;
    --card: #201c2b;
    --ink: #e8e5f2;
    --ink-soft: #a49cc0;
    --accent: #a795e8;
    --accent-ink: #171227;
    --line: #332e44;
    --high: #f08575;
    --high-bg: #47231d;
    --medium: #d9b558;
    --medium-bg: #40351a;
    --low: #a4b697;
    --low-bg: #2a3324;
    --ok: #7fc38f;
    --ok-bg: #223a28;
    --shadow: 0 2px 14px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, including over display:flex on a
   class. Without this, .crop-bar and .tool were shown while hidden. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100%;
}

img { max-width: 100%; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 16px;
  z-index: 40;
  border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius);
  padding: 12px 22px;
  font-weight: 650;
  min-height: 44px;
  text-decoration: none;
  border: 1px solid transparent;
}
.btn-primary:active { transform: translateY(1px); }
.btn-primary[disabled] { opacity: 0.5; cursor: default; }

.btn-ghost {
  display: inline-block;
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 18px;
  min-height: 44px;
  font-weight: 600;
  background: transparent;
}

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  font-size: 1.1875rem;
  color: var(--ink-soft);
}
.icon-btn:not([disabled]):hover { background: var(--paper-2); color: var(--ink); }
.icon-btn[disabled] { opacity: 0.35; cursor: default; }

/* ------------------------------------------------------------- start */

.screen[hidden] { display: none; }

#screen-start { max-width: 860px; margin: 0 auto; padding: 24px 20px 60px; }

.start-hero {
  text-align: center;
  padding: 28px 0 8px;
}
.start-hero .logo { display: block; margin: 0 auto 6px; }
.start-hero h1 {
  margin: 0;
  font-size: 2.75rem;
  letter-spacing: 0.5px;
}
.tagline {
  margin: 2px 0 14px;
  font-size: 1.1875rem;
  font-weight: 600;
  color: var(--accent);
}
.pitch {
  max-width: 34em;
  margin: 0 auto 26px;
  color: var(--ink-soft);
}

.dropzone {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  max-width: 460px;
  min-height: 130px;
  padding: 22px;
  border: 2px dashed var(--accent);
  border-radius: calc(var(--radius) + 6px);
  background: var(--card);
  cursor: pointer;
  font-size: 1.125rem;
}
.dropzone.dragging { background: var(--medium-bg); border-style: solid; }
.drop-hint { font-size: 0.875rem; color: var(--ink-soft); }

.offline-note {
  margin-top: 18px;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

.about-line { text-align: center; margin-top: 30px; }
.about-line a { color: var(--accent); }

.doc-page main { max-width: 680px; margin: 0 auto; padding: 32px 20px; }

.locale-line { text-align: center; margin-top: 26px; }
.locale-line select {
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 44px;
}

.del-chip { border-color: var(--high); color: var(--high); }

.xray-export {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 6px;
}

/* ----------------------------------------------------------- landing */

.landing { margin-top: 56px; }
.lnd { margin: 0 0 46px; }
.lnd h2 { font-size: 1.625rem; margin: 0 0 14px; }
.lnd-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.lnd-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.lnd-card h3 { margin: 0 0 6px; font-size: 1.0625rem; }
.lnd-card p { margin: 0; font-size: 0.90625rem; color: var(--ink-soft); }

.honest-list { padding-left: 20px; color: var(--ink-soft); }
.honest-list li { margin-bottom: 10px; }

.apk-row { margin: 16px 0 6px; }
.apk-note { font-size: 0.875rem; color: var(--ink-soft); }

.lnd-faq details {
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}
.lnd-faq summary { cursor: pointer; font-weight: 600; min-height: 30px; }
.lnd-faq p { color: var(--ink-soft); }

.land-footer {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 18px 0 8px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.875rem;
}
.land-footer a { color: var(--accent); }

/* ------------------------------------------------------------ editor */

#screen-edit {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
#screen-edit[hidden] { display: none; }

.edit-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.top-actions { display: flex; gap: 4px; align-items: center; }

.risk-pill {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  font-weight: 600;
}
.risk-pill.high { color: var(--high); }
.risk-pill.medium { color: var(--medium); }
.risk-pill.clean { color: var(--ok); }

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background:
    repeating-conic-gradient(var(--paper-2) 0% 25%, var(--paper) 0% 50%) 0 0 / 22px 22px;
  overflow: hidden;
  touch-action: none;
}
#canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.crop-bar {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 14px;
  box-shadow: var(--shadow);
  font-size: 0.875rem;
  max-width: calc(100% - 20px);
  flex-wrap: wrap;
  justify-content: center;
}

.tools {
  display: flex;
  gap: 4px;
  padding: 6px 8px 0;
  justify-content: center;
}

.find-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}
.find-bar input {
  flex: 1;
  min-width: 160px;
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.find-count {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.find-note {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  /* viewport-fit=cover draws under the home indicator on notched iPhones;
     without this, Export sits partly behind it in the installed PWA. */
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.toolbar-space { flex: 1; }
.toolbar .btn-primary { white-space: nowrap; }
@media (max-width: 480px) {
  /* The one button that moves you forward never gets clipped: on narrow
     screens it takes its own full-width row under the tools. */
  .toolbar .btn-primary { flex-basis: 100%; text-align: center; }
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 64px;
  min-height: 52px;
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  border: 1px solid transparent;
}
.tool.active {
  background: var(--card);
  border-color: var(--accent);
  color: var(--ink);
  font-weight: 650;
}

.tool-icon { width: 22px; height: 22px; border-radius: 5px; display: block; }
.ink-icon { background: var(--ink); }
.px-icon {
  background:
    repeating-conic-gradient(var(--ink) 0% 25%, var(--ink-soft) 0% 50%) 0 0 / 11px 11px;
}
.crop-icon {
  border: 2.5px solid var(--ink-soft);
  border-radius: 3px;
  background: transparent;
}
.qr-icon {
  background:
    linear-gradient(var(--ink), var(--ink)) 0 0 / 8px 8px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 100% 0 / 8px 8px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 0 100% / 8px 8px no-repeat,
    linear-gradient(var(--ink), var(--ink)) 60% 60% / 5px 5px no-repeat;
}

.tool-note {
  margin: 0;
  padding: 8px 14px;
  background: var(--medium-bg);
  color: var(--ink);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}

/* ------------------------------------------------------------- x-ray */

.xray {
  position: fixed;
  inset: auto 0 0 0;
  max-height: 72dvh;
  overflow: auto;
  background: var(--card);
  border-top: 2px solid var(--accent);
  border-radius: 18px 18px 0 0;
  padding: 14px 18px 26px;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.25);
  z-index: 20;
}
@media (min-width: 780px) {
  .xray {
    inset: 0 0 0 auto;
    width: 400px;
    max-height: none;
    border-radius: 0;
    border-top: none;
    border-left: 2px solid var(--accent);
  }
}

.xray-head { display: flex; align-items: center; justify-content: space-between; }
.xray-head h2 { margin: 0; font-size: 1.25rem; }
.xray-headline { font-weight: 650; }

.xray-list { list-style: none; margin: 0; padding: 0; }
.xray-list li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.90625rem;
}
.sev {
  flex-shrink: 0;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-radius: 999px;
  padding: 2px 9px;
}
.sev-high { background: var(--high-bg); color: var(--high); }
.sev-medium { background: var(--medium-bg); color: var(--medium); }
.sev-low { background: var(--low-bg); color: var(--low); }
.xray-label { font-weight: 650; }
.xray-value { color: var(--ink-soft); overflow-wrap: anywhere; }
.xray-detail { display: block; font-size: 0.85rem; color: var(--ink-soft); margin-top: 2px; }
.xray-act {
  margin-left: auto;
  color: var(--accent);
  font-weight: 600;
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
}
.xray-foot { font-size: 0.85rem; color: var(--ink-soft); }
#thumb-reveal { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin: 10px 0; }
#thumb-img { image-rendering: pixelated; border-radius: 6px; }

/* ------------------------------------------------------------- proof */

#screen-done { padding: 26px 18px 60px; }
.done-inner { max-width: 560px; margin: 0 auto; text-align: center; }

.done-badge {
  width: 74px;
  height: 74px;
  margin: 0 auto 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2.5rem;
  background: var(--ok-bg);
  color: var(--ok);
}
.done-badge.warn { background: var(--high-bg); color: var(--high); }
#done-title { margin: 0 0 4px; }
.done-sub { color: var(--ink-soft); margin: 0 0 18px; }

.done-preview {
  max-height: 260px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.done-report {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 18px 0;
}
.done-report h3, .done-leftover h3 { margin: 0 0 8px; font-size: 0.96875rem; }
.done-report ul, .done-leftover ul { margin: 0; padding-left: 20px; color: var(--ink-soft); font-size: 0.90625rem; }
.done-name { font-size: 0.85rem; color: var(--ink-soft); margin: 10px 0 0; }
.done-report summary { cursor: pointer; min-height: 30px; }
.done-secret { display: block; padding: 2px 0 4px 14px; overflow-wrap: anywhere; }

.done-receipt-note { margin: 0 0 10px; color: var(--ink-soft); font-size: 0.85rem; }
.done-hash {
  display: block;
  overflow-wrap: anywhere;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.85rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 10px;
}

.done-leftover {
  text-align: left;
  background: var(--high-bg);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 18px 0;
}

.fmt-row {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 0.90625rem;
  margin: 0 0 18px;
  border: none;
  padding: 0;
}
.fmt-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
}
.done-size { color: var(--ink-soft); }

.done-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 14px;
}
.done-actions .btn-primary { min-width: 130px; }

#btn-next { margin-top: 10px; }

/* ------------------------------------------------------------- toast */

/* Kept in the accessibility tree at all times: a live region inside
   display:none never reaches a screen reader. Shown with a class. */
.toast {
  position: fixed;
  left: 50%;
  /* Clears the editor's bottom toolbar row (tools + Flatten & export +
     the keyboard hint) so a toast never sits on top of the very buttons
     someone might reach for next, including the repeat-across-pages
     button added there. */
  bottom: 100px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 0.90625rem;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: min(92vw, 480px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s;
}
.toast.show {
  opacity: 1;
  visibility: visible;
}

.kbd-hint {
  margin: 0;
  padding: 5px 14px;
  /* Same reasoning as .toolbar: this can be the bottom-most visible row
     when the canvas has focus, and needs the same clearance. */
  padding-bottom: max(5px, env(safe-area-inset-bottom));
  font-size: 0.85rem;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
  background: var(--paper);
}

@media (prefers-reduced-motion: no-preference) {
  .btn-primary, .tool, .icon-btn { transition: background 0.15s, transform 0.1s; }
  .xray { animation: rise 0.18s ease-out; }
  @keyframes rise { from { transform: translateY(14px); opacity: 0.6; } }

  /* The proof ceremony: the badge settles with a small pop, then the
     facts and receipt rise in one at a time. Opacity plus a small
     translate only, staggered by animation-delay, not by delaying when
     the elements enter the DOM: a screen reader gets the full list the
     moment the screen shows, motion or not. */
  .done-badge { animation: proof-pop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) backwards; }
  @keyframes proof-pop { from { transform: scale(0.6); opacity: 0; } }
  #done-title, #done-sub, .done-report, #done-receipt, .done-actions, #btn-again {
    animation: proof-rise 0.3s ease-out backwards;
  }
  #done-title { animation-delay: 0.05s; }
  #done-sub { animation-delay: 0.09s; }
  .done-report { animation-delay: 0.15s; }
  #done-receipt { animation-delay: 0.22s; }
  .done-actions { animation-delay: 0.29s; }
  #btn-again { animation-delay: 0.35s; }
  @keyframes proof-rise { from { opacity: 0; transform: translateY(6px); } }

  /* Reinforces the armed-close state that already exists (aria-label
     change plus toast); the logic that arms and disarms it is unchanged. */
  .icon-btn.armed { animation: armed-pulse 0.5s ease-out; }
  @keyframes armed-pulse {
    0%, 100% { transform: scale(1); }
    35% { transform: scale(1.2); color: var(--high); }
  }

  .toast.show { animation: toast-in 0.2s ease-out; }
  @keyframes toast-in { from { transform: translate(-50%, 8px); } }

  .box-count.bump, .find-count.bump { animation: count-bump 0.25s ease-out; }
  @keyframes count-bump { 40% { transform: scale(1.15); } }
}


/* ------------------------------------------------------------- blot */

.hero { text-align: center; padding-top: 22px; }
.hero .logo { display: block; margin: 0 auto 6px; }
.hero h1 { margin: 0; font-size: 2.5rem; }
.refusal-badge {
  width: 74px; height: 74px; margin: 22px auto 10px; border-radius: 50%;
  display: grid; place-items: center; font-size: 2.5rem;
  background: var(--medium-bg); color: var(--medium);
}
.page-ind { flex: 1; font-weight: 650; font-size: 0.90625rem; color: var(--ink-soft); }
.tool-note-inline { color: var(--ink-soft); font-size: 0.85rem; align-self: center; padding: 0 6px; }
.box-count { color: var(--ink-soft); font-size: 0.85rem; align-self: center; }
.del-chip { border-color: var(--high); color: var(--high); }
.render-progress {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  font-weight: 650;
}
.locale-line { text-align: center; margin-top: 26px; }
.locale-line select {
  font: inherit; font-size: 0.875rem; color: var(--ink);
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; min-height: 44px;
}
.doc-page main { max-width: 680px; margin: 0 auto; padding: 32px 20px; }
