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

:root {
    --bg-primary: #f5f0e6;
    --bg-secondary: #ebe5d9;
    --text-primary: #2d2d2d;
    --text-secondary: #5a5a5a;
    --accent-red: #c41e3a;
    --accent-blue: #1e3a5f;
    --accent-green: #2d5a27;
    --shadow-soft: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-hover: 0 8px 24px rgba(0,0,0,0.12);
}

body {
    font-family: 'Source Sans 3', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s, visibility 0.5s;
}

#loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.spinner svg {
    width: 60px;
    height: 60px;
    color: var(--accent-red);
    animation: spin 1s linear infinite;
}

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

#loading-overlay p {
    margin-top: 16px;
    font-family: 'Playfair Display', serif;
    font-style: italic;
    color: var(--text-secondary);
}

/* Header */
header {
    text-align: center;
    padding: 48px 24px 32px;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}

h1 {
    font-family: 'Playfair Display', serif;
    font-size: clamp(2.5rem, 8vw, 4rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
    cursor: pointer;
    user-select: none;
    transition: transform 0.3s;
}

h1:hover {
    transform: scale(1.02);
}

.subtitle {
    font-family: 'Playfair Display', serif;
    font-size: clamp(1rem, 3vw, 1.25rem);
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.credit {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.credit a {
    color: var(--accent-blue);
    text-decoration: none;
    transition: color 0.2s;
}

.credit a:hover {
    color: var(--accent-red);
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 0 24px 32px;
    flex-wrap: wrap;
}

#search {
    padding: 12px 20px;
    border: 2px solid var(--bg-secondary);
    border-radius: 30px;
    font-size: 1rem;
    font-family: inherit;
    background: white;
    min-width: 240px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#search:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 4px rgba(30, 58, 95, 0.1);
}

.controls button {
    padding: 12px 20px;
    border: none;
    border-radius: 30px;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--text-primary);
    color: white;
}

.controls button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.controls button.inactive {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

/* Grid */
#grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
    padding: 0 24px 48px;
    max-width: 1400px;
    margin: 0 auto;
}

.pattern-card {
    display: flex;
    gap: 16px;
    padding: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-soft);
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    border: 1px solid rgba(0,0,0,0.05);
}

.pattern-card:hover {
    transform: translateY(-4px) scale(1.01);
    box-shadow: var(--shadow-hover);
}

.pattern-canvas {
    width: 120px;
    height: 120px;
    border-radius: 8px;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.1);
}

.pattern-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.pattern-info h3 {
    font-family: 'Playfair Display', serif;
    font-size: 1.25rem;
    margin-bottom: 8px;
}

.pattern-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    flex-grow: 1;
    line-height: 1.5;
}

.origin-badge {
    display: inline-block;
    padding: 4px 12px;
    background: var(--bg-secondary);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 12px;
    align-self: flex-start;
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px;
    font-family: 'Playfair Display', serif;
    font-style: italic;
    color: var(--text-secondary);
    font-size: 1.25rem;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.modal.open {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 32px;
    background: white;
    border-radius: 16px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal.open .modal-content {
    transform: scale(1);
}

#modal-canvas {
    border-radius: 12px;
    box-shadow: var(--shadow-hover);
}

.modal-info {
    text-align: center;
    max-width: 400px;
}

.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-secondary);
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: var(--accent-red);
    color: white;
    transform: rotate(90deg);
}

#modal-title {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    margin-bottom: 12px;
}

#modal-etymology {
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.6;
}

#modal-origin {
    display: inline-block;
    padding: 6px 16px;
    background: var(--accent-blue);
    color: white;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 20px;
}

#new-colors-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 30px;
    background: linear-gradient(135deg, var(--accent-red), var(--accent-blue));
    color: white;
    font-size: 1rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

#new-colors-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(196, 30, 58, 0.3);
}

.nav-hint {
    margin-top: 16px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Footer */
footer {
    text-align: center;
    padding: 32px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid rgba(0,0,0,0.05);
}

footer p {
    margin-bottom: 12px;
    color: var(--text-secondary);
}

footer a {
    color: var(--accent-blue);
    text-decoration: none;
    transition: color 0.2s;
}

footer a:hover {
    color: var(--accent-red);
}

.share-btn {
    display: inline-block;
    padding: 10px 20px;
    background: #1da1f2;
    color: white !important;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.875rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.share-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(29, 161, 242, 0.3);
    color: white !important;
}

/* Fashion Show Mode */
body.fashion-show {
    animation: rainbow-bg 5s linear infinite;
}

body.fashion-show .pattern-card {
    animation: dance 0.5s ease-in-out infinite alternate;
}

body.fashion-show .pattern-card:nth-child(even) {
    animation-delay: 0.25s;
}

@keyframes rainbow-bg {
    0% { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
}

@keyframes dance {
    from { transform: rotate(-2deg) scale(1); }
    to { transform: rotate(2deg) scale(1.02); }
}

/* Responsive */
@media (max-width: 768px) {
    #grid {
        grid-template-columns: 1fr;
        padding: 0 16px 32px;
    }
    
    .pattern-card {
        padding: 16px;
    }
    
    .pattern-canvas {
        width: 100px;
        height: 100px;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
        padding: 0 16px 24px;
    }
    
    #search {
        min-width: unset;
    }
    
    .modal-content {
        padding: 24px 16px;
        margin: 16px;
    }
    
    .nav-hint {
        display: none;
    }
}

@media (max-width: 400px) {
    header {
        padding: 32px 16px 24px;
    }
    
    .pattern-info h3 {
        font-size: 1.1rem;
    }
    
    .pattern-info p {
        font-size: 0.8rem;
    }
}