/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    color: white;
    margin-bottom: 2rem;
    padding: 2rem 0 1rem;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

header p {
    font-size: 1.1rem;
    opacity: 0.95;
    margin-bottom: 0.5rem;
}

.wiki-link {
    margin-top: 0.5rem;
}

.wiki-link a {
    color: #fff;
    text-decoration: none;
    font-size: 0.95rem;
    opacity: 0.9;
    transition: opacity 0.3s;
    display: inline-block;
}

.wiki-link a:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Main container */
main {
    max-width: 1600px;
    margin: 0 auto;
}

/* Upload page */
.upload-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    max-width: 1000px;
    margin: 0 auto;
}

.upload-box {
    background: white;
    border-radius: 15px;
    padding: 2.5rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.upload-box h2 {
    margin-bottom: 1.5rem;
    color: #667eea;
}

.file-input-wrapper {
    margin-bottom: 1.5rem;
}

input[type="file"] {
    display: none;
}

.file-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    border: 3px dashed #667eea;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    background: #f8f9ff;
}

.file-label:hover {
    background: #e8ebff;
    border-color: #764ba2;
}

.file-icon {
    font-size: 2rem;
    margin-right: 1rem;
}

.file-text {
    font-size: 1.1rem;
    color: #667eea;
}

.upload-btn {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s;
}

.upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.preview-area {
    margin-top: 1.5rem;
    text-align: center;
}

.preview-area h3 {
    margin-bottom: 1rem;
    color: #667eea;
}

#image-preview {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* Instructions */
.instructions {
    background: white;
    border-radius: 15px;
    padding: 2.5rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.instructions h2 {
    color: #667eea;
    margin-bottom: 1rem;
}

.instructions ol {
    margin-left: 1.5rem;
    line-height: 1.8;
    margin-bottom: 1.5rem;
}

.instructions li {
    margin-bottom: 0.5rem;
}

.info-box {
    background: #f8f9ff;
    padding: 1.5rem;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.info-box h3 {
    color: #667eea;
    margin-bottom: 0.5rem;
}

.info-box p {
    line-height: 1.6;
    color: #555;
}

/* Pattern Workspace */
.pattern-workspace {
    display: grid;
    grid-template-columns: 250px 1fr 450px;
    gap: 1.5rem;
    background: white;
    border-radius: 15px;
    padding: 1.5rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

/* Sidebar */
.sidebar {
    background: #f8f9ff;
    padding: 1.5rem;
    border-radius: 10px;
}

.original-preview {
    text-align: center;
}

.original-preview h2 {
    color: #667eea;
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.thumbnail {
    width: 100%;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    margin-bottom: 1rem;
}

.new-upload-btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    background: #667eea;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 0.9rem;
    transition: background 0.3s;
}

.new-upload-btn:hover {
    background: #764ba2;
}

/* Main Controls */
.main-controls {
    display: flex;
    flex-direction: column;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #e0e0e0;
}

.tab-btn {
    padding: 0.75rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: #666;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.tab-btn:hover {
    color: #667eea;
}

.tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

/* Tab Content */
.tab-content {
    flex: 1;
    overflow-y: auto;
    max-height: calc(100vh - 300px);
    padding-right: 0.5rem;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
}

.tab-pane h3 {
    color: #667eea;
    margin-bottom: 0.5rem;
    font-size: 1.3rem;
}

.tab-description {
    color: #666;
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

/* Pattern Grid */
.pattern-grid-modern {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
}

.pattern-card {
    background: #f8f9ff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem 0.5rem;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.pattern-card:hover {
    border-color: #667eea;
    background: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.pattern-card.selected {
    border-color: #667eea;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.pattern-card.selected .pattern-code,
.pattern-card.selected .pattern-label {
    color: white;
}

.pattern-code {
    font-size: 1.5rem;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    color: #667eea;
    margin-bottom: 0.3rem;
}

.pattern-label {
    font-size: 0.8rem;
    color: #666;
}

/* Control Rows */
.control-row {
    margin-bottom: 1.5rem;
}

.control-row input[type="checkbox"] {
    width: auto;
    height: auto;
    cursor: pointer;
}

.control-section-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 2rem 0;
}

.subsection-title {
    color: #764ba2;
    font-size: 1rem;
    font-weight: 600;
    margin: 1.5rem 0 1rem;
}

.control-row label {
    display: block;
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.control-with-value {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.control-with-value input[type="range"] {
    flex: 1;
}

.value-display {
    min-width: 70px;
    font-weight: 700;
    color: #667eea;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    text-align: right;
}

.hint {
    font-size: 0.85rem;
    color: #999;
    margin-top: 0.3rem;
    font-style: italic;
}

/* Range Sliders */
input[type="range"] {
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    transition: background 0.3s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #764ba2;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
    transition: background 0.3s;
}

input[type="range"]::-moz-range-thumb:hover {
    background: #764ba2;
}

/* Size Mode Toggle */
.size-mode-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.mode-btn {
    flex: 1;
    padding: 0.75rem;
    background: #f0f0f0;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s;
}

.mode-btn:hover {
    background: #e8ebff;
    border-color: #667eea;
}

.mode-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.size-mode {
    display: none;
}

.size-mode.active {
    display: block;
}

.mode-description {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    font-style: italic;
}

/* Preset Grid */
.preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.size-preset {
    background: #f8f9ff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

.size-preset:hover {
    border-color: #667eea;
    background: white;
}

.size-preset.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.size-preset.active .preset-name,
.size-preset.active .preset-size {
    color: white;
}

.preset-name {
    display: block;
    font-weight: bold;
    font-size: 0.95rem;
    color: #667eea;
    margin-bottom: 0.25rem;
}

.preset-size {
    display: block;
    font-size: 0.75rem;
    color: #999;
}

/* Action Bar */
.action-bar {
    padding-top: 1rem;
    border-top: 2px solid #e0e0e0;
    margin-top: auto;
}

.generate-btn {
    width: 100%;
    padding: 1rem 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.generate-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

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

.btn-icon {
    font-size: 1.3rem;
}

/* Preview Panel */
.preview-panel {
    background: #f8f9ff;
    padding: 1.5rem;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
}

.preview-panel h2 {
    color: #667eea;
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.loading {
    text-align: center;
    padding: 3rem 1rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.placeholder {
    text-align: center;
    padding: 4rem 1rem;
    color: #999;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

#result-area {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#generated-pattern {
    width: 100%;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.pattern-info {
    text-align: center;
}

.pattern-name-display {
    font-weight: bold;
    color: #667eea;
    font-size: 1.1rem;
    margin-bottom: 0.3rem;
}

.cache-status {
    font-size: 0.85rem;
    color: #666;
    font-style: italic;
}

.download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: #667eea;
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: bold;
    transition: background 0.3s;
}

.download-btn:hover {
    background: #764ba2;
}

/* Footer */
footer {
    text-align: center;
    color: white;
    margin-top: 2rem;
    padding: 1.5rem 0;
    opacity: 0.9;
}

/* Responsive */
@media (max-width: 1400px) {
    .pattern-workspace {
        grid-template-columns: 1fr;
    }

    .tab-content {
        max-height: 500px;
    }
}

@media (max-width: 768px) {
    .upload-container {
        grid-template-columns: 1fr;
    }

    header h1 {
        font-size: 2rem;
    }

    .pattern-grid-modern {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    .tabs {
        flex-wrap: wrap;
    }

    .tab-btn {
        flex: 1;
        min-width: 100px;
    }
}
