/* Marginalia mode-switch host — namespaced marg-mode-* only.
   Never restyles existing reader content, theme or lighting. Uses the
   page's house tokens when present; fallbacks are the Day paper values. */
/* A fixed band at the bottom edge. In Reading mode it shares the reader
   footer's row (the footer is at least --marg-mode-reserve tall and keeps
   --marg-mode-inline clear); in Author mode the band itself is that strip.
   z-index 120: above reader overlays (.overlay z100), so the control stays
   reachable with a modal open; overlays reserve the band below them. */
.marg-mode-layer{
  position:fixed; right:0; bottom:0; z-index:120; box-sizing:border-box;
  display:flex; align-items:center; justify-content:flex-end;
  min-height:34px; padding:3px 12px 3px 8px;
  font:var(--ui-size, 13px)/1.25 var(--font-ui, system-ui, -apple-system, "Segoe UI", sans-serif);
  color:var(--ink, #2b2620);
  pointer-events:none;
}
.marg-mode-layer[hidden], .marg-mode-layer [hidden]{ display:none !important; }
.marg-mode-layer > *{ pointer-events:auto; }
.marg-mode-author{ left:0; background:var(--paper, #f6f1e7); box-shadow:inset 0 1px var(--hairline, #ddd2bf); }
/* Split button: the switch plus the 'Author mode opens' chevron. */
.marg-mode-ctl{
  display:flex; border:1px solid var(--hairline-2, #cfc2aa); border-radius:7px;
  background:var(--card-bg, #faf6ee);
}
.marg-mode-layer button{
  font:inherit; color:inherit; margin:0; border:0; background:none; cursor:pointer;
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  min-height:26px; padding:0 10px; border-radius:6px;
}
.marg-mode-layer .marg-mode-more{
  min-width:26px; padding:0 5px; color:var(--ink-soft, #57503f);
  border-left:1px solid var(--hairline, #ddd2bf); border-radius:0 6px 6px 0;
}
.marg-mode-ctl:has(.marg-mode-more:not([hidden])) .marg-mode-btn{ border-radius:6px 0 0 6px; }
.marg-mode-layer .marg-mode-btn:hover, .marg-mode-layer .marg-mode-more:hover,
.marg-mode-more[aria-expanded="true"]{ background:var(--paper-2, #efe8da); }
.marg-mode-layer button:focus-visible{ outline-offset:-2px; }
.marg-mode-ico{
  width:16px; height:16px; flex:none;
  fill:none; stroke:currentColor; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round;
}
.marg-mode-author .marg-mode-pen, .marg-mode-layer:not(.marg-mode-author) .marg-mode-book{ display:none; }
.marg-mode-busy .marg-mode-btn{ cursor:progress; }
@media (prefers-reduced-motion:no-preference){
  html:not([data-motion="reduce"]) .marg-mode-busy .marg-mode-btn .marg-mode-ico{
    animation:marg-mode-pulse .8s ease-in-out infinite alternate;
  }
}
@keyframes marg-mode-pulse{ to{ opacity:.35; } }
/* Popovers above the band: the entry menu and the transient note. */
.marg-mode-menu, .marg-mode-note{
  position:absolute; right:12px; bottom:calc(100% + 6px); margin:0; box-sizing:border-box;
  max-width:calc(100vw - 24px);
  border:1px solid var(--hairline-2, #cfc2aa); border-radius:9px;
  background:var(--card-bg, #faf6ee); color:var(--ink, #2b2620);
  box-shadow:var(--shadow, 0 6px 24px rgba(60,45,20,.12));
}
.marg-mode-menu{ min-width:220px; padding:8px 6px 6px; outline:none; }
.marg-mode-menu legend{
  float:left; width:100%; padding:0 8px 6px;
  font-size:11px; letter-spacing:.08em; text-transform:uppercase; color:var(--ink-faint, #6d6455);
}
.marg-mode-menu label{
  clear:left; display:flex; align-items:center; gap:8px; min-height:30px; padding:0 8px;
  border-radius:6px; cursor:pointer; white-space:nowrap;
}
.marg-mode-menu label:hover{ background:var(--paper-2, #efe8da); }
/* House-drawn radios: native ones stay white on the Evening card. */
.marg-mode-menu input{
  appearance:none; flex:none; width:16px; height:16px; margin:0; border-radius:50%;
  border:1.5px solid var(--ink-faint, #6d6455); cursor:pointer;
}
.marg-mode-menu input:checked{
  border-color:var(--accent, #b3452a);
  background:radial-gradient(var(--accent, #b3452a) 3.5px, transparent 4px);
}
@media (forced-colors:active){ .marg-mode-menu input{ appearance:auto; } }
.marg-mode-note{ display:none; align-items:center; gap:10px; width:max-content; padding:5px 5px 5px 12px; }
.marg-mode-note.marg-mode-on{ display:flex; }
.marg-mode-prog:empty, .marg-mode-status:empty{ display:none; }
.marg-mode-status{ cursor:pointer; padding-right:7px; }
.marg-mode-err{ color:var(--caution-fg, #9c3d22); }
.marg-mode-layer .marg-mode-cancel{ border:1px solid var(--hairline, #ddd2bf); }
/* The author iframe ends at the band. An iframe is a replaced element
   (height:auto would be 150px), so its height is the viewport minus the
   band. Warm flips only toggle visibility: geometry stays stable. */
.marg-mode-frame{
  position:fixed; left:0; top:0; width:100%; border:0; z-index:110;
  height:calc(100vh - var(--marg-mode-reserve, 0px));
  height:calc(100dvh - var(--marg-mode-reserve, 0px));
  background:var(--paper, #fff); color-scheme:light dark;
}
/* Reader modals (.overlay z100) keep their backdrop full-screen but fit
   their centred content above the band ("body" outranks the reader's own
   later .overlay padding). Nothing else is restyled. */
body .overlay{ padding-bottom:calc(20px + var(--marg-mode-reserve, 0px)); }
/* Touch: 36px targets; the band is 40px. */
@media (hover:none){
  .marg-mode-layer{ min-height:40px; padding-block:1px; }
  .marg-mode-layer button{ min-height:36px; }
  .marg-mode-layer .marg-mode-more{ min-width:36px; }
  .marg-mode-menu label{ min-height:40px; }
}
/* Phones: in Reading mode the switch is its pen glyph (named "Author
   mode") so the footer row keeps its line. */
@media (max-width:479.98px){
  .marg-mode-layer{ padding-right:8px; }
  .marg-mode-layer:not(.marg-mode-author) .marg-mode-lbl{
    position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap;
  }
}
@media print{ .marg-mode-layer{ display:none !important; } }
