:root {
  --ankle-pref-bg: #c0c0c0;
  --ankle-pref-panel: #c0c0c0;
  --ankle-pref-fg: #000;
  --ankle-pref-muted: #4b4b4b;
  --ankle-pref-line: #000;
  --ankle-titlebar-bg: #e8e8e8;
  --ankle-titlebar-fg: #000;
}
html[data-ankle-color-scheme="dark"],
html[data-ankle-resolved-theme="dark"],
html[data-theme="dark"],
body.theme-dark {
  --ankle-pref-bg: #181818;
  --ankle-pref-panel: #242424;
  --ankle-pref-fg: #f5f7fa;
  --ankle-pref-muted: #b8c0cc;
  --ankle-pref-line: #626262;
  --ankle-titlebar-bg: #303030;
  --ankle-titlebar-fg: #f5f7fa;
  --aos-bg: #181818;
  --aos-panel: #242424;
  --aos-ink: #f5f7fa;
  --aos-dim: #b8c0cc;
  --aos-line: #626262;
  color-scheme: dark;
}

html[data-ankle-color-scheme="dark"]:not([data-ankle-authored-surface="true"]),
html[data-ankle-resolved-theme="dark"]:not([data-ankle-authored-surface="true"]),
html[data-theme="dark"]:not([data-ankle-authored-surface="true"]),
body.theme-dark:not([data-aos-surface="personal-site"]) {
  --bg: #181818;
  --fg: #f5f7fa;
  --panel: #242424;
  --muted: #b8c0cc;
  --faint: #718096;
  --line: #626262;
  --chip: #353535;
  --link: #63b3ed;
  --visited: #b794f4;
  --warn: #2d3748;
  --highlight: #2b3a4a;
  background-color: #181818;
  color: #f5f7fa;
}

/* Never blanket-force every div/span white. Legacy surfaces often contain
   deliberately light subpanels; inherited white text on those panels caused
   the unreadable night-mode regression. Repaint only known token surfaces. */
html[data-ankle-color-scheme="dark"]:not([data-ankle-authored-surface="true"]) body:not([data-aos-surface="personal-site"]),
html[data-ankle-color-scheme="dark"]:not([data-ankle-authored-surface="true"]) body:not([data-aos-surface="personal-site"]) :is(
  .hero, .hero-title, .hero-sub, .hero-tag, .hero-doors, .world-thesis,
  .section, .section-head, .section-title, .section-meta, .section-explainer,
  .surface-brief, .surface-brief__intro, .surface-node, .starter-inventory-note, .surface-more,
  .front-post-card, .front-post-card .fp-body, .front-post-card .fp-user,
  .world-card, .world-card .name,
  .active-world-card, .active-world-card .word, .active-world-card .pulse,
  .active-world-card .meta, .active-world-card .aw-host, .active-world-card .aw-state,
  .coin-slate, .coin-slate .ttl, .activity-row .body, .activity-side,
  .market-card, .agent-chip, .world-entry
) {
  color: #f5f7fa !important;
}

html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .ankle-topbar,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .front-post-card,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .world-card,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .active-world-card,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .coin-slate,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .market-card,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .agent-chip,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .activity-side,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .world-entry,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .hero-ico {
  background: #242424 !important;
  border-color: #626262 !important;
}

html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .front-post-card .fp-head,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .front-post-card .fp-foot {
  background: #303030 !important;
  color: #b8c0cc !important;
  border-color: #626262 !important;
}

