/* Reset & Base */
:root {
    /* Light Theme (Default) */
    --bg-body: #f0f0f0;
    --bg-nav: #ddd;
    --bg-card: #fff;
    --bg-input: #fff;
    --bg-hover: #eee;
    --bg-dropdown: #ddd;
    --bg-sidebar: #e0e0e0;
    --bg-code: #f4f4f4;
    --bg-quote: #f9f9f9;

    --text-main: #333;
    --text-muted: #666;
    --text-inverse: #fff;
    --text-link: #000;

    --border-color: #333;
    --border-light: #eee;

    --btn-bg: #333;
    --btn-text: #fff;
    --btn-hover: #555;

    --shadow-color: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    /* Dark Theme Overrides */
    --bg-body: #121212;
    --bg-nav: #1e1e1e;
    --bg-card: #242424;
    --bg-input: #2d2d2d;
    --bg-hover: #333;
    --bg-dropdown: #2d2d2d;
    --bg-sidebar: #1e1e1e;
    --bg-code: #2d2d2d;
    --bg-quote: #242424;

    --text-main: #e0e0e0;
    --text-muted: #aaa;
    --text-inverse: #121212;
    --text-link: #4a90e2;
    /* Lighter blue for dark mode */

    --border-color: #bbb;
    --border-light: #444;

    --btn-bg: #eeeeee88;
    /* Invert button in dark mode? Or keep dark with light text? Let's keep consistent but visible */
    --btn-text: #121212;
    --btn-hover: #ccc;

    --shadow-color: rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: monospace;
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a {
    color: var(--text-link);
    text-decoration: underline;
}

a:hover {
    background-color: var(--bg-hover);
}

/* Layout */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
}

main {
    flex: 1;
}

/* Navbar */
nav {
    background-color: var(--bg-nav);
    border-bottom: 2px solid var(--border-color);
    padding: 10px 0;
    margin-bottom: 20px;
}

nav .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0;
    padding-bottom: 0;
}

.nav-links {
    display: flex;
    gap: 15px;
}

.nav-links a {
    text-decoration: none;
    font-weight: bold;
    padding: 5px 10px;
    border: 1px solid transparent;

}

.nav-links a:hover {
    border: 1px solid var(--border-color);
    background-color: var(--bg-card);
}

/* User Menu Dropdown */
.user-menu {
    position: relative;
    display: inline-block;
    margin-left: 20px;
}

.user-menu-btn {
    background: #bbb;
    /* Keep this one or user var? Let's use a specific var or just standard nav logic. Keeping for now but maybe verify */
    border: 1px solid transparent;
    padding: 5px 10px;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    color: #000;
    /* Force black on this button for now as background is #bbb */
    border: 2px solid var(--text-link);
    /* Use text-link color which is black/white appropriate? No, link is blue in dark mode. let's use text-main inverse or similar */
}

/* Redefining user-menu-btn clearer for dark mode */
.user-menu-btn {
    background: var(--bg-hover);
    color: var(--text-main);
    border: 2px solid var(--border-color);
}

.user-menu-btn:hover {
    border: 2px solid var(--text-main);
    background-color: var(--bg-card);
}

.user-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background-color: var(--bg-dropdown);
    border: 2px solid var(--border-color);
    min-width: 150px;
    z-index: 1000;
    margin-top: 5px;
}

.user-menu-dropdown.active {
    display: block;
}

.user-menu-dropdown a {
    display: block;
    padding: 10px 15px;
    text-decoration: none;
    font-weight: bold;
    border: none;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
}

.user-menu-dropdown a:last-child {
    border-bottom: none;
}

.user-menu-dropdown a:hover {
    background-color: var(--bg-card);
    border: none;
    border-bottom: 1px solid var(--border-color);
}

.user-menu-dropdown a:last-child:hover {
    background-color: var(--bg-card);
    border: none;
    border-bottom: none;
}

