/* Inxai OCR: documentation + playground.
   One idea carries the page: recognized lines drawn over the scan in
   non-photo blue, the proofreader's pencil a copy camera could not see.
   Everything else stays quiet. */

:root {
  --ink: #16263a;
  --ink-soft: #4a5a6d;
  --paper: #fafbfc;
  --glass: #e6ecf1;
  --rule: #cfd8e0;
  --nonphoto: #5bbcdd;
  --nonphoto-wash: rgba(91, 188, 221, 0.14);
  --nonphoto-strong: rgba(91, 188, 221, 0.34);
  --action: #0a6a94;
  --action-ink: #ffffff;
  --correction: #b42f2a;
  --sheet: #ffffff;
  --code-bg: #eef2f5;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.375rem;
  --step-3: 1.875rem;

  --radius: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e3ebf2;
    --ink-soft: #9fb0c0;
    --paper: #0f1a26;
    --glass: #172636;
    --rule: #2b3d50;
    --nonphoto: #6fcbea;
    --nonphoto-wash: rgba(111, 203, 234, 0.16);
    --nonphoto-strong: rgba(111, 203, 234, 0.38);
    --action: #5cb6dd;
    --action-ink: #08131d;
    --correction: #f0837c;
    --sheet: #ffffff;
    --code-bg: #142231;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

/* The hidden attribute must win over any component's display value. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: var(--step-0)/1.55 var(--sans);
}

a { color: var(--action); text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }

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

code, pre, kbd { font-family: var(--mono); font-size: 0.875em; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: 1rem; top: -3rem;
  background: var(--action); color: var(--action-ink);
  padding: 0.4rem 0.8rem; border-radius: var(--radius);
  z-index: 10;
}
.skip:focus { top: 0.5rem; }

/* ---------------------------------------------------------------- header */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.75rem;
  padding: 0.7rem clamp(1rem, 3vw, 2rem);
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--ink);
  font-weight: 700;
  font-size: var(--step-1);
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand-mark { width: 1.6rem; height: 1.6rem; }
.brand-mark rect { fill: var(--sheet); stroke: var(--ink); stroke-width: 1.6; }
.brand-mark path { stroke: var(--nonphoto); stroke-width: 2.6; stroke-linecap: round; }

.tabs { display: flex; gap: 0.25rem; }
.tabs a {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-weight: 600;
  text-decoration: none;
}
.tabs a:hover { color: var(--ink); background: var(--glass); }
.tabs a[aria-current="page"] { color: var(--ink); background: var(--glass); }

.key {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.6rem;
}
.key > label:first-child { font-weight: 600; font-size: var(--step--1); }
.key input[type="password"], .key input[type="text"] { width: min(22rem, 60vw); }
.remember { font-size: var(--step--1); color: var(--ink-soft); display: inline-flex; gap: 0.3rem; align-items: center; }
.key-status { margin: 0; flex-basis: 100%; text-align: right; font-size: var(--step--1); color: var(--ink-soft); }
.key-status[data-state="ok"] { color: var(--ink); }
.key-status[data-state="ok"]::before {
  content: "";
  display: inline-block;
  width: 0.55rem; height: 0.55rem;
  margin-right: 0.4rem;
  border-radius: 50%;
  background: var(--nonphoto);
}
.key-status[data-state="error"] { color: var(--correction); }

/* ---------------------------------------------------------------- controls */

input, select, button, textarea { font: inherit; color: inherit; }

input[type="text"], input[type="password"], input:not([type]), select {
  min-height: 2.25rem;
  padding: 0.35rem 0.6rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
select { padding-right: 1.6rem; }
input:hover, select:hover { border-color: var(--ink-soft); }

button {
  min-height: 2.25rem;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--action);
  border-radius: var(--radius);
  background: var(--action);
  color: var(--action-ink);
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.quiet {
  background: transparent;
  color: var(--action);
  border-color: var(--rule);
}
button.quiet:hover:not(:disabled) { border-color: var(--action); }
button.danger { color: var(--correction); }
button.danger:hover:not(:disabled) { border-color: var(--correction); }

.panel { padding: clamp(1rem, 3vw, 2rem); }

/* ---------------------------------------------------------------- playground */

.bench {
  display: grid;
  grid-template-columns: minmax(18rem, 22rem) minmax(0, 1fr);
  gap: clamp(1rem, 3vw, 2.5rem);
  align-items: start;
}

.controls { display: grid; gap: 1.1rem; }

.field { display: grid; gap: 0.3rem; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > label, .field > .label, .field > legend {
  font-weight: 600;
  font-size: var(--step--1);
  padding: 0;
}
.hint { margin: 0; color: var(--ink-soft); font-size: var(--step--1); }
.hint:empty { display: none; }

.drop {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 8.5rem;
  padding: 1rem;
  text-align: center;
  background: var(--glass);
  border: 1.5px dashed var(--nonphoto);
  border-radius: var(--radius);
  transition: background-color 120ms ease;
}
.drop input {
  position: absolute; inset: 0;
  opacity: 0;
  cursor: pointer;
}
.drop label { display: grid; gap: 0.2rem; pointer-events: none; }
.drop strong { color: var(--action); }
.drop span { color: var(--ink-soft); font-size: var(--step--1); }
.drop:focus-within { outline: 2px solid var(--action); outline-offset: 2px; }
.drop[data-over] { background: var(--nonphoto-strong); }
.file-name { margin: 0.4rem 0 0; font-weight: 600; word-break: break-all; }
.file-name:empty { display: none; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span {
  display: block;
  padding: 0.45rem 0.3rem;
  text-align: center;
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--ink-soft);
}
.segmented label + label span { border-left: 1px solid var(--rule); }
.segmented input:checked + span { background: var(--ink); color: var(--paper); }
.segmented input:focus-visible + span { outline: 2px solid var(--action); outline-offset: -3px; }

.checks { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; }
.check { display: inline-flex; align-items: center; gap: 0.35rem; font-size: var(--step--1); }
.check.small { color: var(--ink-soft); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--action); }

details > summary { cursor: pointer; font-weight: 600; font-size: var(--step--1); color: var(--action); }
.advanced .grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin: 0.8rem 0 0.6rem;
}
.advanced .grid .check { grid-column: 1 / -1; }

