/* CSS Variables */
:root {
    --primary: 263 35% 35%;
    --primary-foreground: 210 20% 98%;
    --background: 0 0% 100%;
    --foreground: 222.2 84% 4.9%;
    --card: 0 0% 100%;
    --card-foreground: 222.2 84% 4.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 222.2 84% 4.9%;
    --muted: 210 40% 96%;
    --muted-foreground: 215.4 16.3% 46.9%;
    --accent: 210 40% 96%;
    --accent-foreground: 222.2 84% 4.9%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 210 20% 98%;
    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;
    --ring: 222.2 84% 4.9%;
    --radius: 0.5rem;

    /* Gradients */
    --gradient-hero: linear-gradient(135deg, hsl(270 50% 25%) 0%, hsl(290 60% 35%) 35%, hsl(283 89% 74%) 70%, hsl(264 83% 69%) 100%);
    --gradient-card: linear-gradient(145deg, hsl(0 0% 100% / 0.95) 0%, hsl(0 0% 100% / 0.85) 100%);
    --gradient-primary: linear-gradient(135deg, hsl(270 50% 25%) 0%, hsl(290 60% 35%) 100%);

    /* Shadows */
    --shadow-soft: 0 4px 6px -1px hsl(0 0% 0% / 0.1), 0 2px 4px -1px hsl(0 0% 0% / 0.06);
    --shadow-medium: 0 10px 15px -3px hsl(0 0% 0% / 0.1), 0 4px 6px -2px hsl(0 0% 0% / 0.05);
    --shadow-large: 0 25px 50px -12px hsl(0 0% 0% / 0.25);
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: 222.2 84% 4.9%;
        --foreground: 210 20% 98%;
        --card: 222.2 84% 4.9%;
        --card-foreground: 210 20% 98%;
        --popover: 222.2 84% 4.9%;
        --popover-foreground: 210 20% 98%;
        --muted: 217.2 32.6% 17.5%;
        --muted-foreground: 215 20.2% 65.1%;
        --accent: 217.2 32.6% 17.5%;
        --accent-foreground: 210 20% 98%;
        --border: 217.2 32.6% 17.5%;
        --input: 217.2 32.6% 17.5%;
        --ring: 212.7 26.8% 83.9%;
    }
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
    color: hsl(var(--foreground));
    background: hsl(var(--background));
}

/* Starry background */
.starry-background {
    position: relative;
    overflow: hidden;
}

.starry-background::before,
.starry-background::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.starry-background::before {
    background-image: 
        radial-gradient(2px 2px at 20% 30%, rgba(255,255,255,0.8), transparent),
        radial-gradient(2px 2px at 40% 70%, rgba(255,255,255,0.6), transparent),
        radial-gradient(1px 1px at 90% 40%, rgba(255,255,255,0.9), transparent),
        radial-gradient(1px 1px at 50% 50%, rgba(255,255,255,0.7), transparent),
        radial-gradient(2px 2px at 80% 10%, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 10% 80%, rgba(255,255,255,0.6), transparent),
        radial-gradient(1px 1px at 70% 20%, rgba(255,255,255,0.9), transparent),
        radial-gradient(2px 2px at 30% 90%, rgba(255,255,255,0.5), transparent),
        radial-gradient(1px 1px at 60% 10%, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 15% 60%, rgba(255,255,255,0.7), transparent);
    background-repeat: repeat;
    background-size: 200px 200px;
    animation: twinkle 4s linear infinite;
}

.starry-background::after {
    background-image:
        radial-gradient(3px 3px at 25% 25%, rgba(255,255,255,1), transparent),
        radial-gradient(2px 2px at 75% 75%, rgba(255,255,255,0.9), transparent),
        radial-gradient(3px 3px at 60% 15%, rgba(255,255,255,0.8), transparent),
        radial-gradient(2px 2px at 10% 45%, rgba(255,255,255,1), transparent),
        radial-gradient(3px 3px at 85% 60%, rgba(255,255,255,0.9), transparent),
        radial-gradient(2px 2px at 45% 85%, rgba(255,255,255,0.8), transparent);
    background-repeat: repeat;
    background-size: 300px 300px;
    animation: twinkle 6s linear infinite reverse;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* Layout */
.min-h-screen {
    min-height: 100vh;
}

.bg-gradient-hero {
    background: var(--gradient-hero);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 3rem;
}

.header-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.icon-wrapper {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    border-radius: 50%;
    padding: 1rem;
    box-shadow: var(--shadow-large);
}

.icon {
    height: 2rem;
    width: 2rem;
    color: white;
}

.main-title {
    font-size: 3rem;
    font-weight: bold;
    color: white;
    margin-bottom: 1rem;
    line-height: 1.1;
}

.subtitle {
    font-size: 1.25rem;
    color: rgba(255, 255, 255, 0.8);
    max-width: 48rem;
    margin: 0 auto;
}

/* Main content */
.main-content {
    max-width: 48rem;
    margin: 0 auto;
}

.card {
    background: var(--gradient-card);
    box-shadow: var(--shadow-large);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius);
    backdrop-filter: blur(20px);
}