/* Cards (Grid) */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.card {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.card-image {
    width: 100%;
    height: 150px;
    background-color: var(--bg-hover);
    margin-bottom: 15px;
    overflow: hidden;
    border: 2px solid var(--border-color);
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card h3 {
    margin-top: 0;
}

.card .meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.btn {
    display: inline-block;
    background: var(--btn-bg);
    color: var(--btn-text);
    padding: 8px 15px;
    text-decoration: none;
    text-align: center;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
}

.btn:hover {
    background: var(--btn-hover);
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

input,
select,
textarea {
    width: 100%;
    padding: 8px;
    border: 2px solid var(--border-color);
    font-family: inherit;
    background-color: var(--bg-input);
    color: var(--text-main);
}

/* Pagination */
.pagination {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 40px;
    padding: 20px;
    border-top: 2px solid var(--border-color);
    color: var(--text-muted);
}

/* Utilities */
.text-center {
    text-align: center;
}

.mb-40 {
    margin-bottom: 40px;
}

.flex-center {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}

.mr-10 {
    margin-right: 10px;
}

.mb-10 {
    margin-bottom: 10px;
}

.danger {
    color: red;
    font-weight: bold;
}

.login-box {
    max-width: 400px;
    margin: 0 auto;
    background: var(--bg-card);
    padding: 20px;
    border: 2px solid var(--border-color);
}

.details-box {
    background: var(--bg-card);
    padding: 20px;
    border: 2px solid var(--border-color);
}

hr {
    border: 0;
    border-top: 2px solid var(--border-color);
    margin: 20px 0;
}

/* Gallery Styles */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.gallery-item {
    border: 2px solid var(--border-color);
    background: #000;
    /* Usually keep compiled black for images/videos background ?? */
    position: relative;
    aspect-ratio: 16/9;
    /* Force consistent aspect ratio */
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.2);
}

.gallery-item img,
.gallery-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-item a {
    display: block;
    width: 100%;
    height: 100%;
}

/* Video specific styling to ensure controls are visible/usable */
.gallery-item video {
    background: #000;
}

/* --- Mobile Responsiveness --- */

/* Hamburger Menu (Hidden by default) */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
}

/* Upload Grid Layout (Desktop default) */
.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* Preview Container */
.preview-container {
    border: 1px solid var(--border-light);
    padding: 15px;
    min-height: 300px;
    background: var(--bg-hover);
}

.under-revision {
    font-size: 0.5em;
    color: #e67e22;
}

/* Description Box */
.description-box {
    margin: 20px 0;
    padding: 15px;
    background: var(--bg-quote);
    border: 1px solid var(--border-light);
}

.login-req-box {
    background: var(--bg-hover);
    padding: 15px;
    border: 1px solid var(--border-color);
}

/* --- Item View Styles --- */
.download-list {
    list-style: none;
    padding: 0;
}

.download-list li {
    margin-bottom: 10px;
}

.download-link {
    display: inline-block;
    padding: 10px 15px;
    background: var(--btn-bg);
    color: var(--btn-text);
    text-decoration: none;
    font-weight: bold;
}

.download-link:hover {
    background: var(--btn-hover);
    color: var(--btn-text);
}

.comment {
    border: 2px solid var(--border-color);
    padding: 15px;
    margin-bottom: 15px;
    background: var(--bg-card);
    box-shadow: 4px 4px 0px var(--shadow-color);
}

.comment-header {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 10px;
}

.comment-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 15px;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

.btn-sm {
    padding: 2px 8px;
    font-size: 0.8rem;
    margin-left: auto;
}

.btn-danger {
    background: #dc3545;
}

.btn-danger:hover {
    background: #c82333;
}


@media (max-width: 768px) {

    /* Layout */
    .container {
        padding: 15px;
    }

    /* Navbar */
    nav .container {
        flex-wrap: wrap;
    }

    .logo {
        flex: 1;
    }

    .menu-toggle {
        display: block;
        /* Show hamburger on mobile */
    }

    .nav-links {
        display: none;
        /* Hide links by default on mobile */
        width: 100%;
        flex-direction: column;
        padding-top: 15px;
        gap: 10px;
    }

    .nav-links.active {
        display: flex;
        /* Show when toggled */
    }

    .nav-links a,
    .nav-links select {
        width: 100%;
        margin: 0 !important;
        /* Override potential margins */
        text-align: center;
    }

    /* User Menu Mobile */
    .user-menu {
        width: 100%;
        margin: 0 !important;
    }

    .user-menu-btn {
        width: 100%;
        text-align: center;
    }

    .user-menu-dropdown {
        position: static;
        width: 100%;
        margin-top: 0;
    }

    .user-menu-dropdown a {
        text-align: center;
    }

    /* Upload View */
    .upload-grid {
        grid-template-columns: 1fr;
        /* Stack columns */
    }

    /* Adjust gallery items */
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}

/* Wiki Layout */
.wiki-container {
    display: flex;
    gap: 30px;
    min-height: 500px;
}

.wiki-sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border: 2px solid var(--border-color);
    padding: 0;
    height: fit-content;
}