.run { min-height: 2.75rem; font-size: var(--step-1); }
.run-hint { margin-top: -0.6rem; }

.curl pre { margin: 0.6rem 0; }

/* ---------------------------------------------------------------- result */

.result { min-width: 0; }

.empty {
  display: grid;
  justify-items: center;
  gap: 1rem;
  padding: clamp(2rem, 8vh, 5rem) 1rem;
  background: var(--glass);
  border-radius: var(--radius);
  text-align: center;
  color: var(--ink-soft);
}
.empty svg { width: 7rem; }
.empty .sheet-outline { fill: var(--sheet); stroke: var(--rule); }
.empty .box { fill: var(--nonphoto-wash); stroke: var(--nonphoto); stroke-width: 1.2; }
.empty p { margin: 0; max-width: 30ch; }

.job-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.4rem 1rem;
  margin-bottom: 1rem;
}
.job-state { margin: 0; font-weight: 700; font-size: var(--step-1); }
.job-head progress { width: 100%; height: 0.4rem; accent-color: var(--nonphoto); }
.job-meta { grid-column: 1 / -1; grid-row: 2; margin: 0; color: var(--ink-soft); font-size: var(--step--1); }
.job-meta code { overflow-wrap: anywhere; }
#delete-job { grid-column: 3; grid-row: 1; }

.error {
  margin: 0 0 1rem;
  padding: 0.7rem 0.9rem;
  border-left: 3px solid var(--correction);
  background: var(--glass);
  color: var(--ink);
}
.error strong { color: var(--correction); }

.viewer {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.page-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}
.page-nav .zoom { margin-left: auto; display: inline-flex; gap: 0.25rem; }
.page-nav button { min-height: 1.9rem; padding: 0 0.6rem; }
.page-nav .zoom button { min-width: 2rem; padding: 0 0.4rem; }
#zoom-reset { min-width: 3.4rem; }

.overlay-toggles { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; margin-bottom: 0.5rem; }
.legend {
  display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem;
  list-style: none; margin: 0 0 0.6rem; padding: 0;
  font-size: var(--step--1); color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.legend li { display: inline-flex; align-items: center; gap: 0.35rem; }
.swatch {
  width: 0.9rem; height: 0.9rem; border-radius: 3px;
  background: color-mix(in srgb, var(--c) 30%, transparent);
  border: 2px solid var(--c);
}

/* The page scrolls inside its own box, so a long page never pushes the
   text column or the rest of the playground out of reach. */
.page-scroll {
  max-height: calc(100vh - 14rem);
  min-height: 20rem;
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--rule);
  background: var(--glass);
}

/* The scanner bed: the page sits on glass, the overlay sits on the page. */
.sheet {
  position: relative;
  padding: 0;
  background: var(--glass);
  border-radius: var(--radius);
  line-height: 0;
}
.sheet img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--sheet);
  border-radius: var(--radius);
}
.sheet svg { position: absolute; inset: 0; width: 100%; height: 100%; }

#overlay polygon {
  fill: var(--nonphoto-wash);
  stroke: var(--nonphoto);
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill 80ms linear;
}
#overlay polygon.layout {
  fill: color-mix(in srgb, var(--c) 14%, transparent);
  stroke: var(--c);
  stroke-width: 2;
  pointer-events: none;
}
#overlay polygon.region {
  fill: none;
  stroke: var(--ink-soft);
  stroke-dasharray: 4 3;
  pointer-events: none;
}
#overlay polygon.active {
  fill: var(--nonphoto-strong);
  stroke: var(--action);
  stroke-width: 2.25;
}

