/* Theme, page base and the store sidebar, shared by index.html and
   multi.html. Page layout and content styles live in each page. */

:root {
    color-scheme: light;
    --bg: #f6f8fb;
    --panel: #ffffff;
    --panel-soft: #eef3f8;
    --text: #17202a;
    --muted: #5f6f80;
    --line: #d9e2ec;
    --accent: #177e89;
    --accent-strong: #10646d;
    --on-accent: #ffffff;
    --accent-glow: rgba(23, 126, 137, 0.08);
    --accent-ring: rgba(23, 126, 137, 0.18);
    --field: #fbfdff;
    --card: #ffffff;
    --warn: #b42318;
    --good: #1a7f37;
    --shadow: 0 16px 40px rgba(31, 45, 61, 0.12);
    --drawer-shadow: 0 24px 70px rgba(23, 32, 42, 0.24);
    --backdrop: rgba(23, 32, 42, 0.42);
}

/* Dark theme: follows the system unless the visitor picked light
   with the toggle; data-theme="dark" forces it either way. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0f1418;
        --panel: #171e24;
        --panel-soft: #1f2830;
        --field: #121a20;
        --card: #1b232a;
        --text: #e6edf3;
        --muted: #95a3b1;
        --line: #2c3842;
        --accent: #3fb3bf;
        --accent-strong: #74d2dc;
        --on-accent: #062a2e;
        --accent-glow: rgba(63, 179, 191, 0.08);
        --accent-ring: rgba(63, 179, 191, 0.28);
        --warn: #ff8a80;
        --good: #56d364;
        --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
        --drawer-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
        --backdrop: rgba(0, 0, 0, 0.6);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f1418;
    --panel: #171e24;
    --panel-soft: #1f2830;
    --field: #121a20;
    --card: #1b232a;
    --text: #e6edf3;
    --muted: #95a3b1;
    --line: #2c3842;
    --accent: #3fb3bf;
    --accent-strong: #74d2dc;
    --on-accent: #062a2e;
    --accent-glow: rgba(63, 179, 191, 0.08);
    --accent-ring: rgba(63, 179, 191, 0.28);
    --warn: #ff8a80;
    --good: #56d364;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    --drawer-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
    --backdrop: rgba(0, 0, 0, 0.6);
}

/* Halloween: night purple with pumpkin orange. Listed after the
   dark rules so it wins over the system dark preference. */
:root[data-theme="halloween"] {
    color-scheme: dark;
    --bg: #120b1a;
    --panel: #1d1328;
    --panel-soft: #281b36;
    --field: #170f21;
    --card: #22172f;
    --text: #f5ead8;
    --muted: #b9a5cc;
    --line: #3a2a4c;
    --accent: #ff7a1a;
    --accent-strong: #ffa04d;
    --on-accent: #1e0b00;
    --accent-glow: rgba(255, 122, 26, 0.12);
    --accent-ring: rgba(255, 122, 26, 0.32);
    --warn: #ff6b6b;
    --good: #8bd17c;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
    --drawer-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
    --backdrop: rgba(8, 3, 14, 0.65);
}

.mascot-halloween {
    display: none;
}

:root[data-theme="halloween"] .mascot-halloween {
    display: block;
    /* Pumpkin glow so the black cat ears show on the dark panel. */
    filter: drop-shadow(0 0 1px rgba(255, 160, 77, 0.9))
        drop-shadow(0 0 4px rgba(255, 122, 26, 0.45));
}

