/* Light palettes share component coverage; the existing midnight palette stays intact. */
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) {
  color-scheme: light;
  --positive: #087b5b;
  --positive-bg: #e9f5ef;
  --positive-line: #beded0;
  --negative: #bc3c51;
  --negative-bg: #fceef0;
  --negative-line: #edc6cc;
  --win: var(--positive);
  --win-bright: var(--positive);
  --win-bg: var(--positive-bg);
  --win-line: var(--positive-line);
  --odd: var(--negative);
  --odd-bright: var(--negative);
  --odd-bg: var(--negative-bg);
  --odd-line: var(--negative-line);
  --danger: var(--negative);
  --shout: var(--negative);
  --warn: #956210;
  --gold: var(--warn);
  --gold-soft: var(--warn);
  --warn-bg: #fff5df;
  --warn-line: #e8cf9a;
  --info: var(--accent);
  --ink-on: var(--ink);
  --ink-2: var(--ink);
  --ios-card: var(--panel);
  --ios-card-2: var(--panel2);
  --ios-sep: var(--line);
  --ios-teal: var(--accent);
  --ios-label: var(--ink);
  --ios-secondary: var(--muted);
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 12px 36px rgba(25, 35, 45, .10);
  --shadow-soft: 0 2px 7px rgba(25, 35, 45, .04);
  scrollbar-color: var(--sb-thumb) var(--bg);
}

html[data-theme="light"] {
  --bg: #f2f6f5;
  --sidebar: #fbfdfc;
  --panel: #ffffff;
  --panel2: #f6f9f7;
  --panel3: #e9f1ed;
  --panel-deep: #ffffff;
  --head: #f5f9f7;
  --ink: #20342c;
  --muted: #566e63;
  --muted-2: #5b7267;
  --accent: #146947;
  --accent-hover: #0e5539;
  --accent-soft: #e3f1e8;
  --accent-line: #a8cbb7;
  --line: #dce6e0;
  --line-strong: #bdcfc3;
  --hover: #eff5f1;
  --hover-2: #e8f1eb;
  --veil: rgba(251, 253, 252, .97);
  --veil-soft: #eef5f0;
  --veil-line: #dce6e0;
  --btn-veil: #edf4ef;
  --sb-thumb: #bacfc1;
}

html[data-theme="paper"] {
  --bg: #f4f4f2;
  --sidebar: #fafaf8;
  --panel: #ffffff;
  --panel2: #f6f6f4;
  --panel3: #ebebe7;
  --panel-deep: #ffffff;
  --head: #f7f7f5;
  --ink: #2a2b29;
  --muted: #62645f;
  --muted-2: #6c6e68;
  --accent: #343a35;
  --accent-hover: #1e2721;
  --accent-soft: #ecefea;
  --accent-line: #b9c2b9;
  --line: #dfdfd9;
  --line-strong: #c4c6bd;
  --hover: #f1f2ed;
  --hover-2: #eaece5;
  --veil: rgba(250, 250, 248, .97);
  --veil-soft: #eeefe9;
  --veil-line: #dfdfd9;
  --btn-veil: #eeefe9;
  --sb-thumb: #c0c3b9;
  --paper-mark: #b84848;
}

html[data-theme="silver"] {
  --bg: #edf0f4;
  --sidebar: #f8fafc;
  --panel: #ffffff;
  --panel2: #f5f7fa;
  --panel3: #e4eaf1;
  --panel-deep: #ffffff;
  --head: #f4f7fa;
  --ink: #283444;
  --muted: #596a7c;
  --muted-2: #5c6e82;
  --accent: #285ec1;
  --accent-hover: #1e4da6;
  --accent-soft: #e6eefc;
  --accent-line: #b4c8ed;
  --line: #dbe2eb;
  --line-strong: #bdc9d9;
  --hover: #edf2f9;
  --hover-2: #e5edf8;
  --veil: rgba(248, 250, 252, .97);
  --veil-soft: #eef2f8;
  --veil-line: #dbe2eb;
  --btn-veil: #edf2f9;
  --sb-thumb: #bdcadb;
}

html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"])[data-pnl-color="cn"] {
  --win: var(--negative);
  --win-bright: var(--negative);
  --win-bg: var(--negative-bg);
  --win-line: var(--negative-line);
  --odd: var(--positive);
  --odd-bright: var(--positive);
  --odd-bg: var(--positive-bg);
  --odd-line: var(--positive-line);
}

