/* everything about theme */
body.light-theme {
    --primary-background: #e8e8e8;
    --secondary-background: #f5f5f5;
    --tertiary-background: #dcdcdc;
    --hover-background: #d4d4d4;
    --active-background: #c8c8c8;
    --text-color: #3a3a3a;
}
body.light-theme header {
    border-bottom-color: #c4c4c4;
}
body.light-theme header > span {
    background-color: #dcdcdc;
    border-color: #b4b4b4;
    color: #3a3a3a;
}
body.light-theme aside {
    border-right-color: #c4c4c4;
}
body.light-theme aside nav img {
    filter: brightness(0) saturate(100%) invert(20%);
}
body.light-theme main file-explorer {
    background-color: #efefef;
    border-right-color: #d4d4d4;
}
body.light-theme main file-explorer img {
    filter: brightness(0) saturate(100%) invert(20%);
}
body.light-theme .toggle-thumb {
    left: calc(100% - 1.25rem);
}


/* view transition api stylings */
::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0.2s;
}
::view-transition-old(root) {
    animation: blur-out 0.2s ease-out;
}
::view-transition-new(root) {
    animation: blur-in 0.2s ease-in;
}

@keyframes blur-out {
    to {
        opacity: 0;
        filter: blur(10px);
    }
}
@keyframes blur-in {
    from {
        opacity: 0;
        filter: blur(10px);
    }
}


/* everything about theme */
header {
    grid-area: header;

    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 0.0625rem solid black;
    position: relative;

    transition: border-color 0.3s ease;
}

header > span {
    padding: 0.3rem;
    min-width: 35rem;

    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;

    background-color: var(--tertiary-background, #5f5f5f);
    border: 0.001rem solid white;
    border-radius: 0.5rem;

    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

/* nav sidebar */
aside {
    grid-area: sidebar;

    position: relative;
    width: 3rem;
    padding: 0.5rem 0;

    border-right: 0.0625rem solid black;

    transition: border-color 0.3s ease, background-color 0.3s ease;
}

aside nav ul {
    list-style: none;

    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

aside nav li {
    border-left: 2px solid transparent;
    transition: border-color 0.2s ease;
}

/* nesting makes sense here for pseudo-classes */
aside nav button,
aside nav a,
aside nav label {
    all: unset;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    height: 3rem;
    cursor: pointer;
    transition: background-color 0.2s ease;

    &:hover {
        background-color: var(--hover-background, #2a2d2e);
    }
}

aside nav img {
    filter: brightness(0) invert(1);
    width: 2rem;
    height: 2rem;
}

main {
    display: contents;
}

/* file explorer stylings */
main file-explorer {
    grid-area: file-explorer;

    overflow-y: auto;
    padding: 0.5rem 0;

    background-color: var(--secondary-background, #2a2a2a);
    border-right: 0.0625rem solid #1a1a1a;
    font-size: 0.8125rem;

    transition: background-color 0.3s ease, border-color 0.3s ease;
}

main file-explorer ul {
    list-style: none;
}

main file-explorer a {
    display: flex;
    text-decoration: none;
    cursor: pointer;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;

    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.75rem;
    line-height: 1.4;

    color: var(--text-color, white);
    font-size: 0.8125rem;

    transition: background-color 0.15s ease;

    &:hover {
        background-color: var(--hover-background, #2a2d2e);
    }

    &:active,
    &:focus,
    &.active {
        background-color: var(--active-background, #37373d);
        outline: none;
    }
}

main file-explorer img {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    filter: brightness(0) invert(1);
}

/* main content frame */
main iframe {
    grid-area: content;

    border: none;
    width: 100%;
    height: 100%;
}

/* footer */
footer {
    grid-area: footer;

    display: flex;
    padding: 0.25rem 1rem;

    background-color: var(--secondary-background, #2a2a2a);
    font-size: 0.75rem;

    transition: background-color 0.3s ease, color 0.3s ease;
}

/* media query for tablet */
@media (max-width: 768px) {
    body {
        grid-template-rows: 2.75rem 1fr 1.5rem; /* Increased header height */
    }

    body:has(#file-explorer-toggle:checked) {
        grid-template-columns: 2.5rem 10rem 1fr;
    }

    body:has(#file-explorer-toggle:not(:checked)) {
        grid-template-columns: 2.5rem 0 1fr;
    }

    header > span {
        min-width: auto;
        width: min(70%, 25rem); /* Narrower and responsive */
        font-size: 0.8125rem;
        padding: 0.35rem 0.75rem; /* More vertical padding */
    }

    aside {
        width: 2.5rem;
        height: calc(100dvh - 4.25rem); /* Adjusted for new header height */
    }

    aside nav button,
    aside nav a,
    aside nav label {
        height: 2.5rem;
    }

    aside nav img {
        width: 1.75rem;
        height: 1.75rem;
    }

    main file-explorer {
        font-size: 0.75rem;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
    }

    main file-explorer a {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
        gap: 0.375rem;
    }

    main file-explorer img {
        width: 0.875rem;
        height: 0.875rem;
    }

    footer {
        font-size: 0.625rem;
        padding: 0.25rem 0.5rem;
    }
}

/* media query for mobile */
@media (max-width: 480px) {
    #theme-toggle {
        right: 0.5rem;
        padding: 0.25rem;
    }
    
    .toggle-track {
        width: 2.5rem;
        height: 1.25rem;
    }
    
    .toggle-thumb {
        width: 0.875rem;
        height: 0.875rem;
        left: 0.125rem;
    }

    body {
        grid-template-rows: 2.5rem 1fr 1.125rem; /* Increased header height */
        grid-template-columns: 2rem 0 1fr !important;
    }

    /* override the grid column changes for mobile */
    body:has(#file-explorer-toggle:checked) {
        grid-template-columns: 2rem 0 1fr !important;
    }

    body:has(#file-explorer-toggle:not(:checked)) {
        grid-template-columns: 2rem 0 1fr !important;
    }
        
    body.light-theme .toggle-thumb {
        left: calc(100% - 1rem);
    }

    header > span {
        font-size: 0.75rem;
        padding: 0.3rem 0.5rem; /* more vertical padding */
        width: min(75%, 18rem); /* narrower and responsive */
    }

    aside {
        width: 2rem;
        height: calc(100dvh - 3.625rem); /* adjusted for new header height */
    }

    aside nav button,
    aside nav a,
    aside nav label {
        height: 2rem;
    }

    aside nav img {
        width: 1.25rem;
        height: 1.25rem;
    }

    /* overlay approach for mobile */
    main file-explorer {
        position: fixed;
        left: 2rem;
        top: 2.5rem; /* adjusted for new header height */
        bottom: 1.125rem;
        width: 12rem;
        z-index: 1000;

        font-size: 0.6875rem;
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.5);

        /* Smooth slide-in animation */
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    /* show file explorer as overlay when checked */
    body:has(#file-explorer-toggle:checked) main file-explorer {
        display: block;
        transform: translateX(0);
    }

    main file-explorer a {
        padding: 0.3rem 0.4rem;
        font-size: 0.6875rem;
    }

    footer {
        font-size: 0.5625rem;
    }
}