.card-content {
    padding: 2rem;
}

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

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--foreground));
    margin-bottom: 0.5rem;
}

.form-help {
    margin-bottom: 0.75rem;
}

.form-help p {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.input-wrapper {
    position: relative;
}

.form-input {
    width: 100%;
    height: 3rem;
    padding: 0.75rem 0.75rem 0.75rem 2.5rem;
    font-size: 1.125rem;
    background: hsl(var(--background));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.2s;
}

.form-input:focus {
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 2px rgba(222, 84, 4.9, 0.2);
}

.input-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    height: 1rem;
    width: 1rem;
    color: hsl(var(--muted-foreground));
}

.submit-btn {
    width: 100%;
    height: 3rem;
    font-size: 1.125rem;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: opacity 0.3s;
    box-shadow: var(--shadow-medium);
}

.submit-btn:hover {
    opacity: 0.9;
}

.submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-icon {
    height: 1.25rem;
    width: 1.25rem;
}

/* Loading */
.loading-container {
    margin-top: 2rem;
    text-align: center;
}

.loading-card {
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--radius);
    padding: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.loading-spinner {
    height: 2rem;
    width: 2rem;
    margin: 0 auto 1rem;
    border: 2px solid hsl(var(--primary));
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

/* Success state */
.success-container {
    text-align: center;
}

.success-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.success-icon svg {
    height: 2rem;
    width: 2rem;
    color: #22c55e;
}

.success-title {
    font-size: 1.5rem;
    font-weight: bold;
    color: hsl(var(--foreground));
    margin-bottom: 1.5rem;
}

.image-container {
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--radius);
    padding: 0.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.converted-image {
    width: 100%;
    border-radius: var(--radius);
    box-shadow: var(--shadow-medium);
}

.button-group {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-outline {
    padding: 0.75rem 1.5rem;
    background: transparent;
    color: hsl(var(--foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    transition: background-color 0.2s;
    box-shadow: var(--shadow-soft);
}

.btn-outline:hover {
    background: hsl(var(--accent));
}

.btn-primary {
    padding: 0.75rem 1.5rem;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    transition: opacity 0.3s;
    box-shadow: var(--shadow-medium);
}

.btn-primary:hover {
    opacity: 0.9;
}

/* Features */
.features-grid {
    margin-top: 4rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    max-width: 64rem;
    margin-left: auto;
    margin-right: auto;
}

.feature-card {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.feature-content {
    padding: 1.5rem;
    text-align: center;
}

.feature-icon {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    padding: 0.75rem;
    width: fit-content;
    margin: 0 auto 1rem;
}

.feature-icon .icon {
    height: 1.5rem;
    width: 1.5rem;
    color: white;
}

.feature-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: white;
    margin-bottom: 0.5rem;
}

.feature-description {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.875rem;
}

/* Toast system */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: white;
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow-large);
    border-left: 4px solid;
    opacity: 1;
    transform: translateX(0);
    transition: all 0.3s ease;
    max-width: 20rem;
}

.toast-success {
    border-left-color: #22c55e;
}

.jason {
    line-height: 2rem;
}

.toast-error {
    border-left-color: hsl(var(--destructive));
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toast-icon {
    flex-shrink: 0;
}

.toast-icon svg {
    height: 1.25rem;
    width: 1.25rem;
}

.toast-success .toast-icon svg {
    color: #22c55e;
}

.toast-error .toast-icon svg {
    color: hsl(var(--destructive));
}

/* htmx utilities */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: block;
}

.htmx-request .submit-btn {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Image Display Section */
.image-display-section {
    margin-top: 2rem;
    width: 100vw;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
    padding: 2rem 0;
}

.checkerboard-container {
    background-image: 
        linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: #ffffff;
    border: 2px solid #e0e0e0;
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    box-shadow: var(--shadow-large);
}

.display-image {
    max-width: 100%;
    max-height: 600px;
    height: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-medium);
    object-fit: contain;
}

/* Dark mode checkerboard */
@media (prefers-color-scheme: dark) {
    .checkerboard-container {
        background-image: 
            linear-gradient(45deg, #404040 25%, transparent 25%), 
            linear-gradient(-45deg, #404040 25%, transparent 25%), 
            linear-gradient(45deg, transparent 75%, #404040 75%), 
            linear-gradient(-45deg, transparent 75%, #404040 75%);
        background-color: #2a2a2a;
        border-color: #404040;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .main-title {
        font-size: 2rem;
    }
    
    .subtitle {
        font-size: 1rem;
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .features-grid {
        grid-template-columns: 1fr;
    }
    
    .checkerboard-container {
        padding: 1rem;
        margin: 0 1rem;
        width: calc(100vw - 2rem);
        min-height: 300px;
    }
    
    .image-display-section {
        padding: 1rem 0;
    }
}