/* ============================================================
   Library — public catalog + PDF preview + registration gate.
   Reuses tokens from style.css (--p1, --p2, --g, --bg, etc).
   ============================================================ */

/* auth-common.js auto-injects decorative `.doodles` SVGs that are styled by
   auth.css (sized + absolutely positioned). We don't load auth.css here, so
   without this rule the doodles would render at full viewport width.
   We use auth-common.js only for AuthUI helpers — the decoration is unwanted. */
body[data-page="library"] > .doodles { display: none !important; }

/* Per-collection tone colors — match LibraryCard.vue exactly so the
   landing's covers and the cabinet's covers feel like the same product. */
:root {
  --tone-english-fun: #1e3a8a;
  --tone-math-clear:  #4c1d95;
  --tone-life-skills: #9d174d;
  --tone-pop-culture: #9a3412;
  --tone-tech-kids:   #1e293b;
  --tone-digest:      #065f46;
  --tone-default:     #1f2937;
}

/* ────────────────────── Page hero ────────────────────── */
.libHero {
  padding: clamp(1.4rem, 1rem + 2vw, 2.6rem) 0 1rem;
}
.libHero__title { margin: 0 0 .5rem; }
.libHero__lead { margin: 0; max-width: 60ch; }

/* ────────────────────── Catalog layout ────────────────────── */
.libCatalog {
  padding: 1rem 0 4rem;
}
.libCatalog__layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: clamp(1rem, .8rem + 1vw, 1.75rem);
  align-items: start;
}
.libCatalog__aside,
.libCatalog__main { min-width: 0; }

@media (max-width: 900px) {
  .libCatalog__layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Aside */
.libCatalog__aside {
  position: sticky;
  top: 92px;
}
@media (max-width: 900px) {
  .libCatalog__aside {
    position: static;
    top: auto;
  }
}

.libCats {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .5rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  box-shadow: var(--shadow2);
}
@media (max-width: 900px) {
  .libCats {
    flex-direction: row;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding: .4rem;
    gap: .35rem;
    -webkit-overflow-scrolling: touch;
  }
  .libCats::-webkit-scrollbar { display: none; }
}

.libCats__btn {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .65rem .8rem;
  border-radius: 14px;
  text-align: left;
  color: var(--text);
  font: inherit;
  transition: background .14s ease, color .14s ease;
  width: 100%;
}
.libCats__btn:hover { background: rgba(72,17,191,.06); }
.libCats__btn.is-active {
  background: var(--p4);
  color: var(--p1);
  font-weight: 600;
}
.libCats__btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

@media (max-width: 900px) {
  .libCats__btn {
    flex: 0 0 auto;
    scroll-snap-align: start;
    padding: .55rem .7rem;
    width: auto;
  }
  .libCats__label { white-space: nowrap; }
}

.libCats__icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.libCats__icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.libCats__label {
  flex: 1;
  font-size: var(--fs-14);
  white-space: nowrap;
}
.libCats__count {
  font-size: 12px;
  color: var(--muted);
  background: rgba(22,36,41,.06);
  padding: 2px 8px;
  border-radius: 999px;
  flex: 0 0 auto;
}
.libCats__btn.is-active .libCats__count {
  background: rgba(72,17,191,.12);
  color: var(--p1);
}

/* ────────────────────── Top filters ────────────────────── */
.libFilters {
  display: flex;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.libFilters__field {
  flex: 1 1 240px;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.libFilters__label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .03em;
  text-transform: uppercase;
  padding-left: .25rem;
}
.libFilters__input,
.libFilters__select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  padding: .75rem 1rem;
  font: inherit;
  color: var(--text);
  transition: border-color .14s ease, box-shadow .14s ease;
}
.libFilters__input:focus-visible,
.libFilters__select:focus-visible {
  outline: none;
  border-color: var(--p2);
  box-shadow: var(--focus);
}
.libFilters__select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text) 50%),
    linear-gradient(135deg, var(--text) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 2.4rem;
}

/* ────────────────────── Grid + Cards ────────────────────── */
.libGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.25rem 1rem;
}
@media (max-width: 480px) {
  .libGrid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem .75rem;
  }
}

.libCard {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: inherit;
  font: inherit;
  transition: transform 200ms cubic-bezier(.23,1,.32,1);
}
.libCard:focus-visible {
  outline: none;
}
.libCard:focus-visible .libCard__cover {
  box-shadow: 0 0 0 3px rgba(140,92,242,.4);
}

