/* The day palette is supplied by the existing application stylesheet. */
html:not([data-theme]) .theme-toggle,
.theme-sun,
[data-theme="dark"] .theme-moon {
    display: none;
}

[data-theme="dark"] .theme-sun { display: block; }

.theme-toggle:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.theme-error-toggle {
    position: absolute;
    inset-block-start: max(0.5rem, env(safe-area-inset-top));
    inset-inline-end: 1rem;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --color-canvas: #16181c;
    --color-surface: #22252b;
    --color-ink: #f5f2f0;
    --color-stone-50: #292c32;
    --color-stone-100: #34373d;
    --color-stone-200: #4a4d55;
    --color-stone-300: #82858e;
    --color-stone-400: #b9b8bd;
    --color-stone-500: #cac8cb;
    --color-stone-600: #d7d5d7;
    --color-stone-700: #e4e1e3;
    --color-stone-800: #eeebed;

    --color-brand-50: #36232c;
    --color-brand-100: #4b2836;
    --color-brand-200: #673445;
    --color-brand-300: #ef92ab;
    --color-brand-400: #ff98b0;
    --color-brand-500: #ffa3b8;
    --color-brand-600: #ffb1c2;
    --color-brand-700: #ffbfd0;
    --color-brand-800: #ffd0db;
    --color-brand-900: #ffdae2;

    --color-amber-50: #332a1d;
    --color-amber-100: #433321;
    --color-amber-200: #60452a;
    --color-amber-300: #694b24;
    --color-amber-700: #ffd18c;
    --color-amber-800: #ffdaa2;
    --color-amber-900: #ffe1b6;
    --color-amber-950: #ffe9c7;
    --color-emerald-50: #192e2a;
    --color-emerald-100: #203e36;
    --color-emerald-200: #325b4e;
    --color-emerald-600: #83e2ba;
    --color-emerald-700: #a2edca;
    --color-emerald-800: #b2f0d5;
    --color-emerald-900: #c4f4e0;
    --color-emerald-950: #d2f6e6;
    --color-sky-50: #192c39;
    --color-sky-100: #20394b;
    --color-sky-200: #30546b;
    --color-sky-600: #8ed8fa;
    --color-sky-700: #a2dfff;
    --color-sky-800: #b8e7ff;
    --color-sky-900: #caedff;
    --color-sky-950: #d7f2ff;
    --color-violet-50: #2b2439;
    --color-violet-100: #382c4d;
    --color-violet-200: #504065;
    --color-violet-500: #c5a8ff;
    --color-violet-600: #d0b5ff;
    --color-violet-700: #d8c1ff;
    --color-violet-800: #e1ceff;
    --color-violet-900: #e8daff;
    --color-violet-950: #efe4ff;
    --color-red-50: #372327;
    --color-red-100: #4a2b30;
    --color-red-200: #683a40;
    --color-red-500: #ffa0a8;
    --color-red-600: #ffb0b7;
    --color-red-700: #ffbec4;
    --color-red-800: #ffccd1;
    --color-red-900: #ffd9dd;
    --color-red-950: #ffe2e5;
    --color-rose-50: #35232c;
    --color-rose-100: #482936;
    --color-rose-200: #673b4b;
    --color-rose-700: #ffb4ca;
    --color-orange-100: #432f23;
    --color-orange-200: #65432c;
    --color-orange-700: #ffc399;
    --color-teal-100: #203b39;
    --color-teal-200: #305653;
    --color-teal-700: #9fe3d8;
    --color-pink-50: #372632;
    --color-pink-200: #613b51;
    --color-pink-700: #ffb8dd;
    --color-slate-100: #2c3442;
    --color-slate-200: #435169;
    --color-slate-700: #c4d3e7;
}

