/* Library — full-screen deck and card browser (src/library.ts, docs/UI-OVERHAUL-PLAN-16.md task C).
   Desktop: deck rail | card grid (title, filters + cost curve, cards) | the chosen card, all at once.
   Phones in landscape (height ≤500) and narrow windows (<1100): crest strip | grid; the filters fold
   behind one button and the card panel slides over from the right.
   Spacing follows home.css (--s1..--s7): tighter inside a group than around it.
   Unlayered on purpose: it sits above the legacy/card/board layers that also style .hand-card etc. */

.library{
  /* shared tokens (--s1..--s7, gold, text, --ink) come from public/tokens.css; the two Library differences stay here */
  --line:var(--line-soft);--tap:44px;--deck:#c9a45c;
  --rail:240px;--detail:372px;--card-min:128px;--pad:var(--s5);
  position:fixed;inset:0;z-index:35;isolation:isolate;overflow:hidden;
  display:grid;grid-template-columns:var(--rail) minmax(0,1fr) var(--detail);
  color:var(--text);background:#08111a;
  font:500 15px/1.55 'Kanit','Leelawadee UI',Tahoma,sans-serif;
  word-break:keep-all;overflow-wrap:anywhere;
  animation:lib-in .18s ease-out;
}
.library[hidden]{display:none}
@keyframes lib-in{from{opacity:0}}
.library :where(button){font:inherit;color:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent}
.library :where(button,input):focus-visible{outline:2px solid var(--gold-1);outline-offset:2px}
.library :where(h2,h3,p){margin:0}
.library .oc-icon{flex:none;display:block}

