/* ============================================================
   BAGARI Font Finder: the tool's own parts, on top of css/style.css.
   The page wears the site: its header, footer, type, Stone / Slate surfaces
   and the one brand red. Everything here is scoped to main.ff and uses the
   site's tokens; nothing redefines them.
   ============================================================ */

.ff {
  --surface-2: color-mix(in srgb, var(--text) 5%, var(--surface));   /* a quiet well for text read out */
  max-width: 72rem;
  margin: 0 auto;
  padding: clamp(6rem, 13vh, 8rem) var(--gutter) var(--s-6);
  display: grid;
  gap: clamp(var(--s-4), 3vh, var(--s-5));
}
@media (min-width: 1200px) { .ff { padding-inline: var(--s-6); } }

/* ---------- intro, in the site's case-page voice ---------- */
.ff .intro { display: grid; gap: var(--s-3); }
.ff .intro h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.5rem, 6vw, 5rem);
  line-height: 0.85;
  letter-spacing: -0.04em;
  max-width: 16ch;
  text-wrap: balance;
}
.ff .intro h1 .l.en { text-transform: uppercase; }
.ff .intro h1 .l.ka { letter-spacing: -0.005em; line-height: 0.92; }
.ff .intro .lede { max-width: 60ch; font-size: clamp(1.0625rem, 0.95rem + 0.5vw, 1.375rem); }
.ff .kicker { color: var(--kicker); }
.ff .kicker .num { color: var(--muted); margin-right: var(--s-2); }
.ff .muted { color: var(--muted); }
.ff .note { font-size: 0.875rem; line-height: 1.45; }
.ff .note a { color: var(--link); text-underline-offset: 0.2em; }
.ff .meta { font-size: 0.8125rem; color: var(--muted); }
.ff .display-sm {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.5rem, 2.6vw, 2.125rem);
  line-height: 1;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.ff .model-info { font-size: 0.8125rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: var(--s-3); }

#ffForm { display: grid; gap: var(--s-3); }

/* ---------- upload ---------- */
.ff .upload { display: grid; gap: var(--s-3); }
.ff .upload-zone {
  position: relative;
  min-height: 9rem;
  display: flex;                 /* not grid: a grid track would grow to the preview's intrinsic width */
  align-items: center;
  justify-content: center;
  padding: var(--s-3);
  border: 1px dashed var(--line-strong);
  cursor: pointer;
  transition: border-color var(--fast) var(--ease), background var(--fast) var(--ease);
}
.ff .upload-zone:hover, .ff .upload-zone.drag-over { border-color: var(--kicker); background: var(--surface-2); }
.ff .upload-content { display: grid; justify-items: center; gap: var(--s-2); text-align: center; color: var(--muted); pointer-events: none; }
.ff .upload-content svg { color: var(--kicker); margin-bottom: var(--s-1); width: 1.5rem; height: 1.5rem; }
.ff .upload-title { color: var(--text); font-weight: 600; }
.ff .upload-hint { font-size: 0.875rem; }
.ff .preview { display: block; max-width: 100%; min-width: 0; max-height: min(26rem, 55vh); }

/* ---------- framing the text: the image with a selection over it ---------- */
.ff .upload-zone.has-image { cursor: default; padding: var(--s-2); border-style: solid; border-color: var(--line); }
.ff .upload-zone.has-image:hover { background: none; }
.ff .crop {
  position: relative;
  max-width: 100%;
  overflow: hidden;              /* keeps the dimming shadow inside the image */
  cursor: crosshair;
  touch-action: none;            /* a finger drags the frame, not the page */
  user-select: none;
  -webkit-user-select: none;
}
.ff .crop-box {
  position: absolute;
  box-sizing: border-box;
  border: 1px dashed #fff;
  outline: 1px dashed #000;      /* two dashes, so the frame shows on light and dark images */
  outline-offset: -2px;
  box-shadow: 0 0 0 100vmax rgba(20, 22, 24, 0.55);
  cursor: move;
}
.ff .crop-box:focus-visible { border-color: var(--mark); border-style: solid; outline-color: var(--mark); }
.ff .crop-box i {
  position: absolute;
  width: 0.75rem; height: 0.75rem;
  margin: -0.375rem 0 0 -0.375rem;
  background: #fff;
  border: 1px solid #000;
}
/* a wider, invisible grip for fingers */
.ff .crop-box i::after { content: ""; position: absolute; inset: -0.75rem; }
.ff .crop-box [data-h="nw"] { left: 0;    top: 0;    cursor: nwse-resize; }
.ff .crop-box [data-h="n"]  { left: 50%;  top: 0;    cursor: ns-resize; }
.ff .crop-box [data-h="ne"] { left: 100%; top: 0;    cursor: nesw-resize; }
.ff .crop-box [data-h="e"]  { left: 100%; top: 50%;  cursor: ew-resize; }
.ff .crop-box [data-h="se"] { left: 100%; top: 100%; cursor: nwse-resize; }
.ff .crop-box [data-h="s"]  { left: 50%;  top: 100%; cursor: ns-resize; }
.ff .crop-box [data-h="sw"] { left: 0;    top: 100%; cursor: nesw-resize; }
.ff .crop-box [data-h="w"]  { left: 0;    top: 50%;  cursor: ew-resize; }
.ff .crop.is-whole .crop-box { box-shadow: none; }
.ff .crop-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-3); }
.ff .crop-bar .note { margin: 0; }
.ff .crop-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }

