:root {
  --bg: #11131a;
  --panel: #1a1d27;
  --line: #2b3040;
  --text: #e6e8ef;
  --dim: #8d93a6;
  --accent: #6ea8fe;
  --ok: #4ade80;
  --err: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem 1.5rem 4rem;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

header { max-width: 1200px; margin: 0 auto 1.5rem; }
h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.sub { margin: 0.25rem 0 0; color: var(--dim); }
main { max-width: 1200px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.25rem;
}

form { display: flex; gap: 0.6rem; }

.or {
  margin: 0.8rem 0 0.6rem;
  color: var(--dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-align: center;
}

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 1.6rem 1rem;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  background: #0d0f16;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.drop:hover, .drop:focus-visible, .drop.over {
  border-color: var(--accent);
  background: #10131c;
  outline: none;
}
.drop strong { font-size: 0.95rem; font-weight: 600; }
.drop span { color: var(--dim); font-size: 0.83rem; }

input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.8rem;
  background: #0d0f16;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  padding: 0.6rem 1.1rem;
  background: var(--accent);
  color: #0d0f16;
  border: 0;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:not(:disabled):hover { filter: brightness(1.1); }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-top: 1rem;
  color: var(--dim);
  font-size: 0.9rem;
}
.controls label { display: flex; align-items: center; gap: 0.45rem; }
.controls input[type="number"] {
  width: 4.5rem;
  padding: 0.3rem 0.45rem;
  background: #0d0f16;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
}
.controls input[type="range"] { width: 8rem; accent-color: var(--accent); }
.controls output { color: var(--text); font-variant-numeric: tabular-nums; }
.check input { accent-color: var(--accent); }

.hint {
  display: inline-grid;
  place-items: center;
  width: 1.05rem; height: 1.05rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 0.7rem;
  cursor: help;
}

.status { margin-top: 0.9rem; min-height: 1.4rem; color: var(--dim); font-size: 0.9rem; }
.status.error { color: var(--err); white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace; font-size: 0.82rem; }
.status.done { color: var(--ok); }

.mask-note {
  margin-bottom: 0.6rem;
  min-height: 1rem;
  color: var(--dim);
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  opacity: 0.75;
}

.bar-wrap { height: 5px; background: #0d0f16; border-radius: 3px; overflow: hidden; }
.bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s ease; }

.result-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 2rem 0 1rem;
  flex-wrap: wrap;
}
.result-head h2 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.actions { display: flex; align-items: center; gap: 0.9rem; }
.count { color: var(--dim); font-size: 0.9rem; font-variant-numeric: tabular-nums; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.slide {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  display: block;
}
.slide:hover { border-color: var(--accent); }
.slide img { width: 100%; display: block; background: #000; aspect-ratio: 16 / 9; object-fit: contain; }
.slide .meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.7rem;
  font-size: 0.82rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.slide .meta .n { color: var(--text); font-weight: 600; }
.slide .meta .again { color: var(--accent); }

.slide .ocr {
  padding: 0 0.7rem 0.6rem;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--dim);
  border-top: 1px solid var(--line);
  padding-top: 0.5rem;
  margin-top: -0.15rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hidden { display: none !important; }

.backend-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.45rem;
  font-size: 0.8rem;
  color: var(--dim);
}

.backend-status {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.backend-status.ok { color: var(--ok); }
.backend-status.warn { color: var(--accent); }

.text-btn {
  background: transparent;
  color: var(--accent);
  border: 0;
  padding: 0;
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: underline;
  cursor: pointer;
}
.text-btn:hover { filter: brightness(1.2); }

.backend-config-box {
  margin-top: 0.6rem;
  padding: 0.8rem;
  background: #0d0f16;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.backend-config-box label {
  font-weight: 600;
  color: var(--text);
}
.config-input-row {
  display: flex;
  gap: 0.5rem;
}
.config-input-row input {
  font-size: 0.85rem;
}
.config-input-row button {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  white-space: nowrap;
}
.hint-text {
  font-size: 0.78rem;
  color: var(--dim);
}
.hint-text code {
  color: var(--accent);
}

/* Offscreen: the sampling source, never meant to be looked at. */
#video { position: fixed; left: -10000px; top: 0; width: 320px; }
