*, *::before, *::after {
    box-sizing: border-box;
}

:root {
    --md-sys-color-background: #0F141A;
    --md-sys-color-surface: #1A2027;
    --md-sys-color-surface-variant: #263340;
    --md-sys-color-primary: #A1C9FF;
    --md-sys-color-on-primary: #00325A;
    --md-sys-color-on-background: #E2E2E6;
    --md-sys-color-on-surface: #C4C7C5;
    --border-radius-large: 24px;
    --border-radius-medium: 16px;
}

body.light-mode {
    --md-sys-color-background: #FDFBFF;
    --md-sys-color-surface: #F0F4FA;
    --md-sys-color-surface-variant: #E1E2EC;
    --md-sys-color-primary: #0061A4;
    --md-sys-color-on-primary: #FFFFFF;
    --md-sys-color-on-background: #1A1C1E;
    --md-sys-color-on-surface: #43474E;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden; 
    max-width: 100vw;
}

main {
    min-height: calc(100vh - 200px);
}

.top-app-bar {
    position: relative;
    background-color: var(--md-sys-color-surface);
    padding: 24px 20px;
    text-align: center;
    border-bottom: 1px solid var(--md-sys-color-surface-variant);
    transition: background-color 0.3s;
}

.top-app-bar h1 {
    margin: 0;
    color: var(--md-sys-color-primary);
    font-size: 2rem;
    letter-spacing: 1px;
}

.top-app-bar p {
    margin: 8px 0 0 0;
    color: var(--md-sys-color-on-surface);
    font-size: 0.9rem;
}

#theme-toggle {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#theme-toggle:hover {
    background-color: var(--md-sys-color-surface-variant);
}

.container {
    max-width: 800px;
    margin: 20px auto;
    padding: 0 16px;
}

.global-warning {
    background-color: rgba(255, 82, 82, 0.1); 
    border: 5px solid #FF5252; 
    color: #FFCDD2; 
    padding: 20px 24px; 
    margin-bottom: 24px;
    border-radius: var(--border-radius-medium);
    font-size: 1.1rem; 
    line-height: 1.6;
}

.global-warning strong {
    color: #FF5252; 
    font-size: 1.25rem; 
    display: inline-block;
    margin-bottom: 6px; 
}

body.light-mode .global-warning {
    background-color: #FFEBEE; 
    border-left-color: #D32F2F;
    color: #B71C1C; 
}

body.light-mode .global-warning strong {
    color: #D32F2F; 
}

.search-container {
    margin-bottom: 24px;
    display: flex;
    gap: 12px;
    align-items: center; 
}

.dropdown {
    position: relative;
    display: inline-block;
}

#sort-dropdown-btn {
    min-width: 180px; 
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: var(--md-sys-color-surface);
    min-width: 200px;
    box-shadow: 0px 8px 16px rgba(0,0,0,0.5);
    z-index: 100;
    border-radius: var(--border-radius-medium);
    margin-top: 8px;
    border: 1px solid var(--md-sys-color-surface-variant);
    overflow: hidden;
}

.dropdown-content.show {
    display: flex;
    flex-direction: column;
}

.dropdown-item {
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--md-sys-color-on-background);
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: bold;
    transition: background-color 0.2s;
}

.dropdown-item:hover {
    background-color: var(--md-sys-color-surface-variant);
}

.control-btn {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface);
    border: none;
    border-radius: var(--border-radius-large);
    padding: 14px 20px; 
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s, color 0.3s;
    white-space: nowrap; 
}

.control-btn:hover {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.search-input-wrapper {
    position: relative;
    flex-grow: 1;
    display: flex;
    align-items: center;
}

#search-input {
    width: 100%;
    padding: 14px 40px 14px 20px; 
    border-radius: var(--border-radius-large);
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-background);
    font-size: 1rem;
    box-sizing: border-box; 
    outline: none;
    border: 2px solid transparent;
    transition: border-color 0.2s, background-color 0.3s, color 0.3s;
}

#search-input:focus {
    border-color: var(--md-sys-color-primary);
}

