/* Global Styles */
* {
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
}

body {
    margin: 0;
    background: #e0dcd5;
    /* Desktop: Flex Column Layout for 100% viewport height */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Changed from height: 100vh to min-height to support all pages */
    line-height: 1.6;
    font-size: 14px;
}

/* Header */
header {
    padding: 16px 24px;
    background: #faf9f6;
    color: #1f2937;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.06);
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

header h1 {
    margin: 0;
    font-size: 22px;
    letter-spacing: -0.5px;
    color: #111827;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
    width: fit-content;
}

header p {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
}

/* Footer */
footer {
    background: #faf9f6;
    padding: 16px;
    text-align: center;
    font-size: 13px;
    color: #9ca3af;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

footer a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
    /* Added from index/about */
    transition: color 0.2s;
}

footer a:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

/* Card */
.card {
    background: #faf9f6;
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .08);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    width: 100%;
    letter-spacing: 0.5px;
    text-decoration: none;
    /* For 404/about links using btn class */
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2), 0 2px 4px -1px rgba(37, 99, 235, 0.1);
    font-size: 16px;
    padding: 14px 20px;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3), 0 4px 6px -2px rgba(37, 99, 235, 0.15);
    transform: translateY(-2px);
}

.btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(5, 150, 105, 0.2);
}

.btn-success:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    box-shadow: 0 10px 15px -3px rgba(5, 150, 105, 0.3);
    transform: translateY(-2px);
}

/* Navigation Buttons (Header) */
.about-btn {
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.2s;
    white-space: nowrap;
}

.about-btn:hover {
    background: #e5e7eb;
    color: #1f2937;
}

.back-btn {
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.back-btn:hover {
    background: #e5e7eb;
    color: #1f2937;
}

/* --- Index Page Specific --- */

/* Main Layout */
.index-main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 362px 1fr;
    gap: 16px;
    padding: 16px;
}

/* Left Panel */
.left-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding-right: 4px;
}

.left-panel select {
    width: 100%;
    padding: 12px 14px;
    padding-right: 36px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    color: #1f2937;
    background-color: #fff;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1.25em 1.25em;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.left-panel select:hover {
    border-color: #d1d5db;
    background-color: #f9fafb;
}

.left-panel select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
    background-color: #fff;
}

/* Form Elements */
label {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin-top: 20px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

label input[type="checkbox"] {
    margin: 0;
    width: 16px;
    height: 16px;
    accent-color: #2563eb;
    cursor: pointer;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

.btn-group-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* File Upload */
.file-upload-wrapper {
    position: relative;
    width: 100%;
    margin-top: 6px;
}

.file-upload-wrapper input[type=file] {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    top: 0;
    left: 0;
}

.upload-btn {
    width: 100%;
    padding: 10px 0;
    border: none;
    border-radius: 8px;
    background: linear-gradient(90deg, #2563eb, #3b82f6);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.upload-btn:hover {
    background: linear-gradient(90deg, #1e40af, #2563eb);
    transform: translateY(-1px);
}

.upload-preview {
    height: 138px;
    border: 1px dashed #ccc;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafafa;
    overflow: hidden;
}

.upload-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain
}

/* Color Grid */
.color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.color-item {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 4px;
    text-align: center;
    font-size: 12px;
}

.color-swatch {
    width: 100%;
    height: 18px;
    border-radius: 3px;
    margin-bottom: 2px;
}

/* Right Panel */
.right-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.right-panel .card {
    display: flex;
    flex-direction: column;
}

/* Canvas */
.canvas-wrap {
    position: relative;
    background: #fff;
    border-radius: 14px;
    padding: 10px;
    cursor: grab;
    overflow: auto;
    flex: 1;
    min-height: 0;
}

canvas {
    background: #fff
}

#tooltip {
    position: absolute;
    pointer-events: none;
    background: rgba(0, 0, 0, .75);
    color: #fff;
    padding: 4px 6px;
    font-size: 12px;
    border-radius: 4px;
    display: none
}

/* Mobile Utils */
.mobile-break {
    display: none;
}

.mobile-result {
    display: none;
}

/* --- About Page Specific --- */
.about-main {
    flex: 1;
    padding: 24px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.about-main .card {
    padding: 24px;
    margin-bottom: 20px;
}

.about-main h2 {
    font-size: 20px;
    margin: 0 0 16px 0;
    color: #1f2937;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.about-main h3 {
    font-size: 16px;
    margin: 20px 0 12px 0;
    color: #374151;
}

.about-main p {
    color: #4b5563;
    margin-bottom: 16px;
}

.about-main ul {
    padding-left: 20px;
    margin: 12px 0;
    color: #4b5563;
}

.about-main li {
    margin-bottom: 8px;
}

/* --- 404 Page Specific --- */
.notfound-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.notfound-main .card {
    padding: 40px;
    text-align: center;
    max-width: 480px;
    width: 100%;
}

.notfound-main h1 {
    font-size: 64px;
    margin: 0;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
    font-weight: 800;
}

.notfound-main h2 {
    font-size: 20px;
    color: #374151;
    margin: 16px 0 8px 0;
}

.notfound-main p {
    color: #6b7280;
    margin: 0 0 24px 0;
}

.notfound-main .btn {
    padding: 12px 24px;
}


/* --- Responsive Media Queries --- */
@media (max-width: 768px) {
    body {
        height: auto;
        overflow: visible;
        display: block;
        background: #e0dcd5;
    }

    /* Index Layout on Mobile */
    .index-main {
        display: flex;
        flex-direction: column;
        height: auto;
        padding: 10px;
        gap: 10px;
    }

    .left-panel {
        width: 100%;
    }

    .right-panel {
        order: -1;
        width: 100%;
        height: 500px;
        /* On mobile, give the canvas area a fixed height or let it scroll */
        min-height: 400px;
    }

    header {
        padding: 12px 16px;
    }

    header h1 {
        font-size: 18px;
    }

    header p {
        font-size: 11px;
    }

    .mobile-break {
        display: inline;
    }

    .desktop-pipe {
        display: none;
    }

    .canvas-wrap {
        display: none;
    }

    .mobile-result {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        overflow: hidden;
    }

    .mobile-result img {
        width: 100%;
        height: auto;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .mobile-hint {
        margin-top: 8px;
        font-size: 12px;
        color: #666;
        text-align: center;
    }

    .btn-group-row {
        gap: 8px;
    }
}

/* Floating QR Code */
.qr-float {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.qr-large {
    position: absolute;
    bottom: 80px;
    right: 0;
    background: #fff;
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.qr-large img {
    width: 180px;
    height: 180px;
    border-radius: 4px;
}

.qr-large p {
    margin: 0;
    font-size: 13px;
    color: #374151;
    font-weight: 500;
}

.qr-thumb {
    width: 60px;
    height: 60px;
    background: #fff;
    padding: 4px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid #fff;
}

.qr-thumb img {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    display: block;
}

.qr-float:hover .qr-large {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.qr-float:hover .qr-thumb {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    border-color: #3b82f6;
}

/* On mobile, might want to hide or adjust it if it blocks content */
@media (max-width: 768px) {
    .qr-float {
        right: 16px;
        bottom: 80px;
        /* Position above mobile toolbar if any, or just higher */
    }

    .qr-thumb {
        width: 50px;
        height: 50px;
    }

    .qr-large {
        bottom: 70px;
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 10001;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: opacity 0.3s ease;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #3b82f6;
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 16px;
}

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

.loading-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.loading-progress {
    font-size: 14px;
    color: #e5e7eb;
}