/* Legacy mobile rules force black with !important; override only light palettes. */
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(body, #app.mac-shell, .workspace, .content, #view-watch, #view-pos, #view-stats) {
  background: var(--bg) !important;
  background-color: var(--bg) !important;
  color: var(--ink);
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .sidebar.tabbar {
  background: var(--sidebar) !important;
  border-color: var(--line) !important;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.side-brand h1, .nav-item, .nav-sub, .nav-parent, .nav-item::before, .side-stats .k) {
  color: var(--muted);
  letter-spacing: 0;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .side-brand h1 { color: var(--ink); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .tabbar button.active.nav-parent::after { border-color: transparent transparent transparent var(--sidebar); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.nav-item.active, .nav-sub.on) {
  color: var(--accent) !important;
  background: var(--accent-soft) !important;
  box-shadow: inset 3px 0 0 var(--accent);
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .nav-item.active::before { color: var(--accent) !important; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .titlebar {
  background: var(--panel) !important;
  border-color: var(--line) !important;
  border-radius: 0;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.panel, #view-watch .panel, #view-pos .panel, #view-stats .panel) {
  background: var(--panel) !important;
  border-color: var(--line) !important;
  border-radius: var(--radius) !important;
  box-shadow: none;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.section-h, .shortcut-head) {
  background: var(--head);
  border-color: var(--line);
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.btn, .section-h .btn, .shout-filters button, .stats-tabs button) {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  box-shadow: none;
  letter-spacing: 0;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.btn, .shout-filters button, .stats-tabs button):hover {
  background: var(--hover);
  color: var(--ink);
  filter: none;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.btn.primary, .section-h .btn.primary, button.primary) {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #ffffff !important;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.btn.primary, button.primary):hover { background: var(--accent-hover) !important; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.btn.on, .btn.active, .stats-tabs button.on, .shout-filters button.on, .density-bar .btn.on) {
  color: var(--accent) !important;
  background: var(--accent-soft) !important;
  border-color: var(--accent-line) !important;
  box-shadow: none;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .btn.danger {
  color: var(--danger);
  background: var(--negative-bg);
  border-color: var(--negative-line);
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .btn.warn { color: var(--warn); border-color: var(--warn-line); background: var(--warn-bg); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
  background: var(--panel-deep) !important;
  color: var(--ink) !important;
  border-color: var(--line-strong) !important;
  border-radius: var(--radius-sm) !important;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(input, select, textarea):focus-visible {
  outline: 2px solid var(--accent-line);
  outline-offset: 2px;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(input[type="checkbox"], input[type="radio"]) { accent-color: var(--accent); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) input::placeholder { color: var(--muted-2); opacity: 1; }

/* A flat settings form keeps the controls readable without nesting dark cards. */
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .settings-panel { background: transparent !important; border: 0 !important; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .settings-panel > .section-h { background: transparent; padding-bottom: 18px; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .settings-panel .settings-grid { gap: 0 28px; max-width: none; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .settings-card {
  background: transparent !important;
  border: 0 !important;
  border-top: 1px solid var(--line) !important;
  border-radius: 0 !important;
  padding: 22px 0 !important;
  box-shadow: none;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .settings-card h3 { font-size: 15px; color: var(--ink); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.settings-card-lead, .muted, .strat-form .hint, .help-term .ht-text, .eq-empty-sub) { color: var(--muted); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .lab-console { background: var(--panel) !important; border-color: var(--line) !important; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.lab-fold, .ctx-header, .ctx-table th, .ca4-contrib-item, .stats-scope-chip) { background: var(--panel2); border-color: var(--line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.recon-verdict, .lab-verdict-hero) { border-radius: 6px !important; box-shadow: none; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .recon-verdict.bad { background: var(--negative-bg); border-color: var(--negative-line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .recon-verdict.warn { background: var(--warn-bg); border-color: var(--warn-line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .recon-verdict.ok { background: var(--positive-bg); border-color: var(--positive-line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.lab-sens-table td .sens-tier, .ctx-table th) { color: var(--ink); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.ticket, .ticket.tape, .pos-card, #view-pos .pos-card, #posList.pos-list.compact .pos-card, .kpi, .ov-card) {
  background: var(--panel) !important;
  border-color: var(--line) !important;
  color: var(--ink);
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.pc-vs, .pc-score, .ticket .vs, #shoutFeed .ticket .vs, #shoutFeed .ticket .sel, .ticket-h .vs, .kpi .v) { color: var(--ink); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.tag-late, .tag.warn) { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.hb-bar.ok #hbMs, .mobile-hb-cap.ok, .tag.good) { color: var(--positive); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .mobile-hb-cap.ok { background: var(--positive-bg); border-color: var(--positive-line); box-shadow: none; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .mobile-hb-cap.idle { color: var(--muted); background: var(--panel2); border-color: var(--line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .mobile-hb-cap.bad { color: var(--negative); background: var(--negative-bg); border-color: var(--negative-line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.mobile-hb-cap.warn, .tag-inc) { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.gate-card, .shortcut-dialog, .shortcut-head, .pair-bar, .pc-menu-body, .mobile-more-panel, .nav-flyout, .tour-card, .open-alert, .chart-tip) {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: var(--shadow);
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.mobile-more-title, .mobile-more-item, .ov-card .ov-title) { color: var(--ink); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .mobile-more-item { background: var(--panel2); border-color: var(--line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .mobile-more-item:active { background: var(--hover-2); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .mobile-more-grab { background: var(--line-strong); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.backup-row, .adv-details, .watch-sub-lock, kbd) { background: var(--panel2); color: var(--ink); border-color: var(--line); box-shadow: none; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.sc-row span, .audit-trail .audit-body b, .empty-state .es-title) { color: var(--ink); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .shortcut-group h4 { border-color: var(--line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .shortcut-close:hover { background: var(--hover-2); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.pass-why, .help-disclaim, .recon-warn) { color: var(--warn); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .help-disclaim { background: var(--warn-bg); border-color: var(--warn-line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .recon-ok { color: var(--positive); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(.recon-bad, .err-state) { color: var(--negative); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .err-state { background: var(--negative-bg); border-color: var(--negative-line); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .tour-spot { box-shadow: 0 0 0 4000px rgba(238, 241, 242, .82); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .skel { background: var(--panel3); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(table th, .cal-table th) { color: var(--muted); background: var(--head); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) table tbody tr:nth-child(even) { background: var(--panel2); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) table tbody tr:hover { background: var(--hover); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .cal-table tfoot td { background: var(--head); color: var(--ink); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .cal-table .c-day b { color: var(--ink); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(#sec-cal, #sec-cal.panel, #view-stats #sec-cal, #app.cockpit-tiled #view-stats #sec-cal.panel, #sec-cal .cal-nav, #sec-cal .cal-grid, #sec-cal .cal-days, #sec-cal .cal-week, #sec-cal .cal-cell) {
  background: var(--panel) !important;
  background-color: var(--panel) !important;
}
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(#sec-cal .cal-cell .d, #sec-cal .cal-cell .n, #sec-cal .cal-cell.up .n, #sec-cal .cal-cell.down .n, #sec-cal .cal-cell.flat .p, #sec-cal .cal-wd, #sec-cal #calTitle) { color: var(--ink) !important; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) #sec-cal .cal-cell.empty { background: transparent !important; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) #sec-cal .cal-cell.today { outline-color: var(--accent); }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) #sec-cal .cal-cell.in { border-color: var(--line-strong); box-shadow: none; }
html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .stats-filter-drawer { border-color: var(--line); }

/* Paper is an ink-led ledger, not a sepia recoloring of the dark interface. */
html[data-theme="paper"] .section-h h2 { font-family: "Songti SC", "Noto Serif SC", Georgia, serif; font-size: 18px; font-weight: 700; }
html[data-theme="paper"] .side-brand { border-bottom: 2px solid var(--ink); }
html[data-theme="paper"] .side-brand h1 { font-family: "Songti SC", "Noto Serif SC", Georgia, serif; }
html[data-theme="paper"] .nav-item.active { box-shadow: inset 3px 0 0 var(--paper-mark); }
html[data-theme="paper"] .section-h { border-bottom: 1px solid var(--line-strong); }
html[data-theme="silver"] .section-h { background: var(--panel); }

.theme-choice-bar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; max-width: 460px; margin: 0; }
.theme-choice-bar .btn.theme-option {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px;
  min-height: 64px !important; min-width: 0; padding: 10px 12px;
  border-radius: 6px; border: 1px solid var(--line-strong);
  font-size: 13px; font-weight: 600; text-align: left;
}
.theme-choice-bar .theme-option.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.theme-swatch {
  flex: 0 0 42px; width: 42px; height: 34px; border-radius: 4px;
  display: grid; grid-template-columns: 10px 1fr; grid-template-rows: 7px 1fr;
  background: var(--sw-bg); border: 1px solid var(--sw-line); overflow: hidden;
}
.theme-swatch::before { content: ""; grid-area: 1 / 1 / 3 / 2; background: var(--sw-side); border-right: 1px solid var(--sw-line); }
.theme-swatch::after { content: ""; grid-area: 2 / 2; background: var(--sw-accent); margin: 4px 5px 9px; border-radius: 1px; }
[data-theme-choice="dark"] { --sw-bg: #1c1c21; --sw-side: #111113; --sw-line: #393940; --sw-accent: #26a69a; }
[data-theme-choice="light"] { --sw-bg: #ffffff; --sw-side: #e3f1e8; --sw-line: #ceded3; --sw-accent: #146947; }
[data-theme-choice="paper"] { --sw-bg: #ffffff; --sw-side: #eceee8; --sw-line: #d7d9d0; --sw-accent: #b84848; }
[data-theme-choice="silver"] { --sw-bg: #ffffff; --sw-side: #e6edf8; --sw-line: #cad6e9; --sw-accent: #285ec1; }

@media (max-width: 720px) {
  html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .side-nav { background: var(--veil) !important; border-color: var(--line) !important; box-shadow: 0 -2px 12px rgba(25, 35, 45, .05) !important; }
  html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .side-nav .nav-item.active { box-shadow: none; }
  html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) :is(#view-stats table th:first-child, #view-stats table td:first-child, table.rule-attr th:first-child, table.rule-attr td:first-child, .admin-table th:first-child, .admin-table td:first-child, .cal-table th:first-child, .cal-table td:first-child) { background: var(--panel); box-shadow: 2px 0 5px rgba(25, 35, 45, .06); }
  html:is([data-theme="light"], [data-theme="paper"], [data-theme="silver"]) .settings-panel .settings-grid { gap: 0; }
  .theme-choice-bar .btn.theme-option { min-height: 66px !important; padding: 10px; gap: 8px; font-size: 12px; }
  .theme-swatch { width: 36px; flex-basis: 36px; }
}
