/* TheoryChamp: the Build Library (library.html) and its Share dialog on
   Team Lab (library-share.js). Loaded by both pages, after theme-phase2.css.

   Tokens only (style.css :root, overridden by theme-phase1.css); the one new
   colour is the favorited heart, #b8234a, which clears 6.2:1 on white and
   5.8:1 on --t-surface. Breakpoints reuse the site's (860 / 640 / 480). */

.lib { max-width: 1100px; margin: 0 auto; padding: 18px 20px 40px; display: flex;
  flex-direction: column; gap: 26px; }
.lib-head-inner { max-width: 1100px; display: flex; align-items: flex-end;
  justify-content: space-between; flex-wrap: wrap; gap: 12px 24px; }
.lib-head-copy { flex: 1 1 420px; min-width: 0; }
button.primary.lib-share-team { width: auto; flex: none; min-height: 44px; padding: 10px 20px; }
.lib-head-inner a { color: var(--accent-dark); }

.lib-sec-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px;
  margin: 0 0 10px; }
.lib-h2 { margin: 0; font-size: 1.15rem; font-weight: 600; letter-spacing: -.015em;
  color: var(--ink); }
.lib-sec-sub { font-size: .85rem; color: var(--muted); }

/* ---- cards ---------------------------------------------------------------- */
.lib-cards { display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }
.lib-cards-top { grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr)); }
.lib-cards[aria-busy="true"] { opacity: .55; transition: opacity .15s var(--t-ease); }

.lib-card {
  display: flex; flex-direction: column; gap: 8px; min-width: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 13px 10px; box-shadow: var(--shadow);
  transition: border-color .2s var(--t-ease), box-shadow .25s var(--t-ease);
}
.lib-card:hover { border-color: var(--line-strong); box-shadow: var(--t-shadow-2); }
.lib-card-top { border-top: 3px solid var(--accent); }
.lib-card-link { display: flex; flex-direction: column; gap: 6px; color: var(--ink);
  text-decoration: none; min-width: 0; }
.lib-card-link:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 4px;
  border-radius: 6px; }
/* Six columns that shrink with the card, so a team is always ONE row of six
   (a fixed 40px sprite wrapped the sixth onto a second row in the 4-up grid,
   giving cards ragged heights). Capped so a wide card doesn't blow them up. */
.lib-card-mons { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); align-items: end;
  gap: 2px; max-width: 300px; }
.lib-sprite { display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: contain; }
.lib-mega { position: relative; display: block; }
.lib-mega-badge {
  position: absolute; left: 50%; bottom: -3px; transform: translateX(-50%);
  font-size: .58rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: #fff; background: var(--accent-dark); border-radius: 999px; padding: 0 5px;
  line-height: 1.5; white-space: nowrap;
}
.lib-card-title { font-size: 1rem; font-weight: 600; letter-spacing: -.012em; line-height: 1.3;
  overflow-wrap: anywhere; }
.lib-card-mega { font-size: .8rem; color: var(--muted); margin-top: -3px; }
.lib-card-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.lib-tag {
  font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--t-surface-2); color: var(--t-ink-2); white-space: nowrap;
}
.lib-card-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px;
  margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line); }