/* ---------- buttons: the site's, plus a small size ---------- */
.ff .btn { cursor: pointer; border-radius: 0; font-family: var(--font); }
.ff .btn:disabled { opacity: 0.35; cursor: not-allowed; }
.ff .analyze-btn { width: 100%; min-height: 3rem; }
.ff .btn-sm { min-height: 2.5rem; padding: 0 var(--s-3); font-size: 0.6875rem; }
.ff .btn-ghost { background: none; color: var(--text); }
.ff .swap .off { display: none; }
.ff .swap.is-alt .on { display: none; }
.ff .swap.is-alt .off { display: inline; }

/* ---------- panels ---------- */
.ff .panel {
  border: 1px solid var(--line-strong);
  padding: var(--s-3) var(--s-4);
  display: grid;
  gap: var(--s-2);
  align-content: start;
  min-width: 0;
}

/* ---------- the email route (engine offline) and the correction fields ---------- */
.ff .send-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.ff .field { display: grid; gap: var(--s-2); min-width: 0; margin: 0; }
.ff .field-wide { grid-column: 1 / -1; }
.ff .field label { font-size: 0.875rem; font-weight: 400; color: var(--muted); margin: 0; }
.ff .field input,
.ff .field textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 0;
  font: inherit;
  font-size: 1rem;
}
.ff .field textarea { resize: vertical; min-height: 4.5rem; }
.ff .field input:focus,
.ff .field textarea:focus { border-color: var(--focus); outline: none; }
.ff .consent {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--s-2);
  align-items: start;
  font-size: 0.875rem;
  cursor: pointer;
}
.ff .consent input { width: 1.1rem; height: 1.1rem; margin: 0.15rem 0 0; accent-color: var(--mark); }
.ff .consent a { color: var(--link); text-underline-offset: 0.2em; }

/* ---------- status ---------- */
.ff .error-box {
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--mark);
  background: color-mix(in srgb, var(--mark) 10%, transparent);
  color: var(--text);
  font-size: 0.9375rem;
}
.ff .error-box:not([data-show="type"]) [data-err="type"],
.ff .error-box:not([data-show="send"]) [data-err="send"],
.ff .error-box:not([data-show="check"]) [data-err="check"] { display: none !important; }
.ff .spinner { display: flex; align-items: center; gap: var(--s-3); }
.ff .spin {
  width: 1.25rem; height: 1.25rem;
  border: 1px solid var(--line-strong);
  border-top-color: var(--mark);
  animation: ff-spin 0.8s linear infinite;
}
@keyframes ff-spin { to { transform: rotate(360deg); } }
.ff .hidden { display: none !important; }

/* live analysis, or the email route when the engine is offline */
#ffForm:not([data-mode="send"]) .mode-send,
#ffForm[data-mode="send"] .mode-analyze { display: none !important; }
.ff .check-box:empty { display: none; }

/* ---------- results: script, typeface, the text read out ---------- */
.ff .results { transition: opacity var(--slow) var(--ease-out); }
.ff .result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.ff .panel-wide { grid-column: 1 / -1; }
.ff .result-side { display: contents; }
.ff .value-row { display: flex; align-items: baseline; gap: var(--s-3); flex-wrap: wrap; }
.ff .badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.625rem;
  letter-spacing: 0.14em;
  line-height: 1.4;
}
.ff .badge .l.en { text-transform: uppercase; }

