/* Role-specific colors are inherited by existing components, including new rows
   and dialogs. No DOM scanning, image filters, timers or additional requests. */
html[data-theme="dark"] {
  color-scheme: dark;
  --night-surface-1: #18241d;
  --night-surface-2: #1e2d24;
  --night-surface-3: #293d30;
  --night-line: #3a5040;
  --night-ink: #e4eee5;
  --night-secondary: #baccbc;
  --night-muted: #9fb4a3;
  --night-green: #a5d5ad;
  --night-danger: #f1a39d;
  --night-gold: #e5c38b;
  --night-blue: #a7c7e8;
  background: #101813;
}
html[data-theme="dark"] body {
  color-scheme: dark;
  scrollbar-color: #536a59 #101813;
}
html[data-theme="dark"] body.admin-studio {
  --studio-bg: #101813; --bg: #101813;
  --ink-soft: #baccbc; --stroke: #3a5040; --stroke-soft: #3a5040; --teal: #a5d5ad; --teal-deep: #293d30;
  background: #101813 !important;
}
html[data-theme="dark"] body.admin-studio :is(.main,.shell) { background: #101813; }
html[data-theme="dark"] body.home-atlas { --atlas-paper: #101813; }
/* Secondary copy in community pages must remain legible on dark panels. */
html[data-theme="dark"] body.feature-page { --text-tertiary: var(--night-muted); --ink-faint: var(--night-muted); }
html[data-theme="dark"] body.portal-v3 { --ink-faint: var(--night-muted); }
/* Media artwork retains its colors; interface surfaces use the night palette. */
html[data-theme="dark"] body.home-v2 .modal.profile-mode .pf-checkin { background: #337422; border-color: #245517; box-shadow: inset 0 2px 0 #ffffff30, 0 4px 0 #245517; }
html[data-theme="dark"] body.home-v2 .modal.profile-mode .pf-checkin.done { background: #293d30; border-color: #3a5040; box-shadow: 0 4px 0 #3a5040; }
html[data-theme="dark"] body.admin-studio :is(.btn,.mini-btn.primary,.gate-card .btn),
html[data-theme="dark"] body.admin-studio :is(.security-body button:not(.secondary),.native-form > button:not(.secondary)) { color: #f4f8ee; }
html[data-theme="dark"] body.admin-studio :is(input,select,textarea,dialog),
html[data-theme="dark"] body.home-v2 .modal.profile-mode .modal-card { color-scheme: dark; }
html[data-theme="dark"] body.admin-studio select option { color: #e4eee5; background: #18241d; }
html[data-theme="dark"] body.admin-studio :is(input,textarea)::placeholder { color: #93aa99; }
html[data-theme="dark"] body.admin-studio .container-audit-entry.active { box-shadow: inset 3px 0 #a5d5ad; }

html[data-theme="dark"] body.home-v2 .modal.profile-mode { --pf-paper: #18241d; --pf-ink: #e4eee5; --pf-muted: #baccbc; --pf-border: #3a5040; }
/* The other public pages already use the site's night palette. Native controls
   now match it as well, including authentication and server-generated pages. */
html[data-theme="dark"] body:not(.admin-studio):not(.home-atlas) { color-scheme: dark; }
html[data-theme="dark"] :is(input,textarea)::placeholder { opacity: 1; }

/* Settings use their own tokens so legacy form and dialog rules cannot leak in. */
.home-v2 .modal.profile-mode .pf-quick-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.home-v2 .modal.profile-mode .pf-quick-header .pf-section-title { margin: 0; }
.home-v2 .modal.profile-mode .pf-settings-entry { display: flex; }
html[data-theme] body .pf-settings-entry .site-settings-trigger { background: var(--settings-field); border-color: var(--settings-line); color: var(--settings-ink); min-height: 40px; padding-inline: 14px; }
html body #siteSettings .site-settings-security { display: grid; grid-template-columns: 40px minmax(0,1fr) 20px; align-items: center; gap: 12px; margin: 16px 0; padding: 18px 14px; border: 1px solid var(--settings-line); border-radius: 10px; background: var(--settings-field); color: var(--settings-ink); text-decoration: none; }
html body #siteSettings .site-settings-security img { image-rendering: pixelated; }
html body #siteSettings .site-settings-security:hover { border-color: #6c967b; }
html body #siteSettings .site-settings-security:focus-visible { outline: 2px solid #78af88; outline-offset: 3px; }
html body #siteSettings .site-settings-arrow { font-size: 22px; }
body { --settings-bg: #18241d; --settings-field: #22342a; --settings-ink: #e4eee5; --settings-muted: #baccbc; --settings-line: #3a5040; }
html[data-theme="light"] body:is(.home-atlas,.admin-studio) { --settings-bg: #f8faf7; --settings-field: #eef3ec; --settings-ink: #21372f; --settings-muted: #5d7063; --settings-line: #cfdbd0; }
html[data-theme] body .site-settings-trigger {
  display: inline-flex; position: relative; align-items: center; justify-content: center; gap: 7px;
  flex: 0 0 auto; width: auto; min-width: 38px; min-height: 38px; margin: 0; padding: 8px 11px;
  border: 1px solid #6c87775c; border-radius: 7px; background: #20392c; color: #e4eee5;
  font: 500 12px/1.4 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  text-shadow: none; letter-spacing: 0; box-shadow: none; cursor: pointer;
}
html[data-theme] body .site-settings-trigger svg { display: block; width: 17px; height: 17px; flex: none; }
html[data-theme] body .site-settings-trigger:hover { background: #2c4b3b; border-color: #8eaf9670; }
html[data-theme] body .site-settings-trigger:focus-visible { outline: 2px solid #a5d5ad; outline-offset: 3px; }
html[data-theme] body .site-settings-trigger.site-settings-standalone { position: fixed; top: max(12px,env(safe-area-inset-top)); right: max(12px,env(safe-area-inset-right)); z-index: 90; }
html[data-theme] body .gate-card > .site-settings-trigger { margin-bottom: 22px; }
html[data-theme] body .studio-page-topbar-inner > .site-settings-trigger { margin-left: auto; }
html body .identity-main > header > .site-settings-trigger { align-self: flex-start; }
html body #siteSettings {
  box-sizing: border-box; position: fixed; inset: 0; margin: auto; width: min(520px,calc(100% - 32px));
  max-width: none; max-height: calc(100dvh - 32px); overflow: auto; overscroll-behavior: contain;
  padding: 0; border: 1px solid var(--settings-line); border-radius: 16px;
  background: var(--settings-bg); color: var(--settings-ink); box-shadow: 0 28px 100px #0005;
  font: 14px/1.6 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif; color-scheme: dark;
  text-align: left; transform: none; opacity: 1; letter-spacing: 0;
}
html[data-theme="light"] body:is(.home-atlas,.admin-studio) #siteSettings { color-scheme: light; }
html body #siteSettings:not([open]) { display: none; }
html body #siteSettings[open] { display: block; }
html body #siteSettings::backdrop { background: #07120ec2; backdrop-filter: blur(4px); }
html body #siteSettings * { box-sizing: border-box; }
html body #siteSettings .site-settings-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 25px 26px 20px; border-bottom: 1px solid var(--settings-line); }
html body #siteSettings h2 { margin: 0; padding: 0; font-family: inherit; font-weight: 700; font-size: 23px; line-height: 1.4; color: var(--settings-ink); background: none; -webkit-text-fill-color: currentColor; letter-spacing: 0; }
html body #siteSettings p { margin: 6px 0 0; padding: 0; color: var(--settings-muted); font: inherit; font-size: 12px; }
html body #siteSettings .site-settings-fields { padding: 4px 26px; }
html body #siteSettings .site-settings-row { display: grid; grid-template-columns: minmax(0,1fr) 138px; align-items: center; gap: 18px; margin: 0; padding: 22px 0; border: 0; border-bottom: 1px solid var(--settings-line); background: none; }
html body #siteSettings .site-settings-row:last-child { border-bottom: 0; }
html body #siteSettings .site-settings-copy { display: grid; gap: 4px; }
html body #siteSettings strong { color: var(--settings-ink); font: 600 14px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif; letter-spacing: 0; }
html body #siteSettings small { color: var(--settings-muted); font: 12px/1.65 "Segoe UI", "Microsoft YaHei", sans-serif; letter-spacing: 0; }
html body #siteSettings .site-settings-select { width: 100%; min-width: 0; min-height: 42px; height: auto; margin: 0; padding: 8px 9px !important; border: 1px solid var(--settings-line); border-radius: 7px; background: var(--settings-field); color: var(--settings-ink); -webkit-text-fill-color: currentColor; font: 13px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif; letter-spacing: 0; box-shadow: none; appearance: auto; color-scheme: inherit; cursor: pointer; }
html body #siteSettings option { background: var(--settings-bg); color: var(--settings-ink); }
html body #siteSettings .site-settings-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 26px; border-top: 1px solid var(--settings-line); }
html body #siteSettings .site-settings-status { margin: 0; }
html body #siteSettings button { display: inline-flex; align-items: center; justify-content: center; flex: none; width: auto; min-height: 36px; margin: 0; padding: 7px 12px; border: 1px solid var(--settings-line); border-radius: 7px; background: var(--settings-field); color: var(--settings-ink); font: 12px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif; box-shadow: none; transform: none; cursor: pointer; }
html body #siteSettings button.site-settings-close { width: 36px; height: 36px; padding: 0; font-size: 24px; line-height: 1; }
html body #siteSettings button:hover { border-color: #6c967b; background: var(--settings-field); }
html body #siteSettings :is(button,select):focus-visible { outline: 2px solid #78af88; outline-offset: 3px; }
@media(max-width:900px) {
  html body .page-head .who { display: none; }
  html body .studio-page-topbar-inner { flex-wrap: wrap; }
}
@media(max-width:600px) {
  html body.home-atlas { min-width: 0; }
  html body.home-atlas .nav { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; padding-block: 12px; }
  html body.home-atlas .nav > .brand { grid-column: 1; grid-row: 1; }
  html body.home-atlas .nav > .nav-toggle { grid-column: 2; grid-row: 1; justify-self: end; }
  html body.home-atlas .nav-actions { grid-column: 1 / -1; grid-row: 2; justify-content: flex-end; }
  html body.home-atlas .nav-links { grid-column: 1 / -1; }
  html body .pnav, html body .pnav-right { flex-wrap: wrap; }
  html body .pnav-right { max-width: 100%; gap: 8px; }
  html body header.nav:not(.home-atlas .nav) { flex-wrap: wrap; }
  html body .nav-actions { gap: 5px; }
  html body .studio-page-topbar-inner > .site-settings-trigger { grid-column: 2; grid-row: 1; justify-self: end; }
  html body .studio-page-site { display: none; }
  html body .topbar .top-actions { flex-wrap: wrap; }
}
@media(max-width:420px) {
  html body #siteSettings .site-settings-heading { padding: 20px; }
  html body #siteSettings .site-settings-fields { padding: 0 20px; }
  html body #siteSettings .site-settings-row { grid-template-columns: minmax(0,1fr); gap: 12px; padding: 18px 0; }
  html body #siteSettings .site-settings-footer { padding: 16px 20px; }
}
/* Finish theme coverage: native widgets, selected states, artwork-adjacent surfaces. */
html[data-theme="dark"] body.admin-studio :is(select,select option,input,textarea,dialog) { color-scheme: dark; }
html[data-theme="dark"] body.admin-studio :is(.nav-item.active,.studio-page-nav a[aria-current=page]) { background: #2d4c3b; color: #d6edc4; border-color: #54745b; }
html[data-theme="dark"] body.admin-studio .nav-item.active .nav-icon { color: #d6edc4; }
html[data-theme="dark"] body.admin-studio :is(.brand-mark,.studio-gate-brand > span) { background: #2d4c3b; color: #d6edc4; box-shadow: 3px 3px #101e16; }
html[data-theme="dark"] body.home-atlas :is(.brand-mark,.hero-action.primary,.hero-action.primary:hover,.ci-btn,.portal-selector button[aria-pressed="true"]) { background: #2d4c3b; color: #d6edc4; border-color: #54745b; box-shadow: 0 3px #122b1d; }
html[data-theme="dark"] body.home-atlas :is(.nav-account .na-avatar.logged,.skip-link) { background: #2d4c3b; color: #d6edc4; }
html[data-theme="dark"] body :is(.auth-submit,.identity-main button:not(.secondary):not(.danger),#cpSend,.pk-btn-primary) { background: #2b6447; color: #eff8ec; border-color: #527a5d; }
html[data-theme="dark"] body.home-v2 .modal.profile-mode .pf-avatar-edit:hover { background: #337422; color: #fff; }
html[data-theme="dark"] body.home-v2 .modal.profile-mode :is(.pf-bind,.pf-checkin.done) { box-shadow: 0 3px 0 #0d1912; }
html[data-theme="dark"] body :is(.sponsor-qr-wrap,.payment-qr-panel) { background: var(--night-surface-2); color: var(--night-ink); border-color: var(--night-line); }
html[data-theme="dark"] body.home-atlas .atlas-star { background: #c7dbc5; }
/* Explicit campsite colors also cover older page-specific color declarations. */
html[data-theme="dark"] body.home-atlas #community :is(.wp-title,.comm-t,.community-link-copy strong,.ci-title) { color: #f3f7f1; }
html[data-theme="dark"] body.home-atlas #community :is(.wp-desc,.comm-d,.community-link-copy small,.ci-sub) { color: #d2dfd3; }
html[data-theme="dark"] body.home-atlas #community :is(.comm-no,.comm-go,.community-link-no,.community-link-go) { color: #bfdfae; }
html[data-theme="dark"] body.home-atlas #community :is(.wp-kicker,.wp-title em) { color: #f1b8ac; }
/* Background tabs keep their UI state without continuously animating it. */
html.page-hidden *, html.page-hidden *::before, html.page-hidden *::after { animation-play-state: paused !important; }
/* Reduced motion respects the OS preference and can also be enabled in settings. */
html[data-motion="reduce"] *, html[data-motion="reduce"] *::before, html[data-motion="reduce"] *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
html[data-motion="reduce"] :is(.cursor-dot,.cursor-ring) { display: none !important; }
html[data-motion="reduce"] .home-atlas .hero :is(.atlas-cloud,.atlas-star,.atlas-island,.portal-membrane) { animation-play-state: paused !important; }

/* Administration appearance uses the same semantic palette on every route. */
html[data-theme-scope="admin"] { --admin-canvas: #f5f7f2; --admin-focus: #326b38; }
html[data-theme-scope="admin"][data-theme="dark"] { --admin-canvas: #101813; --admin-focus: #a5d5ad; }
html[data-theme-scope="admin"] body { background: var(--admin-canvas); color: var(--night-ink); color-scheme: light; }
html[data-theme-scope="admin"][data-theme="dark"] body { color-scheme: dark; }
html[data-theme-scope="admin"] body .admin-appearance {
  display: inline-flex; align-items: center; gap: 8px; flex: 0 0 auto; max-width: 100%;
  position: relative; padding: 4px 8px; border: 1px solid var(--night-line); border-radius: 9px;
  background: var(--night-surface-1); color: var(--night-ink); font: 12px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif;
}
html[data-theme-scope="admin"] body .admin-appearance-icon { color: var(--night-green); font-size: 19px; line-height: 1; width: 20px; text-align: center; }
html[data-theme-scope="admin"] body .admin-appearance-label { display: block; margin: 0; color: var(--night-secondary); font: inherit; white-space: nowrap; }
html[data-theme-scope="admin"] body .admin-appearance-select {
  width: 108px; min-width: 108px; flex: 0 0 108px; min-height: 34px; height: 34px; margin: 0;
  box-sizing: border-box; padding: 4px 26px 4px 6px !important; white-space: nowrap; text-overflow: clip;
  border: 0; border-radius: 5px; background: var(--night-surface-1); color: var(--night-ink);
  font: 600 12px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif; appearance: auto; color-scheme: inherit; box-shadow: none; cursor: pointer;
}
html[data-theme-scope="admin"] body .admin-appearance-select option { background: var(--night-surface-1); color: var(--night-ink); }
html[data-theme-scope="admin"] body .admin-appearance-select:focus-visible { outline: 2px solid var(--admin-focus); outline-offset: 2px; }
html[data-theme-scope="admin"] body .admin-appearance-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
html[data-theme-scope="admin"] body .admin-appearance-login { display: flex; flex-wrap: wrap; width: fit-content; margin: 0 0 26px; }
html[data-theme-scope="admin"] body .admin-appearance-login .admin-appearance-status { position: static; flex-basis: 100%; width: auto; height: auto; clip-path: none; white-space: normal; color: var(--night-secondary); font-size: 11px; padding: 0 3px 3px; }
html[data-theme-scope="admin"] .studio-page-topbar-inner { flex-wrap: wrap; }
html[data-theme-scope="admin"] body.admin-studio :is(.head-actions,.page-head) { flex-wrap: wrap; }
html[data-theme-scope="admin"] body.admin-studio :is(input,select,textarea,dialog) { color-scheme: inherit; }
/* Keep native menus readable, including legacy hover/focus declarations. */
html[data-theme-scope="admin"][data-theme] body.admin-studio select,
html[data-theme-scope="admin"][data-theme] body.admin-studio select:is(:hover,:focus,:disabled) {
  background-color: var(--night-surface-1, #fff);
  color: var(--night-ink, #21372f);
  -webkit-text-fill-color: currentColor;
  border-color: var(--night-line, #cbd8cc);
  color-scheme: inherit;
  text-shadow: none;
}
html[data-theme-scope="admin"][data-theme] body.admin-studio select:focus-visible {
  outline: 2px solid var(--admin-focus, #326b38);
  outline-offset: 2px;
}
html[data-theme-scope="admin"][data-theme] body.admin-studio select:disabled {
  background-color: var(--night-surface-2, #edf3e8);
  color: var(--night-secondary, #4e6454);
  opacity: 1;
  cursor: not-allowed;
}
html[data-theme-scope="admin"][data-theme] body.admin-studio select :is(option,optgroup) {
  background-color: var(--night-surface-1, #fff);
  color: var(--night-ink, #21372f);
  -webkit-text-fill-color: currentColor;
  color-scheme: inherit;
}
html[data-theme-scope="admin"][data-theme] body.admin-studio select option:disabled {
  color: var(--night-secondary, #4e6454);
}
html[data-theme-scope="admin"] body.admin-studio :is(button,a,input,select,textarea,summary,[tabindex]):focus-visible { outline-color: var(--admin-focus); }
html[data-theme-scope="admin"][data-theme="dark"] body.admin-studio :is(.side,.sidebar,.studio-page-topbar) { background: #15221b; color: var(--night-ink); border-color: var(--night-line); }
html[data-theme-scope="admin"][data-theme="dark"] body.admin-studio :is(.studio-page-brand,.studio-page-brand small,.studio-page-site,.studio-page-nav a,.brand-copy b,.brand-copy small,.nav-group-label,.nav-item,.nav-icon,.studio-nav-link,.studio-nav-link small,.logout,.side-collapse) { color: var(--night-secondary); }
html[data-theme-scope="admin"][data-theme="dark"] body.admin-studio :is(.studio-page-nav a:hover,.studio-page-nav a[aria-current],.nav-item:hover,.nav-item.active,.studio-nav-link:hover,.side-collapse:hover) { background: var(--night-surface-3); color: var(--night-ink); }
html[data-theme-scope="admin"] body.admin-studio :is(.command-palette,.log-output,.console-output) { background: var(--night-surface-1); color: var(--night-ink); border-color: var(--night-line); }
html[data-theme-scope="admin"] body.admin-studio :is(.table-wrap,.modal-box,dialog) { scrollbar-color: var(--night-muted) transparent; }
/* Custom administrator login gate has no admin-studio class. */
html[data-theme-scope="admin"] body > form.box { background: var(--night-surface-1); color: var(--night-ink); border-color: var(--night-line); box-shadow: 0 20px 48px #0002; }
html[data-theme-scope="admin"] body > form.box :is(p,label) { color: var(--night-secondary); }
html[data-theme-scope="admin"] body > form.box input { background: var(--night-surface-2); color: var(--night-ink); border-color: var(--night-line); }
html[data-theme-scope="admin"] body > form.box input:focus { outline: 2px solid var(--admin-focus); outline-offset: 2px; box-shadow: none; }
html[data-theme-scope="admin"] body > form.box .msg { color: var(--night-danger); }
html[data-theme-scope="admin"] body > form.box button[type="submit"] { background: #267353; border-color: #267353; color: #fff; }
html[data-theme-scope="admin"] body > form.box button[type="submit"]:hover { background: #1f6045; }
@media(max-width:600px) {
  html[data-theme-scope="admin"] body .admin-appearance-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  html[data-theme-scope="admin"] body .admin-appearance { gap: 3px; padding-inline: 5px; }
  html[data-theme-scope="admin"] body.admin-studio .page-head .head-actions { gap: 7px; }
}
