/* Learning Library specific styles (filters, details panel). */

.library-empty {
  text-align: center;
  color: var(--ink-faint);
  padding: 2.5rem 0;
  line-height: 1.6;
}

/* Said to a screen reader only: the skeleton cards below show it. */
.library-loading {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Smooth loading on Games and Lessons. Nothing that is already on screen may
   move as the page fills in, so every part holds its final size from the first
   frame: skeleton cards keep the "more places" row and the footer below the
   fold, the grade row and Miss Marigold reserve their height, and what arrives
   fades in over its placeholder instead of pushing the page about. */
.tile-skeletons { display: contents; }

.game-tile.is-skeleton {
  pointer-events: none;
  border-color: rgba(255, 229, 150, 0.14);
  box-shadow: none;
}

.game-tile.is-skeleton .game-tile-art,
.game-tile.is-skeleton .game-tile-body span {
  background: linear-gradient(100deg, rgba(255, 255, 255, 0.04) 30%, rgba(255, 255, 255, 0.09) 50%, rgba(255, 255, 255, 0.04) 70%) 0 0 / 300% 100%;
  animation: skeleton-shine 1.6s linear infinite;
}

.game-tile.is-skeleton .game-tile-body span {
  display: block;
  height: 0.95rem;
  border-radius: 6px;
}

.game-tile.is-skeleton .game-tile-body span:first-child { width: 70%; height: 1.15rem; }
.game-tile.is-skeleton .game-tile-body span:nth-child(2) { width: 45%; }
.game-tile.is-skeleton .game-tile-body span:nth-child(3) { width: 90%; height: 2.6rem; }

@keyframes skeleton-shine {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

@keyframes catalogue-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Once, when the real cards replace the skeleton (catalogue.js). */
.game-tiles-grid.is-ready { animation: catalogue-fade-in 0.25s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .game-tile.is-skeleton .game-tile-art,
  .game-tile.is-skeleton .game-tile-body span,
  .game-tiles-grid.is-ready { animation: none; }
}

.library-empty h1 {
  margin: 0 0 0.5rem;
  color: var(--ink);
}

.library-empty .btn {
  margin-top: 1rem;
}

.library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.library-filters select {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-muted);
  background: rgba(10, 18, 48, 0.85);
  border: 1px solid var(--gold-soft);
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.75rem;
  cursor: pointer;
}

.library-filters select:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.details-panel {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(4, 8, 24, 0.6);
}

.details-panel[hidden] {
  display: none;
}

.details-card {
  position: relative;
  width: min(30rem, 100%);
  max-height: min(82vh, 36rem);
  overflow-y: auto;
  padding: 1.25rem 1.35rem 1.5rem;
  border-radius: var(--radius-md, 14px);
  background: rgba(9, 15, 40, 0.98);
  border: 1px solid var(--gold-soft);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  color: var(--ink);
  animation: details-pop-in 0.18s ease-out;
}

@keyframes details-pop-in {
  from { transform: translateY(10px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .details-card {
    animation: none;
  }
}

.details-panel h2 {
  margin: 0.5rem 0 0.35rem;
  color: var(--gold);
  font-size: 1.2rem;
}

.details-panel .details-close {
  position: absolute;
  top: 0.7rem;
  right: 0.8rem;
  border: 1px solid var(--gold-soft);
  background: transparent;
  color: var(--gold);
  font: inherit;
  font-weight: 800;
  border-radius: var(--radius-pill);
  padding: 0.25rem 0.7rem;
  cursor: pointer;
}

.details-panel .details-close:hover {
  background: var(--gold);
  color: var(--navy-800);
}

.details-panel .details-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.6rem 0;
}

.details-panel .details-skill {
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-md);
  background: var(--gold-faint);
  border: 1px solid var(--gold-soft);
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink-muted);
}

.details-panel .details-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
}

.tile-progress-chip {
  margin-top: 0.35rem;
  align-self: flex-start;
}

/* Card refinements for the upgraded library */

.game-tile .game-tile-art {
  display: block;
  text-decoration: none;
}

.game-tile .game-tile-title a {
  color: inherit;
  text-decoration: none;
}

.game-tile .game-tile-title a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.game-tile-desc {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--ink-muted);
}

.game-tile.tile-lesson {
  border-color: rgba(232, 137, 42, 0.55);
}

.game-tile.tile-lesson:hover {
  border-color: #e8892a;
}

