/* A compact finder leaves the games in view. Only its search row stays sticky. */
#library.library-finder{padding-top:48px;scroll-margin-top:20px;min-width:0}
#library .library-heading{display:flex;align-items:center;justify-content:space-between;gap:12px 24px;margin:0 0 12px}
#library .library-heading-title{display:flex;flex-wrap:wrap;align-items:baseline;gap:8px 13px;min-width:0}
#library .library-heading h2{margin:0;color:var(--ink);font-size:clamp(30px,3vw,36px);line-height:1.2;letter-spacing:-.035em;overflow-wrap:break-word}
#library .library-total{color:#a8c0d0;font-size:13px;line-height:1.4;white-space:nowrap}
#library .library-pick{display:inline-flex;align-items:center;justify-content:center;flex:none;min-height:48px;padding:9px 12px;border:1px solid #3f6178;border-radius:12px;background:#122b3d;color:var(--mint);font:inherit;font-size:13px;font-weight:750;line-height:1.35;text-align:center;cursor:pointer}
#library .library-pick:hover{border-color:var(--mint);background:#17384b}
#library .library-pick:disabled{cursor:default;opacity:.55}

#library .library-search-row{position:sticky;top:10px;z-index:15;display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px;align-items:stretch;margin:0 0 10px;padding:6px;background:#071522f5;border-radius:16px;box-shadow:0 4px 14px #0002}
#library .library-search{width:auto;min-width:0;max-width:100%;height:50px;margin:0;padding:0 1px 0 13px;gap:10px;border:1px solid #3e6179;border-radius:11px;background:#0b2031;box-shadow:none}
#library .library-search:focus-within{border-color:var(--mint);box-shadow:0 0 0 3px #56d9c025}
#library .library-search svg{width:20px;height:20px;flex:0 0 20px}
#library .library-search input{width:100%;min-width:0;font-size:16px;line-height:1.4}
#library .library-search input::placeholder{color:#90aaba}
#library .library-search kbd{flex:none;padding:2px 6px;box-shadow:none}
#library .library-search .clear-search{width:48px;height:48px;flex:0 0 48px;border:0;background:transparent;border-radius:9px;color:#c6dbe8;font-size:24px}
#library .library-filter-button{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:48px;padding:10px 16px;border:1px solid #4b6a80;border-radius:11px;background:#173246;color:var(--ink);font:inherit;font-size:14px;font-weight:750;line-height:1.3;cursor:pointer}
#library .library-filter-button:hover{border-color:var(--mint);background:#1d3e53}
#library .library-filter-button svg{width:18px;height:18px;flex:none;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
#library #libraryFilterCount{display:grid;place-items:center;min-width:22px;min-height:22px;padding:1px 5px;border-radius:999px;background:var(--mint);color:#05221c;font-size:12px;font-weight:800}

#library .library-browse-row{display:flex;align-items:flex-start;gap:12px;margin:0 0 8px;min-width:0}
#library .library-subjects{display:flex;align-items:flex-start;flex:1;gap:10px;min-width:0}
#library .library-control-label{display:flex;align-items:center;flex:none;min-height:48px;margin:0;color:#9eb9ca;font-size:12px;font-weight:700;line-height:1.3}
#library #categoryRow.library-subject-chips{display:flex;flex-wrap:wrap;align-items:center;gap:6px;min-width:0;margin:0;padding:0;overflow:visible;mask-image:none;-webkit-mask-image:none}
#library .library-subject-chips button{display:inline-flex;align-items:center;justify-content:center;min-height:48px;padding:8px 10px;border:1px solid #36576f;border-radius:11px;background:#102739;color:#c3d8e5;font:inherit;font-size:12px;font-weight:650;line-height:1.3;white-space:normal;text-align:center;cursor:pointer;box-shadow:none;transform:none}
#library .library-subject-chips button:hover{border-color:#7da0b8;background:#17354b;transform:none}
#library .library-subject-chips button[aria-pressed="true"]{border-color:var(--mint);background:#56d9c01c;color:#8becd9;font-weight:800;box-shadow:inset 0 -2px var(--mint)}
#library .library-subject-mobile{display:none}
#library .library-saved{display:inline-flex;align-items:center;justify-content:center;flex:none;gap:7px;min-height:48px;padding:9px 11px;border:1px solid #4b6171;border-radius:11px;background:#112a3c;color:#ccdeea;font:inherit;font-size:12px;font-weight:750;line-height:1.3;cursor:pointer}
#library .library-saved svg{width:17px;height:17px;flex:none;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linejoin:round}
#library .library-saved[aria-pressed="true"]{color:var(--gold);border-color:#ffd16699;background:#ffd16612}
#library .library-saved[aria-pressed="true"] svg{fill:currentColor}
#library #savedCount{font-size:11px;color:#a8c2d3}

