:root { color-scheme: light; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111315;
  --panel: #1b1e21;
  --text: #c6cbd0;
  --ink: #cfd4d8;
  --muted: #99a3ad;
  --line: #383f45;
  --teal-dark: #08615e;
  --amber: #f0c777;
  --shadow: 0 18px 45px rgb(0 0 0 / 35%);
  --night-raised: #24282c;
  --night-accent: #60b5aa;
  --night-selected: #17332e;
  --night-profit: #4fbc8c;
  --night-loss: #ff8796;
  --night-warning-bg: #332b1c;
  --night-warning: #f0ce8b;
  --night-danger-bg: #35232a;
  --night-button: #076a66;
  --night-on-accent: #d6dce0;
}

.site-header .quick-nav a.nav-copy-tool { background: var(--teal); color: #fff; border-color: var(--teal); }
.theme-control { position: relative; flex: 0 0 auto; margin-left: 10px; }
.theme-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 6px;
  color: inherit;
  background: transparent;
  cursor: pointer;
}
.theme-toggle svg, .theme-menu svg { display: block; flex: 0 0 auto; }
.theme-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 4;
  width: 174px;
  padding: 5px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.theme-menu[hidden] { display: none; }
.theme-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14px;
  white-space: nowrap;
  text-align: left;
  cursor: pointer;
}
.theme-menu button:hover, .theme-menu button:focus-visible { background: rgb(15 143 138 / 14%); }
.theme-menu button[aria-checked="true"] { color: var(--teal-dark); background: rgb(15 143 138 / 12%); }
.theme-check { display: flex; margin-left: auto; visibility: hidden; }
[aria-checked="true"] > .theme-check { visibility: visible; }
.theme-toggle:focus-visible, .theme-menu button:focus-visible { outline: 2px solid var(--teal); outline-offset: 3px; }