.clear-btn {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--md-sys-color-on-surface);
    font-size: 1.2rem;
    cursor: pointer;
    display: none; 
    padding: 5px 12px;
    border-radius: 50%;
    transition: color 0.2s, background-color 0.2s;
}

.clear-btn.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-btn:hover {
    color: var(--md-sys-color-primary);
    background-color: var(--md-sys-color-surface-variant);
}

.app-card {
    background-color: var(--md-sys-color-surface);
    border-radius: var(--border-radius-large);
    padding: 20px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0; 
    flex: 1; 
}

.app-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--border-radius-medium);
    object-fit: contain;
}

.app-title {
    min-width: 0; 
    flex: 1;
}

.app-title h2 {
    margin: 0;
    color: var(--md-sys-color-on-background);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.version-count {
    font-size: 0.9rem;
    font-weight: normal; 
    color: var(--md-sys-color-on-surface); 
    margin-left: 5px; 
    white-space: nowrap; 
}

.version-count-link {
    font-size: 0.9rem;
    font-weight: normal; 
    color: var(--md-sys-color-primary); 
    margin-left: 5px; 
    white-space: nowrap; 
    text-decoration: none;
    transition: opacity 0.2s, text-decoration 0.2s;
}

.version-count-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.package-name {
    font-size: 0.8rem;
    font-family: monospace;
    color: #FFFFFF; 
    margin-top: 2px;
    overflow-wrap: anywhere;
}

body.light-mode .package-name {
    color: #1A1C1E; 
}

.app-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.share-btn {
    background: none;
    border: none;
    color: var(--md-sys-color-on-surface);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s, transform 0.2s;
}

.share-btn:hover {
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-primary);
    transform: scale(1.1);
}

