/* V9.6 | OS-aware SVG and historical-media frame
   Preserve the authored historical SVG and source pictures. Present controls,
   graphic and attribution in SEPARATE layout rows rather than overlays.
   This overrides the old 22px blank titlebar and floating tab/figcaption. */
#book-reader[data-os-family] :is(.book-leaf-content,.book-full-detail-body,.book-evidence-demo-body) .book-art.book-has-archive {
  display:grid!important;
  grid-template-columns:minmax(0,1fr);
  grid-template-rows:auto minmax(0,1fr) auto;
  align-items:stretch!important;
  justify-items:stretch!important;
  padding:0!important;
  gap:0!important;
  min-width:0;min-height:0;
  border:2px solid var(--os-line,#9daea7)!important;
  border-top:2px solid var(--os-line,#9daea7)!important;
  border-radius:var(--os-radius,3px)!important;
  background:var(--os-client,#f4f1e9)!important;
  box-shadow:3px 4px 0 #0003!important;
}
#book-reader[data-os-family] .book-has-archive .book-media-switch {
  grid-column:1;grid-row:1;
  box-sizing:border-box;
  position:relative!important;inset:auto!important;
  display:flex;flex-wrap:wrap;justify-content:flex-start;align-content:center;
  width:100%;max-width:100%;min-width:0;
  padding:.38rem .45rem;margin:0;gap:.35rem;
  min-height:40px;max-height:none;
  border:0;border-bottom:1px solid var(--os-line,#9ba7a0);
  border-radius:0!important;
  background:var(--os-window,#e5e3d8)!important;
  box-shadow:none!important;transform:none!important;
  z-index:2;
}
#book-reader[data-os-family] .book-has-archive .book-media-switch button {
  flex:0 1 auto;min-width:0;min-height:29px;max-width:100%;
  margin:0;padding:.32rem .52rem;
  border:1px solid var(--os-line,#9ba7a0)!important;
  border-radius:var(--os-radius,2px)!important;
  background:var(--os-button,#ece9dd)!important;
  color:var(--os-button-ink,#243d3b)!important;
  box-shadow:none!important;
  font:700 clamp(.62rem,.83vw,.77rem)/1.3 var(--os-ui-font,"Noto Sans TC",sans-serif)!important;
  text-align:center;white-space:normal;overflow-wrap:anywhere;
  cursor:pointer;
}
#book-reader[data-os-family] .book-has-archive .book-media-switch button[aria-pressed="true"] {
  background:var(--os-titlebar,#304b51)!important;
  color:var(--os-title-ink,#fff)!important;
  border-color:var(--os-titlebar,#304b51)!important;
}
#book-reader[data-os-family] .book-has-archive .book-media-switch button:focus-visible {
  outline:3px solid #d99d4f;outline-offset:1px;z-index:1;
}
#book-reader[data-os-family] .book-has-archive > :is(.book-archive-photo,.book-original-diagram) {
  grid-column:1;grid-row:2;
  align-self:stretch;justify-self:stretch;
  width:100%!important;height:100%!important;
  min-width:0!important;min-height:0!important;
  max-width:100%!important;max-height:100%!important;
  object-fit:contain!important;object-position:center;
  background:var(--os-client,#ebe9e0)!important;
  filter:none!important;transform:none!important;
}
#book-reader[data-os-family] .book-has-archive > :is(.book-archive-caption,.book-diagram-caption) {
  grid-column:1;grid-row:3;
  position:relative!important;
  inset:auto!important;transform:none!important;
  box-sizing:border-box;width:100%;max-width:100%;
  margin:0;padding:.42rem .65rem!important;
  min-height:0;
  background:var(--os-window,#ece9df)!important;
  color:var(--os-ink,#293a3b)!important;
  border-top:1px solid var(--os-line,#abb6af);
  font:600 clamp(.65rem,.81vw,.78rem)/1.4 var(--os-ui-font,"Noto Sans TC",sans-serif)!important;
  text-shadow:none!important;overflow-wrap:anywhere;
}
/* An older OS selector targets the bare figcaption element with !important.
   Keep attribution in an opaque, theme-aware footer instead of its black-gradient overlay. */
#book-reader[data-os-family] :is(.book-leaf-content,.book-full-detail-body,.book-evidence-demo-body) .book-art.book-has-archive > :is(.book-archive-caption,.book-diagram-caption) {
  background:var(--os-window,#e5e3d8)!important;
  color:var(--os-ink,#243b40)!important;
  text-shadow:none!important;
}
#book-reader[data-os-family] .book-has-archive .book-archive-caption {
  align-content:center;align-items:center;gap:.2rem .75rem;
  justify-content:space-between;
  flex-wrap:wrap;
}
#book-reader[data-os-family] .book-has-archive .book-archive-caption strong {
  min-width:0;max-width:100%;
  color:var(--os-ink,#293a3b)!important;
  font-size:inherit!important;
}
#book-reader[data-os-family] .book-has-archive .book-archive-caption a {
  min-width:0;max-width:100%;
  color:var(--os-ink,#245c75)!important;
  text-decoration:underline;text-underline-offset:2px;
  font-size:clamp(.6rem,.75vw,.72rem)!important;
}
/* The author-designed atlas SVG is a diagram, not an OS window itself.
   Do not paint a big empty Windows titlebar over its heading. */
#book-reader[data-os-family] .book-leaf-content .book-atlas-art {
  border-top:2px solid var(--os-line,#9aaea2)!important;
  border-radius:var(--os-radius,3px)!important;
  background:var(--os-client,#e8e8e3)!important;
}
#book-reader[data-os-family] .book-atlas-art .book-atlas-standalone {
  object-fit:contain!important;object-position:center;
  min-width:0;min-height:0;
}
/* Nested optional SVG demo uses the same separation of diagram and caption. */
#book-reader[data-os-family] .book-evidence-demo-body .book-art:not(.book-has-archive):has(> .book-original-diagram) {
  display:grid!important;
  grid-template-columns:minmax(0,1fr);
  grid-template-rows:minmax(0,1fr) auto;
  align-items:stretch!important;
  justify-items:stretch!important;
  border-top:2px solid var(--os-line,#9aaea2)!important;
  background:var(--os-client,#ecefe9)!important;
  padding:0!important;
}
#book-reader[data-os-family] .book-evidence-demo-body .book-art:not(.book-has-archive) > .book-original-diagram {
  grid-column:1;grid-row:1;
  display:block!important;
  width:100%;height:100%;min-height:0;max-height:100%;
  object-fit:contain;object-position:center;
}
#book-reader[data-os-family] .book-evidence-demo-body .book-art:not(.book-has-archive) > .book-diagram-caption {
  grid-column:1;grid-row:2;
  position:static!important;inset:auto!important;
  width:100%;padding:.5rem .65rem!important;
  background:var(--os-window,#eff1eb)!important;
  color:var(--os-ink,#23434b)!important;
  border-top:1px solid var(--os-line,#a8b7b6);
  font:650 .75rem/1.5 var(--os-ui-font,"Noto Sans TC",sans-serif)!important;
}
/* The gallery's own controls follow the currently selected historical UI
   without ever recolouring or falsifying the historical photograph itself. */
#book-reader[data-os-family] .book-evidence-tabs button {
  background:var(--os-button,#e8eced)!important;
  color:var(--os-button-ink,#284350)!important;
  border-color:var(--os-line,#9caeac)!important;
  border-radius:var(--os-radius,3px)!important;
  font-family:var(--os-ui-font,"Noto Sans TC",sans-serif)!important;
}
#book-reader[data-os-family] .book-evidence-tabs button[aria-pressed="true"] {
  background:var(--os-titlebar,#254d59)!important;
  color:var(--os-title-ink,#fff)!important;
  border-color:var(--os-titlebar,#254d59)!important;
}
@media(max-width:1100px) {
  #book-reader[data-os-family] .book-has-archive .book-media-switch{
    gap:.22rem;padding:.24rem .3rem;min-height:34px;
  }
  #book-reader[data-os-family] .book-has-archive .book-media-switch button{
    padding:.26rem .37rem;min-height:27px;font-size:.63rem!important;
  }
  #book-reader[data-os-family] .book-has-archive > :is(.book-archive-caption,.book-diagram-caption){
    padding:.3rem .45rem!important;font-size:.67rem!important;line-height:1.35!important;
  }
}
@media(max-width:650px){
  #book-reader[data-os-family] .book-has-archive .book-media-switch button{
    flex:1 1 30%;font-size:.6rem!important;
  }
  #book-reader[data-os-family] .book-has-archive .book-archive-caption{
    gap:.12rem;
  }
}
@media(prefers-reduced-motion:reduce) {
  #book-reader[data-os-family] .book-media-switch button{transition:none!important}
}


/* Also fit original one-piece SVG diagrams when opened from chapters
   05, 13, 15, 17, 19: separate art from its caption in the historical OS shell. */
#book-reader[data-os-family] :is(.book-leaf-content,.book-full-detail-body,.book-evidence-demo-body) .book-art:not(.book-has-archive):not(.book-atlas-art):has(> .book-original-diagram) {
  display:grid!important;
  grid-template-columns:minmax(0,1fr);
  grid-template-rows:minmax(0,1fr) auto;
  align-items:stretch!important;justify-items:stretch!important;
  gap:0!important;padding:0!important;
  border-top:2px solid var(--os-line,#9aaea2)!important;
  background:var(--os-client,#eef0e9)!important;
}
#book-reader[data-os-family] :is(.book-leaf-content,.book-full-detail-body,.book-evidence-demo-body) .book-art:not(.book-has-archive):not(.book-atlas-art) > .book-original-diagram {
  grid-row:1;grid-column:1;
  width:100%!important;height:100%!important;
  max-width:100%!important;max-height:100%!important;
  min-width:0!important;min-height:0!important;
  object-fit:contain!important;transform:none!important;
}
#book-reader[data-os-family] :is(.book-leaf-content,.book-full-detail-body,.book-evidence-demo-body) .book-art:not(.book-has-archive):not(.book-atlas-art) > .book-diagram-caption {
  grid-row:2;grid-column:1;
  position:relative!important;inset:auto!important;
  margin:0!important;padding:.45rem .65rem!important;
  width:100%;max-width:100%;box-sizing:border-box;
  background:var(--os-window,#e6e8df)!important;
  color:var(--os-ink,#293b43)!important;
  text-shadow:none!important;
  border-top:1px solid var(--os-line,#a5b2ad);
  font:600 clamp(.65rem,.8vw,.78rem)/1.4 var(--os-ui-font,"Noto Sans TC",sans-serif)!important;
  overflow-wrap:anywhere;
}
/* Mechanical-era academic SVG already has its own illustrated internal
   header, so an empty blue/purple OS title strip is inappropriate. */
#book-reader[data-os-family] .book-leaf-content .book-art:has(.scroll-stage-diagram) {
  border-top:2px solid var(--os-line,#9daea6)!important;
}

/* On phones and tablets the full-detail view is media-first. A caller who
   deliberately opened an SVG/image should see it before the longer copy. */
@media(max-width:980px){
  #book-reader[data-os-family] .book-full-detail-body > .book-spread > :is(.book-has-archive,.book-atlas-art),
  #book-reader[data-os-family] .book-evidence-demo-body > .book-spread > :is(.book-has-archive,.book-atlas-art) {
    order:-1!important;
  }
  #book-reader[data-os-family] .book-full-detail-body > .book-spread:has(.book-has-archive),
  #book-reader[data-os-family] .book-full-detail-body > .book-spread:has(.book-atlas-art) {
    gap:.65rem!important;
  }
}

/* Atlas illustrations may move from the scaled slide into native full-detail
   or optional demo dialogs. Keep their buttons in the SAME OS skin. */
#book-reader[data-os-family] :is(.book-full-detail-body,.book-evidence-demo-body) .book-atlas-art {
  border:2px solid var(--os-line,#9caba4)!important;
  border-radius:var(--os-radius,3px)!important;
  border-top:2px solid var(--os-line,#9caba4)!important;
  background:var(--os-client,#f0efe9)!important;
  box-shadow:3px 4px 0 #0003!important;
}
#book-reader[data-os-family] :is(.book-full-detail-body,.book-evidence-demo-body) .book-atlas-nav button {
  background:var(--os-button,#ecece8)!important;
  color:var(--os-button-ink,#243f3e)!important;
  border:1px solid var(--os-line,#9ba9a4)!important;
  border-radius:var(--os-radius,3px)!important;
  font-family:var(--os-ui-font,"Noto Sans TC",sans-serif)!important;
}
#book-reader[data-os-family] :is(.book-full-detail-body,.book-evidence-demo-body) .book-atlas-nav button[aria-pressed="true"] {
  background:var(--os-titlebar,#2d4a4f)!important;
  color:var(--os-title-ink,#fff)!important;
  border-color:var(--os-titlebar,#2d4a4f)!important;
}
#book-reader[data-os-family] :is(.book-full-detail-body,.book-evidence-demo-body) .book-atlas-zoom-trigger {
  background:var(--os-button,#e9eeec)!important;
  color:var(--os-button-ink,#243c40)!important;
  border:1px solid var(--os-line,#a1b0a9)!important;
  border-radius:var(--os-radius,3px)!important;
  font-family:var(--os-ui-font,"Noto Sans TC",sans-serif)!important;
}
