* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    /* Disable smooth scrolling to prevent white flash */
    scroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    line-height: 1.6;
    color: #3d2817;
    background: linear-gradient(135deg, #f4e8d8 0%, #e6d5c3 100%);
    background-attachment: fixed;
    min-height: 100vh;
    /* Force GPU acceleration */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

/* Hide all posts by default - JavaScript will show current page */
.post-card {
    display: none;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    /* Improve scrolling performance */
    will-change: transform;
    transform: translateZ(0);
}

header {
    background: #faf7f2;
    padding: 40px 0;
    text-align: center;
    border: 3px solid #d4a574;
    border-radius: 10px;
    margin-bottom: 30px;
    position: relative;
}

.theme-toggle-container {
    position: absolute;
    top: 15px;
    right: 20px;
}

.theme-toggle-btn {
    background: #d4753e;
    border: 2px solid #b85d2c;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.3s ease;
    box-shadow: none;
}

.theme-toggle-btn:hover {
    background: #b85d2c;
    transform: scale(1.1);
}

.theme-toggle-btn:active {
    transform: scale(0.95);
}

.theme-icon {
    display: block;
    line-height: 1;
}

.header-title {
    font-size: 2.5em;
    color: #8b4513;
    margin-bottom: 10px;
}

.header-subtitle {
    font-size: 1.1em;
    color: #9d6b3f;
    font-style: italic;
}

.last-update {
    font-size: 0.9em;
    color: #a0826d;
    margin: 10px 0 15px 0;
    font-style: italic;
}

.posts-count {
    background: #d4753e;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    display: inline-block;
    margin-top: 15px;
    font-weight: bold;
}

.search-container {
    margin: 20px 0;
    text-align: center;
}

.search-wrapper {
    display: inline-flex;
    align-items: center;
    position: relative;
    width: 100%;
    max-width: 500px;
}

.search-box {
    width: 100%;
    padding: 15px 60px 15px 15px;
    border: 2px solid #d4a574;
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
    background: #faf7f2;
}

.search-box:focus {
    border-color: #d4753e;
}

.clear-btn {
    position: absolute;
    right: 55px;
    top: 50%;
    transform: translateY(-50%);
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #c4c4c4;
    border: 2px solid #a0a0a0;
    color: white;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    padding: 0;
    opacity: 0.7;
}

.clear-btn:hover {
    background: #d4753e;
    border-color: #b85d2c;
    opacity: 1;
    transform: translateY(-50%) scale(1.1);
}

.clear-icon {
    display: block;
    line-height: 0.8;
    font-weight: bold;
}

.search-btn {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    background: #d4753e;
    border: 2px solid #b85d2c;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.3s ease;
    box-shadow: none;
}

.search-btn:hover {
    background: #e8884e;
    transform: translateY(-50%) scale(1.05);
}

.search-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.search-icon {
    display: block;
    line-height: 1;
}

.search-results {
    margin-top: 15px;
    font-size: 0.95em;
    color: #8b6f47;
    font-weight: 500;
    min-height: 20px;
}

.search-results.active {
    color: #d4753e;
    font-weight: bold;
}

.posts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 25px;
    margin-top: 30px;
    /* Optimize rendering performance */
    contain: layout style paint;
}

.post-card {
    /* display: none set above */
    background: #faf7f2;
    border-radius: 15px;
    padding: 25px;
    transition: all 0.3s ease;
    border-left: 5px solid #d4753e;
    border-top: 2px solid #d4a574;
    border-bottom: 2px solid #d4a574;
    border-right: 0;
    box-shadow: none !important;
    /* Optimize rendering during scroll */
    content-visibility: auto;
    contain-intrinsic-size: auto 400px;
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}
}

.post-card:hover {
    /* Lighter transform for better performance */
    transform: translateY(-4px) translateZ(0);
    border-top-color: #c99456;
    border-bottom-color: #c99456;
    border-left-color: #e89050;
    border-right: 0;
    box-shadow: none !important;
}

