/* Theme toggle: floating rectangular control in the upper-right corner.
   The JS (assets/theme.js) owns mode state and sets html[data-theme-mode]
   (stored choice: system|light|dark) plus html[data-theme] (effective
   light|dark); this file only paints the button and the color-scheme hint. */

/* Native color-scheme follows the effective theme so scrollbars, form
   controls and the canvas backdrop match without touching theme vars. */
html[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

/* `body .theme-toggle` outranks docsify's plain `button[type]` and
   `button:not([type])` rules (and wins ties by loading later) so the theme
   button styles never leak the "button" look onto this control. */
body .theme-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  z-index: 30; /* above page content, below the native top-layer dialog */
  box-sizing: border-box;
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 0;
  background: var(--color-bg);
  box-shadow: 0 1px 4px rgb(0 0 0 / 12%);
  color: var(--color-text);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--duration-fast),
    border-color var(--duration-fast), color var(--duration-fast);
}

html[data-theme="light"] body .theme-toggle {
  border-color: #cfd4d8;
}

/* JS swaps one 22px stroked SVG (monitor / sun / moon) for the current mode.
   Keeping the paint here guarantees the icon tracks --color-text in both
   themes even if the markup ever forgets its stroke attribute. */
body .theme-toggle svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
}

@media (hover: hover) {
  body .theme-toggle:hover {
    background: var(--color-mono-1);
    border-color: var(--color-mono-3);
  }
}

body .theme-toggle:focus-visible {
  outline: 2px solid var(--theme-color);
  outline-offset: 2px;
}

body .theme-toggle:active {
  background: var(--color-mono-2);
}

/* Compact on touch screens; keep the icon and a transparent 44px hit area. */
@media (pointer: coarse) {
  body .theme-toggle {
    width: 32px;
    height: 32px;
    min-height: 32px;
  }

  body .theme-toggle::before {
    content: '';
    position: absolute;
    inset: -6px -4px;
  }
}

/* The image-viewer <dialog> lives in the top layer and brings its own close
   button to the same corner; hide ours so the two never visually collide. */
html.image-viewer-open body .theme-toggle {
  visibility: hidden;
}

/* Chrome element: matches docsify hiding nav/sidebar chrome when printing. */
@media print {
  body .theme-toggle {
    display: none;
  }
}
