/* MAGLIFICENT mobile catalogue + anchored chapter reader.
   The existing desktop gallery layouts and book/volume pages are unaffected. */

/* Fix mobile screenshot: old desktop selectors still claimed columns in a
   one-column grid, making the first book only a few characters wide. */
@media(max-width:700px) {
  body.theme-forest .archive-home .archive-grid,
  body.theme-wasteland .archive-home .archive-grid {
    display:flex!important;
    flex-direction:column!important;
    grid-template-columns:none!important;
    grid-template-rows:none!important;
    align-items:stretch!important;
    gap:15px!important;
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
    padding:15px 10px 28px!important;
    box-sizing:border-box;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n),
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) {
    position:relative!important;
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
    margin:0!important;
    grid-column:auto!important;
    grid-row:auto!important;
    transform:none!important;
    text-align:left!important;
    align-items:center!important;
    align-content:center!important;
    display:grid!important;
    grid-template-columns:75px minmax(0,1fr)!important;
    grid-template-rows:repeat(4,auto)!important;
    gap:3px 15px!important;
    min-height:170px!important;
    height:auto!important;
    padding:17px 18px!important;
    box-sizing:border-box;
    overflow:hidden!important;
    border-radius:3px!important;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .collection-emblem,
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .collection-emblem {
    display:flex!important;
    grid-column:1!important;
    grid-row:1/5!important;
    width:75px!important;
    height:84px!important;
    min-height:0!important;
    max-height:none!important;
    align-self:center!important;
    justify-content:center!important;
    flex:none!important;
    margin:0!important;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .collection-emblem svg,
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .collection-emblem svg {
    width:72px!important;height:72px!important;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-number,
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-number {
    display:block!important;
    grid-column:2!important;
    grid-row:1!important;
    width:auto!important;
    min-width:0!important;
    margin:0!important;
    overflow-wrap:anywhere;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-tag,
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-tag {
    grid-column:2!important;grid-row:2!important;
    margin:0!important;min-height:0!important;
    font-size:10px!important;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-name,
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-name {
    grid-column:2!important;grid-row:3!important;
    width:100%!important;max-width:100%!important;
    white-space:normal!important;
    word-break:keep-all!important;
    overflow-wrap:break-word!important;
    font-size:clamp(22px,5.7vw,27px)!important;
    line-height:1.35!important;
    letter-spacing:.03em!important;
    margin:2px 0 3px!important;
    min-width:0!important;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-subtitle,
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-subtitle {
    grid-column:2!important;grid-row:4!important;
    width:100%!important;
    max-width:100%!important;
    min-height:0!important;
    margin:0!important;
    font-size:12px!important;
    line-height:1.65!important;
    overflow-wrap:break-word;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-foot,
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-foot {
    display:flex!important;
    grid-column:1/-1!important;
    grid-row:5!important;
    flex-direction:row!important;
    justify-content:space-between!important;
    align-items:center!important;
    width:100%!important;
    margin:9px 0 0!important;
    padding:8px 0 0!important;
    gap:10px!important;
    min-width:0!important;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-foot .card-enter,
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .card-foot .card-enter {
    white-space:normal!important;text-align:right!important
  }

  /* Forest — each entry is a generous landscape specimen card on a
     wooden shelf, while Foundation remains a dark drawer. */
  body.theme-forest .archive-home .archive-grid {
    border:7px solid #413522!important;
    border-top-width:13px!important;
    background:repeating-linear-gradient(180deg,#2d301fef 0 8px,#524329 9px 12px,#1a2a1a 13px 204px)!important;
    box-shadow:inset 0 0 18px #0008;
  }
  body.theme-forest .archive-home .archive-card.collection-card:not(.special-collection):nth-child(n) {
    background:linear-gradient(125deg,#efe6c9,#ccbc91)!important;
    border:1px solid #9f885b!important;
    border-left:5px solid #87916b!important;
    box-shadow:0 5px 0 #1f261bd1!important;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind="atlas"]:nth-child(n) {min-height:185px!important}
  body.theme-forest .archive-home .archive-card.collection-card.special-collection:nth-child(n) {
    background:linear-gradient(120deg,#3c3425,#1e1c15)!important;
    border:5px ridge #a28b62!important;
    min-height:120px!important;
    gap:3px 10px!important;
    box-shadow:inset 0 2px 9px #050404!important;
  }
  body.theme-forest .archive-home .archive-card.collection-card.special-collection:nth-child(n)
    :is(.card-number,.card-name,.card-subtitle,.card-count,.card-enter){color:#f6e8c1!important}
  body.theme-forest .archive-home .archive-card.collection-card.special-collection:nth-child(n) .collection-emblem{color:#ccb681!important}
  /* Wasteland — broader, irregular salvaged reports, alternating paper
     and weathered metal, with readable horizontal labels. */
  body.theme-wasteland .archive-home .archive-grid {
    border:0!important;
    background:none!important;
    padding-inline:13px!important;
    gap:18px!important;
  }
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) {
    border:2px solid #846d55!important;
    border-top:9px solid #9b886c!important;
    background:linear-gradient(128deg,#d9c8a8,#b19b7e)!important;
    box-shadow:5px 6px 0 #100e0b88!important;
    padding:20px 16px 13px!important;
    min-height:167px!important;
    border-radius:3px!important;
  }
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind="chronicle"]:nth-child(n),
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind="journal"]:nth-child(n) {
    background:linear-gradient(130deg,#c7bba4,#a9997f)!important;
    border-top-color:#695c4d!important;
  }
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind="gazetteer"]:nth-child(n){
    background:linear-gradient(130deg,#d5c6a3,#b6ac91)!important;
    border-left:9px solid #805b43!important;
  }
  body.theme-wasteland .archive-home .archive-card.collection-card.special-collection:nth-child(n) {
    background:linear-gradient(125deg,#24221d,#3b362d)!important;
    border:5px ridge #7a6650!important;
    min-height:135px!important;
  }
  body.theme-wasteland .archive-home .archive-card.collection-card.special-collection:nth-child(n)
    :is(.card-number,.card-name,.card-subtitle,.card-count,.card-enter) {color:#eed9af!important}
  body.theme-wasteland .archive-home .archive-card.collection-card.special-collection:nth-child(n) .collection-emblem{color:#c5a47a!important}
  body.theme-wasteland .archive-home .archive-card.collection-card:nth-child(n)::before{
    display:block!important;
    width:65px;height:13px;top:-17px;left:calc(50% - 32px);
    right:auto;background:#8e765ade;border:1px solid #5d4d38;
  }
  /* The heading and chapter menu stay visible while the entire chapter scrolls. */
  body[class*="theme-"] .reader-view {
    height:100%!important;min-height:0!important;max-width:100%!important;
    padding:0!important;overflow:hidden!important;
  }
  body[class*="theme-"] .reader-view .main-content {
    display:flex!important;flex-direction:column!important;
    grid-template-columns:none!important;grid-template-rows:none!important;
    gap:0!important;height:100%!important;min-height:0!important;
    max-height:100%!important;max-width:100%!important;
    margin:0 auto!important;padding:0 10px!important;overflow:hidden!important;
  }
  body[class*="theme-"] .reader-view .reader-rail{display:none!important}
  body[class*="theme-"] .reader-view .reader-header {
    flex:0 0 auto!important;position:relative!important;
    padding:16px 4px 10px!important;margin:0!important;min-width:0!important;
  }
  body[class*="theme-"] .reader-view .reader-breadcrumb {
    gap:5px!important;font-size:11px!important;line-height:1.65!important;
  }
  body[class*="theme-"] .reader-view .reader-breadcrumb button{font-size:11px!important}
  body[class*="theme-"] .reader-view #chapterTitle {
    font-size:clamp(23px,6vw,28px)!important;font-weight:550!important;
    line-height:1.42!important;letter-spacing:.04em!important;
    margin:11px 0 12px!important;padding:0!important;opacity:1!important;
  }
  body[class*="theme-"] .reader-view .reader-tools{
    flex-wrap:wrap!important;gap:7px!important;padding:1px 0 11px!important;
  }
  body[class*="theme-"] .reader-view .reader-tools>span{
    margin-right:auto!important;font-size:12px!important;
  }
  body[class*="theme-"] .reader-view .reader-tools button{
    min-height:36px!important;padding:7px 10px!important;font-size:12px!important;
  }
  body[class*="theme-"] .reader-view .reading-track{height:3px!important}
  body[class*="theme-"] .reader-view .page-container-single {
    display:block!important;flex:1 1 0%!important;
    min-height:0!important;max-height:none!important;height:auto!important;
    min-width:0!important;width:100%!important;align-self:stretch!important;
    overflow-y:auto!important;overflow-x:hidden!important;
    overscroll-behavior-y:contain;-webkit-overflow-scrolling:touch;
    scrollbar-width:none!important;scroll-behavior:auto;
    margin:0!important;padding:0 0 6px!important;
  }
  body[class*="theme-"] .reader-view .page-container-single::-webkit-scrollbar{display:none}
  body[class*="theme-"] .reader-view .page-single{
    width:100%!important;max-width:100%!important;min-width:0!important;
    min-height:0!important;height:auto!important;margin:0!important;
    padding:22px 15px 28px!important;
    font-size:var(--reader-font,18px)!important;line-height:1.85!important;
    word-break:normal!important;overflow-wrap:break-word!important;
  }
  body[class*="theme-"] .reader-view .page-single p{
    font-size:inherit!important;line-height:1.85!important;
    margin-bottom:1.02em!important;word-break:normal!important;
    overflow-wrap:break-word!important;
  }
  body[class*="theme-"] .reader-view .page-single :is(h1,h2,h3,h4){
    line-height:1.55!important;scroll-margin-top:12px;
  }
  body[class*="theme-"] .reader-view .chapter-nav {
    display:grid!important;position:relative!important;bottom:auto!important;
    flex:0 0 auto!important;
    grid-template-columns:minmax(0,1fr) minmax(0,1fr)!important;
    align-items:center!important;gap:7px 10px!important;
    width:100%!important;max-width:100%!important;min-width:0!important;
    min-height:0!important;margin:0!important;
    padding:11px 1px max(10px,env(safe-area-inset-bottom))!important;
    border:0!important;border-top:1px solid var(--border-light)!important;
    background:var(--bg)!important;box-shadow:0 -7px 16px #0000000a!important;
    z-index:11;
  }
  body[class*="theme-"] .reader-view .chapter-nav .nav-left{
    display:flex!important;grid-column:1!important;grid-row:1!important;
    min-width:0!important;width:100%!important;justify-content:flex-start!important;
    align-items:center!important;gap:5px!important;
  }
  body[class*="theme-"] .reader-view .chapter-nav .nav-right{
    display:flex!important;grid-column:2!important;grid-row:1!important;
    min-width:0!important;width:100%!important;
    justify-content:flex-end!important;align-items:center!important;
  }
  body[class*="theme-"] .reader-view .chapter-nav .page-indicator{
    display:block!important;grid-column:1/-1!important;grid-row:2!important;
    order:0!important;width:100%!important;text-align:center!important;
    color:var(--text-secondary)!important;font-size:11px!important;
    line-height:1.55!important;letter-spacing:0!important;
    margin:0!important;opacity:1!important;
  }
  body[class*="theme-"] .reader-view .chapter-nav .page-btn{
    min-width:0!important;min-height:42px!important;
    padding:9px 9px!important;font-size:12px!important;
    white-space:nowrap;opacity:1!important;
  }
  body[class*="theme-"] .reader-view .chapter-nav .page-btn:disabled{opacity:.32!important}
  /* Keep floating tools above the permanently visible chapter menu. */
  body:has(.reader-view[style*="block"]) .fab-container{
    right:7px!important;bottom:max(106px,calc(94px + env(safe-area-inset-bottom)))!important;
  }
  body:has(.reader-view[style*="block"]) .fab{
    width:34px!important;height:34px!important;font-size:13px!important;
  }
}
@media(max-width:365px){
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n),
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) {
    grid-template-columns:57px minmax(0,1fr)!important;
    gap:3px 9px!important;
    padding-inline:11px!important;
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .collection-emblem,
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .collection-emblem{
    width:56px!important;height:65px!important
  }
  body.theme-forest .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .collection-emblem svg,
  body.theme-wasteland .archive-home .archive-card.collection-card[data-kind]:nth-child(n) .collection-emblem svg{
    width:55px!important;height:55px!important
  }
}
@media(prefers-reduced-motion:reduce){
  body[class*="theme-"] .reader-view .page-container-single{scroll-behavior:auto}
  body[class*="theme-"] .reader-view .reading-track>span{transition:none}
}
/* 2026-10-15 — compact reader chrome: the site's fixed header already
   identifies the volume; the mobile reader should prioritize actual text. */
@media(max-width:700px) {
  body[class*="theme-"] .reader-view .reader-header {
    flex:0 0 auto!important;
    padding:5px 2px 4px!important;
    margin:0!important;
    min-height:0!important;
    border:0!important;
    background:transparent!important;
  }
  body[class*="theme-"] .reader-view .reader-breadcrumb,
  body[class*="theme-"] .reader-view #chapterTitle {
    display:none!important;
  }
  body[class*="theme-"] .reader-view .reader-tools {
    display:flex!important;
    flex-wrap:nowrap!important;
    align-items:center!important;
    justify-content:flex-end!important;
    gap:6px!important;
    padding:0 0 5px!important;
    margin:0!important;
    min-height:31px!important;
  }
  body[class*="theme-"] .reader-view .reader-tools>span {
    display:block!important;
    margin-right:auto!important;
    min-width:32px!important;
    font:12px/1.4 monospace!important;
  }
  body[class*="theme-"] .reader-view .reader-tools button {
    flex:0 0 auto!important;
    min-width:35px!important;
    height:31px!important;
    min-height:31px!important;
    max-height:31px!important;
    padding:4px 8px!important;
    margin:0!important;
    font-size:11px!important;
    line-height:1.4!important;
  }
  body[class*="theme-"] .reader-view .reader-tools #readerFocus {
    min-width:65px!important;
  }
  body[class*="theme-"] .reader-view .reading-track {
    height:2px!important;
    margin:0!important;
    padding:0!important;
  }
  body[class*="theme-"] .reader-view .page-container-single {
    flex:1 1 0%!important;
    min-height:0!important;
    margin:0!important;
    padding:0!important;
  }
  body[class*="theme-"] .reader-view .page-single {
    padding-top:13px!important;
    padding-bottom:19px!important;
  }
  body[class*="theme-"] .reader-view .chapter-nav {
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto minmax(0,1fr)!important;
    grid-template-rows:1fr!important;
    align-items:center!important;
    gap:5px!important;
    padding:5px 1px max(5px,env(safe-area-inset-bottom))!important;
    margin:0!important;
    min-height:0!important;
    height:auto!important;
    box-shadow:0 -2px 8px #00000008!important;
    border-top:1px solid var(--border-light)!important;
  }
  body[class*="theme-"] .reader-view .chapter-nav .nav-left {
    grid-column:1!important;
    grid-row:1!important;
    justify-content:flex-start!important;
    gap:4px!important;
    min-width:0!important;
    width:100%!important;
  }
  body[class*="theme-"] .reader-view .chapter-nav .nav-right {
    grid-column:3!important;
    grid-row:1!important;
    justify-content:flex-end!important;
    min-width:0!important;
    width:100%!important;
  }
  body[class*="theme-"] .reader-view .chapter-nav .page-indicator {
    grid-column:2!important;
    grid-row:1!important;
    order:0!important;
    width:auto!important;
    max-width:85px!important;
    margin:0!important;
    padding:0 3px!important;
    font-size:0!important;
    line-height:1!important;
    white-space:nowrap;
    text-align:center!important;
  }
  body[class*="theme-"] .reader-view .chapter-nav .page-indicator::after {
    content:attr(data-compact);
    color:var(--text-secondary);
    font:11px/1.5 monospace;
    white-space:nowrap;
  }
  body[class*="theme-"] .reader-view .chapter-nav .page-btn {
    flex:0 1 auto!important;
    min-height:34px!important;
    height:34px!important;
    padding:5px 7px!important;
    font-size:11px!important;
    line-height:1.25!important;
    white-space:nowrap!important;
  }
  body[class*="theme-"] .reader-view #backToVolumeBtn {
    flex:0 0 32px!important;
    width:32px!important;
    min-width:32px!important;
    padding:4px!important;
  }
  body:has(.reader-view[style*="block"]) .fab-container {
    bottom:max(66px,calc(58px + env(safe-area-inset-bottom)))!important;
  }
}
@media(max-width:365px) {
  body[class*="theme-"] .reader-view .chapter-nav .page-btn {
    padding:4px 5px!important;
    font-size:10px!important;
  }
  body[class*="theme-"] .reader-view .chapter-nav .page-indicator::after {
    font-size:10px;
  }
}