html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) a { color: #63b3ed !important; }
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) a:visited { color: #b794f4 !important; }

html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .surface-actions a,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .nav-right a,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .coin-slate .btn,
html[data-ankle-color-scheme="dark"] body:not([data-aos-surface="personal-site"]) .ankle-top-nav-btn {
  background: #353535 !important;
  color: #f5f7fa !important;
  border-color: #4a5568 !important;
}

html[data-ankle-color-scheme="light"] { color-scheme: light; }

.ankle-skip-link {
  position: fixed; z-index: 2147483647; inset-block-start: 4px; inset-inline-start: 4px;
  transform: translateY(-180%); min-height: 44px; box-sizing: border-box;
  display: inline-flex; align-items: center; padding: 7px 10px; border: 2px outset #fff;
  background: #ffff66; color: #000; font: 700 12px/1.2 "Courier New", Courier, monospace;
}
.ankle-skip-link:focus { transform: translateY(0); }

html[data-ankle-focus="visible"] :focus-visible {
  outline: 3px solid #ffff00 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 5px #000 !important;
}

.ankle-preferences-launcher {
  display: flex; align-items: center; width: 100%; min-height: 44px; box-sizing: border-box;
  margin: 5px 0; padding: 7px 8px; border: 2px outset #fff; border-radius: 0;
  background: var(--ankle-pref-bg); color: var(--ankle-pref-fg); text-align: start;
  font: 700 10px/1.25 "Courier New", Courier, monospace; letter-spacing: .04em;
  text-transform: uppercase; cursor: pointer;
}
.ankle-preferences-launcher:active { border-style: inset; }

.ankle-top-nav-btn {
  display: inline-flex; align-items: center; justify-content: center; height: 24px; box-sizing: border-box;
  margin: 0 3px; padding: 0 8px; border: 2px outset #fff; border-radius: 0;
  background: var(--ankle-pref-bg); color: var(--ankle-pref-fg);
  font: 700 11px/1.2 "Courier New", Courier, monospace; letter-spacing: .03em;
  text-transform: uppercase; cursor: pointer; text-decoration: none; vertical-align: middle;
}
.ankle-top-nav-btn:hover { background: var(--ankle-pref-panel); }
.ankle-top-nav-btn:active { border-style: inset; }

.ankle-top-lang-btn { min-width: 68px; }
.ankle-top-theme-btn { min-width: 44px; font-size: 16px; overflow: hidden; }

.ankle-preferences-dialog {
  width: min(520px, calc(100vw - 24px)); max-height: min(720px, calc(100dvh - 24px));
  min-width: 0; max-width: calc(100vw - 24px); overflow: auto;
  box-sizing: border-box; padding: 0; border: 2px solid var(--ankle-pref-line); border-radius: 0;
  background: var(--ankle-pref-bg); color: var(--ankle-pref-fg); box-shadow: 5px 5px 0 #000;
}
.ankle-preferences-dialog::backdrop { background: rgba(0,0,0,.68); }
.ankle-preferences-titlebar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 44px; box-sizing: border-box; padding: 4px 4px 4px 10px;
  background: var(--ankle-titlebar-bg); color: var(--ankle-titlebar-fg); border-bottom: 2px solid var(--ankle-pref-line);
  font: 700 12px/1.2 "Courier New", Courier, monospace; letter-spacing: .04em; text-transform: uppercase;
}
.ankle-preferences-titlebar > span { min-width: 0; overflow-wrap: anywhere; }
.ankle-preferences-titlebar button,
.ankle-preferences-actions button {
  min-width: 44px; min-height: 44px; border: 2px outset #fff; border-radius: 0;
  background: var(--ankle-pref-bg); color: var(--ankle-pref-fg);
  font: 700 12px/1.2 "Courier New", Courier, monospace; cursor: pointer;
}
.ankle-preferences-titlebar button:active,
.ankle-preferences-actions button:active { border-style: inset; }
.ankle-preferences-body { min-width: 0; max-width: 100%; padding: 16px; box-sizing: border-box; font: 15px/1.5 "Times New Roman", Times, serif; }
.ankle-preferences-body p { min-width: 0; margin: 0 0 16px; color: var(--ankle-pref-fg); overflow-wrap: anywhere; }
.ankle-preferences-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; min-width: 0; max-width: 100%; }
.ankle-preferences-field { display: grid; gap: 6px; min-width: 0; max-width: 100%; }
.ankle-preferences-field label {
  min-width: 0; overflow-wrap: anywhere;
  font: 700 11px/1.25 "Courier New", Courier, monospace; letter-spacing: .06em; text-transform: uppercase;
}
.ankle-preferences-field select {
  width: 100%; min-width: 0; max-width: 100%; min-height: 44px; box-sizing: border-box; padding: 6px 8px;
  border: 2px inset #fff; border-radius: 0; background: var(--ankle-pref-panel);
  color: var(--ankle-pref-fg); font: 14px/1.2 "Courier New", Courier, monospace;
}
.ankle-preferences-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
@media (max-width: 560px) {
  .ankle-preferences-grid { grid-template-columns: minmax(0, 1fr); }
}
.ankle-sr-only {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important; overflow: hidden !important;
  clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important;
}

/* Shared chrome consumes the same resolved mode even on legacy pages whose
   authored body CSS does not yet use theme variables. */
