/* The button stays at the physical right edge in both writing directions. */
.site-header .theme-toggle {
  display: none;
  position: absolute;
  right: 0;
  top: 15px;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 10px;
  color: var(--ink, #1d1d1f);
  background: transparent;
  cursor: pointer;
}

html[data-theme] .site-header .theme-toggle:not([hidden]) { display: grid; }
.theme-toggle svg { width: 20px; height: 20px; pointer-events: none; }
.theme-toggle .theme-sun { display: none; }
.theme-toggle:hover { background: var(--surface, #f5f5f7); }
.theme-toggle:focus-visible {
  outline: 3px solid var(--blue, #006bd6);
  outline-offset: 2px;
}
html[data-theme] .header-inner > .language-switch { margin-right: 48px; }
html[data-theme] .header-inner > .brand { min-width: 0; max-width: 100%; }
html[data-theme] .brand > img { flex: none; }
html[data-theme] .brand > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
html[dir="rtl"][data-theme] .header-inner { direction: ltr; }
html[dir="rtl"][data-theme] .header-inner > :not(.theme-toggle) { direction: rtl; }
html[dir="rtl"][data-theme] .header-inner .language-options { left: auto; right: 0; }

@media (min-width: 851px) {
  html[data-theme] .header-inner {
    grid-template-columns: minmax(6rem, 1fr) minmax(0, max-content) minmax(max-content, 1fr);
    column-gap: clamp(12px, 1.5vw, 24px);
  }
  html[data-theme] .header-inner .desktop-nav {
    min-width: 0;
    flex-wrap: wrap;
    column-gap: clamp(12px, 1.6vw, 30px);
    row-gap: 0;
  }
  html[data-theme] .header-inner > .language-switch { white-space: nowrap; }
  .site-header .theme-toggle { top: 50%; transform: translateY(-50%); }
}

@media (max-width: 850px) {
  html[data-theme] .header-inner > .language-switch {
    margin-left: auto;
    margin-right: 92px;
  }
  html[data-theme] .header-inner > .mobile-menu > summary { right: 46px; }
  html[data-theme] .header-inner > .brand { min-width: 0; max-width: calc(100% - 158px); }
}

@media (max-width: 480px) {
  /* Longer localized headings and links must not widen the viewport beyond
     the right-hand controls, including inside single-column download cards. */
  html[data-theme] main :where(h1, h2, h3, h4, p, li, dt, dd, a, summary),
  html[data-theme] .site-footer a { overflow-wrap: anywhere; }
  html[data-theme] .download-card { min-width: 0; }
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf1f6;
  --muted: #b5becb;
  --blue: #87beff;
  --surface: #20252d;
  --line: #404955;
  --control: #929eaf;
  --theme-page: #14181e;
  --theme-raised: #262c35;
  --theme-subtle: #303844;
  --theme-current: #263b51;
  --theme-on-primary: #131820;
  background-color: var(--theme-page);
}
html[data-theme="dark"] body {
  color: var(--ink);
  background-color: var(--theme-page);
}
html[data-theme="dark"] ::selection { background: #35597f; color: #fff; }
html[data-theme="dark"] .theme-toggle .theme-sun { display: block; }
html[data-theme="dark"] .theme-toggle .theme-moon { display: none; }
html[data-theme="dark"] .site-header {
  background-color: rgb(20 24 30 / 97%);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.language-options, .platform-options) {
  color: var(--ink);
  background-color: var(--theme-raised);
  border-color: var(--line);
  box-shadow: 0 8px 28px rgb(0 0 0 / 35%);
}
html[data-theme="dark"] :is(.language-options, .platform-options) a:is(:hover, [aria-current="page"]),
html[data-theme="dark"] :is(.guide-sidebar, .article-guides, .page-sidebar) a[aria-current="page"] {
  color: var(--ink);
  background-color: var(--theme-current);
}
html[data-theme="dark"] .button,
html[data-theme="dark"] .mobile-languages a[aria-current="page"] {
  color: var(--theme-on-primary);
  background-color: var(--ink);
}
html[data-theme="dark"] .button:hover { color: var(--theme-on-primary); background-color: #cfdae7; }
html[data-theme="dark"] .button.secondary { color: var(--ink); background-color: var(--theme-subtle); }
html[data-theme="dark"] .button.secondary:hover { color: #fff; background-color: #424e60; }
html[data-theme="dark"] .gradient-text {
  background-image: linear-gradient(105deg, #82c2ff 16%, #c79bf1 94%);
}
html[data-theme="dark"] :is(.feature-panel, .android-tv-support) {
  background: linear-gradient(115deg, #203246, #232831);
}
html[data-theme="dark"] :is(.skip-link, .notice, .feature-list > div, .kernel-start .kernel-flow > div,
  .diagram .node, .download-card select) { background-color: var(--theme-raised); color: var(--ink); }
html[data-theme="dark"] :is(.article-contents summary, .package-table th, pre, code) {
  background-color: var(--theme-subtle);
  color: var(--ink);
}
html[data-theme="dark"] .diagram .core { background-color: var(--theme-current); }
html[data-theme="dark"] .note { background-color: #302b20; color: #e4d3b0; }
html[data-theme="dark"] .guide-article a:not(.button):hover { color: #badcff; }
html[data-theme="dark"] .brand-mark { color: white; background-color: #376aa1; }

/* Release blocks are built separately and carry literal light-mode colors. */
html[data-theme="dark"] #current-release {
  color: var(--ink);
  background-color: var(--theme-raised);
  border-color: var(--line);
}
html[data-theme="dark"] #current-release :is(time, small) { color: var(--muted); }
html[data-theme="dark"] #current-release a { color: var(--blue); }
html[data-theme="dark"] [style*="color:#62626a"] { color: var(--muted) !important; }

/* Theme the surrounding page and CSS device illustrations. Screenshot pixels
   and the borders belonging to the images keep their original appearance. */
html[data-theme="dark"] :is(.hero-image, .device, .devices, .device-placeholder, .device-scene,
  .device-composition, .placeholder-devices, .diagram) { background-color: transparent; }
html[data-theme="dark"] :is(.cfw-device-screen, .phone, .laptop, .tablet, .desktop, .monitor, .screen, .mini div,
  .placeholder, .placeholder-device, .shadowrocket-devices .ipad, .shadowrocket-devices .iphone) {
  color: var(--muted);
  background-color: var(--theme-raised);
}
html[data-theme="dark"] :is(.screen, .cfw-device-screen) strong { color: var(--ink); }

/* The footer keeps one compact language control; its full list opens upward.
   Anchor the panel to the footer navigation so wrapped controls near the
   viewport edge can always open inside the available inline width. */
.site-footer .footer-top nav { position: relative; }
.site-footer .locale-footer-options:has(.footer-language-switch) {
  overflow: visible;
  max-height: none;
}
.site-footer .footer-language-switch {
  display: inline-block;
  max-width: 100%;
  color: var(--ink, #1d1d1f);
}
.site-footer .footer-language-switch summary {
  min-height: 44px;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-inline: 10px;
  border-radius: 8px;
  cursor: pointer;
  list-style: none;
  overflow-wrap: anywhere;
}
.site-footer .footer-language-switch summary::-webkit-details-marker { display: none; }
.site-footer .footer-language-switch summary:hover,
.site-footer .footer-language-switch[open] summary {
  background-color: var(--surface, #f5f5f7);
}
.site-footer .footer-language-switch summary:focus-visible {
  outline: 3px solid var(--blue, #006bd6);
  outline-offset: 2px;
}
.site-footer .footer-language-switch summary svg { width: 16px; height: 16px; flex: none; }
.site-footer .footer-language-switch:not([open]) > .footer-language-options { display: none; }
.site-footer .footer-language-options {
  position: absolute;
  z-index: 5;
  inset-inline-end: 0;
  bottom: calc(100% + 6px);
  width: min(18rem, 100%);
  max-height: min(18rem, 52vh);
  max-height: min(18rem, 52dvh);
  padding: 6px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line, #e2e2e7);
  border-radius: 12px;
  background-color: #fff;
  color: var(--ink, #1d1d1f);
  box-shadow: 0 8px 28px rgb(0 0 0 / 14%);
}
.site-footer .footer-language-options a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 7px;
  color: var(--ink, #1d1d1f);
  text-align: start;
  overflow-wrap: anywhere;
  line-height: 1.45;
}
.site-footer .footer-language-options a:is(:hover, [aria-current="page"]) {
  background-color: var(--surface, #f5f5f7);
  color: var(--ink, #1d1d1f);
}
.site-footer .footer-language-options a[aria-current="page"] { font-weight: 700; }
.site-footer .footer-language-options a:focus-visible { outline-offset: -3px; }
html[data-theme="dark"] .site-footer .footer-language-options {
  background-color: var(--theme-raised);
  box-shadow: 0 8px 28px rgb(0 0 0 / 35%);
}
html[data-theme="dark"] .site-footer .footer-language-options a:is(:hover, [aria-current="page"]) {
  background-color: var(--theme-current);
}