.wiki-sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.wiki-sidebar li {
    border-bottom: 1px solid var(--border-color);
}

.wiki-sidebar li:last-child {
    border-bottom: none;
}

.wiki-sidebar a {
    display: block;
    padding: 15px;
    text-decoration: none;
    color: var(--text-main);
    font-weight: bold;
    transition: background 0.2s;
    cursor: pointer;
}

.wiki-sidebar a:hover,
.wiki-sidebar a.active {
    background: var(--btn-bg);
    color: var(--btn-text);
    text-decoration: none;
}

.wiki-content {
    flex: 1;
    background: var(--bg-card);
    padding: 30px;
    border: 2px solid var(--border-color);
    min-width: 0;
}

/* Wiki Content Markdown Styling */
.wiki-content h1 {
    margin-top: 0;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
}

.wiki-content h2 {
    margin-top: 30px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 5px;
}

.wiki-content img {
    max-width: 100%;
    border: 2px solid var(--border-color);
    margin: 10px 0;
}

.wiki-content blockquote {
    margin: 20px 0;
    padding: 15px;
    background: var(--bg-quote);
    border-left: 5px solid var(--border-color);
}

.wiki-content pre {
    background: var(--bg-code);
    padding: 15px;
    border: 1px solid var(--border-light);
    overflow-x: auto;
}

.wiki-content ul,
.wiki-content ol {
    padding-left: 20px;
}

.wiki-content li {
    margin-bottom: 5px;
}

/* Wiki Mobile */
@media (max-width: 768px) {
    .wiki-container {
        flex-direction: column;
    }

    .wiki-sidebar {
        width: 100%;
    }
}

/* Badges */
.badge {
    display: inline-block;
    background-color: #48bb78;
    color: white;
    padding: 6px 12px;
    /* Increased padding */
    font-size: 0.9em;
    /* Increased font size */
    font-weight: bold;
    margin-right: 10px;
    border: 2px solid var(--border-color);
    /* Retro border */
    box-shadow: 2px 2px 0px var(--shadow-color);
    /* Retro shadow */
}

.badge-blue {
    background-color: #4a90e2;
}

.badge-red {
    background-color: #dc3545;
}

.badge-yellow {
    background-color: #ffc107;
}

.badge-pink {
    background-color: #ff69b4;
}

.badge-purple {
    background-color: #9932cc;
}

/* GitHub Styles Alerts */
.markdown-alert {
    padding: 16px;
    margin-bottom: 20px;
    border: none;
    border-left-width: 8px;
    border-left-style: solid;
    background-color: var(--bg-card);
    color: var(--text-main);
    position: relative;
    border-radius: 0;
    box-shadow: 6px 6px 0px var(--shadow-color);
}

.markdown-alert> :last-child {
    margin-bottom: 0;
}