/* the thin red line is the whole chart */
.ff .bar { height: 2px; background: var(--line); }
.ff .bar > i { display: block; height: 100%; width: 0; background: var(--mark); transition: width var(--medium) var(--ease-out); }
.ff .font-scores { display: grid; gap: var(--s-2); padding-top: var(--s-2); border-top: 1px solid var(--line); }
.ff .score-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7rem 3rem;
  gap: var(--s-3);
  align-items: center;
  font-size: 0.8125rem;
}
.ff .score-row .name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ff .score-row .pct { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

.ff .ocr-output {
  font-family: var(--font);
  font-size: clamp(1rem, 0.95rem + 0.4vw, 1.25rem);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 3.5rem;
  max-height: 9rem;
  overflow-y: auto;
  padding: var(--s-2) var(--s-3);
  margin: 0;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.ff .ocr-low { text-decoration: underline dashed var(--muted); text-decoration-skip-ink: none; text-underline-offset: 0.2em; cursor: help; }
.ff .ocr-fixed { text-decoration: underline dotted var(--mark); text-decoration-skip-ink: none; text-underline-offset: 0.2em; cursor: help; }
.ff #copyBtn { justify-self: start; }

/* ---------- corrections: a wrong typeface, a misread word ---------- */
.ff .fix { display: grid; gap: var(--s-2); min-width: 0; }
.ff .fix > .fix-open { justify-self: start; }
.ff .fix-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.ff .fix-form { display: grid; gap: var(--s-2); padding-top: var(--s-2); border-top: 1px solid var(--line); }
.ff .fix-form .field textarea { min-height: 3.5rem; font-size: clamp(1rem, 0.95rem + 0.4vw, 1.25rem); line-height: 1.5; }
.ff .fix-consent { font-size: 0.8125rem; }
.ff .fix-consent a { color: var(--link); text-underline-offset: 0.2em; }
.ff .fix-done, .ff .fix-ok-done { color: var(--kicker); font-size: 0.875rem; }
.ff .fix-hint { font-size: 0.75rem; line-height: 1.4; margin: 0; }
.ff .fix-hint a { color: inherit; text-underline-offset: 0.2em; }
.ff .fix-error { color: var(--mark); font-size: 0.875rem; }
.ff .fix-warn { color: var(--text); font-size: 0.875rem; padding-left: var(--s-2); border-left: 2px solid var(--mark); }

/* ---------- questions: what the tool does, in words a search can read ---------- */
.ff .about { display: grid; gap: var(--s-3); border-top: 1px solid var(--line-strong); padding-top: var(--s-4); }
.ff .about h2 { margin: 0; font-size: 0.75rem; }
.ff .faq { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); margin: 0; }
.ff .faq > div { display: grid; gap: var(--s-2); align-content: start; }
.ff .faq dt { font-weight: 600; line-height: 1.3; }
.ff .faq dd { margin: 0; color: var(--muted); font-size: 0.9375rem; line-height: 1.55; max-width: 60ch; }

/* ---------- phone ---------- */
@media (max-width: 720px) {
  .ff { padding-top: 6.5rem; }
  .ff .send-grid { grid-template-columns: 1fr; }
  .ff .result-grid { grid-template-columns: 1fr; }
  .ff .faq { grid-template-columns: 1fr; gap: var(--s-3); }
  .ff .panel-wide { grid-column: 1; }
  .ff .btn { width: 100%; }
  .ff .btn-sm { width: auto; }
  .ff .score-row { grid-template-columns: minmax(0, 1fr) 5rem 3rem; }
}

/* ---------- results beside the image on wide screens, so nothing needs a scroll ---------- */
@media (min-width: 900px) {
  #ffForm.has-results {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: var(--s-4);
    align-items: start;
    grid-template-rows: auto 1fr;
  }
  #ffForm.has-results > * { grid-column: 1; }
  /* the panels join the form grid: the text read out sits under the image,
     script and typeface stack on the right, and both columns end together */
  #ffForm.has-results > .results,
  #ffForm.has-results .result-grid { display: contents; }
  #ffForm.has-results .upload { grid-row: 1; }
  #ffForm.has-results .result-side { grid-column: 2; grid-row: 1 / span 2; display: grid; gap: var(--s-2); align-content: start; align-self: stretch; grid-template-rows: auto 1fr; }
  #ffForm.has-results #panelText { grid-column: 1; grid-row: 2; align-self: stretch; }
  #ffForm.has-results .font-scores { gap: var(--s-1); }
  #ffForm.has-results .score-row:nth-child(n+4) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .ff .spin { animation-duration: 2.4s; }
}
