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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f3f4f6;
    min-height: 100vh;
    color: #1f2937;
}

h1,
h2,
h3,
p {
    margin: 0;
}

img,
svg {
    display: block;
}

input,
button,
select {
    font-family: inherit;
    font-size: 100%;
    color: inherit;
    margin: 0;
    padding: 0;
}

/* Layout & Sizing */
.container {
    width: 100%;
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
}
.mx-auto {
    margin-left: auto;
    margin-right: auto;
}
.max-w-2xl {
    max-width: 42rem;
}
.max-w-full {
    max-width: 100%;
}
.w-full {
    width: 100%;
}
.h-full {
    height: 100%;
}
.min-w-0 {
    min-width: 0;
}

.w-5 {
    width: 1.25rem;
}
.h-5 {
    height: 1.25rem;
}
.w-6 {
    width: 1.5rem;
}
.h-6 {
    height: 1.5rem;
}
.w-20 {
    width: 5rem;
}
.h-20 {
    height: 5rem;
}
.w-40 {
    width: 10rem;
}

/* Spacing */
.px-4 {
    padding-left: 1rem;
    padding-right: 1rem;
}
.py-8 {
    padding-top: 2rem;
    padding-bottom: 2rem;
}
.py-3 {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}
.py-2 {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}
.p-4 {
    padding: 1rem;
}
.p-2 {
    padding: 0.5rem;
}
.pb-4 {
    padding-bottom: 1rem;
}

.m-0 {
    margin: 0;
}
.mb-4 {
    margin-bottom: 1rem;
}
.mb-8 {
    margin-bottom: 2rem;
}
.mt-2 {
    margin-top: 0.5rem;
}
.mt-3 {
    margin-top: 0.75rem;
}
.mt-4 {
    margin-top: 1rem;
}
.mr-2 {
    margin-right: 0.5rem;
}
.my-4 {
    margin-top: 1rem;
    margin-bottom: 1rem;
}

/* Flexbox & Grid */
.flex {
    display: flex;
}
.flex-col {
    flex-direction: column;
}
.flex-1 {
    flex: 1 1 0%;
}
.items-center {
    align-items: center;
}
.items-start {
    align-items: flex-start;
}
.justify-center {
    justify-content: center;
}
.justify-between {
    justify-content: space-between;
}

.gap-1\.5 {
    gap: 0.375rem;
}
.gap-2 {
    gap: 0.5rem;
}
.gap-4 {
    gap: 1rem;
}
.gap-6 {
    gap: 1.5rem;
}
.space-y-4 > * + * {
    margin-top: 1rem;
}

.grid {
    display: grid;
}
.grid-cols-1 {
    grid-template-columns: repeat(1, minmax(0, 1fr));
}
.grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
.col-span-full {
    grid-column: 1 / -1;
}

@media (min-width: 768px) {
    .md\:grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .lg\:grid-cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Typography */
.text-4xl {
    font-size: 2.25rem;
    line-height: 2.5rem;
}
.text-2xl {
    font-size: 1.5rem;
    line-height: 2rem;
}
.text-xl {
    font-size: 1.25rem;
    line-height: 1.75rem;
}
.text-sm {
    font-size: 0.875rem;
    line-height: 1.25rem;
}
.font-bold {
    font-weight: 700;
}
.font-medium {
    font-weight: 500;
}
.font-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.text-center {
    text-align: center;
}
.whitespace-pre-wrap {
    white-space: pre-wrap;
}
.whitespace-normal {
    white-space: normal;
}
.break-words {
    overflow-wrap: break-word;
    word-break: break-word;
}
.underline {
    text-decoration: underline;
}

/* Colors & Backgrounds */
.text-white {
    color: #ffffff;
}
.text-gray-900 {
    color: #111827;
}
.text-gray-800 {
    color: #1f2937;
}
.text-gray-700 {
    color: #374151;
}
.text-gray-600 {
    color: #4b5563;
}
.text-gray-400 {
    color: #9ca3af;
}
.text-gray-300 {
    color: #d1d5db;
}
.hover\:text-gray-600:hover {
    color: #4b5563;
}

.text-red-600 {
    color: #dc2626;
}
.text-red-500 {
    color: #ef4444;
}
.text-green-600 {
    color: #16a34a;
}
.text-blue-500 {
    color: #3b82f6;
}
.hover\:text-blue-700:hover {
    color: #1d4ed8;
}

.bg-gray-100 {
    background-color: #f3f4f6;
}
.bg-gray-50 {
    background-color: #f9fafb;
}
.bg-red-50 {
    background-color: #fef2f2;
}

.border {
    border: 1px solid #d1d5db;
}
.border-b {
    border-bottom: 1px solid #e5e7eb;
}
.border-gray-300 {
    border-color: #d1d5db;
}

/* Radius & Shadows */
.rounded {
    border-radius: 0.25rem;
}
.rounded-lg {
    border-radius: 0.5rem;
}
.rounded-xl {
    border-radius: 0.75rem;
}
.rounded-full {
    border-radius: 9999px;
}
.shadow {
    box-shadow:
        0 1px 3px 0 rgba(0, 0, 0, 0.1),
        0 1px 2px 0 rgba(0, 0, 0, 0.06);
}
.shadow-md {
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Position & Display */
.relative {
    position: relative;
}
.absolute {
    position: absolute;
}
.right-3 {
    right: 0.75rem;
}
.top-1\/2 {
    top: 50%;
}
.transform {
    transform: translateY(-50%);
}
.-translate-y-1\/2 {
    transform: translateY(-50%);
}
.cursor-pointer {
    cursor: pointer;
}
.hidden {
    display: none !important;
}
.block {
    display: block;
}

/* Interactive & Forms */
#searchInput {
    background-color: #ffffff;
    border: none;
    outline: none;
    transition: box-shadow 0.15s ease-in-out;
}

#searchInput:focus {
    box-shadow:
        0 0 0 2px #3b82f6,
        0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

#clearSearch {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#commentsFilterOption {
    padding: 0.375rem 0.75rem;
    cursor: pointer;
    outline: none;
}

