/* Interaction layer (assets/ux.js). Loads after hand.css and reads its tokens,
   so light, dark and the section colours all carry through. */

.ux-offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }

/* ----- text size: a plain zoom, remembered on the device ----- */
html[data-size="1"] body { zoom: 1.12; }
html[data-size="2"] body { zoom: 1.26; }

/* ----- masthead buttons ----- */
.qbtn, .sizebtn {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border: 2px solid var(--ink);
  border-radius: 20px 16px 22px 14px / 14px 22px 16px 20px;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1 var(--text);
  cursor: pointer;
  transition: background .12s ease, transform .12s ease;
}
.qbtn:hover, .sizebtn:hover { background: var(--sunk); }
.qbtn:active, .sizebtn:active { transform: translateY(1px) scale(.98); }
.qbtn svg { flex: 0 0 auto; }
.qbtn-key, .front-search kbd {
  font: 400 12px/1 var(--mono);
  padding: 3px 6px 2px;
  border: 1.5px solid var(--ink-faint);
  border-radius: 6px;
  color: var(--ink-faint);
  background: var(--sunk);
}
.sizebtn { padding: 0 11px; }
.sizebtn-a { font: 400 21px/1 var(--display); letter-spacing: 0; }
.sizebtn-a small { font-size: 14px; margin-left: 1px; }

@media (max-width: 760px) {
  .qbtn-text, .qbtn-key { display: none; }
  .qbtn { padding: 0 11px; }
}