html[data-theme="dark"] .site-header { background: rgb(17 19 21 / 92%); color: var(--text); border-bottom-color: var(--line); }
html[data-theme="dark"] .site-header.solid,
html[data-theme="dark"] .site-header.is-scrolled { background: rgb(27 30 33 / 96%); color: var(--text); border-bottom-color: var(--line); }
html[data-theme="dark"] .sponsor-nav-group { border-color: #7b858d; }
html[data-theme="dark"] .sponsor-nav-label { color: var(--text); background: var(--panel); }
html[data-theme="dark"] .site-header :is(.quick-nav a, .menu-toggle) { color: var(--night-accent); border-color: var(--line); background: var(--night-raised); }
html[data-theme="dark"] .site-header :is(.nav-auth-register, .nav-copy-tool),
html[data-theme="dark"] .site-header .quick-nav .nav-copy-tool { color: var(--night-on-accent); background: var(--night-button); border-color: var(--night-button); }
html[data-theme="dark"] .site-header :is(.nav-auth-register, .nav-copy-tool):hover { background: #08615e; border-color: #08615e; }
html[data-theme="dark"] .page-title { background: var(--panel); }
html[data-theme="dark"] .hero-overlay { background: rgb(0 0 0 / 32%); }
html[data-theme="dark"] .hero { background-color: var(--bg); color: var(--ink); }
html[data-theme="dark"] .hero-copy { color: var(--text); }
html[data-theme="dark"] .site-footer { background: #151719; color: var(--text); }

html[data-theme="dark"] :is(.capital-panel, .position-overview-card, .bookmark-panel, .review-panel, .push-source-dialog, .live-position-table, .live-position-table tr, .fomo-position-grid .position-metric) {
  color: var(--text);
  background: var(--panel);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.link-item, .community-x-profile, .x-post-item, .position-empty, .position-card, .source-link, .update-item, .mute-message, .position-message, .guestbook-form, .guestbook-item, .guestbook-empty, .meta-list li, .bookmark-close, .position-badges) {
  color: var(--text);
  background: var(--night-raised);
  border-color: var(--line);
}
html[data-theme="dark"] .position-overview-card.is-selected { background: #1b2c27; border-color: var(--night-accent); box-shadow: inset 0 0 0 1px var(--night-accent); }
html[data-theme="dark"] .position-switcher { background: #171a1c; border-color: var(--line); }
html[data-theme="dark"] :is(.position-switcher button, .position-view-toolbar button, .position-votes button, .position-history-more, .review-votes button, .mobile-push [data-push-disable], .mobile-push .push-tutorial-tabs button, .push-source-actions button) {
  color: var(--text);
  background: var(--night-raised);
  border-color: var(--line);
}
html[data-theme="dark"] :is(.position-switcher button.is-active, .position-view-toolbar button[aria-pressed="true"], .review-votes button.is-active, .mobile-push .push-tutorial-tabs button[aria-pressed="true"], .push-source-actions [data-source-save]) {
  background: var(--night-button);
  color: var(--night-on-accent);
  border-color: var(--night-button);
}
html[data-theme="dark"] :is(.button.primary, .button.small, .feature-icon, .source-mark, .review-form button, .history-controls button, .guestbook-submit-row button, .position-comments-form button, .mobile-push [data-push-enable], .mobile-push [data-push-save]) { background: var(--night-button); border-color: var(--night-button); color: var(--night-on-accent); }
html[data-theme="dark"] :is(.fomo-copy-entry, .button.ao-ying-hero-entry, .position-panel .message-copy-link) { background: #b32920; border-color: #b32920; color: var(--night-on-accent) !important; }
html[data-theme="dark"] .message-copy-link { color: var(--night-on-accent) !important; }
html[data-theme="dark"] .button.ghost { color: var(--text); }
html[data-theme="dark"] .position-votes button[aria-pressed="true"] { background: var(--night-selected); color: var(--night-profit); border-color: #428d6b; }
html[data-theme="dark"] .position-votes button[data-position-vote="down"][aria-pressed="true"] { background: var(--night-danger-bg); color: var(--night-loss); border-color: #ab5c70; }
html[data-theme="dark"] :is(input:not([type="checkbox"]):not([type="radio"]), textarea, select) { color: var(--text); background: #15181a; border-color: var(--line); }
html[data-theme="dark"] :is(input, textarea)::placeholder { color: var(--muted); opacity: 1; }
html[data-theme="dark"] :is(.live-position-table th, .position-badges) { background: var(--night-raised); color: var(--muted); }
html[data-theme="dark"] :is(.position-table-scroll, .live-position-table td, .live-position-table td:first-child, .position-history, .position-history-record, .overview-weekly, .position-comments, .x-post-footer, .push-channel-fields fieldset, .mobile-push) { border-color: var(--line); }
html[data-theme="dark"] .fomo-position-grid .position-card dl { background: var(--line); border-color: var(--line); }

html[data-theme="dark"] :is(.overview-name, .overview-metric dd, .position-entry-label strong, .position-symbol, .position-comments-head h3, .position-comment-item p, .position-votes strong, .position-history > summary, .position-history-record summary, .x-post-text, .overview-push-note, .mobile-push) { color: var(--text); }
html[data-theme="dark"] :is(.overview-platform, .overview-status, .overview-label, .overview-metric dt, .overview-return-time, .overview-holdings, .overview-weekly strong, .overview-rate, .paper-public-note, .fomo-source-note, .fomo-source-address, .position-entry-label, .position-comments-head span, .position-comments-feedback, .position-comments-more, .position-comment-item time, .position-comments-empty, .position-votes .position-vote-feedback, .position-history > summary span, .statement-context, .x-feed-profile small, .x-post-author small, .review-summary, .review-meta, .review-item span, .meta-list, .live-position-table td:not(:first-child)::before, .mobile-push [data-push-feedback], .push-source-dialog p, .push-install-gallery figcaption) { color: var(--muted); }
html[data-theme="dark"] :is(.position-site-name, .message-site-mark, .account-margin-balance, .position-account-leverage, .position-actual-leverage, .x-feed-profile, .x-post-author strong, .x-post-footer a, .fomo-source-account-link, .statement-context-line strong) { color: var(--night-accent); }
html[data-theme="dark"] :is(.bookmark-url, .review-meta button, .review-item b:not(.down), .source-action, .update-meta, .update-item a:not(.message-copy-link), .mute-message a:not(.message-copy-link), .position-message a:not(.message-copy-link), .guestbook-item-head strong, .theme-menu button[aria-checked="true"]) { color: var(--night-accent); }
html[data-theme="dark"] :is(.status-pill, .airport-notice, .capital-note, .copy-trade-status-notice, .position-honor-label) { color: var(--night-warning); background: var(--night-warning-bg); border-color: #786137; }
html[data-theme="dark"] :is(.copy-paused-label, .community-warning, .push-channel-button[data-push-channel], .mobile-push [data-push-settings]) { color: var(--night-loss); background: var(--night-danger-bg); border-color: #885060; }
html[data-theme="dark"] .push-channel-button[data-push-channel][aria-pressed="true"] { color: #ffb4c0; background: #4a2532; border-color: #b3657d; }
html[data-theme="dark"] .push-channel-button:not([data-push-channel]) { color: var(--night-accent); background: var(--night-raised); border-color: var(--line); }
html[data-theme="dark"] .bookmark-url { background: var(--night-selected); border-color: #356658; }
html[data-theme="dark"] :is(.text-alert, .community-motto, .capital-invite-codes, .sponsor-nav-invites, .x-feed-invite, .overview-push-note-highlight, .position-history-feedback, .mobile-push [data-push-install] li:nth-child(-n+2)) { color: var(--night-loss); }
html[data-theme="dark"] .capital-page-title .capital-invite-codes { color: var(--night-loss); }
html[data-theme="dark"] :is(.position-positive, .position-overview-card .is-profit, .live-position-table .position-positive, .position-card .position-positive, .position-status-summary .desktop-position-pnl.position-positive) { color: var(--night-profit); }
html[data-theme="dark"] :is(.position-negative, .position-overview-card .is-loss, .live-position-table .position-negative, .position-card .position-negative, .position-status-summary .desktop-position-pnl.position-negative) { color: var(--night-loss); }
html[data-theme="dark"] .fomo-sync-notice { color: var(--night-profit) !important; }
html[data-theme="dark"] .account-margin-balance { color: var(--night-accent) !important; }
html[data-theme="dark"] .community-motto { color: var(--night-loss) !important; }
html[data-theme="dark"] :is(.capital-scroll, .position-comments-list, .guestbook-list, .position-history-list) { scrollbar-color: #6d7b85 var(--night-raised); }
html[data-theme="dark"] :is(.capital-scroll, .position-comments-list, .guestbook-list)::-webkit-scrollbar-track { background: var(--night-raised); }
html[data-theme="dark"] :is(.capital-scroll, .position-comments-list, .guestbook-list)::-webkit-scrollbar-thumb { background: #6d7b85; border-color: var(--night-raised); }
html[data-theme="dark"] .capital-panel > .mobile-scroll-indicator { background: var(--night-raised); }

@media (max-width: 1280px) {
  .site-header {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "brand quick theme menu" "sponsor sponsor sponsor sponsor";
  }
  .theme-control { grid-area: theme; z-index: 2; margin: 0; }
  .theme-toggle { width: 34px; height: 34px; }
  html[data-theme="dark"] .site-nav { color: var(--text); background: var(--panel); border-color: var(--line); }
}
@media (max-width: 600px) {
  .site-header {
    height: 144px;
    grid-template-areas: "brand brand theme menu" "quick quick quick quick" "sponsor sponsor sponsor sponsor";
  }
  .site-header .quick-nav { justify-content: flex-start; gap: 6px; }
  .site-header .quick-nav a { flex: 0 0 auto; min-height: 40px; padding: 0 8px; font-size: 12px; }
  .page-main { padding-top: 144px; }
  .site-header.site-header--invites { height: 184px; }
  .site-header--invites + .page-main { padding-top: 184px; }
}
@media (max-width: 400px) {
  .theme-toggle { width: 32px; height: 32px; }
}
