.theme-toggle {
  appearance: none;
  border: 0;
  font: inherit;
  cursor: pointer;
  color: var(--app-text, #e5edf8);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--app-focus, var(--app-accent-cyan, #22d3ee));
  outline-offset: 3px;
}

.theme-toggle__icon {
  position: relative;
  overflow: hidden;
}

.theme-toggle__icon svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle__moon {
  display: none;
}

[data-theme="light"] .theme-toggle__sun {
  display: none;
}

[data-theme="light"] .theme-toggle__moon {
  display: block;
}

.theme-toggle__label {
  min-width: 0;
}

.theme-toggle--public {
  min-width: 110px;
  min-height: 42px;
  display: inline-grid;
  grid-template-columns: 22px auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--app-border, rgb(148 163 184 / 0.28));
  background: var(--app-surface-elevated, rgb(15 23 42 / 0.74));
  box-shadow: 0 12px 28px rgb(2 6 23 / 0.2);
  color: var(--app-text, #f8fafc);
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

body[data-theme="light"] .theme-toggle--public {
  background: rgb(255 255 255 / 0.82);
  border-color: rgb(15 23 42 / 0.12);
  color: rgb(15 23 42 / 0.9);
  box-shadow: 0 14px 30px rgb(15 23 42 / 0.1);
}

.theme-toggle--public:hover {
  transform: translateY(-1px);
}

.nav-rail--canon .theme-toggle--rail {
  width: 100%;
}

.theme-toggle--rail {
  background: transparent;
}

.theme-toggle--rail .theme-toggle__icon {
  color: currentColor;
}

.theme-toggle--rail .theme-toggle__label {
  text-align: left;
}

.theme-toggle--floating {
  position: fixed;
  right: max(14px, calc(14px + var(--mobile-tab-bar-vv-right, 0px)));
  bottom: calc(
    var(--mobile-tab-bar-vv-bottom, 0px) +
    var(--mobile-tab-bar-h, 60px) +
    env(safe-area-inset-bottom) +
    14px
  );
  z-index: 950;
  width: 44px;
  height: 44px;
  display: none;
  place-items: center;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--app-border, rgb(148 163 184 / 0.3));
  background: var(--app-surface-elevated, rgb(15 23 42 / 0.82));
  color: var(--app-text, #f8fafc);
  box-shadow: 0 16px 34px rgb(2 6 23 / 0.32);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

body[data-theme="light"] .theme-toggle--floating {
  background: rgb(255 255 255 / 0.9);
  border-color: rgb(15 23 42 / 0.12);
  color: rgb(15 23 42 / 0.9);
  box-shadow: 0 16px 34px rgb(15 23 42 / 0.14);
}

.theme-toggle--floating .theme-toggle__label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

body.modal-open .theme-toggle--floating,
body.chat-open .theme-toggle--floating,
body.drawer-open .theme-toggle--floating,
body.sidebar-open .theme-toggle--floating,
body.question-aid-open .theme-toggle--floating,
html.sidebar-open .theme-toggle--floating,
body.has-drawer-open .theme-toggle--floating,
body.has-question-aid-open .theme-toggle--floating,
body.has-question-aid-modal-open .theme-toggle--floating,
body.has-question-aid-sheet-open .theme-toggle--floating,
body.has-question-sheet-open .theme-toggle--floating,
body.qcm-focus-open .theme-toggle--floating,
body.account-open .theme-toggle--floating {
  display: none;
}

body[data-page="account"] .theme-toggle--floating {
  right: auto;
  left: max(14px, calc(14px + var(--mobile-tab-bar-vv-left, 0px)));
}

body[data-page="buy-tokens"] .theme-toggle--floating {
  right: max(18px, calc(18px + var(--mobile-tab-bar-vv-right, 0px)));
}

@media (prefers-reduced-motion: no-preference) {
  .theme-toggle {
    transition:
      transform 180ms ease,
      border-color 180ms ease,
      background 180ms ease,
      box-shadow 180ms ease,
      color 180ms ease;
  }
}

@media (max-width: 1024px) {
  .theme-toggle--floating {
    display: grid;
  }
}

@media (max-width: 760px) {
  .theme-toggle--public {
    min-width: 42px;
    width: 42px;
    height: 42px;
    grid-template-columns: 1fr;
    padding: 0;
  }

  .theme-toggle--public .theme-toggle__label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
}