/* ----- quick search ----- */
.qp { position: fixed; inset: 0; z-index: 90; display: grid; justify-items: center; align-items: start; padding: 9vh 14px 0; }
.qp.is-hidden { display: none; }
.qp-scrim { position: absolute; inset: 0; background: rgba(32, 24, 14, .55); animation: qp-fade .16s ease both; }
.qp-box {
  position: relative;
  width: min(640px, 100%);
  max-height: 78vh; max-height: 78dvh;
  display: flex; flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 26px 22px 28px 24px / 24px 28px 22px 26px;
  box-shadow: var(--lift);
  overflow: hidden;
  animation: qp-pop .2s cubic-bezier(.22, 1, .36, 1) both;
}
.qp-bar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 2.5px dotted var(--rule-strong); color: var(--ink-soft); }
.qp-input {
  flex: 1 1 auto; min-width: 0;
  border: 0; outline: 0; background: transparent;
  font: 400 21px/1.2 var(--text);
  color: var(--ink);
  padding: 6px 2px;
}
.qp-input::placeholder { color: var(--ink-faint); }
.qp-x { border: 0; background: none; font: 400 30px/1 var(--text); color: var(--ink-soft); cursor: pointer; min-width: 40px; min-height: 40px; }
.qp-list { overflow-y: auto; padding: 6px 8px 8px; overscroll-behavior: contain; }
.qp-head { margin: 10px 8px 4px; font: 400 15px/1 var(--display); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); }
.qp-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px; min-height: 52px;
  border-radius: 16px 14px 18px 12px / 14px 18px 12px 16px;
  color: var(--ink); text-decoration: none;
  border: 2px solid transparent;
}
.qp-item:hover { background: var(--sunk); }
.qp-item.is-active { background: var(--sunk); border-color: var(--ink); }
.qp-kind {
  flex: 0 0 auto;
  font: 400 13px/1 var(--display); letter-spacing: .06em; text-transform: uppercase;
  padding: 5px 9px 4px; border-radius: 999px; color: #fff;
}
.qp-drug { background: var(--sec-drugs); }
.qp-cond { background: var(--sec-find); }
html[data-theme="dark"] .qp-kind, :root:not([data-theme="light"]) .qp-kind { color: #1a140d; }
.qp-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.qp-name { font: 400 19px/1.2 var(--text); overflow-wrap: anywhere; }
.qp-name mark { background: transparent; color: inherit; background-image: linear-gradient(transparent 62%, rgba(217, 147, 13, .55) 62%); border-radius: 2px; }
.qp-sub { font: 400 15px/1.3 var(--text); color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qp-star { color: var(--accent-marigold, #d9930d); font-size: 18px; }
.qp-empty { margin: 16px 12px; font: 400 18px/1.4 var(--text); color: var(--ink-soft); }
.qp-empty a { color: var(--sec); font-weight: 700; }
.qp-hint { margin: 0; padding: 8px 16px 10px; font: 400 14px/1.2 var(--mono); color: var(--ink-faint); border-top: 2px dotted var(--rule); }
html.qp-open { overflow: hidden; }

@keyframes qp-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes qp-pop { from { opacity: 0; transform: translateY(-10px) scale(.98); } to { opacity: 1; transform: none; } }

@media (max-width: 760px) {
  .qp { padding: 0; align-items: end; }
  .qp-box { width: 100%; max-height: 88vh; max-height: 88dvh; border-radius: 26px 24px 0 0 / 24px 26px 0 0; border-bottom-width: 0; animation-name: qp-sheet; }
  .qp-hint { display: none; }
  .qp-input { font-size: 18px; }
}
@keyframes qp-sheet { from { transform: translateY(100%); } to { transform: none; } }

/* ----- landing ----- */
.front-search {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  margin: 22px 0 0;
  min-width: 0; max-width: 100%; box-sizing: border-box;
  min-height: 54px; padding: 0 18px;
  border: 3px solid var(--ink);
  border-radius: 28px 24px 30px 26px / 26px 30px 24px 28px;
  background: var(--paper);
  color: var(--ink-soft);
  font: 400 19px/1 var(--text);
  text-align: left;
  cursor: text;
  box-shadow: 0 3px 0 rgba(43, 34, 23, .16);
  transition: transform .12s ease, box-shadow .12s ease;
}
.front-search span { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 760px) { .front-search { font-size: 17px; } }
.front-search:hover { transform: translateY(-1px); box-shadow: 0 5px 0 rgba(43, 34, 23, .2); }
.front-search svg { color: var(--ink); }
.front-recent { margin: 20px 0 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-start; width: 100%; }
.front-recent-h { flex: 0 0 100%; margin: 0 0 2px; font: 400 15px/1 var(--display); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint); text-align: left; }
.chip-link {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 42px; padding: 4px 14px 4px 6px;
  border: 2px solid var(--ink); border-radius: 18px 14px 20px 16px / 16px 20px 14px 18px;
  background: var(--paper); color: var(--ink); text-decoration: none;
  font: 400 17px/1.1 var(--text);
}
.chip-link:hover { background: var(--sunk); }
.front-actions { margin-top: 18px; }

/* ----- card: actions, jump bar, dose copy ----- */
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 16px 0 0; }
.act {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 42px; padding: 0 15px;
  border: 2px solid var(--ink);
  border-radius: 16px 20px 14px 22px / 20px 14px 22px 16px;
  background: var(--paper); color: var(--ink);
  font: 400 17px/1 var(--text); cursor: pointer;
  transition: background .12s ease, transform .12s ease;
}
.act:hover { background: var(--sunk); }
.act:active { transform: translateY(1px) scale(.98); }
.act[aria-pressed="true"] { background: var(--sec); color: #fff; border-color: var(--sec); }
html[data-theme="dark"] .act[aria-pressed="true"], :root:not([data-theme="light"]) .act[aria-pressed="true"] { color: #1a140d; }
.act-ic { font-size: 18px; line-height: 1; }

.jumpbar {
  position: sticky; top: var(--stick, 0px); z-index: 8;
  display: flex; gap: 8px;
  margin: 18px calc(var(--gutter, 18px) * -1) 0;
  padding: 10px var(--gutter, 18px);
  overflow-x: auto; scrollbar-width: none;
  background: var(--paper);
  border-bottom: 2.5px dotted var(--rule-strong);
  scroll-behavior: smooth;
}
.jumpbar::-webkit-scrollbar { display: none; }
.jumpchip {
  flex: 0 0 auto;
  display: inline-flex; align-items: center;
  min-height: 38px; padding: 0 14px;
  border: 2px solid var(--ink); border-radius: 999px;
  color: var(--ink); text-decoration: none;
  font: 400 16px/1 var(--text);
  white-space: nowrap;
  transition: background .12s ease, color .12s ease;
}
.jumpchip:hover { background: var(--sunk); }
.jumpchip.is-current { background: var(--ink); color: var(--paper); }
/* a box's pill head hangs 24px above its box, so the first box needs room
   below the bar or the bar covers half of the head */
.jumpbar + .cards-top { margin-top: 46px; }
.jumpbar + .cards { margin-top: 46px; }
.cbox, .cbox-dose { scroll-margin-top: calc(var(--stick, 0px) + 100px); }
.cbox:focus { outline: none; }

.dose { position: relative; }
.dose-copy {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 8px; min-height: 36px; padding: 0 12px;
  border: 2px solid var(--ink); border-radius: 14px 18px 12px 16px / 16px 12px 18px 14px;
  background: var(--paper); color: var(--ink);
  font: 400 15px/1 var(--text); cursor: pointer;
}
.dose-copy:hover { background: var(--sunk); }

/* ----- weight bar ----- */
.scale-in { transition: padding .18s ease; }
.scale.is-condensed .scale-track,
.scale.is-condensed .scale-hint,
.scale.is-condensed .scale-estimate { display: none; }
.scale.is-condensed .scale-in { padding-top: 6px; padding-bottom: 6px; cursor: pointer; }
.scale.is-condensed .scale-head { margin: 0; }

/* ----- back to top, toast ----- */
.fab {
  position: fixed; right: 16px; bottom: 18px; z-index: 40;
  width: 52px; height: 52px; display: grid; place-items: center;
  border: 3px solid var(--ink); border-radius: 50% 46% 52% 48% / 48% 52% 46% 50%;
  background: var(--paper); color: var(--ink);
  box-shadow: 0 3px 0 rgba(43, 34, 23, .22);
  cursor: pointer;
  transition: transform .15s ease, opacity .15s ease;
}
.fab:hover { background: var(--sunk); }
.fab:active { transform: scale(.94); }
.fab.is-hidden { display: none; }
body:has(.statusbar.is-up) .fab { bottom: 86px; }

.ux-toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 100;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  border: 2.5px solid var(--ink); border-radius: 22px 18px 24px 20px / 20px 24px 18px 22px;
  background: var(--ink); color: var(--paper);
  font: 400 18px/1.2 var(--text);
  transition: opacity .16s ease, transform .2s cubic-bezier(.22, 1, .36, 1);
}
.ux-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ----- list rows: a little feedback on touch and hover ----- */
.result, .content-row, .jump, .sign, .beast { transition: transform .12s ease, background .12s ease; }
.result:active, .content-row:active, .jump:active, .beast:active { transform: scale(.985); }
@media (hover: hover) { .result:hover, .content-row:hover, .jump:hover { transform: translateY(-1px); } }

/* ----- adaptive: bigger targets on touch, calmer on request ----- */
@media (pointer: coarse) {
  .act, .qbtn, .sizebtn, .jumpchip, .dose-copy { min-height: 46px; }
  .qp-item { min-height: 58px; }
}
@media (prefers-reduced-motion: reduce) {
  .qp-scrim, .qp-box { animation: none; }
  .jumpbar { scroll-behavior: auto; }
  * { transition-duration: 0s !important; }
}
@media (min-width: 1120px) {
  .jumpbar { margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
}
@media print {
  .qbtn, .sizebtn, .jumpbar, .hero-actions, .dose-copy, .fab, .ux-toast, .qp, .front-search { display: none !important; }
  html[data-size] body { zoom: 1; }
}

/* ------------------------------------------------- phone grids (find page)
   On a phone the sign index and the ranked conditions set as grids instead of
   one long column: signs as compact tiles, three to five to a row, and the
   ranked conditions two to a row. Selection is carried by fill and a tick, not
   by colour alone. Tablets and desktops keep their own layouts. */
@media (max-width: 760px) {
  .signlist {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .sign {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    align-content: center;
    gap: 2px;
    min-height: 58px;
    padding: 7px 5px;
    text-align: center;
    font: 700 14px/1.15 var(--text);
    overflow-wrap: anywhere;
    hyphens: auto;
  }
  .sign-box { display: none; }
  .sign-n { font-size: 12px; line-height: 14px; }
  .sign[aria-pressed="true"] .sign-name::before { content: "\2713\00a0"; }

  .sec-find .results {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .sec-find .result { padding: 10px 11px; }
  .sec-find .result-name { font-size: 16px; line-height: 1.08; overflow-wrap: anywhere; }
  .sec-find .result-species { font-size: 14px; line-height: 1.3; }
  .sec-find .result .cluster, .sec-find .result .hitlist { font-size: 13px; }
  .sec-find .result-cite {
    font-size: 11px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}
@media (min-width: 440px) and (max-width: 760px) {
  .signlist { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 620px) and (max-width: 760px) {
  .signlist { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (max-width: 339px) {
  .sec-find .results { grid-template-columns: minmax(0, 1fr); }
}

/* Drug list on a phone: two cards to a row. Each card reads top to bottom as
   the drug name, its meat and milk withdrawal labels, what it is for, then a
   compact dose box (label above the figure) and the source. */
@media (max-width: 760px) {
  .sec-drugs .results { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .sec-drugs .drugrow { padding: 10px 11px; }
  .sec-drugs .drugrow-head { flex-direction: column; align-items: stretch; gap: 6px; }
  /* Flatten the name block so the three lines can be ordered. */
  .sec-drugs .drugrow-id { display: contents; }
  .sec-drugs .drugrow-head .result-name { order: 1; font-size: 16px; line-height: 1.08; overflow-wrap: anywhere; }
  /* Meat and milk labels share one line; the clock icon is dropped and the
     label set in the narrower hand font so both fit a 150px card. */
  .sec-drugs .drugrow-flags { order: 2; display: flex; flex-direction: row; flex-wrap: nowrap; align-items: stretch; gap: 4px; }
  .sec-drugs .wd {
    flex: 1 1 auto; min-width: 0; padding: 4px 2px;
    font: 400 10.5px/1 var(--text); letter-spacing: 0; text-transform: none;
  }
  .sec-drugs .wd svg { display: none; }
  .sec-drugs .drugrow-class {
    order: 3; margin-top: 0; font-size: 13px; line-height: 1.3;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  }
  .sec-drugs .dosegrid { grid-template-columns: minmax(0, 1fr); margin-top: 8px; }
  .sec-drugs .dosegrid-key { border-right: 0; border-bottom: 1px solid var(--ink); padding: 4px 6px; font-size: 14px; }
  .sec-drugs .dosegrid-val { padding: 7px 8px; }
  .sec-drugs .dosegrid-rate { font-size: 14px; line-height: 17px; overflow-wrap: anywhere; }
  .sec-drugs .dosegrid-sp { font-size: 10px; }
  .sec-drugs .dosegrid-calc { margin-top: 6px; }
  .sec-drugs .dosegrid-for { font-size: 12px; line-height: 15px; }
  .sec-drugs .drugrow .result-cite {
    margin-top: 7px; font-size: 10.5px; line-height: 1.3; text-align: left;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
}
@media (max-width: 339px) {
  .sec-drugs .results { grid-template-columns: minmax(0, 1fr); }
}
