:root {
  --paper: #EDF1EE;
  --paper-2: #E2E8E3;
  --ink: #17261F;
  --ink-soft: #4A5A52;
  --rule: #C9D3CC;
  --intent-1: #0F6F7C;   /* kingfisher */
  --intent-2: #B7862A;   /* specimen-tag ochre */
  --intent-3: #7A4B7E;   /* plum */
  --intent-4: #3E7A3A;
  --focus: #0F6F7C;
  --radius-img: 6px;
  --font: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121A16; --paper-2: #1A2520; --ink: #E4ECE6; --ink-soft: #A3B3AA; --rule: #2C3A33;
    --intent-1: #4FB3BF; --intent-2: #D9AE5B; --intent-3: #B98BBD; --intent-4: #7DBA77; --focus: #4FB3BF;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.5;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* header ------------------------------------------------------------------ */
.top {
  display: flex; align-items: baseline; gap: 1.25rem; flex-wrap: wrap;
  padding: 1.25rem clamp(1rem, 4vw, 3rem) 0;
}
.brand { font-weight: 700; font-size: 1.125rem; text-decoration: none; letter-spacing: -0.01em; }
.facts { margin: 0; color: var(--ink-soft); font-size: 0.875rem; flex: 1; }
.api-link { font-size: 0.875rem; color: var(--ink-soft); }

main { padding: 0 clamp(1rem, 4vw, 3rem) 3rem; max-width: 1400px; margin: 0 auto; }

/* search: the hero is the question itself ---------------------------------- */
.search { display: flex; gap: 0.5rem; margin: clamp(2rem, 7vh, 4.5rem) 0 1rem; }
.search input {
  flex: 1; min-width: 0; font: inherit; font-size: clamp(1.375rem, 3.2vw, 2.25rem); font-weight: 500;
  letter-spacing: -0.015em; color: var(--ink); background: transparent;
  border: 0; border-bottom: 2px solid var(--ink); padding: 0.35rem 0; border-radius: 0;
}
.search input::placeholder { color: var(--ink-soft); opacity: 0.55; }
.search input:focus { outline: none; border-bottom-color: var(--focus); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search button {
  font: inherit; font-weight: 600; padding: 0 1.4rem; border: 0; border-radius: 999px;
  background: var(--ink); color: var(--paper); cursor: pointer; align-self: center; height: 2.75rem;
}
.search button:hover { background: var(--intent-1); }

.examples { display: flex; flex-wrap: wrap; gap: 0.4rem 0.5rem; align-items: center; font-size: 0.875rem; }
.examples span { color: var(--ink-soft); margin-right: 0.25rem; }
.examples button {
  font: inherit; color: var(--ink); background: var(--paper-2); border: 1px solid var(--rule);
  border-radius: 999px; padding: 0.2rem 0.75rem; cursor: pointer;
}
.examples button:hover { border-color: var(--ink-soft); }

/* how the query was read: the one memorable element --------------------------- */
.reading {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.75rem 2rem;
  margin: 2rem 0 1rem; padding: 0.9rem 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.plan { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.plan .kind { font-weight: 600; margin-right: 0.25rem; }
.intent {
  display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.2rem 0.7rem 0.2rem 0.55rem;
  border-radius: 4px; background: var(--paper-2); font-size: 0.9375rem;
  border-left: 4px solid var(--c, var(--intent-1));
}
.intent small { color: var(--ink-soft); font-size: 0.8125rem; }
.plan .source { color: var(--ink-soft); font-size: 0.8125rem; }
.timing { color: var(--ink-soft); font-size: 0.875rem; font-variant-numeric: tabular-nums; align-self: center; }
.timing strong { color: var(--ink); font-weight: 600; }

.status { color: var(--ink-soft); min-height: 1.5rem; margin: 0.5rem 0; }

/* results ---------------------------------------------------------------- */
.grid {
  list-style: none; padding: 0; margin: 0.5rem 0 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 1.75rem 1.25rem;
}
.hit { position: relative; }
/* v1.1: "Loài gần nhất trong kho" heading, and the keyword photos folded away when the collection lacks the thing */
.section-title { grid-column: 1 / -1; font-weight: 600; color: var(--ink); }
.section-title.keyword { font-weight: 400; color: var(--ink-soft); }
.section-title summary { cursor: pointer; padding: 0.25rem 0; }
.hit button { all: unset; display: block; width: 100%; cursor: zoom-in; }
.hit button:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: var(--radius-img); }
.frame {
  aspect-ratio: 4 / 3; background: var(--paper-2); border-radius: var(--radius-img); overflow: hidden;
  border-bottom: 4px solid var(--c, transparent);
}
.frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame.broken { display: grid; place-items: center; color: var(--ink-soft); font-size: 0.8125rem; padding: 1rem; text-align: center; }
.rank {
  position: absolute; top: 0.5rem; left: 0.5rem; min-width: 1.6rem; height: 1.6rem; padding: 0 0.35rem;
  display: grid; place-items: center; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  background: var(--paper); color: var(--ink); font-variant-numeric: tabular-nums;
}
.label { margin-top: 0.55rem; }
.label .name { font-weight: 600; line-height: 1.3; }
.label .sci { font-style: italic; color: var(--ink-soft); font-size: 0.875rem; }

.skeleton .frame { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* detail dialog ----------------------------------------------------------- */
dialog {
  width: min(1000px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; border: 0;
  border-radius: 10px; background: var(--paper); color: var(--ink);
  display: none; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
}
dialog[open] { display: grid; }
dialog::backdrop { background: rgba(10, 20, 15, 0.6); }
.d-close { position: absolute; top: 0.5rem; right: 0.5rem; }
.d-close button { font: inherit; font-size: 0.875rem; border: 0; background: var(--paper-2); color: var(--ink); border-radius: 999px; padding: 0.3rem 0.8rem; cursor: pointer; }
.d-figure { margin: 0; background: #000; display: grid; place-items: center; min-height: 300px; }
.d-figure img { max-width: 100%; max-height: 80vh; object-fit: contain; }
.d-body { padding: 2.5rem 1.5rem 1.5rem; overflow-y: auto; max-height: calc(100vh - 2rem); }
.d-body h2 { margin: 0; font-size: 1.5rem; line-height: 1.2; letter-spacing: -0.01em; }
.d-sci { font-style: italic; color: var(--ink-soft); margin: 0.25rem 0 0.75rem; }
.d-tax { font-size: 0.8125rem; color: var(--ink-soft); margin: 0 0 1rem; }
.d-desc { margin: 0 0 1rem; max-width: 60ch; }
.d-links { display: flex; gap: 1rem; font-size: 0.9375rem; }
.d-more { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 0.4rem; margin-top: 1.25rem; }
.d-more button { all: unset; cursor: pointer; aspect-ratio: 1; border-radius: 4px; overflow: hidden; background: var(--paper-2); }
.d-more img { width: 100%; height: 100%; object-fit: cover; display: block; }
.d-more button:focus-visible { outline: 2px solid var(--focus); }

.foot { padding: 1rem clamp(1rem, 4vw, 3rem) 2.5rem; color: var(--ink-soft); font-size: 0.875rem; max-width: 1400px; margin: 0 auto; }
.foot summary { cursor: pointer; }
.foot pre { background: var(--paper-2); padding: 0.75rem 1rem; border-radius: 6px; overflow-x: auto; color: var(--ink); }

@media (max-width: 720px) {
  .facts { order: 3; flex-basis: 100%; }
  dialog[open] { grid-template-columns: 1fr; overflow-y: auto; }
  .d-body { max-height: none; }
  .search button { padding: 0 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton .frame { animation: none; }
}

/* the API could not answer: the photos below are only the nearest matches */
#status.warn { color: #8a4b00; background: #fff4e0; border: 1px solid #f0c27a; border-radius: 8px; padding: .6rem .8rem; font-weight: 600; }
@media (prefers-color-scheme: dark) { #status.warn { color: #ffd08a; background: #3a2a10; border-color: #7a5520; } }
