/* Photo extractor — the "workbench" wireframe, built as drawn.
 *
 * The hand-drawn look is deliberate and specified: 1.5px ink strokes, hard
 * offset shadows with no blur, slightly irregular corner radii. Nothing here
 * is a placeholder for a "real" skin later.
 *
 * Fonts are vendored in /static/fonts and never fetched from a CDN — HR
 * machines may be locked down, and a webfont that fails to load silently
 * changes every measurement on the page.
 */

:root {
  --paper:  #fbfaf7;   /* the workbench ground */
  --card:   #ffffff;   /* panel surfaces */
  --rail:   #f4f2ee;   /* tool rail and filmstrip */
  --sunk:   #faf9f6;   /* recessed areas */
  --ink:    #1a1a1a;   /* the pen */
  --pencil: #8a857c;   /* secondary text */
  --rule:   #cfcbc3;   /* light strokes */
  --faint:  #e0ddd6;   /* dividers */
  --blue:   #2f6feb;   /* the one accent: selection, corners, primary action */
  --wash:   #eef4ff;
  --warn:   #fdf7e3;
  --error:  #fdecec;

  --hand: 'Architects Daughter', 'Segoe Print', 'Comic Sans MS', cursive;
  --note: 'Kalam', 'Segoe Print', 'Comic Sans MS', cursive;
  --mono: ui-monospace, 'Cascadia Mono', Menlo, monospace;

  --shadow: 2px 2px 0 rgba(0, 0, 0, .10);
  --stroke: 1.5px solid var(--ink);
  /* Irregular on purpose — a drawn box is never square-cornered. */
  --sketch: 9px 11px 8px 12px;
}

* { box-sizing: border-box; }

/* Several elements below set `display`, which outranks the user-agent's
 * [hidden] { display: none } and leaves them on screen forever. Restore the
 * attribute's meaning once, here, rather than remembering it at every site. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 18px;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 var(--hand);
  -webkit-text-size-adjust: 100%;
}

/* --- layout ------------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) 210px;
  gap: 14px;
  max-width: 1240px;
  margin: 0 auto;
  align-items: start;
}

.rail, .work, .panel {
  border: var(--stroke);
  border-radius: var(--sketch);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.rail  { background: var(--rail); padding: 12px 11px; }
.work  {
  background: var(--card);
  min-height: 420px;
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
}
.panel { background: var(--sunk); padding: 12px 11px; display: flex; flex-direction: column; gap: 10px; }

/* --- shared bits -------------------------------------------------------- */

.eyebrow {
  margin: 0;
  font: 600 10px/1.4 var(--mono);
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--pencil);
}

/* --- tool rail ---------------------------------------------------------- */

.rail-brand { margin: 0 0 10px; font-size: 17px; }

.rail-tools { display: flex; flex-direction: column; gap: 7px; }

.tool {
  display: block;
  border-radius: 6px 7px 5px 8px;
  padding: 6px 9px;
  font-size: 14px;
}
.tool-on  { border: 1.5px solid var(--blue); background: var(--wash); }
.tool-off { border: 1.5px dashed var(--rule); color: var(--pencil); }

.rail-pages { margin-top: 16px; }

.filmstrip {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 340px;
  overflow-y: auto;
}

