/* Sepia. Warm paper and ink. Light is paper, dark is the darkroom. */

:root {
  --paper: #f4ead8;
  --paper-2: #ece0c8;
  --card: #fbf4e7;
  --ink: #2b2017;
  --ink-soft: #6b5b49;
  --accent: #8a4b1f;
  --accent-ink: #fff6ea;
  --line: #d8c9ae;
  --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(43, 32, 23, 0.14);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #181410;
    --paper-2: #221c15;
    --card: #241e17;
    --ink: #ede4d4;
    --ink-soft: #b0a28c;
    --accent: #d98d4a;
    --accent-ink: #221507;
    --line: #3a3126;
    --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; }

/* The root font size stays at the browser's own default (never overridden
   in px), so every rem size below tracks the user's font-size preference
   instead of ignoring it. */
html { font-size: 100%; }

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;
  transition: background 0.15s;
}
.dropzone.dragging { background: var(--medium-bg); border-style: solid; transform: scale(1.015); }
.dropzone.press { transform: scale(0.97); }
.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;
}
/* 44px is the tap-target floor everything else in the app holds; this
   toggle used to fall short at 30px. */
.lnd-faq summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.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.84375rem;
  font-weight: 700;
}
/* The pill used to be color-only text, easy to miss next to the close
   button. A background and border turn it into the verdict of the screen,
   not a caption underneath one. */
.risk-pill:not(:empty) {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.risk-pill.high { color: var(--high); background: var(--high-bg); border-color: var(--high); }
.risk-pill.medium { color: var(--medium); background: var(--medium-bg); border-color: var(--medium); }
.risk-pill.clean { color: var(--ok); background: var(--ok-bg); border-color: var(--ok); }
@media (forced-colors: active) {
  .risk-pill:not(:empty) { border-color: CanvasText; }
}

.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;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  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;
  /* Below the mechanical px/16 conversion (0.78125rem); bumped to the
     0.85rem floor so the smallest labels stay readable. */
  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;
}
/* Windows high-contrast mode strips background/border colors, the only
   signal .tool.active otherwise gives; an outline survives forced-colors. */
@media (forced-colors: active) {
  .tool.active { outline: 2px solid; outline-offset: -1px; }
}

.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.84375rem;
  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;
  /* Below the mechanical px/16 conversion (0.71875rem); bumped to the
     0.85rem floor so the severity tag stays readable. */
  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.8125rem; 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.84375rem; 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.84375rem; color: var(--ink-soft); margin: 10px 0 0; }
/* 44px is the tap-target floor everything else in the app holds; this
   disclosure used to fall short at 30px. */
.done-report summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.done-secret { display: block; padding: 2px 0 4px 14px; overflow-wrap: anywhere; }

.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;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 14px;
}
.done-actions .btn-primary { min-width: 130px; }

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

/* ------------------------------------------------------------ triage */

#screen-triage, #screen-batch { padding: 26px 18px 60px; position: relative; }
.triage-inner, .batch-inner { max-width: 560px; margin: 0 auto; }
#btn-triage-cancel { position: absolute; top: 18px; right: 18px; }
#triage-title, #batch-title { margin: 0 0 6px; font-size: 1.5rem; }
.triage-sub, .batch-sub { color: var(--ink-soft); margin: 0 0 18px; }

.triage-list, .batch-list { list-style: none; margin: 0 0 20px; padding: 0; }
.triage-row, .batch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  margin-bottom: 8px;
  font-size: 0.90625rem;
}
.triage-name, .batch-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.triage-status, .batch-verdict { flex-shrink: 0; font-weight: 650; color: var(--ink-soft); }
.triage-row.clean .triage-status, .batch-verdict.clean { color: var(--ok); }
.triage-row.leftover .triage-status, .batch-verdict.leftover { color: var(--medium); }
.triage-row.fail .triage-status, .batch-verdict.fail { color: var(--high); }
.batch-row .xray-act { margin-left: 4px; }

.triage-actions, .batch-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.triage-actions .btn-primary, .triage-actions .btn-ghost { flex: 1; text-align: center; min-width: 160px; }

/* ------------------------------------------------------------- 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%;
  bottom: 24px;
  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;
  /* Below the mechanical px/16 conversion (0.78125rem); bumped to the
     0.85rem floor so the hint stays readable. */
  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; } }

  /* A held-still target does not read as interactive; a slow breath says
     "drop something on me" without ever moving during the 01-start.png
     shot, which fires well before this delay elapses. The press/drag scale
     transition lives in here too, not on the base rule, so a
     reduced-motion user still gets the .press/.dragging end state, just
     snapped instead of eased. */
  .dropzone { transition: transform 0.15s, background 0.15s; }
  .dropzone:not(.dragging):not(.press) { animation: breathe 4.5s ease-in-out 2.5s infinite; }
  @keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.012); } }

  /* Rows arrive like a scanner reading down the list instead of popping in
     as one static block. */
  .xray-list li { animation: scan-row 0.32s cubic-bezier(0.2, 0.7, 0.3, 1) both; animation-delay: calc(var(--i, 0) * 35ms); }
  @keyframes scan-row { from { opacity: 0; transform: translateY(-6px); } }

  /* The proof screen develops like a print coming out of the tray: the
     preview starts fogged and oversaturated and settles into the real
     image, the verdict fades in a beat behind it. */
  .done-preview { animation: develop 0.9s ease-out both; }
  .done-badge { animation: develop-in 0.5s ease-out both; }
  #done-title { animation: develop-in 0.5s ease-out 0.12s both; }
  .done-sub { animation: develop-in 0.5s ease-out 0.22s both; }
  @keyframes develop {
    0% { filter: sepia(1) contrast(0.55) brightness(1.5) blur(3px); opacity: 0.1; }
    55% { filter: sepia(0.35) contrast(0.9) brightness(1.08) blur(0.6px); opacity: 0.85; }
    100% { filter: none; opacity: 1; }
  }
  @keyframes develop-in {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
  }
}
