html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #050505;
  --surface: #101010;
  --card: #0b0b0b;
  --fg: #e8e7e4;
  --muted: #b4b1ad;
  --dim: #85817e;
  --gold: #b64b45;
  --accent: #ad3f39;
  --accent-bright: #cf6159;
  --accent-soft: #351716;
  --up: #7bac99;
  --down: #c85c55;
  --line: rgba(238, 236, 232, .13);
  --line-2: rgba(238, 236, 232, .25);
}

html[data-theme="dark"] body {
  background: radial-gradient(ellipse at 52% -10%, rgba(103, 35, 31, .16), transparent 48%), var(--bg);
  color: var(--fg);
}
html[data-theme="dark"] body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  opacity: .026;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 160 160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.48'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}
html[data-theme="dark"] header.nav,
html[data-theme="dark"] header.detail-nav {
  background: rgba(5, 5, 5, .96);
  border-color: var(--line);
}
html[data-theme="dark"] .nav .logo span,
html[data-theme="dark"] .detail-home span { color: var(--fg); }
html[data-theme="dark"] .logo img,
html[data-theme="dark"] .detail-home img { filter: grayscale(1) brightness(0) invert(1); }
html[data-theme="dark"] .editorial-hero { position: relative; isolation: isolate; }
html[data-theme="dark"] .editorial-hero::before {
  content: "";
  position: absolute;
  z-index: -1;
  width: min(74vw, 900px);
  height: 560px;
  top: 4%;
  left: 52%;
  transform: translateX(-25%);
  pointer-events: none;
  background: radial-gradient(ellipse, rgba(111, 35, 31, .15), transparent 68%);
  filter: blur(42px);
}
html[data-theme="dark"] .editorial-hero h1 em { color: #a9433e; text-shadow: 0 0 28px rgba(158, 48, 43, .16); }
html[data-theme="dark"] .editorial-hero .eyebrow-serif { color: #a8645f; }
html[data-theme="dark"] .hero-side { color: #8b5a56; }
html[data-theme="dark"] .geometry i { background: #762b27; box-shadow: 0 0 20px rgba(156, 45, 39, .2); opacity: .28; }
html[data-theme="dark"] .theme-toggle { border-color: var(--line-2); }
html[data-theme="dark"] .theme-toggle:hover { background: #17100f; border-color: #74312d; }
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 9px 12px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: transparent;
  color: var(--fg);
  font: 400 10px/1 var(--mono, ui-monospace, monospace);
  letter-spacing: .04em;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.theme-toggle:hover { background: var(--surface); border-color: var(--muted); }
.theme-glyph { font: 16px/1 system-ui, sans-serif; }
html[data-theme="dark"] .btn:not(.ghost),
html[data-theme="dark"] #dlg .source-footer .btn,
html[data-theme="dark"] .detail-actions button:first-child {
  background: #762d29;
  border-color: #8f3a34;
  color: #f5efed;
}
html[data-theme="dark"] .btn:not(.ghost):hover,
html[data-theme="dark"] .detail-actions button:first-child:hover { background: #913a34; }
html[data-theme="dark"] .chip[aria-pressed="true"],
html[data-theme="dark"] .vote[aria-pressed="true"],
html[data-theme="dark"] .grid-view-button[aria-pressed="true"] {
  background: #762d29;
  border-color: #8f3a34;
  color: #f5efed;
}
html[data-theme="dark"] .feature-image,
html[data-theme="dark"] .tile > .thumb,
html[data-theme="dark"] figure,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .empty,
html[data-theme="dark"] .request-contact { background-color: var(--surface); }
html[data-theme="dark"] .feature-image { border-color: var(--line); }
html[data-theme="dark"] .preview-frame { background: linear-gradient(135deg, #141313, #080808 65%, #17100f); border-color: var(--line); }
html[data-theme="dark"] .preview-glow { background: radial-gradient(ellipse at 85% 90%, #a13d3712, transparent 65%), linear-gradient(135deg, #141313, #080808); }
html[data-theme="dark"] .f input,
html[data-theme="dark"] .f textarea,
html[data-theme="dark"] .f select,
html[data-theme="dark"] #lib-q,
html[data-theme="dark"] .lib-bar input { background: #0d0d0d; color: var(--fg); border-color: var(--line-2); }
html[data-theme="dark"] .f input::placeholder,
html[data-theme="dark"] .f textarea::placeholder,
html[data-theme="dark"] #lib-q::placeholder { color: var(--dim); }
html[data-theme="dark"] .link:hover,
html[data-theme="dark"] .text-cta:hover,
html[data-theme="dark"] .detail-actions a:hover,
html[data-theme="dark"] .detail-nav nav a:hover { color: var(--accent-bright); }
html[data-theme="dark"] .counter-new,
html[data-theme="dark"] .total-downloads strong { color: var(--accent-bright); }
html[data-theme="dark"] .lb-bg { background: rgba(5, 5, 5, .98); }
html[data-theme="dark"] dialog::backdrop,
html[data-theme="dark"] #dlg::backdrop { background: rgba(0, 0, 0, .84); }
html[data-theme="dark"] #dlg,
html[data-theme="dark"] dialog { background: #0c0c0c; color: var(--fg); border-color: var(--line-2); }
html[data-theme="dark"] #dlg .source-heading .x:hover { background: #201211; }
html[data-theme="dark"] #dlg .dlg-desc { color: var(--muted); }
html[data-theme="dark"] .source-toolbar { background: #111; color: var(--muted); }
html[data-theme="dark"] #source-wrap { color: var(--fg); border-color: var(--line-2); }
html[data-theme="dark"] #source-wrap[aria-pressed="true"] { background: #261312; color: var(--fg); }
html[data-theme="dark"] #dlg #source-scroll,
html[data-theme="dark"] dialog pre { background: #050505; color: #e1e0dc; scrollbar-color: #625653 transparent; }
html[data-theme="dark"] .code-line:hover { background: #ffffff0b; }
html[data-theme="dark"] #dlg .c { color: #aaa49d; }
html[data-theme="dark"] #dlg .s { color: #b8b5ad; }
html[data-theme="dark"] #dlg .k { color: #d58b83; }
html[data-theme="dark"] #dlg .n { color: #d1b79b; }
html[data-theme="dark"] #dlg .source-footer { background: #0c0c0c; }
html[data-theme="dark"] .source-footer small b,
html[data-theme="dark"] .source-download { color: var(--muted); }
html[data-theme="dark"] .detail-nav > a,
html[data-theme="dark"] .detail-description h2,
html[data-theme="dark"] .detail-description h3,
html[data-theme="dark"] .detail-description summary { color: var(--fg); }
html[data-theme="dark"] .detail-description { color: var(--muted); border-color: var(--line); }
html[data-theme="dark"] .detail-description code { background: #201211; color: var(--fg); }
html[data-theme="dark"] .detail-actions button,
html[data-theme="dark"] .detail-actions a,
html[data-theme="dark"] dialog footer a,
html[data-theme="dark"] dialog footer button { border-color: var(--line-2); }
html[data-theme="dark"] .description-row,
html[data-theme="dark"] .detail-description details { border-color: var(--line); }
html[data-theme="dark"] .detect-image-example,
html[data-theme="dark"] .detect-image-pair figure { background: #0b0b0b; border-color: var(--line); }
html[data-theme="dark"] .screenshot-main .outside-game { border-color: var(--line); }
html[data-theme="dark"] :focus-visible { outline-color: var(--accent-bright); }

@media (max-width: 600px) {
  .theme-toggle { padding: 7px 8px; }
  .theme-label { display: none; }
}