html[data-ankle-color-scheme="dark"] :is(#aos-topchips,#aos-left,#aos-right,#aos-bottom,.aos-tab) {
  background: #181818 !important; color: #f5f7fa !important; border-color: #626262 #141414 #141414 #626262 !important;
}
html[data-ankle-color-scheme="dark"] :is(#aos-topchips,#aos-left,#aos-right,#aos-bottom) a { color: #f5f7fa !important; }
html[data-ankle-color-scheme="dark"] #aos-bottom :is(.aos-bottom-bar,.aos-drawer) { background: #181818 !important; color: #f5f7fa !important; }
html[data-ankle-color-scheme="dark"] #aos-bottom .aos-bottom-bar * { color: #f5f7fa !important; }
html[data-ankle-color-scheme="dark"] :is(#aos-left,#aos-right,#aos-bottom,#aos-topchips) :is(button,input,select,textarea) {
  background: #242424 !important; color: #f5f7fa !important; border-color: #626262 #141414 #141414 #626262 !important;
}
html[data-ankle-color-scheme="dark"] #aos-topchips .aos-post {
  background: #ffffe0 !important; color: #111318 !important; border-color: #4a4a36 !important;
}
html[data-ankle-color-scheme="dark"] #aos-topchips .aos-post * { color: #111318 !important; }
html[data-ankle-color-scheme="dark"] #aos-topchips .aos-top-user > .aos-link {
  background: #242424 !important; color: #f5f7fa !important; border-color: #626262 !important;
}
html[data-ankle-color-scheme="dark"] :is(#aos-left,#aos-right) .aos-link:hover,
html[data-ankle-color-scheme="dark"] :is(#aos-left,#aos-right) .aos-link.active { background: #f5f7fa !important; color: #111318 !important; }

/* RTL mirrors workspace rails while leaving route paths and media controls
   readable. Logical labels align to the start edge automatically. */
html[dir="rtl"] #aos-left { left: auto !important; right: 0 !important; border-left: 2px solid !important; border-right: 0 !important; }
html[dir="rtl"] #aos-right { right: auto !important; left: 0 !important; border-right: 2px solid !important; border-left: 0 !important; }
html[dir="rtl"] .aos-tab-left { left: auto !important; right: 0 !important; margin-left: 0 !important; margin-right: 18px !important; transform: translateY(-50%) rotate(90deg) !important; transform-origin: right center !important; }
html[dir="rtl"] .aos-tab-right { right: auto !important; left: 0 !important; margin-right: 0 !important; margin-left: 18px !important; transform: translateY(-50%) rotate(-90deg) !important; transform-origin: left center !important; }
html[dir="rtl"] :is(.aos-link,.ankle-preferences-launcher,.ankle-preferences-body) { text-align: start; }
@media (min-width: 901px) {
  html[dir="rtl"] body.aos-left-open { padding-left: 0 !important; padding-right: var(--aos-left-w) !important; }
  html[dir="rtl"] body.aos-right-open { padding-right: 0 !important; padding-left: var(--aos-right-w) !important; }
  html[dir="rtl"] body.aos-left-open.aos-right-open { padding-left: var(--aos-right-w) !important; padding-right: var(--aos-left-w) !important; }
}
@media (max-width: 560px) {
  .ankle-preferences-grid { grid-template-columns: 1fr; }
  .ankle-preferences-dialog { max-height: calc(100dvh - 16px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}
@media (forced-colors: active) {
  .ankle-preferences-dialog, .ankle-preferences-launcher, .ankle-skip-link { forced-color-adjust: auto; }
}

/* Shared ANKLE96 contrast. Preserve layout, sizing and owner media. */
html[data-ankle-color-scheme="dark"] body:is(.theme-discmaster,.a96,.ankle96) :is(a.btn:link,a.btn:visited,button.btn,.chip:link,.chip:visited),
html[data-ankle-color-scheme="dark"] .stp-app :is(a.stp-button:link,a.stp-button:visited,button){
 background-color:#353535!important;color:#f4f4f4!important;
 border-color:#777 #141414 #141414 #777!important;
}
html[data-ankle-color-scheme="dark"] body.theme-discmaster :is(.ank-modal,.ank-modal-tb,.ank-modal-x){
 background-color:#242424!important;color:#f4f4f4!important;
}
html[data-ankle-color-scheme="dark"] body.a96 #worldHero .world-action-group :is(a.btn:link,a.btn:visited,button.btn){
 background-color:#353535!important;color:#f4f4f4!important;
 border-color:#777 #141414 #141414 #777!important;
}
