@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Apple Semantic Colors */
    --apple-bg: #000000;
    --apple-glass: rgba(28, 28, 30, 0.7);
    --apple-glass-heavy: rgba(28, 28, 30, 0.9);
    --apple-blue: #007AFF;
    --apple-blue-rgb: 0, 122, 255;
    --apple-gray: #8E8E93;
    --apple-card-border: rgba(255, 255, 255, 0.15);

    /* Semantic Aliases for backward compatibility */
    --primary: var(--apple-blue);
    --text-primary: #ffffff;
    --text-secondary: var(--apple-gray);
    --success: #34C759;

    /* Typography Stack */
    --font-stack: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Inter, sans-serif;

    /* Safe Areas */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    /* Transitions */
    --spring-bounce: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-stack);
    background-color: var(--apple-bg);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

.light-mode body {
    background:
        radial-gradient(circle at 20% 30%, rgba(0, 122, 255, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(175, 82, 222, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(52, 199, 89, 0.04) 0%, transparent 50%),
        linear-gradient(135deg, #F2F2F7 0%, #ffffff 100%);
    background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%;
    animation: gradientShift 20s ease infinite;
    color: var(--apple-text);
}

body {
    background:
        radial-gradient(circle at 20% 30%, rgba(0, 122, 255, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(175, 82, 222, 0.12) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(52, 199, 89, 0.08) 0%, transparent 50%),
        linear-gradient(135deg, #000000 0%, #0a0a0a 100%);
    background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%;
    animation: gradientShift 20s ease infinite;
    display: flex;
    justify-content: center;
}

@keyframes gradientShift {

    0%,
    100% {
        background-position: 0% 0%, 100% 100%, 50% 50%, 0% 0%;
    }

    50% {
        background-position: 100% 100%, 0% 0%, 25% 75%, 0% 0%;
    }
}

/* LIGHT MODE */
body.light-mode {
    --apple-bg: #f5f5f7;
    --apple-glass: rgba(255, 255, 255, 0.8);
    --apple-glass-heavy: rgba(255, 255, 255, 0.95);
    --apple-card-border: rgba(0, 0, 0, 0.1);
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --apple-gray: #86868b;

    background:
        radial-gradient(circle at 20% 30%, rgba(0, 122, 255, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(175, 82, 222, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(52, 199, 89, 0.05) 0%, transparent 50%),
        linear-gradient(135deg, #f5f5f7 0%, #e8e8ed 100%);
}

body.light-mode .result-card,
body.light-mode .drop-zone,
body.light-mode .feature-item {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

body.light-mode .modal {
    background: rgba(0, 0, 0, 0.4);
}

body.light-mode h1 {
    background: linear-gradient(180deg, #1d1d1f 0%, rgba(29, 29, 31, 0.7) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.container {
    width: 100%;
    max-width: 1800px;
    /* Increased for better 4K utilization */
    margin: 0 auto;
    padding: calc(2rem + var(--safe-top)) calc(2rem + var(--safe-right)) calc(2rem + var(--safe-bottom)) calc(2rem + var(--safe-left));
}

/* Large display optimization */
@media (min-width: 2000px) {
    .container {
        max-width: 2000px;
        /* Even wider for ultra-wide displays */
        padding-left: calc(3rem + var(--safe-left));
        padding-right: calc(3rem + var(--safe-right));
        padding-top: calc(1.5rem + var(--safe-top));
        /* Reduced top padding */
    }
}

@media (min-width: 2560px) {
    .container {
        max-width: 2200px;
        /* Maximum for 4K displays */
    }
}

/* 2-COLUMN LAYOUT FOR 4K DISPLAYS */
@media (min-width: 1800px) {
    .container {
        display: grid;
        grid-template-columns: 500px 1fr;
        grid-template-areas:
            "header header"
            "privacy privacy"
            "upload results"
            "features features";
        gap: 2rem;
        align-items: start;
    }

    header {
        grid-area: header;
    }

    .privacy-notice {
        grid-area: privacy;
    }

    .upload-section {
        grid-area: upload;
        position: sticky;
        top: 2rem;
    }

    #main_status,
    #btnDlAll,
    #output {
        grid-area: results;
    }

    .features {
        grid-area: features;
    }
}

header {
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
    z-index: 1;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.header-buttons {
    display: flex;
    gap: 0.5rem;
}

.header-buttons button {
    padding: 0.5rem 1rem !important;
    min-width: auto !important;
}

h1 {
    font-size: clamp(2rem, 6vw, 2.8rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    margin: 0 0 0.3rem 0;
    background: linear-gradient(180deg, #fff 0%, rgba(255, 255, 255, 0.7) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 1rem;
    color: var(--apple-blue);
    font-weight: 600;
    margin: 0;
    letter-spacing: 0.02em;
}

.description {
    color: var(--text-secondary);
    font-size: 0.95rem;
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.5;
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    /* Reduced from 1.5rem */
    margin: 1.5rem 0;
    /* Reduced from 3rem */
}

@media (min-width: 1400px) {
    .features {
        grid-template-columns: repeat(4, 1fr);
        margin: 1rem 0;
        /* Even smaller margin on large screens */
    }
}

@media (min-width: 2200px) {
    .features {
        grid-template-columns: repeat(4, 1fr);
        gap: 1.5rem;
        /* More spacing on 4K */
    }
}

.feature-item {
    background: var(--apple-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 0.5px solid var(--apple-card-border);
    border-radius: 16px;
    /* Reduced from 20px */
    padding: 1rem;
    /* Reduced from 1.5rem */
    transition: transform 0.3s var(--spring-bounce);
}

.feature-item:hover {
    transform: translateY(-3px);
    /* Reduced from -5px */
}

.feature-item h3 {
    font-size: 0.95rem;
    /* Reduced from 1.1rem */
    margin-bottom: 0.4rem;
    /* Reduced from 0.5rem */
    color: white;
}

.feature-item p {
    font-size: 0.8rem;
    /* Reduced from 0.9rem */
    color: var(--text-secondary);
    line-height: 1.4;
    margin: 0;
}

.privacy-notice {
    background: rgba(52, 199, 89, 0.1);
    border: 0.5px solid rgba(52, 199, 89, 0.2);
    border-radius: 16px;
    padding: 1rem 1.5rem;
    margin: 2rem 0;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    color: #34C759;
}

.privacy-notice svg {
    color: var(--success);
    flex-shrink: 0;
}

/* Modal System - CRITICAL/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--apple-glass);
    /* Assuming --apple-card-bg is meant to be --apple-glass based on context */
    border: 1px solid var(--apple-card-border);
    /* Assuming --apple-border is meant to be --apple-card-border based on context */
    border-radius: 28px;
    padding: 2.5rem;
    width: 100%;
    max-width: 550px;
    box-shadow: 0 40px 100px rgba(0, 0, 0, 0.8);
    transform: scale(0.9);
    transition: transform 0.4s var(--spring-bounce);
    /* Assuming --spring-heavy is meant to be --spring-bounce based on context */
}

.modal-overlay.active .modal {
    transform: scale(1);
}

/* Form Styling - Premium Inputs */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    /* Assuming --apple-text-secondary is meant to be --text-secondary based on context */
    margin-bottom: 0.6rem;
    padding-left: 0.5rem;
}

input[type="text"] {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--apple-card-border);
    /* Assuming --apple-border is meant to be --apple-card-border based on context */
    border-radius: 12px;
    padding: 0.8rem 1rem;
    color: white;
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s var(--spring-bounce);
    /* Assuming --spring is meant to be --spring-bounce based on context */
    outline: none;
}

input[type="text"]:focus {
    border-color: var(--apple-blue);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.2);
}

/* Reader Preview JAR Fix */
#reader-frame {
    background: #ffffff !important;
    border-radius: 16px;
    border: 1px solid var(--apple-card-border);
    /* Assuming --apple-border is meant to be --apple-card-border based on context */
    filter: invert(0.9) hue-rotate(180deg);
    /* Adaptive reading mode for dark theme */
}

/* Upload Area */
.upload-section {
    margin: 3rem 0;
}

/* Glassmorphism Refinement */
.upload-section {
    margin-bottom: 2rem;
}

@media (min-width: 1800px) {
    .upload-section {
        margin-bottom: 0;
    }
}

.drop-zone {
    background: var(--apple-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 2px dashed var(--apple-card-border);
    border-radius: 24px;
    padding: 3rem 2rem;
    /* Balanced size */
    text-align: center;
    transition: all 0.3s var(--spring-bounce);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    margin-bottom: 1.5rem;
}

@media (min-width: 1400px) {
    .drop-zone {
        padding: 3.5rem 3rem;
        /* Slightly larger on big screens but not excessive */
    }
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--apple-blue);
    background: rgba(var(--apple-blue-rgb), 0.1);
    transform: scale(1.02);
}

.drop-zone svg {
    width: 64px;
    height: 64px;
    color: var(--primary);
    margin-bottom: 1rem;
}

.drop-zone p {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.drop-zone span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* iPhone 15 Touch Targets & Safe Areas */
@media (max-width: 768px) {
    #output {
        grid-template-columns: 1fr;
    }

    .container {
        padding: calc(var(--safe-top) + 1rem) 1.25rem;
    }

    .modal {
        padding: 1.5rem;
    }

    .dl-btn {
        min-height: 50px;
        /* Enhanced touch target */
        width: 100%;
        border-radius: 16px;
    }

    h1 {
        font-size: 2.5rem;
    }
}

#file {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.options {
    margin-top: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: center;
}

.checkbox-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.checkbox-container input {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
}

/* Status & Results */
#main_status {
    padding: 1rem;
    border-radius: 12px;
    text-align: center;
    font-weight: 500;
    margin: 1.5rem 0;
    animation: fadeIn 0.3s ease;
}

#output {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-top: 0;
    position: relative;
    z-index: 1;
}

/* Standard wide screens - 2 columns */
@media (min-width: 1200px) and (max-width: 1799px) {
    #output {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Ultra-wide in 2-column layout - still 1 column for results */
@media (min-width: 1800px) and (max-width: 2559px) {
    #output {
        grid-template-columns: 1fr;
    }
}

/* 4K ultra-wide - 2 columns for results */
@media (min-width: 2560px) {
    #output {
        grid-template-columns: repeat(2, 1fr);
        gap: 2rem;
    }
}

/* Mobile */
@media (max-width: 768px) {
    #output {
        grid-template-columns: 1fr;
    }
}

.result-card {
    background: var(--apple-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 0.5px solid var(--apple-card-border);
    border-radius: 24px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    animation: fadeIn 0.5s var(--spring-bounce);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 1;
}

.result-header h3 {
    margin: 0;
    font-size: 1.1rem;
    word-break: break-word;
    color: white;
}

.cover-container {
    display: flex;
    gap: 1rem;
}

.cover-preview {
    width: 120px;
    height: 180px;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--apple-card-border);
    cursor: pointer;
    transition: transform 0.3s var(--spring-bounce);
    flex-shrink: 0;
}

.cover-preview:hover {
    transform: scale(1.05);
}

.cover-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cover-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.meta-badge {
    display: inline-block;
    background: rgba(0, 122, 255, 0.15);
    color: var(--apple-blue);
    padding: 0.35rem 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 0.5px solid rgba(0, 122, 255, 0.3);
}

.optimization-checklist {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.opt-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.opt-status {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.opt-status svg {
    width: 14px;
    height: 14px;
    stroke-width: 2.5;
}

/* Applied - We fixed it (Green) */
.opt-item.applied .opt-status {
    background: rgba(52, 199, 89, 0.2);
    color: #34C759;
    border: 1.5px solid #34C759;
}

.opt-item.applied span {
    color: var(--text-primary);
    font-weight: 500;
}

/* Verified - Already good (Blue) */
.opt-item.verified .opt-status {
    background: rgba(0, 122, 255, 0.15);
    color: #007AFF;
    border: 1.5px solid rgba(0, 122, 255, 0.5);
}

.opt-item.verified span {
    color: var(--text-secondary);
}

/* Warning - Couldn't fix (Orange) */
.opt-item.warning .opt-status {
    background: rgba(255, 159, 10, 0.2);
    color: #FF9F0A;
    border: 1.5px solid #FF9F0A;
}

.opt-item.warning span {
    color: #FF9F0A;
}

/* Skipped - Not needed (Gray) */
.opt-item.skipped .opt-status {
    background: rgba(142, 142, 147, 0.15);
    color: #8E8E93;
    border: 1.5px solid rgba(142, 142, 147, 0.3);
}

.opt-item.skipped span {
    color: var(--text-secondary);
    opacity: 0.6;
}

.result-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: auto;
}

/* Buttons */
.dl-btn {
    background: var(--apple-blue);
    color: white;
    border: none;
    padding: 0.9rem 1.8rem;
    border-radius: 14px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    transition: all 0.3s var(--spring-bounce);
    box-shadow: 0 10px 25px rgba(var(--apple-blue-rgb), 0.3);
}

.dl-btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 15px 35px rgba(var(--apple-blue-rgb), 0.4);
}

.dl-btn.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
}

.dl-btn.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

#btnDlAll {
    width: 100%;
    margin-bottom: 2rem;
    display: none;
}

#main_status {
    padding: 1rem;
    border-radius: 12px;
    text-align: center;
    font-weight: 500;
    margin: 1.5rem 0;
    display: none;
}

#btnDlAll {
    width: 100%;
    margin-bottom: 2rem;
}

/* History */
.history-section {
    margin-top: 4rem;
    padding-top: 3rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-top: 1.5rem;
}

.history-item {
    font-size: 0.9rem;
}

.history-item strong {
    color: #60a5fa;
    display: block;
    margin-bottom: 0.25rem;
}

.footer {
    margin-top: 4rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.footer a {
    color: var(--primary);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}