#library .library-order-row{display:flex;align-items:center;justify-content:space-between;gap:8px 20px;margin:0 0 8px;min-width:0}
#library .library-sort-options{display:flex;flex-wrap:wrap;align-items:stretch;gap:3px;max-width:100%;padding:3px;border:1px solid #33566e;border-radius:12px;background:#091d2c}
#library .library-sort-options button{display:inline-flex;align-items:center;justify-content:center;min-height:48px;padding:8px 14px;border:1px solid transparent;border-radius:8px;background:transparent;color:#a9c3d4;font:inherit;font-size:13px;font-weight:700;line-height:1.3;text-align:center;cursor:pointer}
#library .library-sort-options button:hover{color:var(--ink);background:#173348}
#library .library-sort-options button[aria-pressed="true"]{color:#e7f7ff;background:#1b3b51;border-color:#4d738c;box-shadow:0 2px 6px #0002}
#library .library-curriculum-controls{display:flex;align-items:center;justify-content:flex-end;flex-wrap:wrap;gap:8px 16px;min-width:0}
#library .library-class{display:flex;align-items:center;gap:9px;min-width:0;color:#b8d1df;font-size:12px;font-weight:650;line-height:1.45}
#library .library-class select{min-height:48px;min-width:120px;max-width:100%;padding:9px 12px;border:1px solid #4b6a80;border-radius:11px;background:#112a3c;color:#e7f7ff;font:inherit;font-size:14px;cursor:pointer;color-scheme:dark}
#library .library-class select:focus-visible{outline:3px solid var(--mint);outline-offset:3px}
#library .curriculum-grade-pill{font-size:11px}
#library .curriculum-enrichment-pill{font-size:11px;color:#b9c4f2;border-color:#7d89c855}
#library .library-syllabus{display:flex;align-items:center;gap:9px;min-width:0;margin:0;color:#b8d1df;font-size:12px;font-weight:650;line-height:1.45}
#library .library-syllabus select{min-width:0;max-width:100%;min-height:48px;padding:9px 12px;border:1px solid #4b6a80;border-radius:11px;background:#112a3c;color:#e7f7ff;font:inherit;font-size:14px;cursor:pointer;color-scheme:dark}
#library .library-syllabus select:focus-visible{outline:3px solid var(--mint);outline-offset:3px}
#library .library-curriculum-note{margin:0 0 12px;color:#9cb7c9;font-size:12px;line-height:1.5}
#library .library-curriculum-note a{display:inline-flex;align-items:center;min-height:44px;color:#8becd9;text-underline-offset:3px}
#library .library-curriculum-note a:focus-visible{outline:3px solid var(--mint);outline-offset:3px}
#library .library-result-row{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:4px 16px;margin:0 0 12px;min-height:24px}
#library #resultCount{margin:0;padding:0;color:#b8d1df;font-size:13px;line-height:1.45;text-align:left;max-width:none}
#library #resultCount:before{content:none}
#library .library-clear{display:inline-flex;align-items:center;justify-content:center;min-height:48px;padding:8px 10px;border:0;border-radius:9px;background:transparent;color:var(--mint);font:inherit;font-size:13px;font-weight:750;line-height:1.3;text-decoration:underline;text-underline-offset:4px;cursor:pointer}
#library .library-clear:hover{background:#56d9c012}
#library .library-active-filters{display:flex;flex-wrap:wrap;gap:6px;margin:0 0 14px;min-width:0}
#library .library-active-filters:empty{display:none}
#library .library-active-chip{display:inline-flex;align-items:center;justify-content:space-between;gap:9px;min-width:0;max-width:100%;min-height:48px;padding:9px 12px;border:1px solid #53718a;border-radius:11px;background:#163246;color:#d6e7f2;font:inherit;font-size:12px;font-weight:650;line-height:1.4;overflow-wrap:anywhere;text-align:left;cursor:pointer}
#library .library-active-chip:hover{border-color:var(--mint)}