/* RTL Language Support */
.post-card.rtl-post {
    direction: rtl;
    text-align: right;
    border-left: 0;
    border-right: 5px solid #d4753e;
    border-top: 2px solid #d4a574;
    border-bottom: 2px solid #d4a574;
}

.post-card.rtl-post .post-meta {
    direction: rtl;
}

.post-card.rtl-post .post-author {
    text-align: right;
}

.post-card.rtl-post .post-date {
    text-align: left;
}

.post-card.rtl-post .post-tags {
    justify-content: flex-end;
}

.post-title {
    font-size: 1.4em;
    color: #6d3410;
    margin-bottom: 10px;
    font-weight: bold;
}

.post-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    font-size: 0.9em;
    color: #8b6f47;
}

.post-author {
    font-weight: bold;
    color: #d4753e;
}

.post-date {
    font-style: italic;
}

.post-summary {
    color: #5d4a3a;
    margin-bottom: 15px;
    font-style: italic;
}

.file-size {
    font-size: 0.9em;
    color: #8b6f47;
    font-family: monospace;
    margin-top: 10px;
}

.post-tags {
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    background: #fce4d6;
    color: #6d3410;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8em;
    border: 1px solid #d4a574;
}

.add-to-library-btn {
    background: #d4753e;
    color: white;
    border: 2px solid transparent;
    padding: 12px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: bold;
    margin: 15px auto 0 auto;
    transition: all 0.3s ease;
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.add-to-library-btn:hover {
    background: #b85d2c;
    transform: translateY(-3px);
    border: 2px solid #a04d1c;
}

.highlight {
    background-color: #ffff00;
    color: #000;
    font-weight: bold;
    padding: 1px 2px;
    border-radius: 2px;
}

/* Pagination Styles */
.pagination {
    margin: 40px 0 30px;
    padding: 25px;
    background: #faf7f2;
    border-radius: 15px;
    border: 3px solid #d4a574;
}

.pagination-info {
    text-align: center;
    font-size: 1em;
    color: #8b6f47;
    margin-bottom: 20px;
    font-weight: 600;
}

.pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.pagination-btn {
    background: #d4753e;
    color: white;
    border: 2px solid #b85d2c;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: bold;
    text-decoration: none;
    transition: all 0.3s ease;
    display: inline-block;
}

.pagination-btn:hover:not(.disabled) {
    background: #b85d2c;
    transform: translateY(-2px);
    border-color: #a04d1c;
}

.pagination-btn.disabled {
    background: #c4c4c4;
    border-color: #a0a0a0;
    cursor: not-allowed;
    opacity: 0.5;
}

.pagination-pages {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
    justify-content: center;
}

.pagination-number {
    background: #fce4d6;
    color: #6d3410;
    border: 2px solid #d4a574;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: bold;
    text-decoration: none;
    transition: all 0.3s ease;
    display: inline-block;
    min-width: 40px;
    text-align: center;
}

.pagination-number:hover:not(.current) {
    background: #f5d5c0;
    border-color: #c99456;
    transform: translateY(-2px);
}

.pagination-number.current {
    background: #d4753e;
    color: white;
    border-color: #b85d2c;
    cursor: default;
}

.pagination-ellipsis {
    padding: 8px 6px;
    color: #8b6f47;
    font-weight: bold;
}

/* Responsive Pagination */
@media (max-width: 768px) {
    .pagination-controls {
        flex-direction: column;
        gap: 15px;
    }
    
    .pagination-btn {
        width: 100%;
        max-width: 200px;
    }
    
    .pagination-pages {
        order: -1;
    }
}

footer {
    text-align: center;
    margin-top: 50px;
    padding: 30px;
    background: #faf7f2;
    border-radius: 10px;
    border: 3px solid #d4a574;
}

.footer-text {
    color: #9d6b3f;
    font-style: italic;
}

/* Back to Top Button */
.back-to-top-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background: #d4753e;
    border: 2px solid #b85d2c;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
    transition: all 0.3s ease;
    opacity: 0;
    visibility: hidden;
    z-index: 999;
    box-shadow: none;
}