.markdown-alert-title {
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Note */
.wiki-content .markdown-alert-note {
    border-left-color: #0969da !important;
    background-color: var(--alert-note-bg, #ddf4ff);
    color: var(--alert-note-text, #0969da);
}

.markdown-alert-note .markdown-alert-title {
    color: var(--alert-note-text, #0969da);
}

.markdown-alert-note .markdown-alert-title::before {
    content: "ℹ️";
}

[data-theme="dark"] .wiki-content .markdown-alert-note {
    --alert-note-bg: #1a2a3a;
    --alert-note-text: #58a6ff;
}


/* Tip */
.wiki-content .markdown-alert-tip {
    border-left-color: #1a7f37 !important;
    background-color: var(--alert-tip-bg, #dafbe1);
    color: var(--alert-tip-text, #1a7f37);
}

.markdown-alert-tip .markdown-alert-title {
    color: var(--alert-tip-text, #1a7f37);
}

.markdown-alert-tip .markdown-alert-title::before {
    content: "💡";
}

[data-theme="dark"] .wiki-content .markdown-alert-tip {
    --alert-tip-bg: #1a3a2a;
    --alert-tip-text: #3fb950;
}

/* Important */
.wiki-content .markdown-alert-important {
    border-left-color: #8250df !important;
    background-color: var(--alert-important-bg, #f6f1ff);
    color: var(--alert-important-text, #8250df);
}

.markdown-alert-important .markdown-alert-title {
    color: var(--alert-important-text, #8250df);
}

.markdown-alert-important .markdown-alert-title::before {
    content: "💜";
}

[data-theme="dark"] .wiki-content .markdown-alert-important {
    --alert-important-bg: #2a1a3a;
    --alert-important-text: #bc8cff;
}

/* Warning */
.wiki-content .markdown-alert-warning {
    border-left-color: #9a6700 !important;
    background-color: var(--alert-warning-bg, #fff8c5);
    color: var(--alert-warning-text, #9a6700);
}

.markdown-alert-warning .markdown-alert-title {
    color: var(--alert-warning-text, #9a6700);
}

.markdown-alert-warning .markdown-alert-title::before {
    content: "⚠️";
}

[data-theme="dark"] .wiki-content .markdown-alert-warning {
    --alert-warning-bg: #3a2a1a;
    --alert-warning-text: #d29922;
}

/* Caution */
.wiki-content .markdown-alert-caution {
    border-left-color: #cf222e !important;
    background-color: var(--alert-caution-bg, #ffebe9);
    color: var(--alert-caution-text, #cf222e);
}

.markdown-alert-caution .markdown-alert-title {
    color: var(--alert-caution-text, #cf222e);
}

.markdown-alert-caution .markdown-alert-title::before {
    content: "🛑";
}

[data-theme="dark"] .wiki-content .markdown-alert-caution {
    --alert-caution-bg: #3a1a1a;
    --alert-caution-text: #ff7b72;
}


/* --- Admin View Styles --- */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-card);
    padding: 20px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.stat-value {
    font-size: 2em;
    font-weight: bold;
    color: var(--text-main);
}

.stat-label {
    color: var(--text-muted);
    margin-top: 5px;
}

/* Cleanup Cards */
.cleanup-card {
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid transparent;
}

.cleanup-card.loading {
    background: var(--bg-card);
    text-align: center;
    border-color: var(--border-color);
}

.cleanup-card.warning {
    background: var(--alert-warning-bg, #fff3cd);
    border-color: #ffc107;
    color: var(--alert-warning-text, #856404);
}

.cleanup-card.success {
    background: var(--alert-tip-bg, #d4edda);
    border-color: #c3e6cb;
    color: var(--alert-tip-text, #155724);
}

[data-theme="dark"] .cleanup-card.warning {
    --alert-warning-bg: #3a2a1a;
    --alert-warning-text: #d29922;
    border-color: #9a6700;
}

[data-theme="dark"] .cleanup-card.success {
    --alert-tip-bg: #1a3a2a;
    --alert-tip-text: #3fb950;
    border-color: #1a7f37;
}

.cleanup-title {
    margin-top: 0;
    color: inherit;
}

.cleanup-desc {
    color: inherit;
    margin-bottom: 15px;
}

.cleanup-details summary {
    cursor: pointer;
    font-weight: bold;
    color: inherit;
    margin-bottom: 24px;
}

.file-list {
    margin-top: 10px;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-body);
    padding: 15px;
    border: 1px solid var(--border-color);
}

.file-list li {
    margin: 5px 0;
    font-family: monospace;
    font-size: 0.9em;
    color: var(--text-main);
}

.file-list li span {
    color: var(--text-muted);
}

.pending-loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.btn-danger {
    background-color: #dc3545;
    color: white;
}

/* Wiki Comments */
.wiki-comment-form {
    margin-top: 20px;
}

.comment-textarea {
    width: 100%;
    font-family: inherit;
    padding: 10px;
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.wiki-comment {
    border: 2px solid var(--border-color);
    padding: 10px;
    margin-bottom: 15px;
    background: var(--bg-card);
    box-shadow: 5px 5px 0px var(--shadow-color);
    display: flex;
    gap: 10px;
}

.wiki-comment-avatar-container {
    flex-shrink: 0;
}

.wiki-comment-avatar {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

.wiki-comment-content {
    flex-grow: 1;
}

.wiki-comment-header {
    font-weight: bold;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.wiki-comment-date {
    font-weight: normal;
    font-size: 0.8em;
    color: var(--text-muted);
}

.btn-danger-sm {
    padding: 2px 5px;
    font-size: 0.8em;
    background: #ff4444;
    color: white;
    border: none;
    cursor: pointer;
}

.wiki-comment-body {
    font-size: 0.95em;
    color: var(--text-main);
}