/* Library cards preserve the title and learning topic at every text size. */
#library .game-grid{gap:18px;align-items:stretch}
#library .library-card{border-radius:18px;box-shadow:none}
#library .library-card:hover{transform:none;border-color:#6c92ab;box-shadow:0 7px 20px #0003}
#library .library-card .cover-link{aspect-ratio:16/9}
#library .library-card .game-body{padding:16px;min-width:0}
#library .library-card .card-meta{gap:5px 8px;margin-bottom:10px}
#library .library-card .card-meta:empty{display:none}
#library .library-card .category-pill{font-size:11px;line-height:1.35;padding:3px 7px}
#library .library-card .plays-pill,#library .library-card .rating-pill{padding:0;border:0;background:none;color:#a6c0d1;font-size:11px;line-height:1.4}
#library .library-card h3{margin:0 0 8px;font-size:18px;line-height:1.3;letter-spacing:-.015em;overflow-wrap:anywhere}
#library .library-card .description{margin:0 0 10px;color:#c3d7e4;font-size:14px;line-height:1.5;overflow-wrap:anywhere}
#library .library-card .focus{margin:0 0 16px;color:#a3bed0;font-size:12px;line-height:1.5;overflow-wrap:anywhere}
#library .library-card .focus:before{content:"Topic: ";color:#bbd0de;font-weight:700}
#library .library-card .playstyle{margin:0 0 7px;color:var(--mint);font-size:12px;font-weight:700;line-height:1.4}
#library .library-card .card-actions{display:grid;grid-template-columns:minmax(0,1fr) 48px;align-items:stretch;gap:8px;margin-top:auto}
#library .library-card--preview .card-actions{grid-template-columns:minmax(0,1fr) minmax(0,1fr) 48px}
#library .library-card .play-button,#library .library-card .gameplay-preview-button{display:flex;align-items:center;justify-content:center;min-height:48px;padding:10px 8px;border:1px solid transparent;border-radius:10px;font:inherit;font-size:13px;font-weight:800;line-height:1.3;text-align:center;overflow-wrap:break-word}
#library .library-card .play-button{background:var(--mint);color:#05211c}
#library .library-card .gameplay-preview-button{color:#d9eaf4;background:#163347;border-color:#496a80;cursor:pointer}
#library .library-card .gameplay-preview-button:hover{border-color:var(--mint);background:#1b4057}
#library .library-card .favorite-button{display:grid;place-items:center;width:48px;height:48px;min-height:48px;margin:0;padding:0;border-color:#47667c;font-size:20px}
#library .library-card .play-mark{width:34px;height:34px;right:10px;bottom:10px;font-size:13px}

#library .library-empty{padding:32px 20px;border:1px dashed #4c6b7e;border-radius:18px;text-align:center;background:#0b2031;color:#b7cedc}
#library .library-empty h3{margin:0 0 9px;color:var(--ink);font-size:22px;line-height:1.3}
#library .library-empty p{max-width:52ch;margin:0 auto;color:#b7cedc;font-size:15px;line-height:1.55}
#library .library-empty-actions{display:flex;flex-wrap:wrap;justify-content:center;gap:10px;margin-top:18px}
#library .library-empty-actions button{display:inline-flex;align-items:center;justify-content:center;min-height:48px;padding:11px 17px;border:1px solid #4c6e86;border-radius:11px;background:#17384f;color:var(--ink);font:inherit;font-size:14px;font-weight:750;line-height:1.4;cursor:pointer}
#library :is(button,a,select,input):focus-visible{outline:3px solid var(--mint);outline-offset:3px}
#library .library-search input:focus-visible{outline:none}
#library .library-card .cover-link:focus-visible{outline-offset:-4px}
#library [hidden]{display:none!important}

