/* Chopmark Lookup tool — scoped under .cl-tool. Sits inside a standard
   content page, below the intro markdown. */

@font-face {
  font-family: "ChopmarkGlyphs";
  src: url("/fonts/chopmark-glyphs.woff2") format("woff2");
  font-display: swap;
}
/* Expanded library glyphs (~28k). Lazy: the browser only fetches this woff2
   the first time a glyph actually uses it — i.e. once Expanded mode renders
   a result. Superset of the default font, so it covers everything. */
@font-face {
  font-family: "ChopmarkGlyphsExpanded";
  src: url("/fonts/chopmark-glyphs-expanded.woff2") format("woff2");
  font-display: swap;
}

.cl-tool { margin: 1.5rem 0 0.5rem; }

/* Matching-method selector — accessible radio group styled as a segmented
   control. The real <input>s are visually hidden but keep keyboard/AT
   semantics (arrow-key nav, focus ring). */
.cl-modes {
  border: 0;
  /* Bottom margin reserves room for the absolute-positioned per-radio
     .cl-seg-loading message; sized so showing/hiding the message never
     overlaps the canvas/results below. */
  margin: 0 0 1.6rem;
  padding: 0;
  min-width: 0;
}
.cl-modes-legend {
  padding: 0;
  margin: 0 0 0.55rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8a7d68;
}
.cl-seg {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.cl-seg-opt {
  flex: 1 1 200px;
  position: relative;
  margin: 0;
}
.cl-seg-opt input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}
.cl-seg-box {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  height: 100%;
  padding: 0.6rem 0.75rem;
  background: #fdfbf5;
  border: 1px solid #d8cdb6;
  border-radius: 9px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.cl-seg-opt:hover .cl-seg-box { border-color: #b08a3e; }
.cl-seg-opt input:checked + .cl-seg-box {
  border-color: #b08a3e;
  background: #fbf3df;
  box-shadow: inset 0 0 0 1px #b08a3e;
}
.cl-seg-opt input:focus-visible + .cl-seg-box {
  outline: 2px solid #8a6a26;
  outline-offset: 2px;
}
.cl-seg-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #2c2418;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.cl-seg-desc { font-size: 0.74rem; color: #8a7d68; line-height: 1.35; }
/* Per-radio one-time-load indicator — sibling of .cl-seg-box (outside the
   styled button surface) so it reads as a plain status note directly under
   the relevant radio button. Absolute-positioned against the relatively-
   positioned .cl-seg-opt so showing/hiding it doesn't reflow anything
   below the matching-library row (the cl-modes bottom margin reserves
   the room). Hidden by default; the client toggles the [hidden] attribute. */
.cl-seg-loading {
  position: absolute;
  top: 100%;
  left: 0.25rem;
  right: 0.25rem;
  margin-top: 0.25rem;
  font-size: 0.72rem;
  font-style: italic;
  color: #b08a3e;
}
.cl-seg-loading[hidden] { display: none; }

.cl-stage {
  display: flex;
  gap: 1.75rem;
  flex-wrap: wrap;
  align-items: flex-start;
  /* Container-type lets @container rules below query the stage's actual
     inline-size, which is what determines whether the flex children stay
     side-by-side or wrap — viewport-based @media can't capture this
     accurately because the wrap point depends on the page's padding,
     scrollbar, font metrics, and exact rendering (real Safari fits side-
     by-side at viewports where Playwright WebKit reports stacked). */
  container-type: inline-size;
}

.cl-padwrap { flex: 0 0 auto; position: relative; }

/* Small circular button anchored inside the canvas's top-right corner. */
.cl-corner-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fdfbf5;
  border: 1px solid #d8cdb6;
  border-radius: 50%;
  color: #6f6451;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.cl-corner-btn:hover { border-color: #b08a3e; color: #2c2418; background: #fbf3df; }
.cl-corner-btn:focus-visible { outline: 2px solid #8a6a26; outline-offset: 2px; }
.cl-corner-icon { width: 16px; height: 16px; display: block; }

.cl-pad {
  display: block;
  width: 300px;
  height: 300px;
  background: #fffdf8;
  border: 1px solid #d8cdb6;
  border-radius: 10px;
  touch-action: none;
  cursor: crosshair;
}

.cl-controls { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; width: 300px; }

.cl-btn {
  flex: 1 1 45%;
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  color: #3a3128;
  background: #f3ecdd;
  border: 1px solid #d8cdb6;
  border-radius: 7px;
  cursor: pointer;
}
.cl-btn:hover:not(:disabled) { border-color: #b08a3e; }
.cl-btn:disabled { opacity: 0.45; cursor: default; }

/* The picked-character copy/paste line (left column, below the buttons).
   NB: class is `cl-pick`, deliberately NOT `cl-selected` — that class is
   the selected grid-cell state; reusing it leaked this margin onto the
   selected cell and pushed it down. */
.cl-pick {
  width: 300px;
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
  color: #6f6451;
}
.cl-pick:empty { display: none; }
/* Direct Lookup pick block: a single row holding
   "Hanzi: <ch>  Seal: <seal>  (view on Wiktionary)".
   The drawing flows' pickEl renders a single un-wrapped run (no
   .cl-pick-line span) and inherits .cl-pick's block layout, so the
   rules below only kick in for Direct Lookup's nested structure. */
.cl-pick .cl-pick-line {
  display: block;
  margin-top: 0.15rem;
}
.cl-pick .cl-pick-line:first-child { margin-top: 0; }
.cl-pick .cl-pick-label { display: inline-block; }
.cl-pick .cl-pick-ch {
  -webkit-user-select: all;
  user-select: all;
  margin-left: 0.35rem;
  font-size: 1.3rem;
  color: #2c2418;
  cursor: text;
}
/* Spacing between "Hanzi: X" and the "Seal: …" section that follows it on
   the same row. Modest — the Hanzi glyph already has visual weight. */
.cl-pick .cl-pick-seal-section { margin-left: 1rem; }
/* Wider gap between the "Seal:" label and the seal SVG that follows it,
   so it doesn't read as one tight cluster. */
.cl-pick .cl-pick-label-seal { margin-right: 0.4rem; }
/* <img class="seal-glyph"> uses the same sizing as [sealchop:X] in markdown.
   margin-right opens a gap to the "(view on Wiktionary)" tail that follows;
   the seal SVG's viewBox usually has internal padding on its right edge,
   so the visual gap is smaller than the numeric value implies.
   Selector includes `img` so specificity (0,2,1) beats
   `.markdown-content img.seal-glyph` in markdown-content.css (also 0,2,1)
   on source order — the lookup page renders inside a .markdown-content
   wrapper, so without this the global rule wins. */
.cl-pick img.cl-pick-seal {
  height: 1.85em;
  margin-right: 1rem;
  vertical-align: -0.575em;
}
.cl-pick .cl-pick-wik {
  color: #b08a3e;
  text-decoration: underline;
}
.cl-pick .cl-pick-wik:hover { color: #8a6a28; }

.cl-results { flex: 1 1 280px; min-width: 260px; }

/* Scoped under .cl-tool so it outranks the site's
   `.page-content-content h2 { margin-top: 2rem }`, which otherwise pushes
   this heading 2rem below the canvas top (and overrides its size). */
.cl-tool .cl-results-title {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8a7d68;
  margin: 0 0 0.7rem;
  line-height: 1.2;
}

.cl-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: 1fr;      /* every row the same height… */
  align-items: stretch;     /* …and every cell fills its row */
  gap: 0.5rem;
}

/* Placeholder area below the 5×2 grid — full grid width, one-cell tall.
   Future home of collection chopmark photos. Shown only when something is
   drawn (toggled via the [hidden] attribute by the client). */
.cl-collection {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 160px;
  margin-top: 0.5rem;
  padding: 0.75rem 1rem;
  border: 1px solid #e3dac6;
  border-radius: 9px;
  background: #fdfbf5;
}
.cl-collection[hidden] { display: none; }
.cl-collection.cl-collection--filled {
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-start;
  align-content: center;
}
.cl-collection-ph {
  font-size: 0.8rem;
  font-style: italic;
  color: #9a8d76;
  text-align: center;
}
.cl-chopimg {
  width: 150px;
  height: 150px;
  object-fit: contain;
  border: 1px solid #e3dac6;
  border-radius: 6px;
  background: #fffdf8;
  cursor: pointer;
}

.cl-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-sizing: border-box;   /* div + button measured identically */
  width: 100%;
  height: 100%;             /* fill the grid track (buttons too) */
  padding: 0.55rem 0.25rem 0.45rem;
  border: 1px solid #b08a3e;   /* every cell rests at the same gold —     */
  border-radius: 9px;          /* collection chopmarks are no longer the  */
  background: #fbf3df;         /* only ones colored (cl-chop is behavior  */
  font: inherit;               /* only now: tooltip / pinyin / pictures)  */
  text-decoration: none;
  color: inherit;
  min-height: 64px;
  cursor: pointer;          /* every result cell is now selectable */
}
button.cl-cell { -webkit-appearance: none; appearance: none; }
.cl-cell .cl-glyph {
  font-family: "ChopmarkGlyphs", serif;
  font-size: 2.1rem;
  line-height: 1.15;
  color: #2c2418;
}
.cl-tool.cl-expanded .cl-cell .cl-glyph {
  font-family: "ChopmarkGlyphsExpanded", "ChopmarkGlyphs", serif;
}
.cl-cell .cl-py { font-size: 0.72rem; color: #6f6451; margin-top: 0.15rem; }
.cl-cell .cl-def {
  font-size: 0.66rem;
  color: #9a8d76;
  margin-top: 0.05rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Every result cell is clickable and shares one appearance — the same gold
   resting state (set on .cl-cell above) plus the hover / keyboard-focus /
   selected treatment below. Collection chopmarks (.cl-chop) are no longer
   colored differently; the class now only drives behavior (rich tooltip,
   pinyin/defs, collection pictures). cl-selected is intentionally placed
   AFTER cl-rank1 (equal specificity) so a selected rank-1 cell shows the
   selected ring rather than the rank-1 glow. */
.cl-cell:hover { border-color: #8a6a26; background: #f6ead0; }
.cl-cell:focus-visible { outline: 2px solid #8a6a26; outline-offset: 2px; }
.cl-cell.cl-rank1 { box-shadow: 0 0 0 2px rgba(176, 138, 62, 0.35); }
.cl-cell.cl-selected {
  border-color: #8a6a26;
  background: #f1e2bd;
  box-shadow: inset 0 0 0 2px #b08a3e;
}
.cl-cell.cl-rank1.cl-selected {
  box-shadow: inset 0 0 0 2px #b08a3e, 0 0 0 2px rgba(176, 138, 62, 0.35);
}

.cl-empty, .cl-status {
  font-size: 0.8rem;
  color: #8a7d68;
  margin: 0.75rem 0 0;
}
.cl-empty-arrow {
  width: 0.95rem;
  height: 0.95rem;
  vertical-align: -0.25em;
  margin-right: 0.15em;
}
/* Positional-text swap pair used in the Direct Lookup empty state:
   "Enter a Hanzi character <on the left|above> to see…". The mobile half
   is hidden by default; the @media block below flips visibility when the
   stage stacks. */
.cl-pos-mobile { display: none; }
.cl-status.cl-err { color: #b3463d; }

/* Stage transitions from side-by-side (canvas/input on the left, results
   on the right) to stacked (canvas/input on top, results below) when the
   .cl-stage container's inline-size drops below the wrap threshold —
   measured empirically at 607px (606→608 transition in both Chromium and
   WebKit), a bit wider than the naive 300+28+260=588 math because the
   padwrap and results have additional intrinsic content needs (corner
   button, results-title, etc.). When the stage stacks:
   - rotate the empty-state arrow 90° clockwise so it points up at the
     canvas/input column that now sits above the text, instead of left
     toward a column that's no longer there;
   - swap the Direct Lookup empty text's "on the left" → "above".
   The container query tracks the actual stage width (set by container-
   type: inline-size on .cl-stage above), so it fires at the same moment
   the flex children wrap — regardless of viewport-vs-content rendering
   differences across browsers (real Safari, Playwright WebKit, Chromium
   all wrap at the same container width even when their viewports for the
   same content differ). */
@container (max-width: 607px) {
  .cl-empty-arrow { transform: rotate(90deg); }
  .cl-pos-desktop { display: none; }
  .cl-pos-mobile { display: inline; }
}

@media (max-width: 560px) {
  .cl-grid { grid-template-columns: repeat(4, 1fr); }
  .cl-pad, .cl-controls, .cl-pick { width: 260px; }
  .cl-pad { height: 260px; }
}

/* ============================================================ */
/* Seal Script mode                                             */
/* ============================================================ */
/* Tile layout: matched seal SVG on top (centered), then a single inline
   label line "<hanzi> <badge> - <pinyin>" centered, then optional
   meaning below. Pinyin and meaning are independently optional. */
/* Seal-mode cells are deliberately ~20% taller than other modes — the
   matched seal SVG is the primary visual signal, so it gets the extra
   vertical room (holder ~44 vs 28 px) plus a margin below it to separate
   the seal char from the inline label / meaning lines. */
.cl-seal-cell { padding: 0.4rem 0.25rem; gap: 0.2rem; min-height: 78px; }
/* The holder is fixed-height — the inline SVG inside has its viewBox
   re-tightened to the actual ink bbox at mount time (see
   mountNormalizedSvg in chopmark-lookup.js), so every glyph's visible ink
   fills this height uniformly regardless of stock viewBox padding. */
.cl-seal-glyph-holder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  width: 100%;
  margin-bottom: 0.35rem;     /* gap between seal char and label/meaning */
}
.cl-seal-glyph-holder svg {
  height: 100%;
  width: auto;
  max-width: 100%;
  display: block;
}
.cl-seal-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  line-height: 1;
}
.cl-seal-cell .cl-seal-han {
  font-family: inherit;     /* modern Hanzi rendered in system font, not the */
  font-size: 1.15rem;       /* chopmark glyph webfont (it's the LABEL, not   */
  line-height: 1;           /* the matched glyph). Shrunk from 1.4rem so it  */
  color: #2c2418;           /* doesn't dominate the inline "han - pinyin".   */
}
/* Pinyin sitting inline next to the Hanzi label, not on its own line —
   inherits .cl-py colour/size but doesn't get the cl-py block-level
   top margin that styles below the cell already use. */
.cl-seal-cell .cl-seal-py-inline { margin-top: 0; }
.cl-seal-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 0.08rem 0.28rem;
  border-radius: 3px;
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, monospace;
}
.cl-seal-badge-L { background: #2a7a4f; }   /* Liushutong — green */
.cl-seal-badge-S { background: #b53d2e; }   /* Seal — brick */
.cl-seal-badge-B { background: #9a6a2e; }   /* Bronze — bronze */
.cl-seal-badge-J { background: #34579a; }   /* Oracle (Jiǎgǔ) — slate blue */
.cl-seal-badge-X { background: #888; }      /* unknown / fallback */

/* Collection panel in seal mode: grid of all variants of the clicked char,
   grouped by category. Replaces the chopmark-mode coin photos. */
.cl-tool.cl-seal .cl-collection.cl-collection--filled {
  display: block;            /* override row layout from .cl-collection--filled */
  padding: 0.6rem 0.5rem;
  text-align: left;
}
.cl-seal-cat { margin-bottom: 0.9rem; }
.cl-seal-cat:last-child { margin-bottom: 0; }
/* Scoped under .cl-tool so it outranks .page-content-content h3 (1.5rem)
   — without this our font-size rule loses the cascade and the title
   renders at the site's h3 size. Matched to the site's h4 (1.25rem), the
   size #### headings render at on this page. */
.cl-tool .cl-seal-cat-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #6f5d3e;
  margin: 0 0 0.35rem;
  letter-spacing: 0.02em;
}
.cl-seal-cat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.cl-seal-var {
  width: 56px;
  height: 56px;
  object-fit: contain;
  background: transparent;    /* let the .cl-collection cream show through */
  border: 1px solid #e3dac6;
  border-radius: 4px;
  padding: 3px;
  box-sizing: border-box;
  cursor: pointer;            /* matches chop-image hover (.cl-chopimg) */
}
.cl-seal-var:hover { border-color: #8a6a26; }

/* ============================================================ */
/* Direct Lookup (cl-direct)                                    */
/* ============================================================ */
/* Sibling widget under the drawing tool, same .cl-stage flex shape so the
   right-side galleries line up at the same horizontal offset as the
   drawing tool's results column above. */
.cl-direct { margin-top: 1.5rem; }

.cl-direct-inputcol {
  width: 300px;             /* matches .cl-pad, so the right column aligns */
}
.cl-direct-prompt {
  margin: 0 0 0.55rem;
  font-size: 0.85rem;
  color: #6f6451;
  line-height: 1.4;
}
.cl-direct-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.cl-direct-input {
  width: 2.6rem;            /* a little wider than one Hanzi glyph */
  padding: 0.5rem 0.5rem;
  font: inherit;
  font-size: 1.05rem;
  line-height: 1;
  text-align: center;
  color: #2c2418;
  background: #fffdf8;
  border: 1px solid #d8cdb6;
  border-radius: 7px;
  box-sizing: border-box;
}
.cl-direct-input:focus-visible { outline: 2px solid #8a6a26; outline-offset: 2px; }
.cl-direct-find {
  flex: 0 0 auto;
}

.cl-direct-results { flex: 1 1 280px; min-width: 260px; }

/* Two stacked galleries inside the right column (chopmark photos on top,
   seal variants below). The .cl-collection rule above gives a min-height
   of 160px which is fine for the chopmark strip; reset it on the seal
   block when it's empty/loading so we don't bloat the layout. */
.cl-direct-results .cl-collection { margin-top: 0.5rem; }
.cl-direct-results .cl-collection + .cl-collection { margin-top: 0.75rem; }

/* Seal panel here uses the same per-category sectioning as the drawing
   tool's seal mode, but cl-direct-tool doesn't carry the cl-seal class
   so the seal-mode override block: display rule doesn't apply — restamp it. */
.cl-direct-seal.cl-collection--filled {
  display: block;
  padding: 0.6rem 0.5rem;
  text-align: left;
}

@media (max-width: 560px) {
  .cl-direct-inputcol { width: 260px; }
}

/* Site-wide image modal sizing override for seal-lookup SVGs only.
   Hanziyuan SVGs declare tiny intrinsic dimensions (e.g. 65pt × 91pt), so
   the global modal's natural-size-capped scaling renders them postage-stamp
   small. Force a 500-square (capped to viewport on narrow screens) and a
   white plate that's only present in the modal — the in-page thumbnails
   keep the transparent cream-page look set above. !important is needed
   because the modal's setImageSize() writes inline width/height on load. */
.image-modal__img[src*="/data/seal-lookup/svg/"] {
  width: min(500px, calc(100vw - 48px)) !important;
  height: min(500px, calc(100vw - 48px)) !important;
  background: #fff;
  padding: 24px;
  box-sizing: border-box;
  object-fit: contain;        /* hanziyuan SVGs are typically non-square */
}