:root[data-theme="halloween"] .mascot-default {
    display: none;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(
            180deg,
            var(--accent-glow),
            transparent 280px
        ),
        var(--bg);
    color: var(--text);
    font-family:
        Inter,
        ui-sans-serif,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

button,
input {
    font: inherit;
}

body.drawer-open {
    overflow: hidden;
}

.mobile-topbar,
.drawer-backdrop,
.drawer-close {
    display: none;
}

.mobile-topbar {
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.mobile-brand-text {
    min-width: 0;
}

.mascot {
    flex: none;
    width: 72px;
    height: auto;
    border-radius: 8px;
}

.mascot-small {
    width: 40px;
}

.mobile-brand h1 {
    margin: 0 0 2px;
    font-size: 1rem;
    line-height: 1.2;
}

.store-count {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    color: var(--text);
    cursor: pointer;
}

.icon-button:hover {
    border-color: var(--accent);
    color: var(--accent-strong);
}

.drawer-close {
    display: none;
}

.hamburger-icon,
.close-icon {
    position: relative;
    width: 18px;
    height: 14px;
}

.hamburger-icon::before,
.hamburger-icon::after,
.hamburger-icon span {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    content: "";
}

.hamburger-icon::before {
    top: 0;
}

.hamburger-icon span {
    top: 6px;
}

.hamburger-icon::after {
    bottom: 0;
}

.close-icon::before,
.close-icon::after {
    position: absolute;
    top: 7px;
    left: 0;
    width: 100%;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    content: "";
}

.close-icon::before {
    transform: rotate(45deg);
}

.close-icon::after {
    transform: rotate(-45deg);
}

.sidebar {
    align-self: start;
    position: sticky;
    top: 24px;
    /* Scrolls on its own so a long store list doesn't scroll the page. */
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.sidebar-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: -6px 0 22px -6px;
}

.brand {
    margin: 0 0 4px;
    font-size: 1.35rem;
    line-height: 1.2;
}

.brand-block .hint {
    margin: 0;
}

.hint {
    margin: 0 0 24px;
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.45;
}

.store-list {
    display: grid;
    gap: 10px;
    margin: 0 0 18px;
    padding: 0;
    border: 0;
}

.store-list legend {
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.store-group {
    display: grid;
    gap: 10px;
}

.store-group + .store-group {
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.store-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.store-group-header .link-button {
    font-size: 0.8rem;
}

.store-group-title {
    margin: 0;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.store-option {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    cursor: pointer;
    user-select: none;
}

.store-option input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.store-option span {
    font-weight: 700;
}

.store-option .store-note {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
}

.store-option.has-message {
    flex-wrap: wrap;
}

.store-option .store-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: -7px -8px -7px auto;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--muted);
    cursor: pointer;
}

.store-option .store-info:hover,
.store-option .store-info[aria-expanded="true"] {
    color: var(--accent);
}

.store-option .store-info:focus-visible {
    outline: 2px solid var(--accent-ring);
}

.store-option .store-message {
    flex-basis: 100%;
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1.4;
    cursor: auto;
}

.store-option .store-message[hidden] {
    display: none;
}

.selection-actions {
    display: flex;
    gap: 8px;
}

.link-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--accent-strong);
    font-weight: 800;
    cursor: pointer;
}

.sidebar-field {
    display: grid;
    gap: 8px;
    margin-bottom: 18px;
}

.section-label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.deck-link {
    display: block;
    margin-top: 18px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    color: var(--accent-strong);
    font-weight: 800;
    text-decoration: none;
}

.deck-link:hover {
    border-color: var(--accent);
}

.settings {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.settings summary {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 800;
    cursor: pointer;
}

.theme-options {
    display: grid;
    gap: 8px;
    margin: 12px 0 0;
    padding: 0;
    border: 0;
}

.theme-options legend {
    margin-bottom: 8px;
}

.segmented {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 3px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
}

.segmented label {
    position: relative;
    cursor: pointer;
}

.segmented input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.segmented span {
    display: block;
    padding: 6px 0;
    border-radius: 6px;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
    text-align: center;
}

.segmented input:checked + span {
    background: var(--accent);
    color: var(--on-accent);
}

.segmented input:focus-visible + span {
    outline: 2px solid var(--accent-ring);
    outline-offset: 1px;
}

.game-select {
    width: 100%;
    min-height: 42px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    color: var(--text);
    font-weight: 700;
}

.game-select:focus {
    border-color: var(--accent);
    outline: 2px solid var(--accent-ring);
}

.store-option[hidden],
.store-group[hidden] {
    display: none;
}

.status {
    min-height: 22px;
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
}

.status.error {
    color: var(--warn);
    font-weight: 700;
}

@media (max-width: 820px) {
    .mobile-topbar {
        display: flex;
        z-index: 20;
    }

    .drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 30;
        border: 0;
        background: var(--backdrop);
        opacity: 0;
        pointer-events: none;
        transition: opacity 160ms ease;
    }

    body.drawer-open .drawer-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 40;
        width: min(86vw, 340px);
        height: 100vh;
        height: 100dvh;
        max-height: none;
        max-width: 100%;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
        border-radius: 0 8px 8px 0;
        box-shadow: var(--drawer-shadow);
        transform: translateX(-104%);
        transition: transform 180ms ease;
    }

    body.drawer-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-header {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
    }

    .drawer-close {
        display: inline-grid;
    }

    .brand {
        margin-bottom: 2px;
        font-size: 1.2rem;
    }

    .brand-block {
        margin-bottom: 14px;
    }

    .brand-block .mascot {
        width: 52px;
    }

    .hint {
        margin-bottom: 14px;
        font-size: 0.9rem;
    }

    .store-list {
        gap: 6px;
        margin-bottom: 12px;
    }

    .store-list legend {
        margin-bottom: 6px;
    }

    .store-group {
        gap: 6px;
    }

    .store-group + .store-group {
        margin-top: 4px;
        padding-top: 10px;
    }

    .store-option {
        min-height: 34px;
        padding: 6px 10px;
    }

    .store-option input {
        width: 17px;
        height: 17px;
    }

    .store-option span {
        font-size: 0.96rem;
        line-height: 1.18;
    }
}

@media (max-width: 420px) {
    .mobile-topbar {
        padding: 10px;
    }
}