.back-to-top-btn.show {
    opacity: 1;
    visibility: visible;
}

.back-to-top-btn:hover {
    background: #b85d2c;
    transform: translateY(-3px);
    border-color: #a04d1c;
}

.back-to-top-btn:active {
    transform: translateY(-1px);
}

.arrow-up {
    display: block;
    line-height: 1;
    font-weight: bold;
}

/* Popup Modal Styles */
.popup-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}

.popup-content {
    background: #faf7f2;
    border-radius: 15px;
    border: 4px solid #d4753e;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    animation: popupSlideIn 0.3s ease-out;
}

@keyframes popupSlideIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px 15px;
    border-bottom: 1px solid #eee;
}

.popup-header h3 {
    margin: 0;
    color: #6d3410;
    font-size: 1.3em;
}

.popup-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.popup-close:hover {
    background-color: #f1f1f1;
    color: #666;
}

.popup-body {
    padding: 20px 25px;
}

.popup-body label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #6d3410;
}

.qr-section {
    margin-bottom: 20px;
    text-align: center;
}

.qr-container {
    display: inline-block;
    margin: 10px 0;
    padding: 15px;
    background: white;
    border: 2px solid #d4a574;
    border-radius: 10px;
}

.lid-textarea {
    width: 100%;
    min-height: 80px;
    padding: 12px;
    border: 2px solid #d4a574;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    resize: vertical;
    background-color: #faf7f2;
    transition: border-color 0.3s ease;
    cursor: text;
}

.lid-textarea:focus {
    outline: none;
    border-color: #d4753e;
}

.lid-textarea:hover {
    border-color: #b89968;
}

.popup-note {
    margin-top: 10px;
    font-size: 0.9em;
    color: #8b6f47;
    font-style: italic;
}

.popup-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 25px 20px;
    border-top: 1px solid #eee;
}

.btn-primary, .btn-secondary {
    padding: 10px 20px;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: bold;
    transition: all 0.2s ease;
    min-width: 100px;
}

.btn-primary {
    background: #d4753e;
    color: white;
    border-color: transparent;
}

.btn-primary:hover {
    background: #b85d2c;
    transform: translateY(-2px);
    border: 2px solid #a04d1c;
}

.btn-secondary {
    background: #f4e8d8;
    color: #6d3410;
    border: 2px solid #d4a574;
}

.btn-secondary:hover {
    background: #e6d5c3;
    transform: translateY(-2px);
    border: 2px solid #c99456;
}

@media (max-width: 768px) {
    .posts-grid {
        grid-template-columns: 1fr;
    }
    
    .header-title {
        font-size: 2em;
    }
    
    .theme-toggle-container {
        top: 10px;
        right: 10px;
    }
    
    .theme-toggle-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .search-wrapper {
        max-width: 100%;
    }
    
    .search-box {
        padding: 12px 55px 12px 12px;
        font-size: 15px;
    }
    
    .clear-btn {
        width: 30px;
        height: 30px;
        right: 40px;
        font-size: 18px;
    }
    
    .search-btn {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }
    
    .search-results {
        font-size: 0.85em;
        margin-top: 10px;
    }
    
    .back-to-top-btn {
        bottom: 20px;
        right: 20px;
        width: 45px;
        height: 45px;
        font-size: 20px;
    }
    
    .post-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .popup-content {
        width: 95%;
        margin: 20px;
    }
    
    .popup-header {
        padding: 15px 20px 10px;
    }
    
    .popup-body {
        padding: 15px 20px;
    }
    
    .popup-footer {
        padding: 10px 20px 15px;
        flex-direction: column;
    }
    
    .btn-primary, .btn-secondary {
        width: 100%;
    }
}

