/* Shared theme switch. Light mode preserves the site's existing palette. */
#mm-theme-toggle {
    display:inline-flex; align-items:center; justify-content:center; vertical-align:middle;
    width:36px; height:36px; min-width:36px; box-sizing:border-box; margin-left:8px;
    border:1px solid #d5e1de; border-radius:7px; color:#356a60; background:#f7f9f8;
    cursor:pointer; padding:0; font:inherit; line-height:1;
}
#mm-theme-toggle svg { width:20px; height:20px; display:block; }
#mm-theme-toggle .mm-theme-sun { display:none; }
html[data-mm-theme="dark"] #mm-theme-toggle .mm-theme-sun { display:block; }
html[data-mm-theme="dark"] #mm-theme-toggle .mm-theme-moon { display:none; }
#mm-theme-toggle:focus-visible { outline:2px solid #69a399; outline-offset:2px; }
#mm-theme-toggle:hover { border-color:#70a99c; }
@media (max-width:768px) {
    #mm-theme-toggle { width:44px; height:44px; min-width:44px; margin-left:5px; }
}

/* Shared page navigation. Catalogue and history use the same dimensions. */
#mm-history-pagination,#mm-catalogue-pagination {
    display:block!important; width:90%; max-width:100%; margin:.9rem auto 1.2rem;
    padding:0; box-sizing:border-box;
}
:is(#mm-history-pagination,#mm-catalogue-pagination) .pagination {
    display:flex!important; flex-wrap:wrap; align-items:center; justify-content:center;
    width:100%!important; gap:5px!important; padding:0!important; margin:0!important; list-style:none;
}
:is(#mm-history-pagination,#mm-catalogue-pagination) .pagination li { display:block!important; margin:0!important; padding:0; }
:is(#mm-history-pagination,#mm-catalogue-pagination) .pagination li a,
:is(#mm-history-pagination,#mm-catalogue-pagination) .pagination li.current {
    box-sizing:border-box!important; display:inline-flex!important; align-items:center; justify-content:center;
    min-width:40px!important; height:40px!important; padding:0 8px!important; font-size:1rem!important;
    border:1px solid #d5e1de; border-radius:5px; background:#fff; color:#356a60;
    text-decoration:none; line-height:1; font-variant-numeric:tabular-nums;
}
:is(#mm-history-pagination,#mm-catalogue-pagination) .pagination li.current {
    background:#e2f1ed; color:#24655a; border-color:#70a99c; font-weight:700;
}
:is(#mm-history-pagination,#mm-catalogue-pagination) .pagination li a:hover,
:is(#mm-history-pagination,#mm-catalogue-pagination) .pagination li a:focus-visible { background:#eaf3f0; border-color:#70a99c; }
#mm-history-pagination:not(:has(.pagination a)),#mm-catalogue-pagination:not(:has(.pagination a)) { display:none!important; }
@media (max-width:1200px) { #mm-history-pagination,#mm-catalogue-pagination { width:100%; } }
@media (max-width:768px) {
    #mm-history-pagination,#mm-catalogue-pagination { margin:8px auto 16px; }
    :is(#mm-history-pagination,#mm-catalogue-pagination) .pagination { gap:6px!important; }
    :is(#mm-history-pagination,#mm-catalogue-pagination) .pagination li a,
    :is(#mm-history-pagination,#mm-catalogue-pagination) .pagination li.current { min-width:44px!important; height:44px!important; }
}

/* Dark palette. Explicit surfaces are used instead of filter: invert(). */
html[data-mm-theme="dark"] {
    color-scheme:dark;
    --mm-bg:#101214; --mm-panel:#191d20; --mm-control:#22282c;
    --mm-text:#e5e9ec; --mm-muted:#a8b2b9; --mm-border:#394248;
    --mm-accent:#a8d7ce; --mm-accent-text:#bee9e0; --mm-selected:#203c36;
    background:var(--mm-bg); color:var(--mm-text);
}
html[data-mm-theme="dark"] body { background:var(--mm-bg); color:var(--mm-text); }
html[data-mm-theme="dark"] :is(header,footer,.about-cookie-block) { background:var(--mm-bg)!important; color:var(--mm-text); }
html[data-mm-theme="dark"] .about-cookie-block .container { border-color:var(--mm-border)!important; }
html[data-mm-theme="dark"] a { color:var(--mm-accent); }
html[data-mm-theme="dark"] a:visited { color:#b9c9ed; }
html[data-mm-theme="dark"] a:hover { color:#e0f7f2; }
html[data-mm-theme="dark"] :is(input:not([type=hidden]):not([type=checkbox]):not([type=radio]),select,textarea,button) {
    background-color:var(--mm-control); color:var(--mm-text); border-color:var(--mm-border); accent-color:#87bfb2;
}
html[data-mm-theme="dark"] :is(input,textarea)::placeholder { color:var(--mm-muted); opacity:1; }
html[data-mm-theme="dark"] :is(input[type=checkbox],input[type=radio]) { accent-color:#87bfb2; }
html[data-mm-theme="dark"] :is(input,textarea,select,button,a):focus-visible { outline-color:var(--mm-accent); }
html[data-mm-theme="dark"] :is(td,th,hr,fieldset) { border-color:var(--mm-border); }
html[data-mm-theme="dark"] #mm-theme-toggle { background:var(--mm-control); border-color:var(--mm-border); color:var(--mm-accent); }

/* Catalogue, including dynamically replaced rows and filters. */
html[data-mm-theme="dark"] #mm-catalogue-filters { background:var(--mm-panel)!important; border-color:var(--mm-border)!important; color:var(--mm-text)!important; }
html[data-mm-theme="dark"] #mm-catalogue-filters :is(.mf-search input,.mf-sort select,.mf-option > span,.mf-reset) {
    background:var(--mm-control)!important; border-color:var(--mm-border)!important; color:var(--mm-text)!important;
}
html[data-mm-theme="dark"] #mm-catalogue-filters .mf-option input:checked + span {
    background:var(--mm-selected)!important; border-color:#78b3a5!important; color:var(--mm-accent-text)!important; box-shadow:inset 0 0 0 1px #78b3a5;
}
html[data-mm-theme="dark"] :is(#mm-catalogue-count,#mm-catalogue-empty) { color:var(--mm-muted)!important; }
html[data-mm-theme="dark"] #mm-catalogue-error { color:#ffb4ad!important; }
html[data-mm-theme="dark"] .mf-head-action { background:var(--mm-control)!important; color:var(--mm-text)!important; border-color:var(--mm-border)!important; }
html[data-mm-theme="dark"] .mf-head-action .mf-arrow,html[data-mm-theme="dark"] #mm-catalogue-filters .mf-search i { color:var(--mm-accent)!important; }
html[data-mm-theme="dark"] .mf-head-action.mf-active { background:var(--mm-selected)!important; color:var(--mm-accent-text)!important; border-color:#78b3a5!important; }
html[data-mm-theme="dark"] .mf-head-action:hover,html[data-mm-theme="dark"] #mm-catalogue-filters .mf-option:hover > span { border-color:#78b3a5!important; }
html[data-mm-theme="dark"] :is(#mm-catalogue-pagination,#mm-history-pagination) .pagination li a {
    background:var(--mm-panel)!important; border-color:var(--mm-border)!important; color:var(--mm-accent)!important;
}
html[data-mm-theme="dark"] :is(#mm-catalogue-pagination,#mm-history-pagination) .pagination li.current,
html[data-mm-theme="dark"] :is(#mm-catalogue-pagination,#mm-history-pagination) .pagination li a:hover,
html[data-mm-theme="dark"] :is(#mm-catalogue-pagination,#mm-history-pagination) .pagination li a:focus-visible {
    background:var(--mm-selected)!important; color:var(--mm-accent-text)!important; border-color:#78b3a5!important;
}

/* History search and any older search widgets. */
html[data-mm-theme="dark"] :is(.history-search-dropdown,#searchResult,#searchResult *) { background:var(--mm-panel)!important; color:var(--mm-text)!important; border-color:var(--mm-border)!important; }
html[data-mm-theme="dark"] :is(#search-result tr.active,#searchResult li.active,#searchResult li:hover) { background:var(--mm-selected)!important; color:var(--mm-accent-text)!important; }
html[data-mm-theme="dark"] .history-search-dropdown tr:hover { background:var(--mm-selected); }
html[data-mm-theme="dark"] .history-search-dropdown[hidden],html[data-mm-theme="dark"] #searchResult[hidden] { display:none!important; }

/* Order forms and administrative controls. Keep the existing gold action accent. */
html[data-mm-theme="dark"] .orderform :is(input[type=text],input[type=number],select,textarea),
html[data-mm-theme="dark"] .fiters input#search,
html[data-mm-theme="dark"] .search-form input[type=search],
html[data-mm-theme="dark"] .search-form input#search,
html[data-mm-theme="dark"] .iw-form :is(input:not([type=hidden]),select),
html[data-mm-theme="dark"] .sx-admin :is(input:not([type=checkbox]):not([type=hidden]),textarea,select) {
    background-color:var(--mm-control)!important; color:var(--mm-text)!important; border-color:var(--mm-border)!important;
}
html[data-mm-theme="dark"] :is(.inwork .iw-primary,.sx-admin button:not(.sx-secondary),.orderform input[type=submit]) {
    background:#ffdf75!important; color:#202426!important; border-color:#ffdf75!important;
}
html[data-mm-theme="dark"] :is(.iw-form,.sx-admin .sx-panel,.sx-admin .sx-worlds,.sx-admin-row) { border-color:var(--mm-border)!important; }
html[data-mm-theme="dark"] :is(.inwork button:not(.iw-primary),.sx-admin .sx-secondary,button.close-button) { background:var(--mm-control)!important; color:var(--mm-text)!important; border-color:var(--mm-border)!important; }
html[data-mm-theme="dark"] :is(.iw-empty,.iw-source-detail,.sx-muted,.sx-pop-body .sx-status) { color:var(--mm-muted)!important; }
html[data-mm-theme="dark"] .inwork .iw-table tbody tr:nth-child(even) { background:var(--mm-panel); }
html[data-mm-theme="dark"] .inwork .iw-table :is(th,td) { border-color:var(--mm-border)!important; }
html[data-mm-theme="dark"] .inwork .iw-progress-track { background:#343d42!important; }
html[data-mm-theme="dark"] .inwork .iw-progress-value { color:var(--mm-text)!important; }
html[data-mm-theme="dark"] .inwork .iw-progress-complete .iw-progress-value { color:#9ce0b1!important; }
html[data-mm-theme="dark"] :is(.iw-error,.form-error .error,.iw-delete button,.result-error) { color:#ffb4ad!important; }
html[data-mm-theme="dark"] :is(.iw-success,.result-ok) { color:#9ce0b1!important; }
html[data-mm-theme="dark"] .sx-admin .sx-error { background:#402727!important; color:#ffb4ad!important; }
html[data-mm-theme="dark"] .sx-admin .sx-flash { background:#213d31!important; color:#a3e4b7!important; }

/* Cosplay photos keep their natural colors and the existing gold icon. */
html[data-mm-theme="dark"] .sx-pop { background:var(--mm-panel)!important; border-color:#78b3a5!important; color:var(--mm-text)!important; }
html[data-mm-theme="dark"] .sx-pop-close { color:var(--mm-text)!important; background:transparent!important; }
html[data-mm-theme="dark"] .playlist button.sx-mark.sx-cosplay { background:transparent!important; color:var(--mm-text)!important; }
html[data-mm-theme="dark"] .playlist .sx-cosplay .sx-photo-tile { background:#fff1c1; color:#866000; border-color:#e8c35a; }

@media (max-width:768px) {
    html[data-mm-theme="dark"] header :is(a,nav a),
    html[data-mm-theme="dark"] header.mm-menu-ready #mm-site-nav > a,
    html[data-mm-theme="dark"] header.mm-menu-ready #mm-menu-toggle {
        color:var(--mm-text)!important; background:var(--mm-control)!important; border-color:var(--mm-border)!important;
    }
    html[data-mm-theme="dark"] header.mm-menu-ready #mm-site-nav > a[aria-current="page"],
    html[data-mm-theme="dark"] header.mm-menu-ready #mm-site-nav > a:active { background:var(--mm-selected)!important; color:var(--mm-accent-text)!important; border-color:#78b3a5!important; }
    html[data-mm-theme="dark"] :is(.playlist tr,.historylist tr,.playqueue tr,.inwork .iw-public-numbered .iw-mobile-card) {
        background:var(--mm-panel)!important; border-color:var(--mm-border)!important;
    }
    html[data-mm-theme="dark"] :is(.playlist tr.mobile-expanded,.playqueue tr.mobile-expanded,.inwork .iw-public-numbered .iw-mobile-card.mobile-expanded) {
        background:var(--mm-panel)!important; border-color:#78b3a5!important;
    }
    html[data-mm-theme="dark"] :is(.playlist td,.historylist td,.playqueue td,.inwork .iw-table td) { border-bottom-color:var(--mm-border)!important; }
    html[data-mm-theme="dark"] :is(.playlist td,.historylist td,.playqueue td,.inwork .iw-table td)::before { color:var(--mm-muted)!important; }
    html[data-mm-theme="dark"] .inwork .iw-mobile-toggle { color:var(--mm-text)!important; background:transparent!important; }
    html[data-mm-theme="dark"] :is(.playlist td.controls,main div.fiters label,.orderform .form-item:has(input[type=checkbox]),.orderform #checkboxfee,body:has(.playlist) .filters-element label:not(#searchResult *)) {
        background:var(--mm-control)!important; border-color:var(--mm-border)!important; color:var(--mm-text)!important;
    }
    html[data-mm-theme="dark"] :is(.orderform .form-item label,.orderform #checkboxfee label,body:has(.playlist) .filters-element label:not(#searchResult *)) { color:var(--mm-text)!important; }
    html[data-mm-theme="dark"] :is(.playlist td:last-child a.request-btn,.playlist td.controls i.fa,.search-form button[type=submit],form button[type=submit]:not(.search-form button)) {
        background:#abd6cf!important; color:#183e37!important; border-color:#abd6cf!important;
    }
    html[data-mm-theme="dark"] form button[type=reset] { background:var(--mm-control)!important; color:var(--mm-text)!important; border-color:var(--mm-border)!important; }
}