/* Keep background overrides in their original layers so interactive utilities still win. */
@layer components {
    :where([data-theme="dark"]) {
        .card, .btn-ghost, .chip, .input:focus { background-color: var(--color-surface); }
        .btn-ghost:hover, .chip:hover { background-color: var(--color-stone-50); }
        .btn-dark, .chip-active { background-color: #47414c; color: white; }
        .btn-dark:hover, .chip-active:hover { background-color: #554c5b; }
        .btn-primary { background-color: #a52a50; }
        .btn-primary:hover { background-color: #922144; }
        .account-guide .account-guide-confirm { background-color: #a52a50; }
        .account-guide .account-guide-confirm:hover { background-color: #922144; }
        .switch { background-color: #65636c; }
        .peer:checked + .switch { background-color: #ad3157; }
        .input { --tw-ring-color: #797a84; }
        .input-error { --tw-ring-color: var(--color-red-400); }
    }
}

@layer utilities {
    :where([data-theme="dark"]) {
        .bg-white { background-color: var(--color-surface); }
        .peer:checked ~ .peer-checked\:bg-white {
            background-color: var(--color-surface);
            box-shadow: inset 0 0 0 1px var(--color-stone-300);
        }
        .bg-white\/60, .hover\:bg-white\/60:hover { background-color: rgb(34 37 43 / 60%); }
        .bg-white\/80 { background-color: rgb(34 37 43 / 80%); }
        .bg-white\/90 { background-color: rgb(34 37 43 / 90%); }
        .bg-white\/92 { background-color: rgb(34 37 43 / 92%); }
        .bg-white\/95 { background-color: rgb(34 37 43 / 95%); }
        .bg-ink { background-color: #302c36; }
        .aspect-square.bg-ink { box-shadow: inset 0 0 0 1px var(--color-stone-300); }
        .ring-offset-2 { --tw-ring-offset-color: var(--color-surface); }
        .peer[name="color"]:checked + span .text-white { color: #13151a; }
        .bg-ink\/40, .account-guide::backdrop { background-color: rgb(0 0 0 / 65%); }
        .bg-ink .size-1\.5.bg-white, .bg-ink .size-1\.5.bg-white\/60,
        img[src$="/qr.svg"], [aria-labelledby="licenses-title"] .bg-white { background-color: white; }

        .bg-brand-500.text-white { background-color: #a52a50; }
        .bg-amber-500.text-white { background-color: #84531c; }
        .hover\:bg-amber-600:hover { background-color: #714616; }
        .bg-violet-500.text-white { background-color: #684290; }
        .bg-emerald-500.text-white { background-color: #146749; }
        .hover\:bg-emerald-600:hover { background-color: #0e593f; }
        .bg-red-500.text-white { background-color: #a73545; }
        .hover\:bg-red-600:hover { background-color: #902b38; }
        .bg-sky-500.text-white, .bg-sky-600.text-white { background-color: #206289; }
        .hover\:bg-sky-700:hover { background-color: #195373; }
        .text-brand-200 { color: #eba3b6; }
        .text-red-200 { color: #ffc2c7; }
        .text-white\/50 { color: rgb(255 255 255 / 70%); }
        .text-stone-200\/80 { color: #aaa6ae; }
        .text-stone-300, .placeholder\:text-stone-300::placeholder { color: #aaa9b0; }

        .from-brand-400, .from-brand-500 { --tw-gradient-from: #812747; }
        .via-brand-400, .via-brand-500, .via-brand-600 { --tw-gradient-via: #72243e; }
        .to-brand-400, .to-brand-500, .to-brand-600, .to-brand-700 { --tw-gradient-to: #65223a; }
        .from-violet-500, .from-violet-600, .from-violet-700 { --tw-gradient-from: #563378; }
        .to-violet-600 { --tw-gradient-to: #4e326d; }
        .from-sky-500 { --tw-gradient-from: #24516e; }
        .to-amber-400, .to-amber-500 { --tw-gradient-to: #66401e; }
    }
}

[data-theme="dark"] svg[role="img"] line[stroke="#e7e5e4"] { stroke: #55545e; }
[data-theme="dark"] svg[role="img"] text[fill="#78716c"] { fill: var(--color-stone-500); }
[data-theme="dark"] svg[role="img"] text[fill="#44403c"] { fill: var(--color-ink); }

/* The iPhone guide has its own palette, including a replica of the system interface. */
[data-theme="dark"] .ios-page {
    --ink: var(--color-ink);
    --accent: var(--color-brand-500);
    --muted: var(--color-stone-500);
    --line: var(--color-stone-200);
    color: var(--ink);
}

[data-theme="dark"] .ios-skip,
[data-theme="dark"] .ios-steps { background: var(--color-surface); color: var(--color-ink); }
[data-theme="dark"] .ios-page :is(a, summary):focus-visible { outline-color: var(--accent); }
[data-theme="dark"] :is(.ios-eyebrow, .ios-lead, .ios-hero-side > span:last-child, .ios-hero-result > span, .ios-help-intro, .ios-faq p),
[data-theme="dark"] .ios-steps .mo-pc__step p,
[data-theme="dark"] .ios-steps.is-live .mo-pc__step:not(.is-on) h3 { color: var(--muted); }
[data-theme="dark"] :is(.ios-hero h1 span, .ios-kicker, .ios-step-number, .ios-source) { color: var(--accent); }
[data-theme="dark"] .ios-hero-visual,
[data-theme="dark"] .ios-steps :is(.mo-pc__visuals, .ios-step-visual) { background: #30262c; border-color: var(--line); }
[data-theme="dark"] :is(.ios-faq details, .ios-close) { border-color: var(--line); }
[data-theme="dark"] .ios-share-callout { background: #bc2148; }
[data-theme="dark"] :is(.ios-sheet-site small, .ios-install-note, .ios-name > span, .ios-sheet-site > span) { color: #595963; }
[data-theme="dark"] :is(.ios-sheet-nav > span, .ios-point, .ios-toolbar) { color: #135db0; }