/* Manual Dark Theme Toggle */
body.dark-theme {
    color: #e8dcc8;
    background: linear-gradient(135deg, #2a1f15 0%, #3d2e20 100%);
}

body.dark-theme header {
    background: #3d2e20;
    color: #e8dcc8;
    border-color: #8b5a2b;
}

body.dark-theme .header-title {
    color: #d4a574;
}

body.dark-theme .header-subtitle {
    color: #a89579;
}

body.dark-theme .last-update {
    color: #a89579;
}

body.dark-theme .search-box {
    background: #3d2e20;
    color: #e8dcc8;
    border-color: #8b5a2b;
}

body.dark-theme .search-box:focus {
    border-color: #d4753e;
}

body.dark-theme .search-box::placeholder {
    color: #a89579;
}
body.dark-theme .clear-btn {
    background: #5a5a5a;
    border-color: #4a4a4a;
}

body.dark-theme .clear-btn:hover {
    background: #c87840;
    border-color: #a65e30;
}

body.dark-theme .search-btn {
    background: #c87840;
    border-color: #a65e30;
}

body.dark-theme .search-btn:hover {
    background: #e89050;
    border-color: #d4753e;
}

body.dark-theme .search-results {
    color: #a89579;
}

body.dark-theme .search-results.active {
    color: #e8995e;
}

body.dark-theme .post-card {
    background: #3d2e20;
    border-left: 5px solid #d4753e;
    border-top: 2px solid #8b5a2b;
    border-bottom: 2px solid #8b5a2b;
    border-right: 0;
    box-shadow: none !important;
}

body.dark-theme .post-card.rtl-post {
    border-left: 0;
    border-right: 5px solid #d4753e;
    border-top: 2px solid #8b5a2b;
    border-bottom: 2px solid #8b5a2b;
}

body.dark-theme .post-title {
    color: #e8c9a0;
}

body.dark-theme .post-meta {
    color: #a89579;
}

body.dark-theme .post-author {
    color: #e8995e;
}

body.dark-theme .post-date {
    color: #a89579;
}

body.dark-theme .post-summary {
    color: #c9b89d;
}

body.dark-theme .file-size {
    color: #a89579;
}

body.dark-theme .tag {
    background: #5a4232;
    color: #e8c9a0;
    border-color: #8b5a2b;
}

body.dark-theme .highlight {
    background-color: #ffff00;
    color: #000;
}

body.dark-theme footer {
    background: #3d2e20;
    border-color: #8b5a2b;
}

body.dark-theme .footer-text {
    color: #a89579;
}

body.dark-theme .popup-overlay {
    background-color: rgba(42, 31, 21, 0.85);
}

body.dark-theme .popup-content {
    background: #3d2e20;
    color: #e8dcc8;
    border-color: #d4753e;
}

body.dark-theme .popup-header {
    border-bottom-color: #5a4232;
}

body.dark-theme .popup-header h3 {
    color: #e8c9a0;
}

body.dark-theme .popup-close {
    color: #a89579;
}

body.dark-theme .popup-close:hover {
    background-color: #5a4232;
    color: #e8dcc8;
}

body.dark-theme .popup-body label {
    color: #e8c9a0;
}

body.dark-theme .popup-footer {
    border-top-color: #5a4232;
}

body.dark-theme .btn-secondary {
    background: #5a4232;
    color: #e8c9a0;
    border-color: #8b5a2b;
}

body.dark-theme .btn-secondary:hover {
    background: #6d5242;
}

body.dark-theme .qr-container {
    background: #5a4232;
    border-color: #8b5a2b;
}

body.dark-theme .lid-textarea {
    background-color: #3d2e20;
    color: #e8dcc8;
    border-color: #8b5a2b;
}

body.dark-theme .lid-textarea:focus {
    border-color: #d4753e;
}

body.dark-theme .lid-textarea:hover {
    border-color: #a0826d;
}

body.dark-theme .back-to-top-btn {
    background: #d4753e;
    border-color: #b85d2c;
}

body.dark-theme .back-to-top-btn:hover {
    background: #e89050;
    border-color: #d4753e;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    body:not(.light-theme) {
        color: #e8dcc8;
        background: linear-gradient(135deg, #2a1f15 0%, #3d2e20 100%);
    }
    
    body:not(.light-theme) header {
        background: #3d2e20;
        color: #e8dcc8;
        border-color: #8b5a2b;
    }
    
    body:not(.light-theme) .header-title {
        color: #d4a574;
    }
    
    body:not(.light-theme) .last-update {
        color: #a89579;
    }
    
    body:not(.light-theme) .search-box {
        background: #3d2e20;
        color: #e8dcc8;
        border-color: #8b5a2b;
    }
    
    body:not(.light-theme) .search-box:focus {
        border-color: #d4753e;
    }
    
    body:not(.light-theme) .search-box::placeholder {
        color: #aaa;
    }
    
    body:not(.light-theme) .clear-btn {
        background: #5a5a5a;
        border-color: #4a4a4a;
    }
    
    body:not(.light-theme) .clear-btn:hover {
        background: #c87840;
        border-color: #a65e30;
    }
    
    body:not(.light-theme) .search-btn {
        background: #c87840;
        border-color: #a65e30;
    }
    
    body:not(.light-theme) .search-btn:hover {
        background: #e89050;
        border-color: #d4753e;
    }
    
    body:not(.light-theme) .search-results {
        color: #a89579;
    }
    
    body:not(.light-theme) .search-results.active {
        color: #e8995e;
    }
    
    body:not(.light-theme) .post-card {
        background: #3d2e20;
        border-left: 5px solid #d4753e;
        border-top: 2px solid #8b5a2b;
        border-bottom: 2px solid #8b5a2b;
        border-right: 0;
        box-shadow: none !important;
    }
    
    body:not(.light-theme) .post-title {
        color: #e8c9a0;
    }
    
    body:not(.light-theme) .post-author {
        color: #e8995e;
    }
    
    body:not(.light-theme) .post-date {
        color: #a89579;
    }
    
    body:not(.light-theme) .post-summary {
        color: #c9b89d;
    }
    
    body:not(.light-theme) .file-size {
        color: #a89579;
    }
    
    body:not(.light-theme) .tag {
        background: #5a4232;
        color: #e8c9a0;
        border-color: #8b5a2b;
    }
    
    body:not(.light-theme) .highlight {
        background-color: #ffff00;
        color: #000;
    }
    
    body:not(.light-theme) footer {
        background: #3d2e20;
        border-color: #8b5a2b;
    }
    
    body:not(.light-theme) .footer-text {
        color: #a89579;
    }
    
    body:not(.light-theme) .popup-overlay {
        background-color: rgba(42, 31, 21, 0.85);
    }
    
    body:not(.light-theme) .popup-content {
        background: #3d2e20;
        color: #e8dcc8;
        border-color: #d4753e;
    }
    
    body:not(.light-theme) .popup-header {
        border-bottom-color: #5a4232;
    }
    
    body:not(.light-theme) .popup-header h3 {
        color: #e8c9a0;
    }
    
    body:not(.light-theme) .popup-close {
        color: #a89579;
    }
    
    body:not(.light-theme) .popup-close:hover {
        background-color: #5a4232;
        color: #e8dcc8;
    }
    
    body:not(.light-theme) .popup-footer {
        border-top-color: #5a4232;
    }
    
    body:not(.light-theme) .btn-secondary {
        background: #5a4232;
        color: #e8c9a0;
        border-color: #8b5a2b;
    }
    
    body:not(.light-theme) .btn-secondary:hover {
        background: #6d5242;
    }
    
    body:not(.light-theme) .qr-container {
        background: #5a4232;
        border-color: #8b5a2b;
    }
    
    body:not(.light-theme) .back-to-top-btn {
        background: #d4753e;
        border-color: #b85d2c;
    }
    
    body:not(.light-theme) .back-to-top-btn:hover {
        background: #e89050;
        border-color: #d4753e;
    }
}

/* FORCE REMOVE ALL SHADOWS FROM CARDS */
.post-card,
.post-card:hover,
.post-card:focus,
.post-card:active,
article.post-card,
article.post-card:hover,
article.post-card:focus,
article.post-card:active {
    box-shadow: none !important;
    -webkit-box-shadow: none !important;
    -moz-box-shadow: none !important;
}