/* ==========================================================================
   WebManga Taxonomy Index
   --------------------------------------------------------------------------
   Every value is a token on .wmti, and every token falls back through the host
   theme first:

       --wmti-surface: var(--wt-surface-2, #171d2e)

   On a site that already has a token layer the index simply adopts it - dark
   mode, accent colour and radii included - with nothing to configure. On any
   other site the literal after the comma applies. That is why there are no
   hardcoded colours below this block: overriding one token restyles every
   component that uses it.

   Scoped entirely under .wmti. The plugin never styles a bare element.
   ========================================================================== */

.wmti {
  --wmti-surface:     var(--wt-surface-2, #171d2e);
  --wmti-surface-alt: var(--wt-surface-3, #1f2739);
  --wmti-line:        var(--wt-line, #262f45);
  --wmti-ink:         var(--wt-ink, #e7eaf3);
  --wmti-ink-muted:   var(--wt-ink-muted, #a4adc2);
  --wmti-ink-faint:   var(--wt-ink-faint, #8b94aa);
  --wmti-accent:      var(--wt-accent, #d946ef);
  --wmti-accent-ink:  var(--wt-accent-ink, #0a0d16);
  --wmti-accent-soft: rgba(217, 70, 239, 0.12);
  --wmti-accent-line: rgba(217, 70, 239, 0.5);
  --wmti-radius:      var(--wt-radius, 10px);
  --wmti-radius-pill: var(--wt-radius-pill, 999px);
  --wmti-dur:         var(--wt-dur, 160ms);
  --wmti-ease:        var(--wt-ease, cubic-bezier(0.2, 0, 0.2, 1));

  --wmti-cols: 5;

  color: var(--wmti-ink);
}

.wmti,
.wmti *,
.wmti *::before,
.wmti *::after { box-sizing: border-box; }

/* Standalone light mode. Only the FALLBACK literals change - a host theme that
   defines --wt-* still wins, because those are resolved at use. */
@media (prefers-color-scheme: light) {
  .wmti {
    --wmti-surface:     var(--wt-surface-2, #eceef3);
    --wmti-surface-alt: var(--wt-surface-3, #e3e6ee);
    --wmti-line:        var(--wt-line, #d9dde7);
    --wmti-ink:         var(--wt-ink, #1b2030);
    --wmti-ink-muted:   var(--wt-ink-muted, #4a5268);
    --wmti-ink-faint:   var(--wt-ink-faint, #6b7488);
    --wmti-accent:      var(--wt-accent, #a21caf);
    --wmti-accent-ink:  var(--wt-accent-ink, #ffffff);
    --wmti-accent-soft: rgba(162, 28, 175, 0.10);
    --wmti-accent-line: rgba(162, 28, 175, 0.45);
  }
}

.wmti--cols-1 { --wmti-cols: 1; }
.wmti--cols-2 { --wmti-cols: 2; }
.wmti--cols-3 { --wmti-cols: 3; }
.wmti--cols-4 { --wmti-cols: 4; }
.wmti--cols-5 { --wmti-cols: 5; }
.wmti--cols-6 { --wmti-cols: 6; }

/* Visually hidden, still announced. Used for the search label and the
   accessible labels. */
.wmti__sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Title
   -------------------------------------------------------------------------- */

.wmti__title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 18px;
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 700;
  line-height: 1.2;
  color: var(--wmti-ink);
}

/* The badge is a WRAPPER around the icon rather than styling applied to the
   <svg> itself. An <svg> is a replaced element and browsers have disagreed
   about how padding interacts with its viewBox, so the tinted box is a plain
   span and the glyph is sized inside it - which behaves the same everywhere. */
.wmti__badge {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: clamp(34px, 4vw, 42px);
  height: clamp(34px, 4vw, 42px);
  border: 1px solid var(--wmti-accent-line);
  border-radius: var(--wmti-radius);
  background: var(--wmti-accent-soft);
  color: var(--wmti-accent);
}

.wmti__badge .wmti-icon {
  width: 55%;
  height: 55%;
}

.wmti-icon {
  display: block;
  width: 100%;
  height: 100%;
}

/* --------------------------------------------------------------------------
   Sort tabs
   -------------------------------------------------------------------------- */

.wmti__sort {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--wmti-line);
}

.wmti__sort-label {
  font-size: 14px;
  color: var(--wmti-ink-faint);
}

/* Underline tabs rather than pills: these are a different VIEW of the page,
   while the letter row below filters the current one. Giving both the pill
   shape would read as two rows of the same control. */
.wmti__sort-link {
  padding: 10px 2px;
  border-bottom: 3px solid transparent;
  color: var(--wmti-ink-muted);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  transition:
    color var(--wmti-dur) var(--wmti-ease),
    border-color var(--wmti-dur) var(--wmti-ease);
}

.wmti__sort-link.is-active {
  border-bottom-color: var(--wmti-accent);
  color: var(--wmti-accent);
}

@media (hover: hover) {
  .wmti__sort-link:hover {
    color: var(--wmti-ink);
    border-bottom-color: var(--wmti-accent-line);
  }

  .wmti__sort-link.is-active:hover {
    border-bottom-color: var(--wmti-accent);
    color: var(--wmti-accent);
  }
}

/* --------------------------------------------------------------------------
   Letter filter
   -------------------------------------------------------------------------- */

.wmti__letters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}

.wmti__letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--wmti-radius-pill);
  background: transparent;
  color: var(--wmti-ink-muted);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition:
    color var(--wmti-dur) var(--wmti-ease),
    background-color var(--wmti-dur) var(--wmti-ease),
    border-color var(--wmti-dur) var(--wmti-ease);
}

.wmti__letter.is-active {
  background: var(--wmti-surface-alt);
  border-color: var(--wmti-line);
  color: var(--wmti-ink);
}

@media (hover: hover) {
  .wmti__letter:hover {
    background: var(--wmti-accent-soft);
    border-color: var(--wmti-accent-line);
    color: var(--wmti-accent);
  }
}

/* --------------------------------------------------------------------------
   Search
   -------------------------------------------------------------------------- */

.wmti__search {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 26px;
  gap: 8px;
}

.wmti__input {
  min-width: 0;
  width: 100%;
  min-height: 52px;
  padding: 0 18px;
  border: 1px solid var(--wmti-line);
  border-radius: var(--wmti-radius-pill);
  background: var(--wmti-surface);
  color: var(--wmti-ink);
  font: inherit;
  font-size: 15px;
  transition: border-color var(--wmti-dur) var(--wmti-ease);
}

.wmti__input::placeholder { color: var(--wmti-ink-faint); }

.wmti__input:focus {
  border-color: var(--wmti-accent-line);
  outline: none;
}

/* --------------------------------------------------------------------------
   Results
   --------------------------------------------------------------------------
   CSS columns rather than grid, on purpose. A grid would give every group its
   own row and leave ragged gaps under the short ones; columns let a long group
   flow into the next column the way a printed index does, which is what the
   reference layout does too.

   The cost is that column layout is display-driven: changing pages or filters reflows the columns. Only the
   current page is present in the document.
   -------------------------------------------------------------------------- */

.wmti__results {
  /* AS MANY COLUMNS AS FIT, UP TO THE CONFIGURED MAXIMUM.
     With BOTH column-width and column-count set, the browser uses whichever is
     smaller: the number of 170px columns that fit, or the configured count. So
     the setting is a ceiling and the viewport decides the rest - no breakpoint
     list to keep in sync with it.

     THIS REPLACED A LADDER OF FIXED CAPS, which was wrong. Capping at 4 below
     1400px meant a 1280px laptop - most laptops - could never reach 5 or 6
     however the plugin was configured, because min(6, 4) is 4. The bug was
     invisible on a wide monitor and total on a normal one.

     170px is the floor for a readable chip: about 146px of content after
     padding, enough for a genre or artist name plus its count before
     .wmti__name starts eliding. */
  column-width: 170px;
  column-count: var(--wmti-cols);
  column-gap: 16px;
}

/* Phones keep TWO columns even where 170px each would not fit - one column
   turns a 40-term index into a very long scroll. column-width goes back to
   auto so the count alone decides; leaving it set would let the browser drop
   to a single column on a narrow handset. Gap and padding tighten to buy the
   names a few more pixels. */
@media (max-width: 520px) {
  .wmti__results {
    column-width: auto;
    column-count: min(2, var(--wmti-cols));
    column-gap: 10px;
  }

  .wmti__link {
    padding: 8px 10px;
    gap: 6px;
  }

  .wmti__item { margin-bottom: 5px; }
}

.wmti__group {
  break-inside: auto;
  margin: 0 0 4px;
}

.wmti__group[hidden] { display: none; }

/* Never leave a letter heading stranded at the foot of a column. */
.wmti__group-head {
  break-after: avoid;
  break-inside: avoid;
  margin: 14px 0 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--wmti-line);
  color: var(--wmti-ink-faint);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
}

.wmti__list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.wmti__item {
  break-inside: avoid;
  margin: 0 0 6px;
  list-style: none;
}

.wmti__item[hidden] { display: none; }

.wmti__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: var(--wmti-radius);
  background: var(--wmti-surface);
  color: var(--wmti-ink-muted);
  font-size: 14px;
  line-height: 1.3;
  text-decoration: none;
  transition:
    color var(--wmti-dur) var(--wmti-ease),
    background-color var(--wmti-dur) var(--wmti-ease),
    border-color var(--wmti-dur) var(--wmti-ease);
}

.wmti__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wmti__count {
  flex: 0 0 auto;
  color: var(--wmti-ink-faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

@media (hover: hover) {
  .wmti__link:hover {
    background: var(--wmti-accent-soft);
    border-color: var(--wmti-accent-line);
    color: var(--wmti-ink);
  }

  .wmti__link:hover .wmti__count { color: var(--wmti-accent); }
}

/* The host theme may define no focus ring at all, so one is declared here
   rather than assumed. :focus-visible keeps it off mouse clicks. */
.wmti__link:focus-visible,
.wmti__letter:focus-visible,
.wmti__sort-link:focus-visible,
.wmti__input:focus-visible {
  outline: 2px solid var(--wt-focus, var(--wmti-accent));
  outline-offset: 2px;
}

.wmti__submit:focus-visible,
.wmti__page:focus-visible,
.wmti__reset:focus-visible {
  outline: 2px solid var(--wt-focus, var(--wmti-accent));
  outline-offset: 2px;
}

.wmti__submit,
.wmti__page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border: 1px solid var(--wmti-line);
  border-radius: var(--wmti-radius);
  background: var(--wmti-surface);
  color: var(--wmti-ink);
  font: inherit;
  text-decoration: none;
}

.wmti__submit { cursor: pointer; flex-shrink: 0; }
.wmti__page.is-active { border-color: var(--wmti-accent); font-weight: 700; }
.wmti__pagination { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 24px 0; }
.wmti__summary { color: var(--wmti-ink-muted); font-size: 14px; }
.wmti__reset { color: var(--wmti-accent); }

@media (max-width: 360px) {
  .wmti__results { column-count: 1; }
  .wmti__search { flex-wrap: wrap; }
}

/* Keep compact spacing after the base chip rules in the cascade. */
@media (max-width: 520px) {
  .wmti__link { padding: 8px 10px; gap: 6px; }
  .wmti__item { margin-bottom: 5px; }
}

/* --------------------------------------------------------------------------
   Empty state and editor notice
   -------------------------------------------------------------------------- */

.wmti__empty {
  margin: 24px 0;
  padding: 20px;
  border: 1px dashed var(--wmti-line);
  border-radius: var(--wmti-radius);
  color: var(--wmti-ink-faint);
  text-align: center;
}

.wmti__empty[hidden] { display: none; }

.wmti-notice {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--wmti-accent, #d946ef);
  background: rgba(127, 127, 127, 0.08);
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  .wmti *,
  .wmti *::before,
  .wmti *::after {
    transition-duration: 0.01ms !important;
  }
}