/* the Home scene, pushed far back so the cards carry the screen */
.lib-art{position:absolute;inset:0;z-index:-1;pointer-events:none;
  background:
    radial-gradient(90% 70% at 55% 0%,color-mix(in srgb,var(--deck) 16%,transparent),transparent 70%),
    linear-gradient(180deg,#07101ae6,#07101af2 40%,#050a11fa),
    image-set(url('assets/bg-home-s.webp') type('image/webp'),url('assets/bg.jpg') type('image/jpeg')) 55% 40%/cover no-repeat}

/* ---------- left: decks ---------- */
.lib-rail{display:flex;flex-direction:column;gap:var(--s4);min-height:0;padding:var(--s4) var(--s3) var(--s4) var(--s4);
  background:linear-gradient(180deg,#0a131df2,#08101ae6);border-right:1px solid var(--line);overflow-y:auto;scrollbar-width:none}
.lib-rail::-webkit-scrollbar{display:none}
.lib-rail-head{display:flex;align-items:center;gap:var(--s2);min-height:48px}
.lib-back{display:grid;place-items:center;flex:none;width:48px;height:48px;padding:0;border:1px solid var(--line);border-radius:50%;background:var(--ink);color:var(--gold-1)}
.lib-back .oc-icon{width:22px;height:22px}
.lib-back:hover{background:#ffffff12;border-color:#e2c58966}
.lib-rail-title{font:700 20px/1.25 'Taviraj',Georgia,serif;color:#fff4dc;letter-spacing:.02em}
.lib-decks{display:flex;flex-direction:column;gap:var(--s1)}
.lib-deck{position:relative;display:grid;grid-template-columns:48px minmax(0,1fr);align-items:center;gap:var(--s3);min-height:64px;padding:var(--s2) var(--s2) var(--s2) var(--s2);
  border:1px solid transparent;border-radius:12px;background:none;text-align:left;color:var(--text-dim);transition:background .15s,border-color .15s}
.lib-deck:hover{background:#ffffff0a;color:var(--text)}
.lib-deck.active{color:var(--text);border-color:color-mix(in srgb,var(--deck) 55%,transparent);
  background:linear-gradient(90deg,color-mix(in srgb,var(--deck) 26%,transparent),color-mix(in srgb,var(--deck) 6%,transparent))}
.lib-deck.active::before{content:'';position:absolute;left:-1px;top:14px;bottom:14px;width:3px;border-radius:2px;background:var(--deck);box-shadow:0 0 10px var(--deck)}
.lib-crest{position:relative;isolation:isolate;display:grid;place-items:center;width:48px;height:48px;color:#fff}
.lib-crest::before{content:'';position:absolute;inset:0;z-index:-1;clip-path:polygon(50% 0,96% 25%,96% 75%,50% 100%,4% 75%,4% 25%);
  background:linear-gradient(170deg,color-mix(in srgb,var(--deck) 70%,#fff) 0%,var(--deck) 42%,color-mix(in srgb,var(--deck) 45%,#000) 100%)}
.lib-crest .oc-icon{width:26px;height:26px;filter:drop-shadow(0 1px 1px #0008)}
.lib-deck:not(.active) .lib-crest{filter:saturate(.55) brightness(.78)}
.lib-deck:not(.active):hover .lib-crest{filter:saturate(.8) brightness(.92)}
.lib-deck.all{--deck:#c9a45c}
.lib-deck.all .lib-crest::before{background:linear-gradient(170deg,#3b4a5c,#1b2633)}
.lib-deck.all .lib-crest{color:var(--gold-1)}
.lib-deck.all.active .lib-crest::before{background:linear-gradient(170deg,var(--gold-1),var(--gold-2) 45%,var(--gold-3))}
.lib-deck.all.active .lib-crest{color:#2c1a05}
.lib-using{position:absolute;right:-5px;bottom:-3px;display:grid;place-items:center;width:20px;height:20px;border-radius:50%;
  color:#2c1a05;background:linear-gradient(180deg,var(--gold-1),var(--gold-2));box-shadow:0 0 0 2px #0a131d,0 0 10px #e2b053aa}
.lib-using .oc-icon{width:13px;height:13px}
.lib-deck-copy{display:flex;flex-direction:column;min-width:0}
.lib-deck-copy strong{font:700 17px/1.3 'Taviraj',Georgia,serif;color:inherit;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.lib-deck.active .lib-deck-copy strong{color:#fff4dc}
.lib-deck-copy small{font-size:12.5px;line-height:1.3;color:var(--text-faint)}
.lib-deck-copy small b{font-weight:600;color:var(--gold-1)}
.lib-rail-rule{height:1px;margin:var(--s2) var(--s2);background:var(--line)}

/* ---------- centre: title, tools, grid ---------- */
.lib-main{position:relative;display:flex;flex-direction:column;gap:var(--s4);min-width:0;min-height:0;padding:var(--pad) var(--pad) 0}
.lib-head{display:flex;align-items:center;justify-content:space-between;gap:var(--s5);min-height:64px}
.lib-title{display:flex;align-items:center;gap:var(--s4);min-width:0}
.lib-head-crest{position:relative;isolation:isolate;display:grid;place-items:center;flex:none;width:64px;height:64px;color:#fff;filter:drop-shadow(0 6px 14px #0009)}
.lib-head-crest::before{content:'';position:absolute;inset:0;z-index:-1;clip-path:polygon(50% 0,96% 25%,96% 75%,50% 100%,4% 75%,4% 25%);
  background:linear-gradient(170deg,color-mix(in srgb,var(--deck) 70%,#fff),var(--deck) 42%,color-mix(in srgb,var(--deck) 45%,#000))}
.lib-head-crest .oc-icon{width:34px;height:34px;filter:drop-shadow(0 1px 1px #0008)}
.lib-head-crest.all::before{background:linear-gradient(170deg,var(--gold-1),var(--gold-2) 45%,var(--gold-3))}
.lib-head-crest.all{color:#2c1a05}
.lib-title-copy{display:flex;flex-direction:column;min-width:0}
.lib-kicker{font:600 12px/1.3 'Kanit',sans-serif;letter-spacing:.14em;text-transform:uppercase;color:color-mix(in srgb,var(--deck) 55%,var(--gold-1))}
.lib-title h2{margin-top:2px;font:700 30px/1.25 'Taviraj',Georgia,serif;color:#fff4dc;text-shadow:0 2px 12px #000a}
.lib-desc{margin-top:var(--s1);font-size:14px;line-height:1.55;color:var(--text-dim);max-width:60ch}
.lib-actions{display:flex;align-items:center;gap:var(--s2);flex:none}
.lib-use{--cut:14px;display:inline-flex;align-items:center;justify-content:center;gap:var(--s2);height:48px;min-width:156px;padding:0 var(--s5);border:0;
  clip-path:polygon(var(--cut) 0,calc(100% - var(--cut)) 0,100% 50%,calc(100% - var(--cut)) 100%,var(--cut) 100%,0 50%);
  background:linear-gradient(180deg,var(--gold-1),var(--gold-2) 52%,var(--gold-3));color:#2c1a05;font-weight:700;font-size:16px;line-height:1.25;filter:drop-shadow(0 6px 14px #000a)}
.lib-use .oc-icon{width:20px;height:20px}
button.lib-use:hover{background:linear-gradient(180deg,#fff1c8,#ecbe62 52%,#ab7128)}
.lib-use.is-using{background:linear-gradient(180deg,#e2b0532e,#e2b05314);color:var(--gold-1);filter:none;box-shadow:inset 0 0 0 1px #e2b05366;cursor:default}
.lib-edit{display:inline-flex;align-items:center;gap:var(--s2);height:48px;padding:0 var(--s4);border:1px solid var(--line);border-radius:10px;background:#ffffff06;color:var(--text-faint);font-size:15px;line-height:1.25;font-weight:600}
.lib-edit .oc-icon{width:18px;height:18px}
.lib-edit:hover{color:var(--text-dim);background:#ffffff0c}
.lib-filter-toggle{display:none;position:relative;place-items:center;width:var(--tap);height:var(--tap);padding:0;border:1px solid var(--line);border-radius:50%;background:var(--ink);color:var(--gold-1)}
.lib-filter-toggle .oc-icon{width:20px;height:20px}
.lib-dot{position:absolute;top:6px;right:6px;width:9px;height:9px;border-radius:50%;background:var(--gold-2);box-shadow:0 0 0 2px #0a131d,0 0 8px var(--gold-2);opacity:0}
.lib-filter-toggle.on .lib-dot{opacity:1}
.library.filters-open .lib-filter-toggle{background:#e2b05330;border-color:var(--gold-2)}

/* tools: type chips (with the deck's counts) · cost curve (tap a bar to filter) · search */
.lib-tools{display:flex;flex-wrap:wrap;align-items:center;gap:var(--s2) var(--s5);padding:var(--s2) var(--s3);border:1px solid var(--line);border-radius:14px;background:var(--ink);box-shadow:0 8px 22px #0006}
.lib-types{display:flex;flex-wrap:nowrap;gap:var(--s1)}
.lib-chip{display:inline-flex;align-items:center;gap:var(--s1);height:var(--tap);padding:0 var(--s3) 0 var(--s2);border:1px solid transparent;border-radius:10px;background:none;color:var(--text-dim);font-size:14px;line-height:1.25;white-space:nowrap}
.lib-chip .oc-icon{width:18px;height:18px;color:var(--text-faint)}
.lib-chip b{margin-left:2px;min-width:2ch;font:600 12.5px/1 'Kanit',sans-serif;font-variant-numeric:tabular-nums;color:var(--text-faint)}
.lib-chip:hover:not(:disabled){background:#ffffff0c;color:var(--text)}
.lib-chip.active{border-color:#e2b05399;background:linear-gradient(180deg,#e2b05338,#e2b05314);color:var(--gold-1)}
.lib-chip.active .oc-icon,.lib-chip.active b{color:var(--gold-1)}
.lib-chip:disabled{opacity:.35;cursor:default}
.lib-curve{display:flex;align-items:stretch;gap:2px;height:60px;padding-left:var(--s4);border-left:1px solid var(--line)}
.lib-curve-label{display:grid;place-items:center;margin-right:var(--s2);color:var(--text-faint)}
.lib-curve-label .oc-icon{width:16px;height:16px}
.lib-bar{display:grid;grid-template-rows:13px minmax(0,1fr) 15px;justify-items:center;width:30px;padding:2px 0;border:0;border-radius:6px;background:none;color:var(--text-faint)}
.lib-bar:hover:not(:disabled){background:#ffffff0c}
.lib-bar-n{font:600 10.5px/13px 'Kanit',sans-serif;font-variant-numeric:tabular-nums;color:var(--text-faint)}
.lib-bar-fill{align-self:end;width:14px;height:var(--h);min-height:2px;border-radius:2px 2px 0 0;background:linear-gradient(180deg,#e2b053d0,#9c642099)}
.lib-bar-x{font:600 12px/15px 'Kanit',sans-serif;color:var(--text-dim)}
.lib-bar.empty .lib-bar-fill{background:#ffffff1a}
.lib-bar:disabled{cursor:default}
.lib-curve:has(.lib-bar.active) .lib-bar:not(.active) .lib-bar-fill{opacity:.35}
.lib-bar.active{background:#e2b05322}
.lib-bar.active .lib-bar-fill{background:linear-gradient(180deg,var(--gold-1),var(--gold-2));box-shadow:0 0 10px #e2b05388}
.lib-bar.active .lib-bar-x,.lib-bar.active .lib-bar-n{color:var(--gold-1)}
.lib-search{display:flex;align-items:center;gap:var(--s2);flex:1 1 160px;min-width:120px;max-width:320px;height:var(--tap);margin-left:auto;padding:0 var(--s3);border:1px solid var(--line);border-radius:22px;background:#ffffff08;color:var(--text-faint)}
.lib-search:focus-within{border-color:#e2c589a0;background:#ffffff0e}
.lib-search .oc-icon{width:18px;height:18px}
.lib-search input{flex:1;min-width:0;height:100%;padding:0;border:0;outline:0;background:none;color:var(--text);font:500 15px/1.4 'Kanit',sans-serif}
.lib-search input::placeholder{color:var(--text-faint)}
.lib-search input::-webkit-search-cancel-button{filter:invert(.7) sepia(1)}

/* the grid: real cards, many at once, the count of copies on each */
.library .lib-grid{all:unset;box-sizing:border-box;flex:1 1 auto;min-height:0;overflow-y:auto;overscroll-behavior:contain;
  display:grid;grid-template-columns:repeat(auto-fill,minmax(var(--card-min),1fr));align-content:start;gap:var(--s4) var(--s3);
  margin:0 calc(-1 * var(--s2));padding:var(--s2) var(--s2) var(--s5);scrollbar-width:thin;scrollbar-color:#e2c58955 transparent}
.library .lib-card{all:unset;box-sizing:border-box;position:relative;display:block;cursor:pointer;border-radius:8px;transition:transform .15s ease;-webkit-tap-highlight-color:transparent}
.library .lib-card:focus-visible{outline:2px solid var(--gold-1);outline-offset:3px}
.lib-face{display:block}
.lib-name{display:block;margin-top:var(--s1);padding:0 2px;font-size:13px;line-height:1.35;color:var(--text-dim);text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.library .lib-card.selected .lib-name{color:var(--gold-1)}
.lib-face .illustrated-card{width:100%;filter:brightness(.9) drop-shadow(0 8px 12px #000b)}
.library .lib-card:hover{transform:translateY(-3px)}
.library .lib-card:hover .illustrated-card{filter:brightness(1) drop-shadow(0 12px 16px #000c)}
.library .lib-card.selected .illustrated-card{filter:brightness(1.04) drop-shadow(0 0 1px #fffbe9) drop-shadow(0 0 3px #ffd27a) drop-shadow(0 0 7px var(--gold-2))}
.library .copy-count{all:unset;position:absolute;z-index:6;top:-6px;right:-6px;display:grid;place-items:center;min-width:34px;height:24px;padding:0 6px;box-sizing:border-box;
  font:700 13px/1 'Kanit',sans-serif;font-variant-numeric:tabular-nums;color:#2c1a05;
  clip-path:polygon(7px 0,calc(100% - 7px) 0,100% 50%,calc(100% - 7px) 100%,7px 100%,0 50%);
  background:linear-gradient(180deg,var(--gold-1),var(--gold-2) 55%,var(--gold-3))}
/* copies the player owns (account collection): a quiet mark on the art, under the deck count */
.library .lib-owned{position:absolute;z-index:6;left:9%;bottom:15%;display:inline-flex;align-items:center;gap:2px;height:20px;padding:0 6px 0 4px;border-radius:var(--r-pill);
  font:700 var(--fs-xs)/1 var(--font-ui);font-variant-numeric:tabular-nums;color:var(--text);background:#0b141ee0;box-shadow:inset 0 0 0 1px var(--line)}
.library .lib-owned .oc-icon{width:12px;height:12px;color:var(--gold-1)}
.lib-empty{grid-column:1/-1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:var(--s3);min-height:240px;color:var(--text-faint)}
.lib-empty .lib-empty-icon{width:40px;height:40px;color:#e2c58955}
.lib-empty p{font-size:16px;line-height:1.55}
.lib-clear{height:var(--tap);padding:0 var(--s5);border:1px solid var(--gold-2);border-radius:10px;background:#2a1c0899;color:var(--gold-1);font-weight:600}

/* ---------- right: the chosen card ---------- */
.lib-detail{position:relative;display:flex;flex-direction:column;min-height:0;border-left:1px solid var(--line);
  background:linear-gradient(180deg,#0d1824f5,#08111af5)}
.lib-detail-scroll{flex:1;min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:var(--pad) var(--pad) var(--s6);scrollbar-width:thin;scrollbar-color:#e2c58955 transparent}
.lib-detail-card{width:min(100%,calc(32*var(--xvh,1dvh)),340px);margin:0 auto}
.lib-detail-card .illustrated-card{width:100%;filter:drop-shadow(0 16px 26px #000c)}
.lib-detail-body{display:flex;flex-direction:column;gap:var(--s4);margin-top:var(--s5)}
.lib-detail-head{display:flex;flex-direction:column;gap:2px}
.lib-detail-deck{display:inline-flex;align-items:center;gap:var(--s1);font-size:13px;line-height:1.3;font-weight:600;color:color-mix(in srgb,var(--deck) 60%,#fff)}
.lib-detail-deck .oc-icon{width:16px;height:16px}
.lib-detail-head h3{font:700 24px/1.3 'Taviraj',Georgia,serif;color:#fff4dc}
.lib-detail-kind{font-size:13px;line-height:1.3;color:var(--text-faint)}
.lib-stats{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:var(--s2)}
/* label (icon + word) on top, the number large under it, so 10,000 never breaks */
.lib-stat{display:grid;grid-template-columns:auto minmax(0,1fr);grid-template-rows:auto auto;align-items:center;column-gap:var(--s1);min-width:0;padding:var(--s1) var(--s2) var(--s2);border:1px solid var(--line);border-radius:8px;background:#ffffff08}
.lib-stat .oc-icon{grid-row:1;width:14px;height:14px;color:var(--gold-2)}
.lib-stat b{grid-row:2;grid-column:1/-1;font:700 18px/1.2 'Kanit',sans-serif;font-variant-numeric:tabular-nums;white-space:nowrap;overflow-wrap:normal;color:var(--text)}
.lib-stat small{grid-row:1;grid-column:2;font-size:12px;line-height:1.3;color:var(--text-faint);white-space:nowrap}
.lib-stat.cost .oc-icon{color:#8fd0f0}
.lib-stat.damage .oc-icon{color:#ef8a6c}
.library .ability-copy{margin:0;padding:var(--s4) 0 0;border-top:1px solid var(--line)}
.lib-trait{display:block;margin-bottom:var(--s2);font-size:12.5px;line-height:1.3;letter-spacing:.04em;color:var(--gold-2)}
.library .lib-rules{display:block;font-size:15px;line-height:1.65;white-space:normal;color:#ece4d1}
.lib-line{display:block}
.lib-line+.lib-line{margin-top:var(--s2)}
.lib-line.tier{position:relative;padding-left:30px;margin-top:var(--s1)}
.lib-tier{position:absolute;left:0;top:.2em;display:grid;place-items:center;width:22px;height:20px;font:700 12px/1 'Kanit',sans-serif;color:#2c1a05;border-radius:4px;background:linear-gradient(180deg,var(--gold-1),var(--gold-2))}
.lib-kw{display:inline-block;margin:0 2px 0 0;padding:0 6px;border-radius:5px;font-weight:600;font-size:13px;line-height:1.55;color:var(--gold-1);background:#e2b05324;box-shadow:inset 0 0 0 1px #e2b05340}
.lib-line.trig{display:flex;align-items:center;gap:var(--s1);color:var(--gold-1);font-weight:600}
.lib-line.trig .oc-icon{width:16px;height:16px}
/* the printed trigger line is explained by the Trigger box below; keep it in the text, show it once */
.lib-text:has(~ .lib-trigger) .lib-line.trig{display:none}
.lib-hide{display:none}
.lib-note{display:flex;align-items:center;gap:var(--s2);margin-top:var(--s3);font-size:13.5px;line-height:1.45;color:var(--text-dim)}
.lib-note .oc-icon{width:16px;height:16px;color:var(--gold-2)}
.lib-trigger{display:flex;gap:var(--s3);padding:var(--s3);border:1px solid #e2b05355;border-radius:10px;background:#e2b05312}
.lib-trigger>.oc-icon{width:22px;height:22px;color:var(--gold-1)}
.lib-trigger strong{display:block;font-size:14px;line-height:1.3;color:var(--gold-1)}
.lib-trigger p{margin-top:2px;font-size:13.5px;line-height:1.55;color:var(--text-dim)}
.lib-source{display:inline-flex;align-items:center;gap:var(--s2);align-self:flex-start;height:var(--tap);padding:0 var(--s4);border:1px solid var(--line);border-radius:10px;background:#ffffff08;color:var(--gold-1);font-size:14px;font-weight:600}
.lib-source .oc-icon{width:18px;height:18px}
.lib-detail-close{display:none}
.lib-scrim{display:none}

/* ---------- large screens: a step larger, many cards and a big card ---------- */
@media (min-width:1600px) and (min-height:900px){
  :where(body:not(.xr-staged)) .library{--rail:272px;--detail:452px;--card-min:142px;--pad:var(--s5);font-size:16px}
  :where(body:not(.xr-staged)) .lib-rail{padding:var(--s5) var(--s4)}
  :where(body:not(.xr-staged)) .lib-deck{min-height:72px;grid-template-columns:52px minmax(0,1fr)}
  :where(body:not(.xr-staged)) .lib-crest{width:52px;height:52px}:where(body:not(.xr-staged)) .lib-crest .oc-icon{width:28px;height:28px}
  :where(body:not(.xr-staged)) .lib-deck-copy strong{font-size:19px}:where(body:not(.xr-staged)) .lib-deck-copy small{font-size:13px}
  :where(body:not(.xr-staged)) .lib-title h2{font-size:34px}:where(body:not(.xr-staged)) .lib-desc{font-size:15px}
  :where(body:not(.xr-staged)) .lib-head-crest{width:72px;height:72px}:where(body:not(.xr-staged)) .lib-head-crest .oc-icon{width:38px;height:38px}
  :where(body:not(.xr-staged)) .lib-tools{padding:var(--s2) var(--s4)}
  :where(body:not(.xr-staged)) .lib-curve{height:56px}:where(body:not(.xr-staged)) .lib-bar{width:34px}
  :where(body:not(.xr-staged)) .lib-detail-card{width:min(100%,calc(36*var(--xvh,1dvh)),380px)}
  :where(body:not(.xr-staged)) .lib-detail-head h3{font-size:28px}
  :where(body:not(.xr-staged)) .library .lib-rules{font-size:16px}
}
/* the same on the fixed 1920x1080 stage, where the window size does not count */
:where(body.xr-staged) .library{--rail:272px;--detail:452px;--card-min:142px;--pad:var(--s5);font-size:16px}
  :where(body.xr-staged) .lib-rail{padding:var(--s5) var(--s4)}
  :where(body.xr-staged) .lib-deck{min-height:72px;grid-template-columns:52px minmax(0,1fr)}
  :where(body.xr-staged) .lib-crest{width:52px;height:52px}:where(body.xr-staged) .lib-crest .oc-icon{width:28px;height:28px}
  :where(body.xr-staged) .lib-deck-copy strong{font-size:19px}:where(body.xr-staged) .lib-deck-copy small{font-size:13px}
  :where(body.xr-staged) .lib-title h2{font-size:34px}:where(body.xr-staged) .lib-desc{font-size:15px}
  :where(body.xr-staged) .lib-head-crest{width:72px;height:72px}:where(body.xr-staged) .lib-head-crest .oc-icon{width:38px;height:38px}
  :where(body.xr-staged) .lib-tools{padding:var(--s2) var(--s4)}
  :where(body.xr-staged) .lib-curve{height:56px}:where(body.xr-staged) .lib-bar{width:34px}
  :where(body.xr-staged) .lib-detail-card{width:min(100%,calc(36*var(--xvh,1dvh)),380px)}
  :where(body.xr-staged) .lib-detail-head h3{font-size:28px}
  :where(body.xr-staged) .library .lib-rules{font-size:16px}
/* mid desktops (1100–1440): a little tighter; chips drop their icons so the tools stay on one line */
@media (max-width:1440px) and (min-width:1100px){
  :where(body:not(.xr-staged)) .library{--rail:216px;--detail:332px;--card-min:120px;--pad:var(--s4)}
  :where(body:not(.xr-staged)) .lib-tools{gap:var(--s4)}
  :where(body:not(.xr-staged)) .lib-chip{padding:0 var(--s2)}
  :where(body:not(.xr-staged)) .lib-chip .oc-icon,:where(body:not(.xr-staged)) .lib-curve-label{display:none}
  :where(body:not(.xr-staged)) .lib-curve{padding-left:var(--s3)}
  :where(body:not(.xr-staged)) .lib-bar{width:24px}
  :where(body:not(.xr-staged)) .lib-search{flex-basis:120px}
  :where(body:not(.xr-staged)) .lib-title h2{font-size:26px}
  :where(body:not(.xr-staged)) .lib-stats{gap:6px}
  :where(body:not(.xr-staged)) .lib-stat{padding:var(--s1) 6px 6px}
  :where(body:not(.xr-staged)) .lib-stat b{font-size:16px;letter-spacing:-.01em}
  :where(body:not(.xr-staged)) .lib-head-crest{width:56px;height:56px}:where(body:not(.xr-staged)) .lib-head-crest .oc-icon{width:30px;height:30px}
}
@media (max-width:1300px) and (min-width:1100px){
  :where(body:not(.xr-staged)) .library{--rail:200px;--detail:316px}
  :where(body:not(.xr-staged)) .lib-deck{grid-template-columns:44px minmax(0,1fr);gap:var(--s2)}
  :where(body:not(.xr-staged)) .lib-crest{width:44px;height:44px}
}
/* desktop windows too short for the tools on one line keep the description to one line */
@media (min-width:1100px) and (max-height:800px){
  :where(body:not(.xr-staged)) .lib-desc{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  :where(body:not(.xr-staged)) .lib-detail-body{margin-top:var(--s4);gap:var(--s3)}
}

/* ---------- phones in landscape and narrow windows ---------- */
@media (max-width:1099px), (max-height:500px){
  :where(body:not(.xr-staged)) .library{--rail:68px;--card-min:100px;--pad:var(--s3);grid-template-columns:var(--rail) minmax(0,1fr);font-size:14px}
  :where(body:not(.xr-staged)) .lib-rail{align-items:center;gap:var(--s2);padding:max(var(--s2),env(safe-area-inset-top)) var(--s1) var(--s2) max(var(--s1),var(--xsl,env(safe-area-inset-left)))}
  :where(body:not(.xr-staged)) .lib-rail-head{flex-direction:column;min-height:0}
  :where(body:not(.xr-staged)) .lib-back{width:var(--tap);height:var(--tap)}
  :where(body:not(.xr-staged)) .lib-rail-title,:where(body:not(.xr-staged)) .lib-deck-copy{display:none}
  :where(body:not(.xr-staged)) .lib-decks{align-items:center;gap:2px}
  :where(body:not(.xr-staged)) .lib-deck{display:grid;place-items:center;grid-template-columns:none;width:52px;height:48px;min-height:0;padding:0;border-radius:10px}
  :where(body:not(.xr-staged)) .lib-deck.active::before{top:10px;bottom:10px;left:-3px}
  :where(body:not(.xr-staged)) .lib-crest{width:40px;height:40px}:where(body:not(.xr-staged)) .lib-crest .oc-icon{width:22px;height:22px}
  :where(body:not(.xr-staged)) .lib-using{width:17px;height:17px;right:-6px;bottom:-4px}:where(body:not(.xr-staged)) .lib-using .oc-icon{width:11px;height:11px}
  :where(body:not(.xr-staged)) .lib-rail-rule{width:28px;margin:var(--s1) 0}

  :where(body:not(.xr-staged)) .lib-main{gap:var(--s2);padding:var(--s2) max(var(--s3),var(--xsr,env(safe-area-inset-right))) 0 var(--s3)}
  :where(body:not(.xr-staged)) .lib-head{min-height:48px;gap:var(--s3)}
  :where(body:not(.xr-staged)) .lib-title{gap:var(--s3)}
  :where(body:not(.xr-staged)) .lib-head-crest,:where(body:not(.xr-staged)) .lib-desc{display:none}
  :where(body:not(.xr-staged)) .lib-kicker{font-size:11px;letter-spacing:.1em}
  :where(body:not(.xr-staged)) .lib-title h2{margin-top:0;font-size:20px;line-height:1.25;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  :where(body:not(.xr-staged)) .lib-actions{gap:var(--s2)}
  :where(body:not(.xr-staged)) .lib-filter-toggle{display:grid}
  :where(body:not(.xr-staged)) .lib-use{height:var(--tap);min-width:0;padding:0 var(--s4);font-size:14px;--cut:11px}
  :where(body:not(.xr-staged)) .lib-use .oc-icon{width:18px;height:18px}
  :where(body:not(.xr-staged)) .lib-edit{height:var(--tap);padding:0 var(--s3);font-size:13.5px}

  /* the filters fold into a panel under the title row */
  :where(body:not(.xr-staged)) .lib-tools{position:absolute;z-index:8;top:calc(var(--s2) + 48px + var(--s2));right:max(var(--s3),var(--xsr,env(safe-area-inset-right)));
    display:none;flex-direction:column;align-items:stretch;gap:var(--s3);width:min(440px,calc(100% - 2 * var(--s3)));padding:var(--s3);
    background:linear-gradient(180deg,#0e1a27,#0a131d);border-color:#e2c58955;box-shadow:0 18px 40px #000d}
  :where(body:not(.xr-staged)) .library.filters-open .lib-tools{display:flex;animation:lib-drop .16s ease-out}
  :where(body:not(.xr-staged)) .lib-search{order:-1;max-width:none;width:100%;margin:0;flex:none}
  :where(body:not(.xr-staged)) .lib-types{gap:var(--s1)}
  :where(body:not(.xr-staged)) .lib-chip{padding:0 var(--s2) 0 var(--s1);border-color:var(--line)}
  :where(body:not(.xr-staged)) .lib-curve{height:64px;padding:var(--s2) 0 0;border-left:0;border-top:1px solid var(--line);justify-content:space-between}
  :where(body:not(.xr-staged)) .lib-bar{flex:1;width:auto;min-width:var(--tap)}
  :where(body:not(.xr-staged)) .lib-bar-fill{width:16px}

  :where(body:not(.xr-staged)) .library .lib-grid{gap:var(--s3) var(--s2);padding:var(--s2) var(--s2) var(--s4)}
  :where(body:not(.xr-staged)) .library .copy-count{min-width:30px;height:21px;font-size:12px;top:-4px;right:-4px}

  /* the chosen card slides over from the right; a tap outside or back closes it */
  :where(body:not(.xr-staged)) .lib-scrim{display:block;position:fixed;inset:0;z-index:9;background:#03070cc4;opacity:0;pointer-events:none;transition:opacity .2s}
  :where(body:not(.xr-staged)) .library.detail-open .lib-scrim{opacity:1;pointer-events:auto}
  :where(body:not(.xr-staged)) .lib-detail{position:fixed;z-index:10;top:0;right:0;bottom:0;width:min(600px,calc(80*var(--xvw,1vw)));border-left:1px solid #e2c58966;box-shadow:-24px 0 50px #000c;
    transform:translateX(105%);visibility:hidden;transition:transform .22s cubic-bezier(.2,.8,.3,1),visibility 0s .22s}
  :where(body:not(.xr-staged)) .library.detail-open .lib-detail{transform:none;visibility:visible;transition:transform .22s cubic-bezier(.2,.8,.3,1)}
  :where(body:not(.xr-staged)) .lib-detail-scroll{display:grid;grid-template-columns:auto minmax(0,1fr);align-items:start;gap:var(--s4);
    padding:max(var(--s3),env(safe-area-inset-top)) max(var(--s4),var(--xsr,env(safe-area-inset-right))) var(--s4) var(--s4)}
  :where(body:not(.xr-staged)) .lib-detail-card{position:sticky;top:0;width:auto;height:min(calc(calc(100*var(--xvh,1dvh)) - 2 * var(--s3)),320px);aspect-ratio:2/3;margin:0}
  :where(body:not(.xr-staged)) .lib-detail-card .illustrated-card{height:100%;width:auto}
  :where(body:not(.xr-staged)) .lib-detail-body{margin-top:0;gap:var(--s3);padding-top:var(--s1);padding-right:40px}
  :where(body:not(.xr-staged)) .lib-detail-head h3{font-size:20px}
  :where(body:not(.xr-staged)) .lib-stat b{font-size:16px}
  :where(body:not(.xr-staged)) .library .ability-copy{padding-top:var(--s3)}
  :where(body:not(.xr-staged)) .library .lib-rules{font-size:14px;line-height:1.6}
  :where(body:not(.xr-staged)) .lib-detail-close{display:grid;place-items:center;position:absolute;z-index:2;top:max(var(--s2),env(safe-area-inset-top));right:max(var(--s2),var(--xsr,env(safe-area-inset-right)));
    width:var(--tap);height:var(--tap);padding:0;border:1px solid var(--line);border-radius:50%;background:#0b141ee6;color:var(--gold-1)}
  :where(body:not(.xr-staged)) .lib-detail-close .oc-icon{width:18px;height:18px}
}
/* very short phones: six crests and back still fit without scrolling */
@media (max-height:420px){
  :where(body:not(.xr-staged)) .lib-rail{gap:var(--s1)}
  :where(body:not(.xr-staged)) .lib-deck{height:44px}
  :where(body:not(.xr-staged)) .lib-crest{width:38px;height:38px}
  :where(body:not(.xr-staged)) .lib-rail-rule{margin:2px 0}
}
@keyframes lib-drop{from{opacity:0;transform:translateY(-6px)}}
/* a short-and-narrow phone: the locked edit button keeps only its lock */
@media (max-width:760px) and (max-height:500px){
  :where(body:not(.xr-staged)) .lib-edit span{display:none}
  :where(body:not(.xr-staged)) .lib-edit{width:var(--tap);justify-content:center;padding:0}
  :where(body:not(.xr-staged)) .lib-detail-card{height:min(calc(calc(100*var(--xvh,1dvh)) - 2 * var(--s3)),280px)}
  :where(body:not(.xr-staged)) .lib-detail{width:min(560px,calc(84*var(--xvw,1vw)))}
}
@media (prefers-reduced-motion:reduce){
  .library,.library.filters-open .lib-tools{animation:none}
  .lib-detail,.library.detail-open .lib-detail,.lib-scrim,.library .lib-card{transition:none}
}
