/* The same labelled theme switch is used in every site header. */
html button.kb-theme-switch {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 7px 10px;
  border: 1px solid #d7aab9;
  border-radius: 10px;
  background: #fff4f7;
  color: #78304d;
  font: 800 12px/normal 'Plus Jakarta Sans', sans-serif;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: none;
}
html button.kb-theme-switch[hidden] { display: none; }
html button.kb-theme-switch:hover { background: #ffe6ee; border-color: #b94b70; }
html button.kb-theme-switch:focus-visible { outline: 3px solid #c63d6d; outline-offset: 3px; }
.kb-theme-switch .theme-track { box-sizing: border-box; display: inline-flex; align-items: center; width: 40px; height: 24px; padding: 2px; border-radius: 999px; background: #dfb5c2; flex: none; }
.kb-theme-switch .theme-thumb { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #fff; color: #9c4561; box-shadow: 0 1px 3px #54243b42; }
.kb-theme-switch .theme-thumb svg { width: 14px; height: 14px; }
.kb-theme-switch .theme-moon { display: none; }
html[data-theme="night"] button.kb-theme-switch { background: #372c37; border-color: #6b505e; color: #ffe5ee; }
html[data-theme="night"] button.kb-theme-switch:hover { background: #4a3644; }
html[data-theme="night"] .kb-theme-switch .theme-sun { display: none; }
html[data-theme="night"] .kb-theme-switch .theme-moon { display: block; }
html[data-theme="night"] .kb-theme-switch .theme-track { background: #a0607a; }
html[data-theme="night"] .kb-theme-switch .theme-thumb { transform: translateX(16px); background: #ffdfeb; color: #6e2949; }
@media (prefers-reduced-motion: no-preference) {
  .kb-theme-switch .theme-thumb { transition: transform .45s cubic-bezier(.2,.8,.2,1), background-color .45s ease, color .45s ease; }
}
/* The sign-in page has no standard navigation; keep its control next to the brand. */
html[data-kb-page="admin"] .login-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
@media (max-width: 600px) {
  .kb-tool-header { gap: 8px; }
  .kb-tool-header > .brand { order: 0; min-width: 0; max-width: calc(100% - 162px); }
  .kb-tool-header > .brand > span:last-child { min-width: 0; }
  .kb-tool-header > .brand small { white-space: normal; }
  .kb-tool-header > button.kb-theme-switch { order: 1; margin-left: auto; }
  .kb-tool-header > .topnav { order: 2; flex-basis: 100%; }
  html[data-kb-page="contact"] .contact-header nav { flex-wrap: wrap; justify-content: center; }
  html[data-kb-page="ambient"] .top-inner .brand { min-width: 0; max-width: calc(100% - 162px); white-space: normal; }
  html[data-kb-page="ambient"] .top-inner .kb-theme-switch { order: 1; }
  html[data-kb-page="ambient"] .top-inner .home-link { order: 2; flex-basis: 100%; }
}
@media (max-width: 380px) { html .home-header button.kb-theme-switch { font-size: 11px; gap: 5px; padding: 7px 5px; } }

/* Decorative transition overlays never intercept input or enter the accessibility tree. */
.kb-theme-effect { position: fixed; inset: 0; z-index: 2147483647; pointer-events: none; overflow: hidden; }
@media (prefers-reduced-motion: no-preference) {
  /* The original gentle radial wave, now shared by all pages. */
  .kb-theme-effect--wave {
    background: radial-gradient(circle at 90% 0%, rgba(173,139,212,.35), rgba(126,103,178,.12) 48%, transparent 78%);
    animation: kb-theme-wave .85s ease-out both;
  }
  .kb-theme-effect--wave.kb-theme-effect--to-day {
    background: radial-gradient(circle at 90% 0%, rgba(255,207,146,.38), rgba(247,177,179,.12) 48%, transparent 78%);
  }
  @keyframes kb-theme-wave {
    0% { clip-path: circle(0 at 90% 0%); opacity: .7; }
    65% { opacity: .32; }
    100% { clip-path: circle(150vmax at 90% 0%); opacity: 0; }
  }
  /* A curtain in the previous palette withdraws downwards, revealing the new theme from the top. */
  .kb-theme-effect--wipe { background: #fff9f4; animation: kb-theme-wipe 1s cubic-bezier(.45,0,.2,1) both; }
  .kb-theme-effect--wipe.kb-theme-effect--from-night { background: #231e27; }
  @keyframes kb-theme-wipe {
    0% { clip-path: inset(0 0 0 0); }
    100% { clip-path: inset(100% 0 0 0); }
  }
  /* A staggered grid of split-flap tiles, inspired by airport departure boards. */
  .kb-theme-effect--flap { display: grid; grid-template-columns: repeat(12, 1fr); grid-template-rows: repeat(8, 1fr); gap: 2px; perspective: 900px; }
  .kb-theme-flap {
    position: relative; display: grid; place-items: center; min-width: 0; min-height: 0;
    overflow: hidden; border-radius: 3px; color: #fff2e7; background: #463640;
    font: 700 clamp(14px, 3vw, 40px)/1 ui-monospace, monospace;
    transform-origin: 50% 0; backface-visibility: hidden;
    animation: kb-theme-flip .68s cubic-bezier(.45,0,.35,1) both;
  }
  .kb-theme-effect--from-night .kb-theme-flap { color: #fde7d5; background: #211d29; }
  .kb-theme-flap::after { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 2px solid #160f1b; box-shadow: 0 1px #ffffff25; }
  @keyframes kb-theme-flip {
    0%, 12% { transform: rotateX(0); opacity: 1; }
    75%, 100% { transform: rotateX(-90deg); opacity: 0; }
  }
  .kb-theme-flap--step-0 { animation-delay: 0s; }
  .kb-theme-flap--step-1 { animation-delay: .04s; }
  .kb-theme-flap--step-2 { animation-delay: .08s; }
  .kb-theme-flap--step-3 { animation-delay: .12s; }
  .kb-theme-flap--step-4 { animation-delay: .16s; }
  .kb-theme-flap--step-5 { animation-delay: .20s; }
  .kb-theme-flap--step-6 { animation-delay: .24s; }
  .kb-theme-flap--step-7 { animation-delay: .28s; }
  .kb-theme-flap--step-8 { animation-delay: .32s; }
  .kb-theme-flap--step-9 { animation-delay: .36s; }
  .kb-theme-flap--step-10 { animation-delay: .40s; }
  .kb-theme-flap--step-11 { animation-delay: .44s; }
}
@media (prefers-reduced-motion: reduce) { .kb-theme-effect { display: none; } }