.libCard__cover {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  background: var(--tone, var(--tone-default));
  box-shadow: 0 4px 12px -4px rgba(13,10,35,.16);
  transition: transform 200ms cubic-bezier(.23,1,.32,1),
              box-shadow 200ms cubic-bezier(.23,1,.32,1);
}
@media (hover:hover) and (pointer:fine) {
  .libCard:hover .libCard__cover {
    transform: translateY(-2px);
    box-shadow: 0 16px 32px -12px rgba(13,10,35,.24);
  }
}
.libCard--english-fun  { --tone: var(--tone-english-fun); }
.libCard--math-clear   { --tone: var(--tone-math-clear); }
.libCard--life-skills  { --tone: var(--tone-life-skills); }
.libCard--pop-culture  { --tone: var(--tone-pop-culture); }
.libCard--tech-kids    { --tone: var(--tone-tech-kids); }
.libCard--digest       { --tone: var(--tone-digest); }

.libCard__thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
  z-index: 1;
}
.libCard__placeholderLabel {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: rgba(255,255,255,.78);
  text-align: center;
  z-index: 0;
}

.libCard__meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 2px;
}
.libCard__title {
  margin: 0;
  font-size: 14px;
  line-height: 1.32;
  font-weight: 600;
  letter-spacing: -.005em;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.libCard__sub {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}
.libCard__age { margin-left: 4px; }

/* ────────────────────── Pager ────────────────────── */
.libPager {
  display: flex;
  justify-content: center;
  gap: .35rem;
  margin-top: 1.75rem;
}
.libPager__dot {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  width: 38px;
  height: 38px;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background .14s, color .14s, border-color .14s;
}
.libPager__dot:hover { background: rgba(72,17,191,.06); }
.libPager__dot.is-active {
  background: var(--grad);
  color: #fff;
  border-color: transparent;
}
.libPager__dot:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* ────────────────────── Empty / loading / error ────────────────────── */
.libEmpty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted);
  background: rgba(255,255,255,.5);
}
.libEmpty__btn {
  margin-top: .75rem;
}

/* ============================================================
   Modal — PDF preview reader + registration gate
   ============================================================ */
html.libModal-open,
body.libModal-open {
  overflow: hidden;
}

.libModal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  background: rgba(15, 12, 30, .55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  align-items: stretch;
  justify-content: center;
  padding: 0;
  animation: libModalFade .12s ease;
}
.libModal.is-open { display: flex; }

@keyframes libModalFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.libModal__shell {
  position: relative;
  width: 100%;
  max-width: 1100px;
  margin: 24px;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 32px 80px rgba(13, 10, 35, .28);
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 48px);
}
@media (max-width: 720px) {
  .libModal__shell {
    margin: 0;
    border-radius: 0;
    max-height: 100dvh;
  }
}

.libModal__close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 0;
  background: rgba(13, 10, 35, .65);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background .14s;
}
.libModal__close:hover { background: rgba(13, 10, 35, .85); }
.libModal__close:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(255,255,255,.7);
}

.libModal__layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  flex: 1;
  min-height: 0;
}
@media (max-width: 900px) {
  .libModal__layout {
    grid-template-columns: 1fr;
  }
}

.libModal__meta {
  background: var(--bg);
  border-right: 1px solid var(--line);
  padding: 1.5rem 1.25rem;
  overflow: auto;
}
@media (max-width: 900px) {
  .libModal__meta {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 1rem 1rem .75rem;
    overflow: visible;
  }
}

