/* Shared reading controls for every composition page. */
:root { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
}
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }

.top-in > .mark { flex-shrink: 0; }
.top-in > .chipnav { min-width: 0; }
.theme-toggle {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: 500 14px/1.4 var(--body);
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:hover { border-color: var(--grid-strong); }
.theme-toggle:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }
.theme-toggle-icon { width: 18px; font-size: 20px; line-height: 1; text-align: center; }

/* Keep the control in the first row and let mobile chapters scroll below it. */
@media (max-width: 760px) {
  .top-in { flex-wrap: wrap; gap: 8px 10px; }
  .top-in > .theme-toggle { order: 1; }
  .top-in > .chipnav,
  .top-in > .jump,
  .top-in > .writing-progress {
    order: 2;
    flex: 1 0 100%;
    width: 100%;
    min-width: 0;
  }
  .top-in > .chipnav { padding: 2px 0; }
  .top-in > .jump { overflow-x: auto; }
  .top-in > .writing-progress { flex-wrap: wrap; justify-content: space-between; }
  .top-in > .writing-progress .cells.off { display: none; }
  .top-in > .writing-progress:has(.cells.off) { display: none !important; }
  html { scroll-padding-top: calc(128px + env(safe-area-inset-top, 0px)); }
  .top-in .mark > span:not(.cm) { display: inline; }
}

/* Printing always uses dark text on white paper, even in night mode. */
@media print {
  :root, :root[data-theme], :root:not([data-theme="light"]) {
    color-scheme: light;
    --bg: #FFFFFF;
    --card: #FFFFFF;
    --ink: #1E2A45;
    --muted: #5D6678;
    --line: #D4DAD4;
    --grid: #B9D3C6;
    --grid-strong: #6FA58B;
    --soft: #E9EEE9;
    --rouge: #B8323F;
    --green: #2D7560;
    --on-ink: #FFFFFF;
    --on-rouge: #FFFFFF;
  }
  .theme-toggle { display: none !important; }
  body { background: #FFFFFF; color: var(--ink); }
}
