:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --secondary: #334155;
    --secondary-hover: #475569;
    --accent: #ec4899;
    --border-color: #334155;

    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
}

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

header {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeInDown 0.6s ease-out;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, #8b5cf6, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
}

/* Upload Section */
.upload-section {
    max-width: 600px;
    margin: 0 auto;
    animation: fadeIn 0.8s ease-out;
}

.upload-box {
    border: 2px dashed var(--border-color);
    border-radius: 16px;
    padding: 4rem 2rem;
    text-align: center;
    background: rgba(30, 41, 59, 0.5);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.upload-box:hover,
.upload-box.dragover {
    border-color: var(--primary);
    background: rgba(139, 92, 246, 0.05);
    transform: translateY(-2px);
}

.upload-box svg {
    color: var(--primary);
    margin-bottom: 8px;
}

.upload-box p {
    font-size: 1.25rem;
    font-weight: 500;
}

.upload-box span {
    color: var(--text-muted);
}

/* Workspace Grid */
.workspace {
    display: grid;
    grid-template-columns: 320px 1fr;
    grid-template-rows: auto auto;
    gap: 1.5rem;
    animation: fadeIn 0.5s ease-out;
}

.controls-panel {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
}

.results-panel {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
}

@media (max-width: 900px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        grid-column: 1 / 2;
        grid-row: 1 / 2;
    }

    .results-panel {
        grid-column: 1 / 2;
        grid-row: 2 / 3;
    }
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.card h3 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Info Box */
.info-box {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.info-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.info-row span {
    color: var(--text-muted);
}

.info-row strong {
    color: #fff;
    font-variant-numeric: tabular-nums;
}

/* Controls */
.control-group {
    margin-bottom: 1.5rem;
}

.control-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.control-header label {
    font-weight: 500;
    color: #cbd5e1;
    font-size: 0.95rem;
}

.control-header input[type="number"] {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--primary);
    font-weight: 600;
    font-size: 0.95rem;
    font-family: inherit;
    border-radius: 4px;
    padding: 2px 6px;
    width: 60px;
    text-align: right;
    outline: none;
    transition: border-color 0.2s;
    font-variant-numeric: tabular-nums;
}

.control-header input[type="number"]:focus {
    border-color: var(--primary);
}

/* Ocultar flechas de inputs numéricos */
.control-header input[type="number"]::-webkit-outer-spin-button,
.control-header input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.control-header input[type="number"] {
    -moz-appearance: textfield; /* Firefox */
}

input[type=range] {
    width: 100%;
    -webkit-appearance: none;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: #334155;
    border-radius: 2px;
}

.control-group small {
    display: block;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Buttons */
.actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 2rem;
}

.btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-align: center;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(139, 92, 246, 0.4);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

/* Canvas Area */
.canvas-container {
    position: relative;
    max-width: 100%;
    max-height: 70vh;
    overflow: auto;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: repeating-conic-gradient(#1e293b 0% 25%, #0f172a 0% 50%) 50% / 20px 20px;
    display: flex;
}

.canvas-wrapper {
    position: relative;
    margin: auto;
    transition: width 0.15s ease-out, height 0.15s ease-out;
}

#imageCanvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: auto; /* keeps it smooth, will pixelate via JS if zoomed far */
}

#gridCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    width: 100%;
    height: 100%;
}

/* Results */
.summary {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
}

.color-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 8px;
}

.color-list::-webkit-scrollbar {
    width: 6px;
}

.color-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.color-list::-webkit-scrollbar-thumb {
    background: var(--secondary);
    border-radius: 3px;
}

.color-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: transform 0.2s, background 0.2s;
}

.color-item:hover {
    transform: translateX(4px);
    background: rgba(255, 255, 255, 0.06);
}

.color-swatch {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    margin-right: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.color-info {
    flex: 1;
}

.color-hex {
    font-family: monospace;
    font-size: 0.95rem;
    color: #fff;
    font-weight: 600;
}

.color-rgb {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.color-count {
    font-weight: 700;
    font-size: 1.1rem;
    background: var(--primary);
    padding: 4px 12px;
    border-radius: 999px;
    color: white;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

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

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

/* Modal 3D */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: var(--card-bg);
    border: none;
    border-radius: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #fff;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #ec4899;
}

.modal-body {
    flex: 1;
    position: relative;
    background: #000;
    /* Dark space for 3D model */
}

/* Blueprint Tool Overlay */
.blueprint-controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(30, 41, 59, 0.85);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    z-index: 10;
    min-width: 260px;
    backdrop-filter: blur(8px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.layer-input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #8b5cf6;
    font-weight: 600;
    font-size: 0.95rem;
    font-family: inherit;
    border-radius: 4px;
    padding: 2px 6px;
    width: 60px;
    text-align: right;
    outline: none;
    transition: border-color 0.2s;
    font-variant-numeric: tabular-nums;
    -moz-appearance: textfield;
}

.layer-input::-webkit-outer-spin-button,
.layer-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.layer-input:focus {
    border-color: #8b5cf6;
}

/* Saved Projects */
.saved-projects {
    max-width: 800px;
    margin: 3rem auto 0;
    animation: fadeIn 0.8s ease-out;
}

.saved-projects h3 {
    text-align: center;
    color: var(--text-main);
    margin-bottom: 1.5rem;
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
}

.project-card {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.project-card:hover {
    transform: translateY(-2px);
    background: rgba(139, 92, 246, 0.1);
    border-color: var(--primary);
}

.project-card img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 8px;
    background: repeating-conic-gradient(#1e293b 0% 25%, #0f172a 0% 50%) 50% / 10px 10px;
}

.project-card .info {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-card .delete-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.project-card .edit-btn {
    position: absolute;
    top: 5px;
    right: 32px;
    background: rgba(139, 92, 246, 0.9); /* primary color */
    color: white;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 11px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
}

.project-card:hover .delete-btn,
.project-card:hover .edit-btn {
    opacity: 1;
}

.project-card .delete-btn:hover {
    background: #dc2626;
}

.project-card .edit-btn:hover {
    background: #7c3aed;
}