.libModal__chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .25rem .6rem;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #fff;
  background: var(--tone, var(--tone-default));
  margin-bottom: .75rem;
}
.libModal__title {
  margin: 0 0 .35rem;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 700;
  color: var(--ink);
}
.libModal__subtitle {
  margin: 0 0 1rem;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.45;
}
.libModal__highlights {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.libModal__highlights li {
  position: relative;
  padding-left: 1.2rem;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
}
.libModal__highlights li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--g);
  font-weight: 800;
}
.libModal__pages-count {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

.libModal__main {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: auto;
  background: #f1eef9;
  -webkit-overflow-scrolling: touch;
}

.libModal__pages-host {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 28px 18px 0;
}
.libModal__page {
  position: relative;
  width: 100%;
  max-width: 720px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(13, 10, 35, .14);
  overflow: hidden;
}
.libModal__page canvas {
  display: block;
  width: 100%;
  height: auto;
}
.libModal__pageLabel {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(13, 10, 35, .65);
  color: #fff;
  padding: 3px 8px;
  border-radius: 999px;
  pointer-events: none;
}

.libModal__loading {
  padding: 4rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ────────────────────── Gate (over PDF after page 2) ────────────────────── */
.libModal__gate {
  position: relative;
  margin-top: 28px;
  padding: 1.5rem 1.25rem 1.75rem;
  background: linear-gradient(to bottom, rgba(255,255,255,0) 0, var(--surface) 56px);
}
.libModal__gate::before {
  content: "";
  position: absolute;
  top: -64px;
  left: 0;
  right: 0;
  height: 88px;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(241,238,249,0) 0%, rgba(241,238,249,.92) 75%, rgba(255,255,255,1) 100%);
}

.libModal__gateBody {
  position: relative;
  max-width: 540px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  animation: libGateRise .22s cubic-bezier(.2,.8,.3,1);
}
@keyframes libGateRise {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.libModal__gateLock {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--p4);
  color: var(--p1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: .85rem;
  font-size: 22px;
}
.libModal__gateTitle {
  margin: 0 0 .4rem;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 700;
  color: var(--ink);
}
.libModal__gateLead {
  margin: 0 0 1.25rem;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
}

/* ────────────────────── Form ────────────────────── */
.libForm {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.libForm__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .65rem;
}
@media (max-width: 480px) {
  .libForm__row { grid-template-columns: 1fr; }
}

.libForm__field {
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.libForm__input {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 14px;
  padding: .8rem 1rem;
  font: inherit;
  color: var(--text);
  transition: border-color .14s ease, box-shadow .14s ease;
}
.libForm__input:focus-visible {
  outline: none;
  border-color: var(--p2);
  box-shadow: var(--focus);
}
.libForm__input.is-error {
  border-color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220,38,38,.16);
}
.libForm__hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  padding-left: .25rem;
}
.libForm__hint.is-error { color: #dc2626; }

/* intl-tel-input visual fit (override default styling) */
.libForm .iti { width: 100%; }
.libForm .iti--separate-dial-code .iti__selected-dial-code {
  font-weight: 500;
}
.libForm .iti__country-list {
  border-radius: 12px;
  box-shadow: var(--shadow);
}

/* Role segmented control */
.libForm__roleRow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .35rem;
  background: var(--bg);
  padding: .25rem;
  border-radius: 14px;
  border: 1px solid var(--line);
}
.libForm__role {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  padding: .55rem .35rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background .14s, color .14s;
}
.libForm__role:hover { color: var(--text); }
.libForm__role.is-active {
  background: var(--surface);
  color: var(--p1);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(13,10,35,.06);
}
.libForm__role:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.libForm__alert {
  margin: 0;
  padding: .65rem .85rem;
  border-radius: 12px;
  background: rgba(220,38,38,.08);
  border: 1px solid rgba(220,38,38,.22);
  color: #b91c1c;
  font-size: 13px;
}

.libForm__submit {
  margin-top: .35rem;
  width: 100%;
  padding: .9rem 1rem;
}
.libForm__submit[disabled] {
  opacity: .6;
  cursor: progress;
}

.libForm__legal {
  margin: .25rem 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
  text-align: center;
}
.libForm__legal a {
  color: var(--p1);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ============================================================
   Teaser section on index.html (and other landing pages)
   ============================================================ */
.libTeaser__grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1rem;
}
@media (max-width: 1100px) {
  .libTeaser__grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 560px) {
  .libTeaser__grid { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
}

.libTeaser__card {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-decoration: none;
  transition: transform 200ms cubic-bezier(.23,1,.32,1);
}
.libTeaser__cover {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  background: var(--tone, var(--tone-default));
  box-shadow: 0 4px 12px -4px rgba(13,10,35,.16);
  transition: transform 200ms cubic-bezier(.23,1,.32,1),
              box-shadow 200ms cubic-bezier(.23,1,.32,1);
}
@media (hover:hover) and (pointer:fine) {
  .libTeaser__card:hover .libTeaser__cover {
    transform: translateY(-2px);
    box-shadow: 0 16px 32px -12px rgba(13,10,35,.24);
  }
}
.libTeaser__card--english-fun .libTeaser__cover { --tone: var(--tone-english-fun); }
.libTeaser__card--math-clear  .libTeaser__cover { --tone: var(--tone-math-clear); }
.libTeaser__card--life-skills .libTeaser__cover { --tone: var(--tone-life-skills); }
.libTeaser__card--pop-culture .libTeaser__cover { --tone: var(--tone-pop-culture); }
.libTeaser__card--tech-kids   .libTeaser__cover { --tone: var(--tone-tech-kids); }
.libTeaser__card--digest      .libTeaser__cover { --tone: var(--tone-digest); }

.libTeaser__thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
  z-index: 1;
}
.libTeaser__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(255,255,255,.8);
  text-align: center;
  padding: 12px;
}
.libTeaser__title {
  margin: 0;
  font-size: 13px;
  line-height: 1.3;
  font-weight: 600;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  padding: 0 2px;
}

/* ────────────────────── Reduced motion ────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .libCard, .libCard__cover,
  .libTeaser__card, .libTeaser__cover,
  .libModal, .libModal__gateBody {
    animation: none !important;
    transition: none !important;
  }
}