.thumb {
  display: block;
  width: 100%;
  padding: 0;
  border: 1.5px solid var(--rule);
  border-radius: 4px;
  background: var(--card);
  cursor: pointer;
  overflow: hidden;
  line-height: 0;
}
.thumb img { width: 100%; height: auto; display: block; }
.thumb.on { border: 2px solid var(--blue); }
.thumb-n {
  display: block;
  font: 600 9px/1.7 var(--mono);
  color: var(--pencil);
  line-height: 15px;
  background: var(--rail);
}
.thumb.on .thumb-n { background: var(--blue); color: #fff; }

.rail-note {
  margin: 16px 0 0;
  font-family: var(--note);
  font-size: 12px;
  line-height: 1.4;
  color: var(--pencil);
}

.langs { display: flex; gap: 4px; margin-top: 14px; }
.lang {
  flex: 1;
  border: 1.5px solid var(--rule);
  border-radius: 11px 13px 11px 14px;
  background: var(--card);
  color: var(--pencil);
  font: 600 10px/1.6 var(--mono);
  letter-spacing: .04em;
  padding: 3px 0;
  cursor: pointer;
}
.lang.on { border: 2px solid var(--blue); background: var(--wash); color: var(--ink); }
.lang:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* --- work area ---------------------------------------------------------- */

.banner {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  border-bottom: 1.5px solid var(--faint);
  background: var(--wash);
  font-size: 14px;
}
.banner-mark {
  flex: none;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--blue);
}
.banner-text { margin: 0; flex: 1; }
.banner-tag { font-family: var(--note); font-size: 11px; color: var(--pencil); }

.banner.is-warn  { background: var(--warn); }
.banner.is-error { background: var(--error); }
.banner.is-warn .banner-mark,
.banner.is-error .banner-mark {
  width: auto; height: auto; border-radius: 0;
  background: none; font-size: 14px;
}
.banner.is-warn  .banner-mark::before { content: '!'; }
.banner.is-error .banner-mark::before { content: '\00d7'; }

.drop {
  margin: 14px;
  padding: 22px;
  min-height: 170px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-align: center;
  border: 2px dashed #b6bcc7;
  border-radius: 12px;
  background: #fdfdfd;
  cursor: pointer;
}
.drop.over { border-color: var(--blue); background: var(--wash); }
.drop:focus-within { outline: 2px solid var(--blue); outline-offset: 3px; }
.drop-big { font-size: 17px; }
.drop-small { font-family: var(--note); font-size: 13px; color: var(--pencil); }

/* The page has to fit beside the preview panel, not push it off screen: the
 * whole point of this layout is seeing the crop and the result at once. */
.stage {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: auto;
}
.frame {
  position: relative;
  line-height: 0;
  touch-action: none;
  user-select: none;
  box-shadow: var(--shadow);
  background: repeating-linear-gradient(135deg, #f2f1ee 0 5px, #e8e6e1 5px 10px);
}
#page {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 190px);
}
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#quad {
  fill: rgba(47, 111, 235, .12);
  stroke: var(--blue);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.handle {
  fill: #fff;
  stroke: var(--blue);
  stroke-width: 3;
  cursor: grab;
  vector-effect: non-scaling-stroke;
}
.handle:focus { outline: none; stroke: var(--ink); stroke-width: 4; }

#loupe {
  position: absolute;
  width: 180px; height: 180px;
  border-radius: 50%;
  border: 2px solid var(--blue);
  background: #fff;
  pointer-events: none;
  display: none;
}

.stage-hint {
  position: absolute;
  right: 10px; bottom: 8px;
  margin: 0;
  padding: 3px 9px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .88);
  font-family: var(--note);
  font-size: 12px;
  color: var(--pencil);
}

/* --- right panel -------------------------------------------------------- */

.preview {
  border: var(--stroke);
  border-radius: 5px 6px 5px 7px;
  background: var(--card);
  display: grid;
  place-items: center;
  min-height: 150px;
  padding: 7px;
}
.preview img { max-width: 100%; max-height: 210px; display: block; }
.preview-empty {
  margin: 0;
  font-family: var(--note);
  font-size: 12px;
  color: var(--pencil);
  text-align: center;
}
.preview.is-stale { opacity: .45; }

.readout { margin: 0; font: 10.5px/1.4 var(--mono); color: var(--pencil); }