.text-col { min-width: 0; }
.text-col-head { margin: 0 0 0.6rem; font-size: var(--step--1); color: var(--ink-soft); min-height: 1.9rem; display: flex; align-items: center; }

.lines {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: calc(100vh - 14rem);
  min-height: 20rem;
  overflow: auto;
  overscroll-behavior: contain;
  border-top: 1px solid var(--rule);
}
.lines li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  unicode-bidi: plaintext;
}
.lines li:hover, .lines li.active { background: var(--nonphoto-wash); }
.lines li.active { box-shadow: inset 3px 0 0 var(--nonphoto); }
.lines .conf {
  font-size: var(--step--1);
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  direction: ltr;
}
.lines .conf.low { color: var(--correction); }

/* Each section starts with a heading and a divider, so a long page of
   results reads as separate blocks rather than one run of controls. */
.outputs {
  margin-top: 2.25rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--rule);
  scroll-margin-top: 1rem;
}
.section-head { margin: 0 0 0.75rem; font-size: var(--step-1); }
.output-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  border-bottom: 1px solid var(--rule);
}
.output-bar .output-tabs { border-bottom: 0; min-width: 0; }
.output-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  border-bottom: 1px solid var(--rule);
}
.output-tabs button {
  min-height: 2rem;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--ink-soft);
  padding: 0.3rem 0.7rem;
}
.output-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--nonphoto); }
.output-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.4rem 0; }
.output-actions .segmented { margin-right: 0.25rem; }
.preview {
  display: block;
  width: 100%;
  height: min(72vh, 52rem);
  min-height: 24rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  color-scheme: light;
}

pre {
  margin: 0;
  padding: 0.8rem 1rem;
  overflow: auto;
  background: var(--code-bg);
  border-radius: var(--radius);
  line-height: 1.5;
}
.output {
  max-height: 60vh;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;
  text-align: start;
}

/* ---------------------------------------------------------------- docs */

.docs {
  display: grid;
  grid-template-columns: 13rem minmax(0, 1fr);
  gap: clamp(1rem, 4vw, 3.5rem);
  align-items: start;
}

.toc { position: sticky; top: 5.5rem; font-size: var(--step--1); }
.toc ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--rule); }
.toc a {
  display: block;
  padding: 0.25rem 0 0.25rem 0.9rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--ink-soft);
  text-decoration: none;
}
.toc a:hover { color: var(--ink); }
.toc a[aria-current="true"] { color: var(--ink); border-left-color: var(--nonphoto); font-weight: 600; }

.prose { max-width: 46rem; }
.prose h1 { font-size: var(--step-3); line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 1.5rem; }
.prose h2 {
  font-size: var(--step-2);
  letter-spacing: -0.01em;
  line-height: 1.25;
  margin: 3rem 0 0.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  scroll-margin-top: 5rem;
}
.prose section:first-of-type h2 { border-top: 0; margin-top: 0; padding-top: 0; }
.prose h3 { font-size: var(--step-1); margin: 1.75rem 0 0.5rem; }
.prose p, .prose li { max-width: 72ch; }
.prose p { margin: 0 0 0.9rem; }
.prose ul, .prose ol { padding-left: 1.3rem; margin: 0 0 1rem; }
.prose li { margin-bottom: 0.35rem; }
.prose pre { margin: 0 0 1rem; }
.prose :not(pre) > code {
  padding: 0.08em 0.3em;
  background: var(--code-bg);
  border-radius: 4px;
  overflow-wrap: anywhere;
}

.table-wrap { overflow-x: auto; margin: 0 0 1.25rem; }
table { border-collapse: collapse; width: 100%; font-size: var(--step--1); }
th, td { text-align: left; vertical-align: top; padding: 0.5rem 0.7rem 0.5rem 0; border-bottom: 1px solid var(--rule); }
th { font-weight: 600; color: var(--ink-soft); }
td:first-child { white-space: nowrap; }
tr.unavailable td { color: var(--ink-soft); }
.tag { font-size: var(--step--1); color: var(--correction); }

/* ---------------------------------------------------------------- narrow */

@media (max-width: 1100px) {
  .viewer { grid-template-columns: 1fr; }
  .lines { max-height: 40vh; min-height: 0; }
  .page-scroll { max-height: 75vh; }
}

@media (max-width: 860px) {
  .bench { grid-template-columns: 1fr; }
  .docs { grid-template-columns: 1fr; }
  .toc { position: static; }
  .toc ol { display: flex; flex-wrap: wrap; gap: 0.2rem 0.6rem; border-left: 0; }
  .toc a { padding: 0.15rem 0; border-left: 0; }
  .bar { position: static; }
  .key { margin-left: 0; width: 100%; }
  .key > label:first-child { flex-basis: 100%; }
  .key input[type="password"], .key input[type="text"] { flex: 1 1 10rem; width: auto; min-width: 0; }
  .key-status { text-align: left; }
  td:first-child { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
}