.expand-btn {
    background: none;
    border: none;
    color: var(--md-sys-color-primary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.expand-btn.open {
    transform: rotate(180deg);
}

.app-important {
    background-color: rgba(255, 82, 82, 0.1);
    border-left: 4px solid #FF5252;
    color: #FFCDD2;
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 4px 8px 8px 4px;
    font-size: 0.9rem;
    line-height: 1.4;
}

body.light-mode .app-important {
    background-color: #FFEBEE;
    border-left-color: #D32F2F;
    color: #B71C1C;
}

.version-warning {
    flex-basis: 100%; 
    background-color: rgba(255, 193, 7, 0.1); 
    border-left: 4px solid #FFC107;
    color: #FFE082;
    padding: 10px 14px;
    margin-bottom: 12px; 
    border-radius: 4px 8px 8px 4px;
    font-size: 0.85rem;
    line-height: 1.4;
}

body.light-mode .version-warning {
    background-color: #FFF8E1;
    border-left-color: #FFA000;
    color: #E65100;
}

.app-important a,
.version-warning a,
.version-note a, 
.patch-desc a {
    color: var(--md-sys-color-primary);
    text-decoration: underline;
    font-weight: bold;
    transition: opacity 0.2s;
}

.app-important a:hover,
.version-warning a:hover,
.version-note a:hover,
.patch-desc a:hover {
    opacity: 0.8;
}

.version-note {
    flex-basis: 100%;
    background-color: rgba(76, 175, 80, 0.1); 
    border-left: 4px solid #4CAF50;
    color: #A5D6A7;
    padding: 10px 14px;
    margin-bottom: 12px;
    border-radius: 4px 8px 8px 4px;
    font-size: 0.85rem;
    line-height: 1.4;
}

body.light-mode .version-note {
    background-color: #E8F5E9;
    border-left-color: #388E3C;
    color: #1B5E20;
}

.version-list {
    display: none;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
    border-top: 1px solid var(--md-sys-color-surface-variant);
    padding-top: 16px;
}

.version-list.show {
    display: flex;
}

.version-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; 
    background-color: var(--md-sys-color-surface-variant);
    padding: 12px 16px;
    border-radius: var(--border-radius-medium);
    transition: background-color 0.3s;
}

.version-details {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 60%; 
}

.patch-desc {
    font-size: 0.85rem;
    color: var(--md-sys-color-on-surface);
    margin-top: 4px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.version-size {
    font-size: 1rem;
    color: var(--md-sys-color-on-background);
}

.version-hash {
    font-size: 1rem;
    color: var(--md-sys-color-on-background);
}

.version-hash code {
    background-color: var(--md-sys-color-background);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    user-select: all; 
    font-size: 0.9rem;
}

.button-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.download-btn {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    transition: opacity 0.2s, background-color 0.3s, color 0.3s;
}

.download-btn:hover {
    opacity: 0.8;
}

.bottom-footer {
    background-color: var(--md-sys-color-surface);
    border-top: 1px solid var(--md-sys-color-surface-variant);
    padding: 5px 10px;
    margin-top: auto; 
    transition: background-color 0.3s;
}

.footer-content {
    text-align: center;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap; 
}

.footer-links a {
    color: var(--md-sys-color-primary);
    background-color: var(--md-sys-color-surface-variant);
    text-decoration: none;
    font-weight: bold;
    padding: 12px 24px;
    border-radius: var(--border-radius-large);
    transition: background-color 0.2s, color 0.3s;
}

.footer-links a:hover {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.footer-credits {
    color: var(--md-sys-color-on-surface);
    font-size: 0.9rem;
    margin: 0;
}

.back-btn {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--md-sys-color-primary);
    text-decoration: none;
    font-weight: bold;
    padding: 8px 16px;
    border-radius: 20px;
    background-color: var(--md-sys-color-surface-variant);
    transition: opacity 0.2s;
}

.back-btn:hover {
    opacity: 0.8;
}

.patch-supported {
    font-size: 0.8rem;
    color: var(--md-sys-color-on-surface);
    margin-top: 6px;
    font-weight: bold;
}

.patch-supported strong {
    font-weight: normal;
    color: var(--md-sys-color-primary);
}

.patch-tag {
    font-size: 0.75rem;
    font-weight: normal;
    margin-left: 6px;
    display: inline-block;
    vertical-align: middle;
}

.default-tag {
    color: #81C784; 
}

body.light-mode .default-tag {
    color: #2E7D32; 
}

.config-tag {
    color: #FFB74D; 
}

body.light-mode .config-tag {
    color: #F57F17; 
}

@media (max-width: 600px) {
    .top-app-bar {
        padding: 20px 16px 24px 16px;
    }
    
    .top-app-bar h1 {
        font-size: 1.5rem;
    }
    
    .top-app-bar p {
        font-size: 0.8rem;
        margin-top: 16px; 
    }

    #theme-toggle {
        top: 16px; 
        right: 20px;
        transform: none; 
        font-size: 1.1rem; 
        padding: 6px; 
    }

    .search-container {
        flex-direction: column;
        align-items: stretch;
    }

    .search-input-wrapper {
        order: 1; 
        width: 100%; 
    }

    .dropdown {
        order: 2;
        width: 100%;
        display: flex;
    }

    #sort-dropdown-btn {
        width: 100%;
    }

    .dropdown-content {
        width: 100%; 
    }

    #toggle-all-btn {
        order: 3;
        width: 100%;
    }

    .version-item {
        flex-direction: column;
        align-items: flex-start; 
        gap: 12px;
    }
    
    .version-details {
        max-width: 100%; 
    }

    .button-group {
        width: 100%;
        justify-content: stretch; 
    }
    
    .download-btn {
        flex: 1; 
        text-align: center;
    }

    .version-hash code {
        font-size: 0.78rem;
        display: block;
        margin-top: 4px;
        width: fit-content; 
        word-break: break-all;
    }
}

@media (max-width: 416px) {
    .container {
        padding: 0 10px;
    }

    #sort-dropdown-btn, 
    .dropdown-content {
        min-width: 0;
        width: 100%;
    }

    .control-btn {
        padding: 12px 10px;
        font-size: 0.85rem;
    }

    .app-icon {
        width: 48px;
        height: 48px;
    }

    .app-header-left {
        gap: 12px;
    }

    .app-title h2 {
        font-size: 1.2rem;
    }

    .version-item {
        padding: 12px 10px;
    }
}