.tile-details-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.45rem;
  align-self: flex-start;
  border: none;
  background: none;
  padding: 0;
  color: var(--ink-faint);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tile-details-btn:hover {
  color: var(--gold);
}

.details-note {
  min-height: 1.2em;
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
  color: #8ee8a8;
}

/* Miss Marigold above the grade buttons (assets/catalogue-guide.js). */
.catalogue-guide:not(:empty) { margin: 0 0 1rem; max-width: 40rem; }

/* Set from the cached session in the page head, before the first frame: her
   place is held at her face's height while three.js and her voice load. */
:root[data-catalogue-guide] .catalogue-guide { min-height: 6.5rem; margin: 0 0 1rem; max-width: 40rem; }
.catalogue-guide > .tg { animation: catalogue-fade-in 0.3s ease-out; }

/* Grade buttons: one per year here, then All (assets/catalogue.js). Navy and
   gold like the tiles below; the pressed one is gold-tinted with a tick.
   One row at every width: padding, gaps, the icon and the label scale with
   the viewport (clamp), so five buttons fit 760 px of content on an 800 px
   tablet and the 920 px column on a 1340 px one; if a large text setting
   still makes them too wide, the row scrolls sideways instead of wrapping.
   Phones scroll the row sideways too. Buttons stay ≥ 52 px tall. */
.library-filters.grade-buttons {
  flex-wrap: nowrap;
  gap: clamp(0.35rem, 0.8vw, 0.6rem);
  margin-bottom: 1.25rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  /* room for the focus ring and the card shadow inside the scroller */
  padding: 4px 4px 8px;
  margin-inline: -4px;
  /* The row is empty until the registry is in: hold one button's height. */
  min-height: calc(52px + 12px);
}

.grade-btn { animation: catalogue-fade-in 0.2s ease-out; }

.library-filters.grade-buttons::-webkit-scrollbar { display: none; }

.grade-btn {
  flex: 1 0 auto;
  justify-content: center;
  display: inline-flex;
  align-items: center;
  gap: clamp(0.3rem, 0.7vw, 0.55rem);
  min-height: 52px;
  padding: 0.35rem clamp(0.5rem, 1.3vw, 1rem) 0.35rem clamp(0.35rem, 0.8vw, 0.55rem);
  font: inherit;
  font-family: var(--font-body);
  color: var(--ink);
  background: rgba(10, 18, 48, 0.88);
  border: 2px solid var(--gold-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.grade-btn:hover { border-color: var(--gold); }
.grade-btn:focus-visible { outline: 3px solid var(--sky-deep); outline-offset: 2px; }

.grade-btn-icon {
  flex: none;
  width: clamp(24px, 3vw, 32px);
  height: clamp(24px, 3vw, 32px);
  object-fit: contain;
}

.grade-btn-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  text-align: left;
}

.grade-btn-label {
  font-size: clamp(0.98rem, 0.3rem + 1.6vw, 1.15rem);
  font-weight: 800;
  white-space: nowrap;
}

.grade-btn-mine {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gold);
  opacity: 0.85;
  white-space: nowrap;
}

/* The tick keeps its space on every button, so choosing one never moves the row. */
.grade-btn-check {
  flex: none;
  width: clamp(1.1rem, 1.8vw, 1.4rem);
  height: clamp(1.1rem, 1.8vw, 1.4rem);
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 900;
  line-height: clamp(1.1rem, 1.8vw, 1.4rem);
  text-align: center;
  color: var(--navy-900);
  background: var(--gold);
  visibility: hidden;
}

.grade-btn.is-on {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(255, 229, 150, 0.24), rgba(255, 229, 150, 0.1)), var(--navy-800);
}

.grade-btn.is-on .grade-btn-label { color: var(--gold); }
.grade-btn.is-on .grade-btn-check { visibility: visible; }

@media (max-width: 560px) {
  .library-filters.grade-buttons { gap: 0.45rem; min-height: calc(48px + 12px); }
  .grade-btn { flex: none; min-height: 48px; padding: 0.35rem 0.7rem 0.35rem 0.45rem; gap: 0.4rem; }
  .grade-btn-label { font-size: 1.02rem; }
}

@media (prefers-reduced-motion: reduce) {
  .grade-btn { transition: none; }
  .grade-btn,
  .catalogue-guide > .tg { animation: none; }
}