.lib-card-by { font-size: .8rem; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.lib-card-by a { color: var(--accent-dark); text-decoration: none; font-weight: 600; }
.lib-card-by a:hover { text-decoration: underline; }
.lib-staff, .lib-reg, .lib-hidden-badge {
  font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.lib-staff { color: #6b4e12; background: #fff6e6; border: 1px solid #f0d9a8; }
.lib-reg { color: var(--t-ink-2); background: var(--t-surface-2); }
.lib-hidden-badge { color: #7d2932; background: #fdecef; }

/* The heart. Pressed = favorited. On someone's own team it explains itself
   on press instead of being a dead control (aria-disabled, not disabled). */
.lib-fav {
  margin-left: auto; display: inline-flex; align-items: center; gap: 5px;
  min-height: 30px; padding: 4px 11px; border-radius: 999px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line-strong); color: var(--muted);
  font: inherit; font-size: .82rem; font-weight: 600;
  transition: color .15s var(--t-ease), border-color .15s var(--t-ease), background .15s var(--t-ease);
}
.lib-fav svg { flex: none; }
.lib-fav:hover { border-color: #b8234a; color: #b8234a; }
.lib-fav.on { color: #b8234a; border-color: #e7b3c1; background: #fdf3f5; }
.lib-fav[aria-disabled="true"] { cursor: default; color: var(--t-faint); border-color: var(--line); }
.lib-fav[aria-disabled="true"]:hover { color: var(--t-faint); border-color: var(--line); }
.lib-fav:active { transform: scale(.96); transition: transform .1s ease-out; }
.lib-fav-big { margin-left: 0; min-height: 40px; padding: 7px 16px; font-size: .92rem; }

/* ---- sorts + filters ------------------------------------------------------ */
.lib-sorts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lib-sorts-mine { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.lib-sorts-mine[hidden] { display: none; }
.lib-sort, .lib-chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  min-height: 32px; padding: 6px 14px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line-strong); color: var(--t-ink-2);
  font: inherit; font-size: .85rem; font-weight: 600;
  transition: background .15s var(--t-ease), border-color .15s var(--t-ease), color .15s var(--t-ease);
}
.lib-sort:hover, .lib-chip:hover { border-color: var(--accent); color: var(--accent-dark); }
.lib-sort[aria-pressed="true"], .lib-chip[aria-pressed="true"] {
  background: var(--accent-dark); border-color: var(--accent-dark); color: #fff;
}
.lib-sort:active, .lib-chip:active { transform: scale(.97); transition: transform .1s ease-out; }
.lib-sort-note { margin: 8px 0 12px; font-size: .82rem; color: var(--muted); }
.lib-chip { min-height: 28px; padding: 4px 11px; font-size: .8rem; }
.lib-chip-n { font-size: .7rem; font-weight: 700; color: var(--muted); }
.lib-chip[aria-pressed="true"] .lib-chip-n { color: #fff; }

.lib-filters {
  display: flex; flex-direction: column; gap: 9px; margin-bottom: 14px;
  background: var(--t-surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 13px;
}
.lib-frow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.lib-frow[hidden] { display: none; }
.lib-flabel {
  display: inline-block; min-width: 76px; font-size: .7rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.lib-frow-pick { gap: 10px 18px; align-items: flex-end; }
.lib-pick { display: flex; flex-direction: column; gap: 4px; }
.lib-pick-box { position: relative; }
.lib-pick input, .lib-pick select {
  font: inherit; font-size: .9rem; color: var(--ink); background: var(--card);
  border: 1px solid var(--line-strong); border-radius: 9px; padding: 7px 10px;
  min-height: 36px; width: 240px; max-width: 100%;
}
.lib-pick input:focus, .lib-pick select:focus { outline: none; border-color: var(--ink); }
.lib-pick-list { min-width: 360px; }
.lib-pick-list .pick-item img { width: 40px; height: 40px; }
.lib-pick-types { display: flex; gap: 3px; flex: none; }
.lib-tag-more { background: var(--card); border: 1px solid var(--line-strong); }
.lib-older { display: inline-flex; align-items: center; gap: 7px; font-size: .85rem;
  color: var(--t-ink-2); min-height: 36px; cursor: pointer; }
.lib-chosen { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; }
.lib-chosen[hidden] { display: none; }
.lib-mon-chip { padding: 2px 6px 2px 2px; font-size: .85rem; }
.lib-mon-chip .chip-mini { width: 32px; height: 32px; }
.lib-mon-chip button { min-width: 24px; min-height: 24px; }
.lib-clear, .lib-linkbtn {
  background: none; border: 0; padding: 4px 2px; min-height: 28px; cursor: pointer;
  font: inherit; font-size: .85rem; font-weight: 600; color: var(--accent-dark);
  text-decoration: underline; text-underline-offset: 2px;
}
.lib-empty { text-align: center; color: var(--muted); padding: 26px 12px; font-size: .95rem; }
.lib-empty p { margin: 0 0 12px; }
.lib-empty .ghost { width: auto; padding: 9px 18px; }
#lib-pager { margin-top: 14px; }
#lib-pager .pager-btns .pager-count { padding: 0 8px; }

/* ---- the "make your own" call ---------------------------------------------- */
.lib-cta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding: 18px 20px; }
.lib-cta h2 { flex: 1 0 100%; }
.lib-cta p { flex: 1 1 380px; margin: 0; color: var(--t-ink-2); font-size: .95rem; line-height: 1.5; }
.lib-cta-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px;
  padding: 10px 20px; border-radius: 9px; background: var(--cta); color: #fff;
  font-weight: 600; font-size: .92rem; text-decoration: none; white-space: nowrap;
  transition: background .18s var(--t-ease);
}
.lib-cta-btn:hover { background: var(--cta-hover); }
.lib-cta-btn:active { transform: scale(.985); }

/* ---- one team ---------------------------------------------------------------- */
.lib-detail { display: flex; flex-direction: column; gap: 12px; }
.lib-back { align-self: flex-start; font-size: .9rem; font-weight: 600; color: var(--accent-dark);
  text-decoration: none; padding: 4px 0; }
.lib-back:hover { text-decoration: underline; }
.lib-note { margin: 0; }
.lib-d-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 10px; }
.lib-d-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.lib-d-tags .lib-tag { font-size: .8rem; padding: 3px 10px; }
.lib-asked { margin: 0; font-size: .92rem; color: var(--muted); }
.lib-asked i { color: var(--ink); }
.lib-detail .team-grid { margin: 4px 0 0; }
.lib-detail .avoid-h { margin: 8px 0 0; }
.lib-detail .ai-paste { margin: 0; }
.lib-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-actions button { flex: 1 1 170px; }
.lib-pitch {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  background: #eef7fc; border-left: 3px solid var(--accent); border-radius: 10px;
  padding: 12px 16px;
}
.lib-pitch p { flex: 1 1 320px; margin: 0; font-size: .95rem; line-height: 1.5; color: var(--t-ink-2); }
.lib-pitch b { color: var(--ink); }
.lib-d-foot { display: flex; justify-content: flex-end; }
.lib-similar { margin-top: 10px; }
.lib-similar .lib-sec-sub { display: block; margin: 2px 0 10px; }
.lib-sim-list { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.lib-sim {
  display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
.lib-sim:hover { border-color: var(--line-strong); box-shadow: var(--t-shadow-2); }
.lib-sim-mons { display: flex; flex-wrap: wrap; }
.lib-sim-sprite { width: 32px; height: 32px; object-fit: contain; }
.lib-sim-title { font-weight: 600; font-size: .92rem; }
.lib-sim-by { font-size: .78rem; color: var(--muted); }
/* What a crawler (or a visitor with scripts off) sees of a team. */
.lib-ssr h2 { margin: 0 0 4px; font-size: 1.15rem; }
.lib-ssr p { margin: 0 0 6px; color: var(--muted); }

/* ---- dialogs (report, build one like this, share) --------------------------- */
.lib-dialog { max-width: 32rem; }
.lib-dlg-sub { margin: -.6rem 0 1rem; font-size: .92rem; line-height: 1.5; color: var(--t-ink-2); }
.lib-dlg-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.1rem; }
.lib-dlg-actions > * { flex: 1 1 140px; }
.lib-dlg-actions button:not(.primary) {
  min-height: 46px; background: var(--card); border: 1px solid var(--line-strong);
  color: var(--ink); border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer;
}
.lib-dlg-status { min-height: 1.3em; margin: .6rem 0 0; font-size: .85rem; color: var(--t-ink-2); }
.lib-dialog input[type="text"], .lib-dialog textarea {
  width: 100%; font: inherit; font-size: .95rem; color: var(--ink); background: var(--card);
  border: 1px solid var(--line-strong); border-radius: 9px; padding: 8px 10px; margin: 4px 0 2px;
}
.lib-dialog input[type="text"]:focus, .lib-dialog textarea:focus { outline: none; border-color: var(--ink); }
.lib-dialog .lib-flabel { margin-top: .7rem; }
.lib-radios { display: flex; flex-direction: column; gap: 4px; }
.lib-radios label, .lib-check {
  display: flex; align-items: baseline; gap: 8px; font-size: .92rem; color: var(--ink);
  padding: 4px 0; cursor: pointer; line-height: 1.4;
}
.lib-check { margin-top: .4rem; }
.ls-help { margin: 2px 0 0; font-size: .8rem; color: var(--muted); line-height: 1.45; }
.ls-styles { border: 0; padding: 0; margin: .5rem 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.ls-styles legend { padding: 0; margin-bottom: 4px; }
.ls-style {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; cursor: pointer;
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line-strong);
  font-size: .88rem; font-weight: 600; color: var(--t-ink-2); background: var(--card);
}
.ls-style:has(input:checked) { border-color: var(--accent-dark); background: #eaf6fd; color: var(--ink); }
.ls-req { color: var(--t-ink-2); }
.ls-similar { margin: .6rem 0 0; font-size: .85rem; line-height: 1.45; padding: 8px 10px;
  border-radius: 8px; background: #fff6e6; color: #6b4e12; }
.ls-similar a { color: #6b4e12; font-weight: 700; }
.ls-public { margin: .7rem 0 0; font-size: .82rem; line-height: 1.5; padding: 9px 11px;
  border-radius: 8px; background: var(--t-surface); color: var(--t-ink-2); }
.ls-public b { color: var(--ink); }

.lib-lt-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.lib-lt {
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
  padding: 8px 4px; border-radius: 10px; border: 2px solid var(--line); background: var(--card);
  font: inherit; font-size: .8rem; font-weight: 600; color: var(--ink); text-align: center;
}
.lib-lt-sprite { width: 52px; height: 52px; object-fit: contain; }
.lib-lt[aria-pressed="true"] { border-color: var(--accent-dark); background: #eaf6fd; }
.lib-lt:disabled { cursor: default; color: var(--muted); background: var(--t-surface); }
.lib-lt:disabled img { opacity: .5; }

/* ---- the build picker ("Share a team") ---------------------------------------- */
.lib-pb-dialog { max-width: 36rem; }
.lib-pb-list { display: flex; flex-direction: column; gap: 8px; max-height: min(60vh, 520px);
  overflow-y: auto; margin: 0 -4px; padding: 2px 4px; }
.lib-pb {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--card); color: var(--ink); font: inherit; text-decoration: none;
  transition: border-color .15s var(--t-ease), background .15s var(--t-ease);
}
.lib-pb:hover:not(:disabled) { border-color: var(--accent); background: #eaf6fd; }
.lib-pb:disabled { cursor: progress; opacity: .7; }
.lib-pb-shared { background: var(--t-surface); border-color: var(--line); }
.lib-pb-mons { display: grid; grid-template-columns: repeat(6, 32px); flex: none; }
.lib-pb-sprite { width: 32px; height: 32px; object-fit: contain; }
.lib-pb-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lib-pb-name { font-size: .9rem; font-weight: 600; overflow-wrap: anywhere; }
.lib-pb-when { font-size: .76rem; color: var(--muted); }
.lib-pb-tag { align-self: flex-start; font-size: .7rem; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; color: var(--accent-dark); background: #eaf6fd; }
@media (max-width: 480px) {
  .lib-pb { flex-direction: column; align-items: flex-start; gap: 6px; }
  .lib-pb-mons { grid-template-columns: repeat(6, minmax(0, 1fr)); width: 100%; }
  .lib-pb-sprite { width: 100%; height: auto; aspect-ratio: 1; max-width: 44px; }
}

/* ---- the status line ----------------------------------------------------------- */
.lib-toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 1100;
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px);
  padding: 10px 12px 10px 16px; border-radius: 10px; background: var(--ink); color: #fff;
  font-size: .9rem; box-shadow: 0 12px 30px -8px rgba(13, 18, 20, .45);
}
.lib-toast[hidden] { display: none; }
.lib-toast-btn {
  flex: none; min-height: 32px; padding: 5px 12px; border: 0; border-radius: 7px; cursor: pointer;
  background: #fff; color: var(--ink); font: inherit; font-size: .85rem; font-weight: 600;
}

/* ---- on Team Lab: the share button and the saved list ----------------------- */
.lib-share-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  cursor: pointer; line-height: 1.2;
}
.lib-share-btn svg, .lib-shared-link svg { flex: none; color: var(--accent-dark); }
.lib-shared-link {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; flex: 1;
  padding: 11px; border-radius: 9px; background: var(--card); border: 1px solid var(--line-strong);
  color: var(--ink); font-weight: 600; font-size: .9rem; text-decoration: none; line-height: 1.2;
}
.lib-shared-link:hover { border-color: var(--accent); color: var(--accent-dark); }
/* At the top of a build, beside "Share team image" (both stay together and
   wrap as a pair on a narrow screen). */
.ba-head-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.ba-head .lib-share-ctl { padding: 8px 14px; flex: 0 0 auto; }
@media (max-width: 480px) {
  .ba-head-actions { width: 100%; }
  .ba-head-actions > * { flex: 1 1 0; min-height: 44px; margin: 0; }
}
.mybuild-lib {
  flex: 0 0 auto; font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  color: var(--accent-dark); background: #eaf6fd; white-space: nowrap;
}

.lib-filter-toggle { display: none; }

@media (max-width: 640px) {
  .lib { padding: 14px 16px 32px; gap: 22px; }
  .lib-filter-toggle {
    display: flex; align-items: center; justify-content: space-between; width: 100%;
    min-height: 44px; margin-bottom: 10px; padding: 8px 14px; cursor: pointer;
    background: var(--t-surface); border: 1px solid var(--line); border-radius: 12px;
    font: inherit; font-size: .92rem; font-weight: 600; color: var(--ink);
  }
  .lib-filter-toggle::after { content: "▾"; color: var(--muted); transition: transform .15s var(--t-ease); }
  .lib-filter-toggle[aria-expanded="true"]::after { transform: rotate(180deg); }
  .lib-filters:not(.open) { display: none; }
  .lib-sorts-mine { margin-left: 0; }
  .lib-flabel { min-width: 0; flex: 1 0 100%; }
  .lib-pick, .lib-pick input, .lib-pick select { width: 100%; }
  .lib-frow-pick { flex-direction: column; align-items: stretch; }
  .lib-pick-list { min-width: 0; }
  .lib-lt-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lib-fav-big { flex: 1 1 auto; justify-content: center; }
}

/* Reduced motion: no transitions and no press scale. Every control still
   works the same; only the movement goes. */
@media (prefers-reduced-motion: reduce) {
  .lib-card, .lib-fav, .lib-sort, .lib-chip, .lib-cta-btn, .lib-filter-toggle::after, .lib-pb,
  .lib-cards[aria-busy="true"] { transition: none; }
  .lib-fav:active, .lib-sort:active, .lib-chip:active, .lib-cta-btn:active { transform: none; }
}
