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

:root {
    --primary-blue: #4A90E2;
    --primary-dark: #357ABD;
    --text-dark: #1a1a1a;
    --text-gray: #666;
    --text-light: #999;
    --bg-light: #f8f9fa;
    --border-color: #e0e0e0;
    --white: #ffffff;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-dark);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Navigation */
nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 5%;
    background: var(--white);
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--text-dark);
    text-decoration: none;
}

.logo i { color: var(--primary-blue); }

.nav-buttons { display: flex; gap: 1rem; align-items: center; }

.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    text-decoration: none;
    display: inline-block;
    font-size: 0.9rem;
}

.btn-ghost { background: transparent; color: var(--text-dark); }
.btn-ghost:hover { background: var(--bg-light); }

.btn-primary { background: var(--primary-blue); color: var(--white); }
.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Hero Section */
.hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4rem 5%;
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
}

.hero h1 {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

.hero p {
    font-size: 1.1rem;
    color: var(--text-gray);
    margin-bottom: 2rem;
}

.badge {
    background: var(--primary-blue);
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Upload Box */
.upload-box {
    background: var(--white);
    border: 2px dashed var(--border-color);
    border-radius: 20px;
    padding: 3rem 2rem;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 600px;
    transition: border-color 0.3s, background 0.3s;
}

.upload-box.drag-over {
    border-color: var(--primary-blue);
    background: rgba(74, 144, 226, 0.05);
}

.upload-btn {
    background: var(--primary-blue);
    color: white;
    padding: 1rem 2.5rem;
    border-radius: 50px;
    border: none;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    margin-bottom: 1rem;
    transition: all 0.3s;
}

.upload-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(74, 144, 226, 0.3);
}

.upload-box p { color: var(--text-gray); margin-bottom: 0.5rem; }
.upload-box small { color: var(--text-light); font-size: 0.8rem; }

/* Footer */
footer {
    background: var(--text-dark);
    color: white;
    padding: 2rem 5%;
    text-align: center;
    font-size: 0.85rem;
    color: #999;
}

/* ========== Workspace ========== */
#workspace { display: none; }
#workspace.active { display: flex; flex-direction: column; min-height: calc(100vh - 60px); }

.workspace-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 2rem;
    background: var(--white);
    border-bottom: 1px solid var(--border-color);
}

.workspace-toolbar .back-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-gray);
    font-weight: 500;
}

.workspace-toolbar .back-btn:hover { color: var(--text-dark); }

.workspace-toolbar .file-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.workspace-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e8e8e8;
    background-image:
        linear-gradient(45deg, #d0d0d0 25%, transparent 25%),
        linear-gradient(-45deg, #d0d0d0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d0d0d0 75%),
        linear-gradient(-45deg, transparent 75%, #d0d0d0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    padding: 2rem;
    position: relative;
    overflow: auto;
}

.canvas-area canvas {
    max-width: 100%;
    max-height: calc(100vh - 180px);
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

/* Control Panel */
.control-panel {
    width: 320px;
    min-width: 320px;
    background: var(--white);
    border-left: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
}

.control-section h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-light);
    margin-bottom: 0.8rem;
}

.prompt-form {
    display: flex;
    gap: 0.5rem;
}

.prompt-form input {
    flex: 1;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.3s;
}

.prompt-form input:focus { border-color: var(--primary-blue); }

/* Results List */
.results-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.results-list li {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    background: var(--bg-light);
    cursor: pointer;
    transition: background 0.2s;
}

.results-list li:hover { background: #e8ecf0; }
.results-list li.selected { background: rgba(74, 144, 226, 0.1); border: 1px solid var(--primary-blue); }

.mask-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    flex-shrink: 0;
}

.mask-score {
    font-size: 0.85rem;
    font-weight: 600;
    margin-left: auto;
}

.mask-label { font-size: 0.85rem; }

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: auto;
}

.action-buttons .btn { text-align: center; width: 100%; }

.btn-outline {
    background: transparent;
    color: var(--text-dark);
    border: 1px solid var(--border-color);
}

.btn-outline:hover { background: var(--bg-light); }

.btn-download {
    background: #27ae60;
    color: white;
}

.btn-download:hover {
    background: #219a52;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.3);
}

.btn-download:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

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

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Status message */
.status-msg {
    font-size: 0.85rem;
    color: var(--text-gray);
    text-align: center;
    padding: 0.5rem;
}

.status-msg.error { color: #e74c3c; }

/* Responsive */
@media (max-width: 768px) {
    .hero h1 { font-size: 2rem; }
    .workspace-main { flex-direction: column; }
    .control-panel { width: 100%; min-width: unset; border-left: none; border-top: 1px solid var(--border-color); }
    .canvas-area { min-height: 300px; }
}
