/* Glow colour system. Each palette owns every role in both modes.
 * Root and miniature previews deliberately share the SAME token declarations.
 * Legacy aliases below bridge routine and editor/settings components during migration. */
html[data-palette="classic"][data-theme="light"],
html[data-theme="light"] .theme-mini[data-palette="classic"] {
    --canvas: #f8f6f2;
    --panel: #ffffff;
    --inset: #f0ebf2;
    --ink: #2b2930;
    --muted: #6b6470;
    --line: #8f8097;
    --primary: #6f5278;
    --secondary: #92602d;
    --success: #4b705e;
    --on-accent: #ffffff;
    --border-width: 1px;
    --danger-color: #a32032;
    --elevation: 0 8px 24px -12px color-mix(in srgb, #30251e 18%, transparent);
}
html[data-palette="classic"][data-theme="dark"],
html[data-theme="dark"] .theme-mini[data-palette="classic"] {
    --canvas: #0d0f14;
    --panel: #151821;
    --inset: #1c2130;
    --ink: #f5f3ef;
    --muted: #a8a29e;
    --line: #78716c;
    --primary: #a5b4fc;
    --secondary: #e0c097;
    --success: #34d399;
    --on-accent: #0d0f14;
    --border-width: 1px;
    --danger-color: #ffbdc4;
    --elevation: 0 12px 28px -16px rgba(0, 0, 0, .6);
}
html[data-palette="botanical"][data-theme="light"],
html[data-theme="light"] .theme-mini[data-palette="botanical"] {
    --canvas: #f4efdf;
    --panel: #e7efdf;
    --inset: #eee3cb;
    --ink: #22352b;
    --muted: #4b5944;
    --line: #6d8262;
    --primary: #255b3e;
    --secondary: #774561;
    --success: #285d44;
    --on-accent: #ffffff;
    --border-width: 1px;
    --danger-color: #a32032;
    --elevation: 0 8px 24px -12px color-mix(in srgb, #1c3528 18%, transparent);
}
html[data-palette="botanical"][data-theme="dark"],
html[data-theme="dark"] .theme-mini[data-palette="botanical"] {
    --canvas: #10261e;
    --panel: #302b28;
    --inset: #263b30;
    --ink: #f3f5e6;
    --muted: #cbd0b5;
    --line: #8e9b7a;
    --primary: #aed6ad;
    --secondary: #e5b2c8;
    --success: #a9ddb3;
    --on-accent: #10261e;
    --border-width: 1px;
    --danger-color: #ffbdc4;
    --elevation: 0 12px 28px -16px rgba(0, 0, 0, .6);
}
html[data-palette="ocean"][data-theme="light"],
html[data-theme="light"] .theme-mini[data-palette="ocean"] {
    --canvas: #d8eaff;
    --panel: #fff6e7;
    --inset: #c8dff8;
    --ink: #102e50;
    --muted: #3a5674;
    --line: #577997;
    --primary: #174db8;
    --secondary: #8b431e;
    --success: #216048;
    --on-accent: #ffffff;
    --border-width: 1px;
    --danger-color: #a32032;
    --elevation: 0 8px 24px -12px color-mix(in srgb, #102e50 18%, transparent);
}
html[data-palette="ocean"][data-theme="dark"],
html[data-theme="dark"] .theme-mini[data-palette="ocean"] {
    --canvas: #071733;
    --panel: #182c46;
    --inset: #332c29;
    --ink: #edf6ff;
    --muted: #c5cdd9;
    --line: #8399b0;
    --primary: #abcaff;
    --secondary: #ffc29b;
    --success: #8bddbb;
    --on-accent: #071733;
    --border-width: 1px;
    --danger-color: #ffbdc4;
    --elevation: 0 12px 28px -16px rgba(0, 0, 0, .6);
}
html[data-palette="rose"][data-theme="light"],
html[data-theme="light"] .theme-mini[data-palette="rose"] {
    --canvas: #f4e2e8;
    --panel: #fff7e8;
    --inset: #dde9df;
    --ink: #482334;
    --muted: #724357;
    --line: #936778;
    --primary: #873b5a;
    --secondary: #35644b;
    --success: #35634d;
    --on-accent: #ffffff;
    --border-width: 1px;
    --danger-color: #a32032;
    --elevation: 0 8px 24px -12px color-mix(in srgb, #482334 18%, transparent);
}
html[data-palette="rose"][data-theme="dark"],
html[data-theme="dark"] .theme-mini[data-palette="rose"] {
    --canvas: #301b29;
    --panel: #23342f;
    --inset: #49303b;
    --ink: #fff0f4;
    --muted: #dfc7d0;
    --line: #aa8797;
    --primary: #ebb5ce;
    --secondary: #abd3bb;
    --success: #a6d6b7;
    --on-accent: #301b29;
    --border-width: 1px;
    --danger-color: #ffbdc4;
    --elevation: 0 12px 28px -16px rgba(0, 0, 0, .6);
}
html[data-palette="sunset"][data-theme="light"],
html[data-theme="light"] .theme-mini[data-palette="sunset"] {
    --canvas: #f0ddbf;
    --panel: #fff4e7;
    --inset: #d8e8df;
    --ink: #422c20;
    --muted: #6b4935;
    --line: #8b6a4d;
    --primary: #873c24;
    --secondary: #1b605b;
    --success: #315e3e;
    --on-accent: #ffffff;
    --border-width: 1px;
    --danger-color: #a32032;
    --elevation: 0 8px 24px -12px color-mix(in srgb, #422c20 18%, transparent);
}
html[data-palette="sunset"][data-theme="dark"],
html[data-theme="dark"] .theme-mini[data-palette="sunset"] {
    --canvas: #302018;
    --panel: #173b3a;
    --inset: #463023;
    --ink: #fff0d8;
    --muted: #e1cbb3;
    --line: #aa947b;
    --primary: #f4cc83;
    --secondary: #9cd6ce;
    --success: #b3d6a1;
    --on-accent: #302018;
    --border-width: 1px;
    --danger-color: #ffbdc4;
    --elevation: 0 12px 28px -16px rgba(0, 0, 0, .6);
}
html[data-palette="contrast"][data-theme="light"],
html[data-theme="light"] .theme-mini[data-palette="contrast"] {
    --canvas: #ffffff;
    --panel: #ffffff;
    --inset: #ededed;
    --ink: #000000;
    --muted: #292929;
    --line: #595959;
    --primary: #0044cc;
    --secondary: #003b8e;
    --success: #005c37;
    --on-accent: #ffffff;
    --border-width: 2px;
    --danger-color: #a32032;
    --elevation: none;
}
html[data-palette="contrast"][data-theme="dark"],
html[data-theme="dark"] .theme-mini[data-palette="contrast"] {
    --canvas: #000000;
    --panel: #080808;
    --inset: #1c1c1c;
    --ink: #ffffff;
    --muted: #e3e3e3;
    --line: #bdbdbd;
    --primary: #9bc6ff;
    --secondary: #ffffff;
    --success: #9af3c0;
    --on-accent: #000000;
    --border-width: 2px;
    --danger-color: #ffbdc4;
    --elevation: none;
}
html[data-palette="violet"][data-theme="light"],
html[data-theme="light"] .theme-mini[data-palette="violet"] {
    --canvas: #e7daf6;
    --panel: #fff0e1;
    --inset: #dfe8df;
    --ink: #37194d;
    --muted: #603c7a;
    --line: #86639e;
    --primary: #692898;
    --secondary: #4e592b;
    --success: #305c40;
    --on-accent: #ffffff;
    --border-width: 1px;
    --danger-color: #a32032;
    --elevation: 0 8px 24px -12px color-mix(in srgb, #37194d 18%, transparent);
}
html[data-palette="violet"][data-theme="dark"],
html[data-theme="dark"] .theme-mini[data-palette="violet"] {
    --canvas: #251137;
    --panel: #28362e;
    --inset: #493052;
    --ink: #faf0ff;
    --muted: #d8c6e3;
    --line: #aa91ba;
    --primary: #deb2ff;
    --secondary: #cbd99a;
    --success: #ace0bd;
    --on-accent: #251137;
    --border-width: 1px;
    --danger-color: #ffbdc4;
    --elevation: 0 12px 28px -16px rgba(0, 0, 0, .6);
}
html[data-palette="cherry"][data-theme="light"],
html[data-theme="light"] .theme-mini[data-palette="cherry"] {
    --canvas: #ffdce0;
    --panel: #fff5df;
    --inset: #dce8f0;
    --ink: #4d1424;
    --muted: #7b3042;
    --line: #9c5c6d;
    --primary: #9b1838;
    --secondary: #1c606a;
    --success: #2d6045;
    --on-accent: #ffffff;
    --border-width: 1px;
    --danger-color: #a32032;
    --elevation: 0 8px 24px -12px color-mix(in srgb, #4d1424 18%, transparent);
}
html[data-palette="cherry"][data-theme="dark"],
html[data-theme="dark"] .theme-mini[data-palette="cherry"] {
    --canvas: #350d18;
    --panel: #18353a;
    --inset: #4b2833;
    --ink: #fff0f1;
    --muted: #efd0d4;
    --line: #bb8c97;
    --primary: #ffadc1;
    --secondary: #9cdae0;
    --success: #a2e3b9;
    --on-accent: #350d18;
    --border-width: 1px;
    --danger-color: #ffbdc4;
    --elevation: 0 12px 28px -16px rgba(0, 0, 0, .6);
}

/* Semantic aliases: both app shells now consume one colour system. */
html[data-palette] {
    color-scheme: light;
    --bg-color: var(--canvas); --bg: var(--canvas);
    --surface-bg: var(--panel); --surface-1: var(--panel);
    --surface-2: var(--inset); --surface-3: var(--inset);
    --surface-border: var(--line); --border: var(--line);
    --surface-hover-border: var(--primary);
    --text-primary: var(--ink); --text: var(--ink);
    --text-secondary: var(--muted); --text-muted: var(--muted); --text-2: var(--muted); --text-3: var(--muted);
    --accent-iris: var(--primary); --iris: var(--primary);
    --accent-gold: var(--secondary); --gold: var(--secondary);
    --accent-emerald: var(--success); --ok: var(--success);
    --accent-iris-soft: var(--inset); --iris-soft: var(--inset);
    --accent-gold-soft: var(--inset); --accent-emerald-soft: var(--inset);
    --button-text: var(--on-accent); --danger: var(--danger-color);
    --danger-bg: var(--inset); --shadow-card: var(--elevation);
    --theme-glow: none;
    --progress-gradient: linear-gradient(90deg, var(--secondary), var(--primary));
    --font-heading: 'Cormorant Garamond', Georgia, serif;
    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --consent-bg: var(--panel); --consent-text: var(--ink); --consent-accent: var(--primary);
    --consent-border: var(--line); --consent-button: var(--inset); --consent-button-text: var(--on-accent);
}
html[data-theme="dark"] { color-scheme: dark; }
/* Neutral component literals used to overpower palette changes. Keep colour here semantic. */
html[data-palette] body.view-pm { --theme-glow: none; }
html[data-palette] :is(.slider-track, .streak-chip, .weather-chip, .step-product, .progress-bar, .app-status-retry) { background: var(--inset); }
html[data-palette] .slider-thumb { background: var(--panel); }
html[data-palette] .streak-fire-icon { color: var(--secondary); }
html[data-palette] .view-toggle button.active { border-color: var(--primary); }
html[data-palette] #toggle-am.active { border-color: var(--secondary); }
html[data-palette] .step-item.completed { background: var(--inset); border-color: var(--success); }
html[data-palette] .check-icon { stroke: var(--on-accent); }
html[data-palette] .app-status[data-tone="offline"] { color: var(--secondary); }
html[data-palette] .app-status[data-tone="pending"] { color: var(--primary); }
html[data-palette] .app-status[data-tone="ready"] { color: var(--success); }
html[data-palette] :is(.btn-primary, .day-step.done .check) { color: var(--on-accent); }
html[data-palette] .step-row:hover { border-color: var(--primary); }
html[data-palette] .cal-dot.am.partial { background: color-mix(in srgb, var(--secondary) 45%, transparent); }
html[data-palette] .cal-dot.pm.partial { background: color-mix(in srgb, var(--primary) 45%, transparent); }
html[data-palette] :is(header, .step-item, .progress-card, .view-toggle, .card, .step-row) { border-width: var(--border-width); }
html[data-palette] :is(button, a, input, select, textarea, summary):focus-visible { outline: 3px solid var(--primary); outline-offset: 3px; }
html[data-palette] :is(button, a):active { filter: brightness(.92); }
html[data-palette] button:disabled { cursor: not-allowed; }

/* Picker: the miniature is an actual semantic canvas/card/control composition. */
.theme-picker { min-width: 0; border: 0; padding: 0; margin: 20px 0; }
.theme-picker legend { font-size: 1rem; font-weight: 700; }
.theme-picker-note { font-size: .8rem; color: var(--muted); line-height: 1.6; margin: 8px 0 14px; }
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.theme-option { position: relative; display: block; min-width: 0; cursor: pointer; }
.theme-option input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; cursor: pointer; }
.theme-preview { display: block; height: 100%; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
.theme-option:hover .theme-preview { border-color: var(--primary); }
.theme-option input:checked + .theme-preview { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.theme-option input:focus-visible + .theme-preview { outline: 3px solid var(--primary); outline-offset: 3px; }
.theme-mini { display: grid; gap: 7px; background: var(--canvas); color: var(--ink); padding: 12px; border-bottom: 1px solid var(--line); min-height: 112px; pointer-events: none; }
.theme-mini-heading { display: flex; align-items: center; justify-content: space-between; font: 600 12px/1.2 Georgia, serif; color: var(--ink); }
.theme-mini-dot { width: 8px; height: 8px; background: var(--primary); border-radius: 50%; }
.theme-mini-tabs { display: flex; gap: 4px; background: var(--inset); border-radius: 5px; padding: 3px; }
.theme-mini-tabs span { flex: 1; text-align: center; font: 600 9px/1.6 system-ui; color: var(--muted); }
.theme-mini-tabs span:first-child { background: var(--primary); color: var(--on-accent); border-radius: 3px; }
.theme-mini-card { display: flex; align-items: center; gap: 6px; background: var(--panel); border: var(--border-width) solid var(--line); border-radius: 5px; padding: 7px; box-shadow: var(--elevation); }
.theme-mini-check { border: 1px solid var(--success); background: var(--success); color: var(--on-accent); border-radius: 50%; width: 13px; height: 13px; text-align: center; font: 700 9px/12px system-ui; }
.theme-mini-lines { flex: 1; height: 12px; border-top: 3px solid var(--ink); border-bottom: 2px solid var(--muted); margin-right: 6px; }
.theme-caption { display: block; padding: 10px; color: var(--ink); }
.theme-name { display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: .8rem; font-weight: 700; line-height: 1.4; }
.theme-selected { visibility: hidden; font-size: .8rem; color: var(--primary); }
.theme-option input:checked + .theme-preview .theme-selected { visibility: visible; }
.theme-description { display: block; font-size: .7rem; color: var(--muted); line-height: 1.5; margin-top: 3px; }
.theme-status { font-size: .8rem; color: var(--muted); min-height: 1.5em; margin: 12px 0 0; line-height: 1.5; }
.glow-menu .theme-picker { border-top: 1px solid var(--line); padding-top: 16px; }
.glow-menu .theme-picker legend { padding: 12px 0 0; }
/* Leave room to compare previews on an unfolded display; stay inside a narrow pane. */
.glow-menu { width: min(400px, calc(100vw - 24px)); width: min(400px, calc(100dvw - 24px)); }
@media (min-width: 700px) { .glow-menu { width: 440px; } }
@media (max-width: 359px) { .theme-grid { grid-template-columns: 1fr; } }
@media (horizontal-viewport-segments: 2) {
    .glow-menu { left: auto; right: 0; width: min(440px, calc(env(viewport-segment-width 1 0, 100vw) - 16px)); }
}
@media (prefers-reduced-motion: reduce) { body, body::before, .theme-preview { transition: none !important; } }
@media (forced-colors: active) {
    .theme-preview { border-color: CanvasText; }
    .theme-option input:checked + .theme-preview { outline: 3px solid Highlight; }
    .theme-selected { forced-color-adjust: auto; }
}


/* Classic preserves the original Midnight Velvet / Ivory, Plum & Sage identity.
   Decorative card borders remain subtle; control outlines still use --line. */
html[data-palette="classic"][data-theme="dark"] {
    --surface-bg: rgba(21, 24, 33, .78);
    --surface-border: rgba(224, 192, 151, .12);
    --surface-hover-border: rgba(224, 192, 151, .24);
    --accent-gold-soft: rgba(224, 192, 151, .14);
    --accent-iris-soft: rgba(165, 180, 252, .14);
    --accent-emerald-soft: rgba(52, 211, 153, .16);
    --theme-glow: radial-gradient(circle at 50% -10%, rgba(224,192,151,.08), rgba(224,192,151,.02) 45%, transparent 70%);
    --shadow-card: 0 20px 40px -15px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.08);
}
html[data-palette="classic"][data-theme="light"] {
    --surface-border: #ded8e1; --surface-hover-border: #b9adbf;
    --accent-gold-soft: rgba(148,97,45,.08);
    --accent-iris-soft: rgba(111,82,120,.08);
    --accent-emerald-soft: rgba(82,120,102,.10);
    --theme-glow: radial-gradient(circle at 50% -10%, rgba(148,97,45,.06), rgba(148,97,45,.01) 45%, transparent 70%);
    --shadow-card: 0 10px 30px -10px rgba(43,41,48,.06), 0 2px 6px -1px rgba(43,41,48,.04);
}
html[data-palette="classic"] { --progress-gradient: linear-gradient(90deg, var(--secondary), var(--success)); }
html[data-palette="classic"] body.view-pm { --theme-glow: radial-gradient(circle at 50% -10%, color-mix(in srgb, var(--primary) 8%, transparent), transparent 70%); }
html[data-palette="classic"] #toggle-am.active { background: var(--accent-gold-soft); }
html[data-palette="classic"] #toggle-pm.active { background: var(--accent-iris-soft); }
html[data-palette="classic"] .step-item.completed { background: var(--accent-emerald-soft); }
html[data-palette="classic"] .checkbox { border-color: var(--line); }
html[data-palette="classic"] .step-item.completed .checkbox { border-color: var(--success); }
html[data-theme="dark"] .theme-mini[data-palette="classic"] .theme-mini-card { background: rgba(21,24,33,.78); }