/* Native dialogs supply the focus boundary, Escape and an inert background. */
:is(.library-filter-dialog,.library-choice-dialog){width:min(600px,calc(100% - 32px));max-width:600px;max-height:90dvh;margin:auto;padding:0;border:1px solid #4b6e85;border-radius:22px;background:var(--panel);color:var(--ink);box-shadow:0 24px 90px #000a;overflow:auto;overscroll-behavior:contain}
:is(.library-filter-dialog,.library-choice-dialog):not([open]){display:none}
:is(.library-filter-dialog,.library-choice-dialog)::backdrop{background:#020b14c7;backdrop-filter:blur(5px)}
:is(.library-filter-dialog,.library-choice-dialog) .library-dialog-header{position:sticky;top:0;z-index:2;display:flex;align-items:center;justify-content:space-between;gap:16px;padding:14px 18px;border-bottom:1px solid var(--line);background:var(--panel)}
:is(.library-filter-dialog,.library-choice-dialog) .library-dialog-header h2{min-width:0;margin:0;font-size:23px;line-height:1.3;letter-spacing:-.02em;overflow-wrap:anywhere}
:is(.library-filter-dialog,.library-choice-dialog) .library-dialog-close{display:flex;align-items:center;justify-content:center;flex:0 0 48px;width:48px;height:48px;padding:0;border:1px solid #4a6d83;border-radius:11px;background:#163347;color:var(--ink);font:inherit;font-size:25px;line-height:1;cursor:pointer}
.library-filter-fields{display:grid;gap:18px;padding:18px}
.library-filter-fields .library-field{display:grid;gap:7px;min-width:0;margin:0;color:#dceaf2;font-size:14px;font-weight:700;line-height:1.4}
.library-filter-fields .library-field :is(input,select){display:block;width:100%;min-width:0;min-height:48px;margin:0;padding:11px 12px;border:1px solid #4b6d84;border-radius:11px;background:#091d2c;color:var(--ink);font:inherit;font-size:16px;font-weight:500;line-height:1.4}
.library-filter-fields .library-field small{color:#a7c0d1;font-size:12px;font-weight:400;line-height:1.5}
.library-filter-fields .library-field option{background:#0c2132;color:var(--ink)}
.library-filter-fields>.library-control-label{margin:0;color:#a7c0d1;font-size:12px;font-weight:700;line-height:1.4}
.library-selected-topic{margin:0;color:#c1d7e5;font-size:13px;line-height:1.5;overflow-wrap:anywhere}
.library-topic-options{max-height:280px;padding:5px;border:1px solid #3d5e75;border-radius:12px;background:#091d2c;overflow:auto;overscroll-behavior:contain}
.library-topic-option{display:flex;align-items:flex-start;gap:11px;min-height:48px;margin:0;padding:11px 9px;border:1px solid transparent;border-radius:8px;color:#c7deeb;font-size:14px;line-height:1.5;overflow-wrap:anywhere;cursor:pointer}
.library-topic-option:hover{background:#18384f}
.library-topic-option:has(input:checked){background:#193c50;border-color:#56d9c055;color:#e5f8f3}
.library-topic-option input{flex:0 0 20px;width:20px;height:20px;margin:1px 0 0;accent-color:var(--mint);cursor:pointer}
.library-topic-status{margin:0;color:#aac4d5;font-size:13px;line-height:1.5}
:is(.library-filter-dialog,.library-choice-dialog) .library-dialog-actions{position:sticky;bottom:0;z-index:2;display:flex;align-items:stretch;justify-content:space-between;gap:12px;margin:0;padding:14px 18px calc(14px + env(safe-area-inset-bottom,0px));border-top:1px solid var(--line);background:var(--panel)}
:is(.library-action-primary,.library-action-secondary){display:inline-flex;align-items:center;justify-content:center;min-width:0;min-height:48px;padding:11px 17px;border:1px solid transparent;border-radius:11px;font:inherit;font-size:14px;font-weight:800;line-height:1.4;text-align:center;overflow-wrap:anywhere;cursor:pointer}
.library-action-primary{flex:1;background:var(--mint);color:#05211c}
.library-action-primary:hover{background:#7be6d1}
.library-action-secondary{background:#153247;color:#d1e6f2;border-color:#496b82}
.library-action-secondary:hover{border-color:var(--mint);background:#1c4057}
.library-choice-dialog figure{margin:0;background:#071522}
.library-choice-dialog #choiceImage{display:block;width:100%;height:auto;max-height:300px;aspect-ratio:16/9;object-fit:cover;background:#071522}
.library-choice-dialog figcaption{padding:7px 18px;color:#a4bdce;font-size:12px;line-height:1.4}
.library-choice-body{padding:18px}
.library-choice-body p{margin:0 0 12px;color:#c1d8e6;font-size:15px;line-height:1.55;overflow-wrap:anywhere}
.library-choice-body p:last-child{margin-bottom:0}
.library-choice-body #choiceContext{color:#94b4c8;font-size:12px}
.library-choice-body #choiceTopic{color:#a9c8d9;font-size:13px}
:is(.library-filter-dialog,.library-choice-dialog) :is(button,a,input,select):focus-visible{outline:3px solid var(--mint);outline-offset:3px}
:is(.library-filter-dialog,.library-choice-dialog) [hidden]{display:none!important}

@media(max-width:1100px) and (min-width:701px){
  #library .game-grid{grid-template-columns:repeat(2,minmax(0,1fr))}
}
@media(max-width:1000px){
  #library .library-subjects{display:none}
  #library .library-subject-mobile{display:flex;align-items:center;flex:1;gap:9px;min-width:0;min-height:48px;padding:0 11px;border:1px solid #42637a;border-radius:11px;background:#0d2537;color:#a7c0d1;font-size:12px;font-weight:700;line-height:1.4}
  #library .library-subject-mobile select{flex:1;min-width:0;width:100%;min-height:48px;margin:0;padding:6px 3px;border:0;outline:0;background:transparent;color:var(--ink);font:inherit;font-size:14px;font-weight:700}
  #library .library-subject-mobile option{background:var(--panel);color:var(--ink)}
}
@media(max-width:700px){
  #library.library-finder{padding-top:36px;scroll-margin-top:16px}
  #library .library-heading{align-items:center;gap:10px;margin-bottom:12px}
  #library .library-heading-title{display:grid;gap:3px}
  #library .library-heading h2{font-size:28px;line-height:1.2}
  #library .library-total{font-size:12px;line-height:1.4}
  #library .library-pick{flex:0 1 118px;min-height:48px;padding:8px 9px;font-size:12px}
  #library .library-search-row{position:static;grid-template-columns:minmax(0,1fr) auto;gap:8px;margin-bottom:10px;padding:0;background:none;box-shadow:none;border-radius:0}
  #library .library-search{height:50px;gap:8px;padding-left:11px}
  #library .library-search svg{width:18px;height:18px;flex-basis:18px}
  #library .library-search kbd{display:none}
  #library .library-filter-button{gap:6px;padding:9px 11px;font-size:13px}
  #library .library-filter-button svg{width:17px;height:17px}
  #library .library-browse-row{align-items:stretch;gap:8px;margin-bottom:8px}
  #library .library-subject-mobile{gap:7px;padding-inline:10px}
  #library .library-subject-mobile select{font-size:14px}
  #library .library-saved{gap:6px;padding:9px 10px;font-size:12px}
  #library .library-order-row{align-items:stretch;flex-direction:column;gap:4px;margin-bottom:8px}
  #library .library-sort-options{display:flex;flex-wrap:nowrap;width:100%;gap:2px;padding:2px;border-radius:11px}
  #library .library-sort-options button{flex:1;min-width:0;min-height:48px;padding:6px 7px;font-size:12px;line-height:1.3}
  #library .library-curriculum-controls{width:100%;justify-content:space-between;gap:8px}
  #library .library-class,#library .library-syllabus{font-size:12px;line-height:1.5;margin-top:5px}
  #library .library-class select,#library .library-syllabus select{flex:1;min-width:0;font-size:16px}
  #library .library-result-row{margin-bottom:12px;gap:4px 8px;min-height:20px}
  #library #resultCount{font-size:12px}
  #library .library-clear{font-size:12px}
  #library .library-active-filters{margin-bottom:12px}
  #library .game-grid{grid-template-columns:minmax(0,1fr);gap:14px}
  #library .library-card .game-body{padding:16px}
  #library .library-card h3{font-size:18px}
  #library .library-card .description{font-size:14px}
  #library .library-card .focus{font-size:13px}
  :is(.library-filter-dialog,.library-choice-dialog){position:fixed;inset:auto 0 0;width:100%;max-width:none;max-height:94dvh;margin:0 auto;border-width:1px 0 0;border-radius:22px 22px 0 0}
  :is(.library-filter-dialog,.library-choice-dialog) .library-dialog-header{padding:12px 16px}
  :is(.library-filter-dialog,.library-choice-dialog) .library-dialog-header h2{font-size:21px}
  .library-filter-fields{gap:16px;padding:16px}
  .library-topic-options{max-height:240px}
  :is(.library-filter-dialog,.library-choice-dialog) .library-dialog-actions{gap:9px;padding-inline:16px}
  :is(.library-action-primary,.library-action-secondary){padding-inline:12px;font-size:13px}
  .library-choice-body{padding:16px}
  .library-choice-dialog figcaption{padding-inline:16px}
  #library .library-empty{padding:26px 16px}
}
@media(min-width:560px) and (max-width:700px){#library .game-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media(max-width:360px){
  #library .library-heading h2{font-size:26px}
  #library .library-pick{flex-basis:108px;padding-inline:8px}
  #library .library-search{padding-left:9px;gap:6px}
  #library .library-filter-button{padding-inline:9px}
  #library .library-filter-button svg{display:none}
  #library .library-subject-mobile>span{font-size:11px}
  #library .library-saved{padding-inline:8px}
  #library .library-card .game-body{padding:14px}
}
@media(prefers-reduced-motion:reduce){
  #library .library-card,#library .library-card .game-cover{transition:none}
  #library .library-card:hover .game-cover{transform:none}
}
@media(forced-colors:active){
  #library :is(.library-search,.library-filter-button,.library-subject-mobile,.library-saved,.library-sort-options,.library-sort-options button,.library-subject-chips button,.library-active-chip,.library-card,.library-empty),:is(.library-filter-dialog,.library-choice-dialog),.library-topic-options,.library-topic-option{border-color:CanvasText}
  #library :is(.library-subject-chips button,.library-sort-options button)[aria-pressed="true"],#library .library-saved[aria-pressed="true"]{border-color:Highlight;outline:2px solid Highlight;outline-offset:-3px}
  #library :is(button,a,select,input):focus-visible,:is(.library-filter-dialog,.library-choice-dialog) :is(button,a,input,select):focus-visible{outline-color:Highlight}
  #library .library-search input:focus-visible{outline:2px solid Highlight;outline-offset:-2px}
}
@media print{#library .library-search-row{position:static}:is(.library-filter-dialog,.library-choice-dialog){display:none!important}}

/* Play modes combine with the existing subject, search and saved controls. */
.library-play-modes{display:flex;gap:8px;flex-wrap:wrap;margin:14px 0 8px}
.library-play-modes button{display:inline-flex;align-items:center;justify-content:center;gap:7px;min-height:44px;padding:9px 16px;border:1px solid #345569;border-radius:999px;background:#102638;color:#c8deec;font:inherit;font-size:14px;font-weight:700;cursor:pointer}
.library-play-modes button:hover{border-color:#69dcc7;color:#efffff}
.library-play-modes button[aria-pressed="true"]{background:#74e7ce;border-color:#74e7ce;color:#062d31}
.library-play-modes button:focus-visible{outline:3px solid #ffcb5b;outline-offset:3px}
.library-play-modes [data-play-mode-count]{font-size:11px;min-width:18px;line-height:18px;border-radius:20px;background:rgba(0,0,0,.15);color:inherit;text-align:center}
.library-play-modes [data-play-mode-count]:empty{display:none}
@media(max-width:600px){.library-play-modes{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px;margin:12px 0 8px}.library-play-modes button{padding:8px 6px;font-size:12px;gap:5px;white-space:nowrap;min-width:0}}


@media(max-width:390px){#library .library-curriculum-controls{flex-direction:column;align-items:stretch}#library .library-class,#library .library-syllabus{width:100%}}
