:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --brown: #795548;
  --brown-soft: #efebe9;
  --pink: #ec4899;
  --surface: #fff;
  --body: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 12px 30px rgba(15, 23, 42, .09);
  --gradient-brand: linear-gradient(135deg, var(--primary), var(--pink));
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--body); color: #334155; font-family: Inter, Roboto, Arial, sans-serif; line-height: 1.6; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
.shell { width: min(1160px, calc(100% - 32px)); margin: 0 auto; }
.header { position: sticky; top: 0; width: 100%; z-index: 1000; background: rgba(255,255,255,.94); border-bottom: 1px solid rgba(226,232,240,.6); backdrop-filter: blur(16px) saturate(180%); }
.header-content { display: flex; align-items: center; justify-content: space-between; height: 72px; }
.logo { display: flex; align-items: center; gap: .4rem; color: var(--primary); font-size: 1.65rem; font-weight: 800; letter-spacing: -.03em; }
.logo img { width: auto; height: 70px; margin-top: 6px; object-fit: contain; }
.logo span { color: var(--pink); }
.nav-links { display: flex; gap: 1.75rem; align-items: center; }
.nav-link { position: relative; color: #334155; font-size: .9rem; font-weight: 500; }
.nav-link:hover { color: var(--primary); }
.header-actions { display: flex; align-items: center; gap: .75rem; }
.lang-switch { appearance: none; min-height: 40px; padding: .42rem 1.8rem .42rem .9rem; border: 1.5px solid var(--border); border-radius: 8px; background: transparent; color: #334155; cursor: pointer; outline: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .6rem center; background-size: .9rem; }
.lang-switch:hover { border-color: var(--primary); }
[dir="rtl"] .lang-switch { padding: .42rem .9rem .42rem 1.8rem; background-position: left .6rem center; }
.menu-toggle { display: none; padding: .3rem; border: 0; background: none; color: var(--text); cursor: pointer; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 9px 17px; border: 0; border-radius: 10px; cursor: pointer; font-weight: 700; transition: transform .18s, box-shadow .18s, opacity .18s; }
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .55; }
.button-primary { color: #fff; background: linear-gradient(135deg, var(--primary), var(--pink)); box-shadow: 0 5px 14px rgba(99,102,241,.25); }
.button-outline { color: var(--text); background: #fff; border: 1px solid var(--border); }
.button-soft { color: var(--primary-dark); background: #eef2ff; }
.button-brown { color: var(--brown); background: var(--brown-soft); }
.catalogue-hero { padding: 80px 0 54px; text-align: center; background: radial-gradient(circle at 20% 20%, #e0e7ff, transparent 38%), radial-gradient(circle at 80% 40%, #fce7f3, transparent 36%), #fff; }
.eyebrow { display: inline-block; margin-bottom: 12px; color: var(--primary-dark); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; }
.catalogue-hero h1 { margin: 0; color: var(--text); font-size: clamp(2.2rem, 6vw, 4.4rem); line-height: 1.08; }
.catalogue-hero p { max-width: 720px; margin: 18px auto 0; color: var(--muted); font-size: 1.08rem; }
.catalogue-layout { padding: 44px 0 80px; }
.filters { display: grid; grid-template-columns: minmax(260px, 1fr) 190px 150px auto auto; gap: 12px; align-items: end; padding: 18px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(15,23,42,.04); }
.filters label { display: grid; gap: 5px; color: var(--text); font-size: .8rem; font-weight: 700; }
.filters input, .filters select, .game-picker select { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 9px; background: #fff; color: var(--text); }
.clear-link { align-self: center; color: var(--muted); font-weight: 700; }
.language-fallback-note { margin: 18px 0 0; padding: 11px 14px; color: #3730a3; background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 9px; font-size: .9rem; }
.tag-cloud { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 22px 0; }
.tag-cloud > span { margin-inline-end: 5px; color: var(--muted); font-weight: 700; }
.tag-cloud a, .detail-tags a { padding: 5px 11px; color: var(--brown); background: var(--brown-soft); border-radius: 999px; font-size: .82rem; font-weight: 700; }
.result-count { margin: 24px 0 14px; color: var(--muted); font-weight: 700; }
.library-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; }
.library-card { overflow: hidden; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 5px 18px rgba(15,23,42,.05); transition: transform .2s, box-shadow .2s; }
.library-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.card-image { position: relative; display: grid; place-items: center; height: 190px; overflow: hidden; background: linear-gradient(135deg, #efebe9, #d7ccc8); }
.card-image img { width: 100%; height: 100%; object-fit: cover; }
.image-placeholder, .banner-placeholder { color: rgba(121,85,72,.45); font-size: 4rem; }
.type-chip { position: absolute; top: 14px; inset-inline-start: 14px; padding: 5px 10px; border-radius: 999px; color: #fff; background: rgba(121,85,72,.92); font-size: .76rem; font-weight: 800; }
.card-body { padding: 19px; }
.card-body h2 { margin: 0 0 8px; color: var(--text); font-size: 1.2rem; line-height: 1.3; }
.card-body > p { min-height: 50px; margin: 0 0 13px; color: var(--muted); display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.card-meta, .detail-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; color: var(--muted); font-size: .8rem; }
.card-tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0; }
.card-tags span { color: var(--brown); font-size: .76rem; font-weight: 700; }
.card-link, .exercise-link { color: var(--primary-dark); font-weight: 800; }
.empty-state { padding: 70px 20px; text-align: center; background: #fff; border: 1px dashed #cbd5e1; border-radius: var(--radius); }
.pagination { display: flex; justify-content: center; align-items: center; gap: 24px; margin-top: 36px; font-weight: 700; }
.pagination a { color: var(--primary-dark); }
.breadcrumbs { display: flex; flex-wrap: wrap; gap: 8px; padding: 24px 0 14px; color: var(--muted); font-size: .86rem; }
.breadcrumbs a { color: var(--primary-dark); }
.detail-shell { padding-bottom: 70px; }
.detail-card { overflow: hidden; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.detail-banner { position: relative; display: grid; place-items: center; height: 280px; overflow: hidden; background: #e7e5e4; }
.detail-banner img { width: 100%; height: 100%; object-fit: contain; background: linear-gradient(135deg, #292524, #78716c); }
.detail-banner .type-chip { top: 16px; }
.detail-content { padding: 30px; }
.title-row { display: block; }
.title-row h1 { margin: 0 0 9px; color: var(--text); font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.18; }
.actions { display: grid; grid-template-columns: minmax(300px, 1fr) repeat(3, max-content); align-items: end; gap: 10px; width: 100%; margin-top: 24px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: #f8fafc; }
.actions.path-actions { display: inline-flex; width: auto; max-width: 100%; flex-wrap: wrap; }
.actions .button { min-height: 46px; white-space: nowrap; }
.game-action { display: grid; grid-template-columns: minmax(140px, 1fr) max-content; align-items: end; gap: 10px; }
.game-picker { display: grid; gap: 3px; min-width: 150px; color: var(--muted); font-size: .72rem; font-weight: 700; }
.game-picker select { min-height: 42px; }
.usage-message { min-height: 24px; margin-top: 14px; color: var(--primary-dark); font-weight: 700; text-align: end; }
.usage-message.error { color: #b91c1c; }
.detail-tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 24px; }
.detail-description { display: flex; align-items: flex-start; gap: 18px; margin: 24px 0 30px; }
.detail-thumb { display: flex; flex: 0 0 auto; flex-direction: column; align-items: center; gap: 12px; }
.detail-thumb__frame { position: relative; width: 250px; max-width: 100%; height: 160px; border-radius: 12px; overflow: hidden; background: linear-gradient(135deg, #f5f1ee, #e7dcd5); box-shadow: 0 10px 18px rgba(90, 60, 40, .15); }
.detail-thumb__img { width: 100%; height: 100%; object-fit: contain; display: block; background: #fff; }
.detail-thumb__actions { display: flex; justify-content: center; gap: 8px; }
.detail-thumb__actions .button { min-height: 38px; padding: 7px 14px; }
.detail-thumb__icon-button { width: 42px; padding: 7px !important; background-repeat: no-repeat; background-position: center; background-size: 20px; }
.detail-thumb__view-button { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%234f46e5'%3E%3Cpath d='M1.5 12s4.5-7 10.5-7 10.5 7 10.5 7-4.5 7-10.5 7S1.5 12 1.5 12zm10.5 4.5a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9z'/%3E%3C/svg%3E"); }
.detail-thumb__download-button { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230f172a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v11m0 0 4-4m-4 4-4-4M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2'/%3E%3C/svg%3E"); }
.lead-description { margin: 0; font-size: 1.08rem; }
.questions-section h2, .path-section h2 { margin: 0; color: var(--text); font-size: 1.35rem; }
.question-list, .path-list { padding: 0; margin: 16px 0 0; list-style: none; }
.question-list > li { display: grid; grid-template-columns: auto 1fr; align-items: start; gap: 12px; padding: 13px 15px; border-top: 1px solid var(--border); }
.question-list > li:last-child { border-bottom: 1px solid var(--border); }
.question-type { display: inline-flex; padding: 3px 8px; border-radius: 6px; color: #6d28d9; background: #f3e8ff; font-size: .68rem; font-weight: 800; text-transform: uppercase; }
.question-label { margin: 0; color: var(--text); }
.section-heading-row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.section-heading-row > span { color: var(--muted); font-size: .85rem; font-weight: 700; }
.path-list { display: grid; gap: 15px; }
.path-step { display: grid; grid-template-columns: 42px 1fr; gap: 16px; padding: 20px; border: 1px solid var(--border); border-radius: 12px; }
.step-number { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; color: #fff; background: var(--brown); font-weight: 800; }
.path-step h3 { margin: 0 0 8px; color: var(--text); font-size: 1.18rem; }
.exercise-description { margin: 0; }
.step-meta { color: var(--muted); font-size: .82rem; }
.exercise-link { display: inline-block; margin-top: 14px; }
.footer { padding: 4rem 0 2rem; color: #f1f5f9; background: #0f172a; }
.footer-grid { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 3rem; margin-bottom: 3rem; }
.footer-logo { display: inline-flex; margin-bottom: 1.5rem; color: #fff; }
.footer-logo img { height: 50px; margin: 0; }
.footer-col p { max-width: 250px; margin: 0; color: #94a3b8; }
.footer-col h4 { margin: 0 0 1.25rem; color: #fff; font-size: .95rem; }
.footer-links { padding: 0; margin: 0; list-style: none; }
.footer-links li { margin-bottom: .6rem; }
.footer-links a { color: #94a3b8; font-size: .88rem; }
.footer-links a:hover { color: #818cf8; }
.social-links { display: flex; gap: 1rem; margin-top: 1.25rem; }
.social-links a { display: flex; width: 36px; height: 36px; align-items: center; justify-content: center; color: #94a3b8; background: rgba(255,255,255,.06); border-radius: 8px; transition: all .2s; }
.social-links a:hover { color: #fff; background: var(--primary); transform: translateY(-2px); }
.footer-bottom { display: flex; padding-top: 1.75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 1rem; border-top: 1px solid rgba(255,255,255,.08); color: #64748b; font-size: .84rem; }
.footer-bottom p { margin: 0; }
.footer-language { margin-inline-start: auto; }
.lang-switch-footer { min-width: 150px; color: #cbd5e1; border-color: rgba(255,255,255,.18); background-color: rgba(255,255,255,.05); }
.lang-switch-footer option { color: var(--text); background: #fff; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.print-view { background: #fff; }
.print-view .detail-shell { width: 100%; padding: 0; }
.print-view .detail-card { border: 0; box-shadow: none; }

.library-game-preview { position: fixed; inset: 0; z-index: 5000; display: flex; flex-direction: column; background: #0f172a; }
.library-game-preview[hidden] { display: none; }
.library-game-toolbar { display: flex; min-height: 58px; padding: max(.45rem, env(safe-area-inset-top)) max(.8rem, env(safe-area-inset-right)) .45rem max(.8rem, env(safe-area-inset-left)); align-items: center; gap: 1rem; color: #fff; background: #0f172a; direction: ltr; }
.library-game-toolbar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; }
.library-game-close { display: inline-flex; min-height: 42px; padding: .55rem .8rem; align-items: center; gap: .4rem; color: #fff; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15); border-radius: 8px; cursor: pointer; }
.library-game-close[hidden] { display: none; }
.library-game-close svg { width: 20px; height: 20px; }
.library-game-status { position: absolute; inset: 58px 0 0; z-index: 1; display: flex; padding: 2rem; align-items: center; justify-content: center; flex-direction: column; gap: 1rem; color: #fff; background: radial-gradient(circle at 50% 35%, #25345a, #0f172a 60%); text-align: center; }
.library-game-status[hidden], .library-game-status .button[hidden] { display: none; }
.library-game-status p { max-width: 34rem; margin: 0; color: #e2e8f0; font-size: 1rem; line-height: 1.5; }
.library-game-spinner { width: 48px; height: 48px; border: 4px solid rgba(255,255,255,.2); border-top-color: #fff; border-radius: 50%; animation: library-game-spin .8s linear infinite; }
#library-game-frame { width: 100%; min-height: 0; border: 0; flex: 1; background: #000; }
.library-game-gate { position: absolute; inset: 0; z-index: 3; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.1rem; padding: 2rem; color: #fff; background: radial-gradient(circle at 50% 35%, #25345a, #0f172a 60%); border: 0; cursor: pointer; font: inherit; text-align: center; }
.library-game-gate[hidden] { display: none; }
.library-game-gate svg { width: 72px; height: 72px; }
.library-game-gate span { max-width: 24rem; font-size: 1.15rem; font-weight: 700; }
body.library-game-open { overflow: hidden; }

.library-image-preview { position: fixed; inset: 0; z-index: 5100; display: flex; padding: 24px; align-items: center; justify-content: center; background: rgba(15,23,42,.92); }
.library-image-preview[hidden] { display: none; }
.library-image-preview__toolbar { position: absolute; top: max(16px, env(safe-area-inset-top)); inset-inline: max(16px, env(safe-area-inset-right)); display: flex; align-items: center; justify-content: space-between; gap: 16px; color: #fff; }
.library-image-preview__toolbar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-image-preview__close { display: inline-flex; min-height: 42px; padding: .55rem .8rem; align-items: center; gap: .4rem; flex: 0 0 auto; color: #fff; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22); border-radius: 8px; cursor: pointer; font: inherit; }
.library-image-preview__close svg { width: 20px; height: 20px; }
#library-image-preview-image { max-width: 100%; max-height: calc(100vh - 100px); object-fit: contain; box-shadow: 0 18px 60px rgba(0,0,0,.45); }
body.library-image-preview-open { overflow: hidden; }

@keyframes library-game-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .library-game-spinner { animation-duration: 1.6s; }
}

@media (max-width: 1024px), (pointer: coarse) {
  .library-game-toolbar { position: absolute; top: max(6px, env(safe-area-inset-top)); left: max(6px, env(safe-area-inset-left)); z-index: 2; min-height: 0; padding: 0; background: transparent; pointer-events: none; }
  .library-game-toolbar strong { display: none; }
  .library-game-close { width: 44px; height: 44px; min-height: 44px; padding: 0; justify-content: center; border-radius: 50%; background: rgba(15,23,42,.86); border-color: rgba(255,255,255,.28); box-shadow: 0 2px 8px rgba(0,0,0,.28); pointer-events: auto; }
  .library-game-close span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
  .library-game-close svg { width: 18px; height: 18px; }
  .library-game-status { inset: 0; }
}

@media (min-width: 1025px) and (pointer: fine) {
  .library-game-preview { inset: 5vh 5vw; border-radius: var(--radius); box-shadow: 0 30px 80px rgba(15,23,42,.45); overflow: hidden; }
  body.library-game-open::after { content: ''; position: fixed; inset: 0; z-index: 4999; background: rgba(15,23,42,.82); }
}

@media (max-width: 900px) {
  .nav-links, .header-actions { display: none; }
  .menu-toggle { display: block; }
  .header.menu-open .nav-links, .header.menu-open .header-actions { position: absolute; inset-inline: 0; top: 72px; display: flex; width: 100%; padding: 1.5rem; flex-direction: column; gap: 1rem; background: #fff; box-shadow: var(--shadow); }
  .header.menu-open .header-actions { top: calc(72px + 188px); padding-top: 0; border-bottom: 1px solid var(--border); box-shadow: none; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters label:first-child { grid-column: 1 / -1; }
  .library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .actions { grid-template-columns: 1fr 1fr; }
  .game-action { grid-column: 1 / -1; }
  .actions .button { width: 100%; }
  .actions.path-actions .button { width: auto; }
  .usage-message { text-align: start; }
  .detail-description { flex-direction: column; }
  .detail-thumb { align-self: center; }
  .footer-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
  .shell { width: min(100% - 20px, 1160px); }
  .catalogue-hero { padding: 58px 0 40px; }
  .filters { grid-template-columns: 1fr; }
  .filters label:first-child { grid-column: auto; }
  .library-grid { grid-template-columns: 1fr; }
  .detail-banner { height: 210px; }
  .detail-content { padding: 20px 15px; }
  .actions { grid-template-columns: 1fr; padding: 10px; }
  .game-action { grid-column: auto; grid-template-columns: 1fr; }
  .actions > * { width: 100%; }
  .actions.path-actions { display: flex; width: 100%; }
  .actions.path-actions .button { width: auto; }
  .path-step { grid-template-columns: 34px 1fr; padding: 15px 11px; gap: 10px; }
  .step-number { width: 32px; height: 32px; }
  .question-list > li { grid-template-columns: 1fr; }
  .footer-grid { grid-template-columns: 1fr; }
}
@media print {
  @page { margin: 14mm; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .header, .footer, .breadcrumbs, .actions, .usage-message, .exercise-link { display: none !important; }
  .detail-shell { width: 100%; padding: 0; }
  .detail-card { border: 0; box-shadow: none; }
  .detail-banner { height: 120px; }
  .detail-content { padding: 16px 0; }
  .question-list > li, .path-step { break-inside: avoid; }
}

/* in library.css, the .card-body > p rule */
.card-body > p {
    line-clamp: 2;
}

/* ── Browse-limit popup ──────────────────────────────────────────────────── */
#lib-limit-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.lib-limit-card {
  width: min(480px, 100%);
  padding: 40px 36px 36px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
  text-align: center;
}
.lib-limit-icon {
  margin-bottom: 14px;
  font-size: 2.6rem;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.lib-limit-card h2 {
  margin: 0 0 12px;
  color: var(--text);
  font-size: clamp(1.35rem, 4vw, 1.8rem);
  line-height: 1.22;
}
.lib-limit-card > p {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.65;
}
.lib-limit-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lib-limit-btn {
  width: 100%;
  justify-content: center;
  font-size: .95rem;
  min-height: 50px;
}
@media (min-width: 440px) {
  .lib-limit-actions { flex-direction: row; }
  .lib-limit-btn { width: auto; flex: 1; }
}
@media (max-width: 439px) {
  .lib-limit-card { padding: 30px 20px 24px; }
}
.related-section { margin-top: 40px; padding-top: 30px; border-top: 1px solid var(--border); }
.related-section h2 { margin: 0 0 18px; color: var(--text); font-size: 1.3rem; }
.related-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.related-grid .card-image { height: 130px; }
.related-grid .card-body h3 { margin: 0 0 6px; font-size: 1rem; line-height: 1.3; }
.related-grid .card-body > p { min-height: 0; margin: 0 0 8px; font-size: .85rem; -webkit-line-clamp: 2; }
@media (max-width: 900px) { .related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 540px) { .related-grid { grid-template-columns: 1fr; } }

