/* Shared appearance tokens. Portal-specific layouts load after this file. */
:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --page-background: #0b1018;
  --surface: #121b27;
  --surface-raised: #1a2533;
  --surface-soft: #101722;
  --text-primary: #f1f5fa;
  --text-secondary: #a2b1c4;
  --border-color: #2a394b;
  --accent: #fb4965;
  --action-fill: #d82d4c;
  --accent-soft: #fb496518;
  --accent-border: rgba(251,73,101,.3);
  --accent-border-soft: rgba(251,73,101,.25);
  --success: #6bdfb3;
  --success-soft: #192b32;
  --success-border: rgba(107,223,179,.28);
  --warning: #edc579;
  --warning-soft: #24292e;
  --warning-border: rgba(237,197,121,.25);
  --shadow-panel: 0 8px 28px #00000020;
  --theme-toolbar-height: 46px;
  --bg: var(--page-background);
  --panel: var(--surface);
  --panel2: var(--surface-raised);
  --border: var(--border-color);
  --muted: var(--text-secondary);
  --text: var(--text-primary);
  --red: var(--accent);
  --green: var(--success);
}
html[data-theme="light"] {
  color-scheme: light;
  --page-background: #f3f5f8;
  --surface: #ffffff;
  --surface-raised: #f5f7fa;
  --surface-soft: #edf1f6;
  --text-primary: #192637;
  --text-secondary: #5d6d80;
  --border-color: #dce3ec;
  --accent: #d82d4c;
  --accent-soft: #fff0f3;
  --accent-border: rgba(216,45,76,.3);
  --accent-border-soft: rgba(216,45,76,.25);
  --success: #157857;
  --success-soft: #ecf4f2;
  --success-border: rgba(21,120,87,.28);
  --warning: #8c5c10;
  --warning-soft: #f6f2ec;
  --warning-border: rgba(140,92,16,.25);
  --shadow-panel: 0 8px 28px #24354d08;
}
html { background: var(--page-background); }
body { background: var(--page-background); color: var(--text-primary); font-family: Arial,"PingFang TC","Microsoft JhengHei",sans-serif; }
::selection { background: var(--accent); color: #fff; }
#racing-theme-controls { position:sticky; top:0; z-index:40; }
.theme-toolbar { min-height:var(--theme-toolbar-height); padding:5px clamp(16px,3vw,32px); display:flex; justify-content:space-between; align-items:center; gap:12px; background:var(--surface); color:var(--text-secondary); border-bottom:1px solid var(--border-color); font-size:11px; }
.theme-context { display:flex; align-items:center; gap:8px; white-space:nowrap; }
.theme-status { color:var(--text-primary); font-weight:600; }
.theme-status-dot { width:6px; height:6px; border-radius:50%; background:var(--accent); box-shadow:0 0 0 3px var(--accent-soft); }
.theme-clock { padding-left:10px; margin-left:2px; border-left:1px solid var(--border-color); font-size:10px; font-variant-numeric:tabular-nums; letter-spacing:.4px; }
.theme-options { display:flex; align-items:center; padding:3px; gap:3px; border:1px solid var(--border-color); border-radius:9px; background:var(--surface-raised); }
.theme-option { min-height:28px; padding:4px 13px; color:var(--text-secondary); background:transparent; border:1px solid transparent; border-radius:6px; font-size:11px; line-height:1.2; }
.theme-option:hover { color:var(--text-primary); background:var(--surface); }
.theme-option[aria-pressed="true"] { background:var(--surface); border-color:var(--border-color); color:var(--accent); font-weight:700; box-shadow:0 1px 4px #0b152010; }
.theme-option:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }

/* Existing screens use a mix of variables and fixed dark colors. Normalize shared surfaces. */
html[data-theme] :is(.member-app,.admin-app) { color:var(--text-primary); background:var(--page-background); }
html[data-theme] :is(.panel,.metric,.modal,.lock-card,.source-card,.research-stats>div,.detail-stats) { background:var(--surface); border-color:var(--border-color); color:var(--text-primary); box-shadow:var(--shadow-panel); }
html[data-theme] :is(.member-header,.admin-header,.admin-sidebar,.member-subheader,.member-export-bar,.panel-head,.table-tools,.table-foot,.pick-footer,.source-config,.date-box,.date-tools .icon-btn,.seg,.search,.feature-icon,.source-icon,.demo-note,.detail-note,.research-rules) { background:var(--surface-raised); border-color:var(--border-color); }
html[data-theme] :is(input,select,textarea,.member-venue-select,.hkjc-controls input,.hkjc-controls select) { background-color:var(--surface); border-color:var(--border-color); color:var(--text-primary); color-scheme:inherit; }
html[data-theme] :is(input,textarea)::placeholder { color:var(--text-secondary); opacity:.8; }
html[data-theme] .search input { background:transparent; }
html[data-theme] .member-date-input input { color-scheme:inherit; background:transparent; }
html[data-theme] :is(.outline,.race-tabs button,.horse-number,.odds,.seg button.on) { color:var(--text-primary); background:var(--surface-raised); border-color:var(--border-color); }
html[data-theme] .outline:hover { color:var(--accent); background:var(--accent-soft); border-color:var(--accent); }
html[data-theme] .primary { background:var(--action-fill); color:#fff; border-color:var(--action-fill); box-shadow:0 4px 12px #d82d4c12; }
html[data-theme] .primary:hover { filter:brightness(1.08); }
html[data-theme] :is(.badge,.badge.subtle) { color:var(--text-secondary); background:var(--surface-raised); border-color:var(--border-color); }
html[data-theme] :is(.badge.red,.points-pill,.odds.favorite,.horse-number.n1,.horse-number.n2,.horse-number.n3,.horse-number.n4) { color:var(--accent); background:var(--accent-soft); border-color:var(--accent-border); }
html[data-theme] .badge.green { color:var(--success); background:var(--success-soft); border-color:var(--success-border); }
html[data-theme] :is(.race-tabs button.active) { background:var(--action-fill); border-color:var(--action-fill); color:#fff; }
html[data-theme] .race-tabs button.active span { color:#fff; opacity:.85; }
html[data-theme] .section-toolbar .seg button.on { color:var(--accent); background:var(--accent-soft); border-color:var(--accent); }
html[data-theme] :is(.member-header nav button.active,.breadcrumb b,.empty h3,.ai-model b,.invite-hero h2) { color:var(--text-primary); }
html[data-theme] :is(.member-header nav button,.admin-sidebar nav button,.member-subheader,.member-export-bar,.breadcrumb,.hkt,.page-status,.race-meta,.metric>span,.metric-bottom,.page-heading p,.eyebrow,.table-foot,.model-caption,.pick small,.pick-footer,.factor-note,.app-footer,.empty,.profile-card>p,.profile-row>span,.security-item p,.security-item small,.ai-summary p,.ai-model,.source-row p,.source-card p,.source-card small,.source-config,.hkjc-note,.hkjc-controls label,.hkjc-race summary span,.hkjc-race p,.hkjc-demo>summary,.weather-grid small,.weather-grid span,.meeting-shortcuts,.research-stats span,.research-actions>span,.research-rules p,.research-center details>p,.modal-heading p,.modal form label,.settings-form label,.password-rules,.modal-foot,.detail-note,.detail-stats span,.quick-panel small,.member-cell small,.data-summary span,.sidebar-user small,.sidebar-label,.chart-axis,.lock-card p,.lock-perks,.lock-card>small,.wallet-hero p,.wallet-hero span,.invite-hero p,.invite-hero h2 span,.mobile-scroll-hint) { color:var(--text-secondary); }
html[data-theme] :is(th,td,.panel-head,.profile-row,.security-item,.source-row,.hkjc-race,.research-job,.pick,.app-footer,.sidebar-user,.data-summary>div,.detail-stats>div) { border-color:var(--border-color); }
html[data-theme] th { color:var(--text-secondary); background:var(--surface-raised); }
html[data-theme] tbody tr:hover { background:var(--surface-raised); }
html[data-theme] :is(td>small,td>div>small,.horse-name small,.race-tabs span,.metric strong small,.seg button,.seg button span) { color:var(--text-secondary); }
html[data-theme] .member-app table :is(th,td):first-child { background:var(--surface); }
html[data-theme] .member-app table th:first-child { background:var(--surface-raised); }
html[data-theme] .race-banner { color:var(--text-primary); background:linear-gradient(115deg,var(--surface),var(--surface-raised)); border-color:var(--border-color); }
html[data-theme] .race-serial { border-color:var(--border-color); }
html[data-theme] .race-serial span { color:var(--text-primary); }
html[data-theme] :is(.admin-welcome,.ai-summary,.wallet-hero,.invite-hero) { color:var(--text-primary); background:linear-gradient(115deg,var(--accent-soft),var(--surface)); border-color:var(--border-color); }
html[data-theme] .admin-welcome p { color:var(--text-secondary); }
html[data-theme] :is(.icon-btn,.panel-head svg,.feature-icon,.source-icon,.quick-panel>button>svg,.prob-chart>button) { color:var(--text-secondary); }
html[data-theme] .icon-btn:hover { background:var(--surface-raised); color:var(--text-primary); }
html[data-theme] :is(.text-btn,.register-link,.prob-chart>button b,.pick>b,.pick>b small,.hkjc-note a,.hkjc-race a) { color:var(--accent); }
html[data-theme] .text-btn.muted { color:var(--text-secondary); }
html[data-theme] .avatar { color:var(--accent); background:var(--accent-soft); border-color:var(--accent-border-soft); }
html[data-theme] .info-strip { color:var(--text-secondary); border-color:var(--border-color); background:var(--surface-raised); }
html[data-theme] .warning { color:var(--warning); background:var(--warning-soft); border-color:var(--warning-border); }
html[data-theme] :is(.form-error,.hkjc-error) { color:var(--accent); background:var(--accent-soft); border-color:var(--accent-border-soft); }
html[data-theme] .hkjc-success { color:var(--success); background:var(--success-soft); }
html[data-theme] .prob-track,html[data-theme] .prob-chart>button>div { background:var(--surface-soft); }
html[data-theme] .radar text { fill:var(--text-secondary); }
html[data-theme] .radar text.radar-score { fill:var(--text-primary); }
html[data-theme="light"] .modal-backdrop { background:#24334b70; }
html[data-theme="light"] .guest-lock { background:linear-gradient(#f3f5f855,#f3f5f8bb 60%,#f3f5f8); }
html[data-theme="light"] .toast { background:#edf9f2; color:#1d6546; border-color:#a0d4b4; }
html[data-theme="light"] .toast-error { background:#fff0f3; color:#a51e39; border-color:#e8aaba; }
html[data-theme="light"] .selected-meeting { color:var(--accent)!important; border-color:var(--accent)!important; }
html[data-theme="light"] :is(.member-app .table-scroll,.member-app .member-header nav) { scrollbar-color:#bbc7d5 #f3f5f8; }
html[data-theme="light"] :is(.member-app .table-scroll,.member-app .member-header nav)::-webkit-scrollbar-track { background:#f3f5f8; }
html[data-theme="light"] :is(.member-app .table-scroll,.member-app .member-header nav)::-webkit-scrollbar-thumb { background:#bbc7d5; }
/* The access gate remains neutral and reveals no admin navigation before verification. */
html[data-theme="dark"] :is(.search-surface,.google-shell) { color:var(--text-primary); background:var(--page-background); color-scheme:dark; }
html[data-theme="dark"] :is(.google-top,.google-offer,.google-footer) { color:var(--text-secondary); }
html[data-theme="dark"] :is(.google-search,.google-search input,.google-buttons button,.google-footer) { color:var(--text-primary); background:var(--surface); border-color:var(--border-color); }
html[data-theme="dark"] .google-footer>p { border-color:var(--border-color); }
html[data-theme="dark"] :is(.google-offer span,.google-return) { color:#8ab4f8; }
html[data-theme="light"] .member-app .search-surface { color-scheme:light; }
html[data-theme="light"] .racing-home { --race-red:var(--accent); }
html[data-theme="light"] :is(.racing-home,.racing-header,.racing-footer,.racing-feature,.racing-preview) { color:var(--text-primary); background:var(--surface); border-color:var(--border-color); }
html[data-theme="light"] :is(.racing-header .logo b,.racing-feature h2,.racing-feature-top) { color:var(--text-primary); }
html[data-theme="light"] :is(.racing-header nav a,.racing-header nav button,.racing-feature p,.racing-feature small,.racing-method p,.racing-join,.racing-footer p,.racing-copyright) { color:var(--text-secondary); }
html[data-theme="light"] .racing-header nav .active { color:var(--accent); }
html[data-theme="light"] :is(.racing-header nav,.racing-preview-head,.racing-method,.racing-footer small) { border-color:var(--border-color); }
html[data-theme="light"] .racing-hero { color:#f6f5f3; background:#080b0d; }
html[data-theme="light"] .racing-preview-lock { color:var(--text-primary); background:linear-gradient(#ffffffbb,#ffffff77); }
html[data-theme="light"] .racing-preview-lock :is(p,svg) { color:var(--text-secondary); }
html[data-theme="light"] .racing-menu-toggle { color:var(--text-primary); border-color:var(--border-color); }
@media(max-width:760px) { html[data-theme="light"] .racing-header nav { background:var(--surface); } }
@media(max-width:600px) {
  :root { --theme-toolbar-height:48px; }
  .theme-toolbar { padding:4px 12px; gap:6px; }
  .theme-clock { display:none; }
  .theme-context { font-size:10px; gap:6px; }
  .theme-options { gap:1px; padding:2px; }
  .theme-option { min-height:34px; padding:5px 10px; font-size:11px; }
}
@media(prefers-reduced-motion:reduce) { .theme-option { transition:none; } }
@media print { #racing-theme-controls { display:none; } }