#densitySelect,
#customDensityInput {
    height: 32px;
    font-size: 0.875rem;
    line-height: 1.25rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background-color: #ffffff;
    color: #111827;
    box-sizing: border-box;
}

#densitySelect {
    padding: 0 0.5rem;
    cursor: pointer;
    outline: none;
}

#customDensityInput {
    padding: 0 0.5rem;
    width: 7.25rem;
    text-align: center;
}

#commentsFilterOption:focus,
#densitySelect:focus,
#customDensityInput:focus {
    border-color: #3b82f6;
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.3s ease,
        visibility 0.3s ease;
}

.modal.show {
    display: flex;
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border-radius: 8px;
    width: 80%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    font-weight: bold;
    font-size: 28px;
    float: right;
    color: #aaa;
    line-height: 1;
    cursor: pointer;
    outline: none;
}

.modal-close:hover {
    color: black;
}

/* App Cards */
.app-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    transition:
        transform 0.2s,
        box-shadow 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.app-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 12px rgba(0, 0, 0, 0.15);
}

.screenshots-container {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding: 8px 0;
    scrollbar-width: thin;
}

.screenshots-container img {
    height: 200px;
    border-radius: 8px;
    object-fit: cover;
}

.description-toggle,
.comments-toggle {
    color: #3b82f6;
    cursor: pointer;
    text-decoration: underline;
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
    font-family: inherit;
}

.comments-toggle {
    display: flex;
    align-items: center;
}

.download-btn {
    background-color: #3b82f6;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s;
}

.download-btn:hover {
    background-color: #2563eb;
}

.version-history-btn {
    color: #3b82f6;
    cursor: pointer;
    text-decoration: underline;
    display: inline-block;
}

/* Ratings */
.rating {
    display: flex;
    align-items: center;
    gap: 4px;
}

.rating-star {
    color: #fbbf24;
}

.rating-star-half {
    position: relative;
    display: inline-block;
}

.rating-star-bg {
    color: #d1d5db;
}

.rating-star-fg {
    color: #fbbf24;
    position: absolute;
    left: 0;
    top: 0;
    width: 50%;
    overflow: hidden;
}

/* Image Preview Modal */
#imagePreviewModal {
    display: flex;
    align-items: center;
    justify-content: center;
}

#imagePreviewModal .modal-content {
    background: transparent;
    box-shadow: none;
    margin: 0;
    padding: 0;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    overflow: visible;
    position: relative;
}

#imagePreviewModal .imageClose {
    position: fixed;
    top: 20px;
    right: 20px;
    color: white;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

#imagePreviewModal .imageClose:hover {
    color: #ddd;
}

#previewImage {
    max-height: 85vh;
    max-width: 85vw;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#prevImage,
#nextImage {
    opacity: 0.8;
    transition: opacity 0.2s;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    padding: 12px;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

#prevImage svg,
#nextImage svg {
    width: 24px;
    height: 24px;
    stroke: #ffffff;
    display: block;
}

#prevImage {
    left: 20px;
}
#nextImage {
    right: 20px;
}

#prevImage:hover,
#nextImage:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.7);
}

@media (max-width: 640px) {
    #prevImage,
    #nextImage {
        padding: 8px;
    }

    #prevImage svg,
    #nextImage svg {
        width: 20px;
        height: 20px;
    }
}

#imageProgress {
    position: absolute;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: opacity 0.2s;
    white-space: nowrap;
    z-index: 10;
}

#imageProgress:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* GitHub Sub-header Link */
.github-sub-link {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 1rem;
    padding: 0.25rem 0.625rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #4b5563;
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 9999px;
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: all 0.15s ease-in-out;
}

.github-sub-link:hover {
    color: #111827;
    background-color: #f9fafb;
    border-color: #d1d5db;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
}

.github-sub-link svg {
    width: 1rem;
    height: 1rem;
    fill: currentColor;
    flex-shrink: 0;
}