.sizes, .formats { margin: 0; padding: 0; border: 0; }
.sizes { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.sizes legend, .formats legend { padding: 0 0 5px; }
.formats { display: flex; gap: 5px; flex-wrap: wrap; }
.formats legend { width: 100%; }

.size, .fmt {
  border: 1.5px solid var(--rule);
  background: var(--card);
  color: var(--ink);
  font-family: var(--hand);
  font-size: 13px;
  cursor: pointer;
  padding: 7px 5px;
  border-radius: 5px 6px 5px 7px;
}
.size small { display: block; font-family: var(--note); font-size: 10px; color: var(--pencil); }
.fmt { flex: 1; border-radius: 14px; padding: 5px; }
.size.on, .fmt.on { border: 2px solid var(--blue); background: var(--wash); }
.size:focus-visible, .fmt:focus-visible, .thumb:focus-visible,
.go:focus-visible, summary:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.custom { font-size: 13px; }
.custom summary {
  cursor: pointer;
  padding: 6px 8px;
  border: 1.5px dashed var(--rule);
  border-radius: 5px 6px 5px 7px;
}
.custom-row { display: flex; flex-direction: column; gap: 6px; padding: 8px 2px 0; }
.custom-row label { display: flex; align-items: center; gap: 6px; }
.custom-row input {
  width: 62px;
  border: 1.5px solid var(--rule);
  border-radius: 4px;
  padding: 4px 6px;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--card);
  color: var(--ink);
}
.custom-row span { font-family: var(--note); font-size: 11px; color: var(--pencil); }

.go {
  margin-top: auto;
  border: var(--stroke);
  border-radius: 6px 8px 6px 9px;
  background: var(--blue);
  color: #fff;
  font-family: var(--hand);
  font-size: 15px;
  padding: 9px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.go:disabled { background: #b9c9ef; border-color: var(--rule); cursor: default; box-shadow: none; }
.go:not(:disabled):active { transform: translate(2px, 2px); box-shadow: none; }

.status { margin: 0; font-family: var(--note); font-size: 12px; color: var(--pencil); min-height: 1.2em; }

.notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.notes li {
  border: var(--stroke);
  border-radius: 5px 6px 5px 7px;
  padding: 7px 9px;
  font-family: var(--note);
  font-size: 12px;
  line-height: 1.35;
  background: var(--warn);
}
.notes li.is-error { background: var(--error); }

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

@media (max-width: 940px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-start; }
  .rail-tools { flex-direction: row; flex-wrap: wrap; }
  .rail-pages { margin-top: 0; width: 100%; }
  .filmstrip { flex-direction: row; max-height: none; overflow-x: auto; }
  .thumb { width: 74px; flex: none; }
  .rail-note { margin-top: 0; }
  .go { margin-top: 8px; }
  /* Stacked, the preview sits below the page. Keep the page short enough that
   * adjusting a corner and checking the result is not a long scroll. */
  #page { max-height: 58vh; }
}

/* --- Russian ------------------------------------------------------------ */

/* Architects Daughter and Kalam publish latin and latin-ext only, so Cyrillic
 * would fall back to a system sans and lose the sketch identity entirely --
 * and Russian is the default language, so that would be most users. Caveat is
 * the hand-drawn face that does ship cyrillic.
 *
 * The whole stack swaps rather than letting the browser pick per glyph: a
 * string like "Страница 1" would otherwise be drawn by two different pens,
 * since the digits are Latin. Caveat sits smaller and lighter than Architects
 * Daughter, hence the size bump; the two type roles are kept apart by weight
 * instead of by family. */
html[lang="ru"] {
  --hand: 'Caveat', 'Segoe Script', cursive;
  --note: 'Caveat', 'Segoe Script', cursive;
}
html[lang="ru"] body { font-size: 17.5px; font-weight: 600; }
html[lang="ru"] .rail-note,
html[lang="ru"] .status,
html[lang="ru"] .notes li,
html[lang="ru"] .preview-empty,
html[lang="ru"] .drop-small,
html[lang="ru"] .stage-hint,
html[lang="ru"] .banner-tag,
html[lang="ru"] .size small { font-weight: 400; }
/* The monospace roles (.eyebrow, .readout, .thumb-n, .lang) need no rule here:
 * each sets a `font:` shorthand, which already pins family, size and weight
 * against the body changes above. An earlier attempt to "protect" them with
 * `font-size: unset` did the opposite — unset means inherit, so they took the
 * 17.5px body size and the panel labels wrapped. */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
