/* ==========================================================================
   Layout: sidebar, mobile top bar and drawer, content area, footer
   ========================================================================== */

.ambient {
    position: fixed;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* --- Sidebar --------------------------------------------------------------- */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    width: var(--sidebar-width);
    padding: var(--space-5) var(--space-4);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    -webkit-backdrop-filter: blur(18px) saturate(1.2);
    backdrop-filter: blur(18px) saturate(1.2);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.sidebar-top {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* The logo has white lettering and a light-pink TV, so it sits on a deep berry panel where both
   read clearly. logo.png is trimmed to its artwork, so it is shown whole, never cropped. */
.brand {
    position: relative;
    display: grid;
    place-items: center;
    flex: 1;
    height: 96px;
    border-radius: var(--radius-lg);
    background: var(--logo-panel);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 10px 26px var(--brand-glow);
    overflow: hidden;
    isolation: isolate;
    transition: transform var(--normal) var(--ease), box-shadow var(--normal) var(--ease);
}

.brand::after,
.topbar-brand::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: radial-gradient(140px 70px at 18% 10%, rgba(255, 255, 255, 0.3), transparent 70%),
        radial-gradient(120px 80px at 95% 100%, var(--logo-glow), transparent 70%);
}

.brand img,
.topbar-brand img {
    height: auto;
    filter: drop-shadow(0 2px 8px rgba(60, 10, 50, 0.35));
}

.brand img {
    width: 188px;
    max-width: 82%;
}

.brand:hover {
    transform: translateY(-1px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 14px 32px var(--brand-glow);
}

.sidebar .sidebar-close {
    display: none;
}

.nav-heading {
    margin: 0 0 var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.nav-list {
    display: grid;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 44px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-weight: 560;
    text-decoration: none;
    transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}

.nav-link .icon {
    color: var(--text-faint);
    transition: color var(--fast) var(--ease), transform var(--fast) var(--ease);
}

.nav-link:hover {
    color: var(--text);
    background: var(--brand-tint);
}

.nav-link:hover .icon {
    color: var(--brand-text);
}

.nav-link.is-active {
    color: var(--brand-text);
    background: var(--brand-soft);
    font-weight: 650;
}

.nav-link.is-active .icon {
    color: var(--brand-strong);
}

.nav-link.is-active::before {
    content: "";
    position: absolute;
    left: -16px;
    top: 10px;
    bottom: 10px;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--brand-gradient-strong);
}

.sidebar-bottom {
    display: grid;
    gap: var(--space-3);
    margin-top: auto;
    padding-top: var(--space-5);
    border-top: 1px solid var(--border);
}

.community {
    display: grid;
    gap: var(--space-2);
}

.community-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text);
    font-size: var(--text-sm);
    font-weight: 600;
    text-decoration: none;
    transition: border-color var(--fast) var(--ease), transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}

.community-link img {
    width: 20px;
    height: 20px;
    border-radius: 6px;
}

.community-link span {
    flex: 1;
}

.community-link .icon {
    color: var(--text-faint);
}

.community-link:hover {
    border-color: var(--brand);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

/* --- Theme switch ------------------------------------------------------------ */

.theme-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    width: 100%;
    padding: 10px var(--space-3);
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: 600;
    text-align: left;
}

.theme-switch:hover {
    background: var(--brand-tint);
    color: var(--text);
}

.theme-switch-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
}

.theme-switch-track {
    position: relative;
    width: 40px;
    height: 24px;
    border-radius: var(--radius-pill);
    background: var(--border-strong);
    transition: background-color var(--normal) var(--ease);
}

.theme-switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform var(--normal) var(--ease);
}

[data-theme="dark"] .theme-switch-track {
    background: var(--brand-gradient-strong);
}

[data-theme="dark"] .theme-switch-thumb {
    transform: translateX(16px);
}

/* Moon in light mode, sun in dark mode. */
.icon-sun,
[data-theme="dark"] .icon-moon {
    display: none;
}

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

/* --- Top bar (small screens) --------------------------------------------------- */

.topbar {
    display: none;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-xs);
    transition: border-color var(--fast) var(--ease), background-color var(--fast) var(--ease);
}

.icon-button:hover {
    border-color: var(--brand);
    background: var(--brand-tint);
}

.scrim {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(30, 10, 25, 0.38);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity var(--normal) var(--ease);
}

.scrim.is-visible {
    opacity: 1;
}

/* --- Content area ------------------------------------------------------------- */

.page {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin-left: var(--sidebar-width);
    /* Decorative glows may extend past the edge; never let them cause sideways scrolling. */
    overflow-x: clip;
}

.main {
    flex: 1;
    width: 100%;
    max-width: calc(var(--content-max) + 2 * var(--space-7));
    margin: 0 auto;
    padding: var(--space-7) var(--space-7) var(--space-8);
}

.main:focus {
    outline: none;
}

/* --- Footer ----------------------------------------------------------------- */

.site-footer {
    border-top: 1px solid var(--border);
    background: var(--surface-glass);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

.footer-inner {
    display: grid;
    gap: var(--space-3);
    max-width: calc(var(--content-max) + 2 * var(--space-7));
    margin: 0 auto;
    padding: var(--space-6) var(--space-7);
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.footer-brand {
    color: var(--text);
    font-weight: 600;
}

.footer-brand .pixel {
    color: var(--brand-text);
}

.footer-note {
    max-width: 80ch;
    color: var(--text-faint);
}

.footer-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-5);
}

.footer-links a {
    color: var(--text-muted);
    font-weight: 600;
    text-decoration: none;
}

.footer-links a:hover {
    color: var(--brand-text);
}

.footer-links span {
    color: var(--text-faint);
}

/* --- Responsive ----------------------------------------------------------------- */

@media (max-width: 1024px) {
    .topbar {
        position: sticky;
        top: 0;
        z-index: 30;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
        height: var(--topbar-height);
        padding: 0 var(--space-4);
        padding-top: env(safe-area-inset-top);
        background: var(--surface-glass);
        border-bottom: 1px solid var(--border);
        -webkit-backdrop-filter: blur(16px) saturate(1.2);
        backdrop-filter: blur(16px) saturate(1.2);
    }

    .topbar-brand {
        position: relative;
        display: grid;
        place-items: center;
        height: 44px;
        padding: 0 var(--space-4);
        border-radius: var(--radius-md);
        background: var(--logo-panel);
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 6px 16px var(--brand-glow);
        overflow: hidden;
        isolation: isolate;
    }

    .topbar-brand img {
        width: 92px;
    }

    .sidebar {
        width: min(320px, 86vw);
        box-shadow: var(--shadow-lg);
        transform: translateX(-102%);
        transition: transform var(--normal) var(--ease);
        visibility: hidden;
    }

    .sidebar.is-open {
        transform: none;
        visibility: visible;
    }

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

    .page {
        margin-left: 0;
    }

    .main {
        padding: var(--space-6) var(--space-5) var(--space-7);
    }

    .footer-inner {
        padding: var(--space-6) var(--space-5);
    }
}

@media (max-width: 560px) {
    .main {
        padding: var(--space-5) var(--space-4) var(--space-7);
    }

    .footer-inner {
        padding: var(--space-5) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom));
    }
}

body.drawer-open {
    overflow: hidden;
}
