:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #242836;
    --border: #2e3345;
    --text: #e8eaed;
    --text-muted: #9aa0b4;
    --primary: #6c5ce7;
    --primary-hover: #5a4bd1;
    --success: #00b894;
    --danger: #ff6b6b;
    --radius: 12px;
    --shadow: 0 8px 32px rgba(0,0,0,0.35);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

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

/* Header */
.header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}

.logo-icon {
    font-size: 1.8rem;
    color: var(--primary);
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.tagline {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Card */
.main-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) + 4px);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.upload-section h2 {
    font-size: 1.35rem;
    margin-bottom: 0.35rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.75rem;
}

/* Form */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--text-muted);
}

select {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239aa0b4' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.9rem center;
}

select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Drop zone */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background: var(--surface-2);
    margin-bottom: 1.5rem;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-zone:hover,
.drop-zone.dragover {
    border-color: var(--primary);
    background: rgba(108, 92, 231, 0.08);
}

.drop-icon {
    font-size: 2rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.drop-content p {
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}

.hint {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.preview-container {
    position: relative;
    width: 100%;
    max-width: 220px;
}

.preview-container img {
    width: 100%;
    border-radius: 8px;
    display: block;
    max-height: 200px;
    object-fit: contain;
}

.btn-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--danger);
    color: white;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 0.85rem 1.25rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

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

.btn-secondary {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.65rem 1.2rem;
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
}

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

/* Result */
.result {
    margin-top: 1.75rem;
}

.success-box {
    background: rgba(0, 184, 148, 0.1);
    border: 1px solid rgba(0, 184, 148, 0.3);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
}

.success-box h3 {
    color: var(--success);
    margin-bottom: 0.5rem;
}

.code-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin: 1rem 0;
    background: var(--surface);
    padding: 0.85rem 1.25rem;
    border-radius: 8px;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    font-family: 'Courier New', monospace;
}

.btn-copy {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-copy:hover {
    opacity: 1;
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 2.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ========== VIEWER PAGE ========== */
.viewer-body {
    margin: 0;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 10;
}

.viewer-header .logo {
    margin: 0;
    gap: 0.4rem;
}

.viewer-header .logo h1 {
    font-size: 1.15rem;
}

.viewer-code {
    font-family: monospace;
    font-size: 0.9rem;
    color: var(--text-muted);
    background: var(--surface-2);
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
}

.viewer-canvas-wrap {
    flex: 1;
    position: relative;
    background: #111;
}

#canvas3d {
    width: 100%;
    height: 100%;
    display: block;
}

.viewer-controls {
    position: absolute;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    background: rgba(26, 29, 39, 0.9);
    backdrop-filter: blur(8px);
    padding: 0.5rem;
    border-radius: 50px;
    border: 1px solid var(--border);
}

.control-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--surface-2);
    color: var(--text);
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.control-btn.active {
    background: var(--primary);
}

.finish-picker {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    padding: 0 0.4rem;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

.finish-btn {
    padding: 0.35rem 0.65rem;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.finish-btn:hover {
    color: var(--text);
    background: var(--surface-2);
}

.finish-btn.active {
    background: var(--primary);
    color: white;
}

.bg-picker {
    display: flex;
    gap: 0.35rem;
    align-items: center;
    padding: 0 0.5rem;
}

.bg-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s;
}

.bg-swatch:hover {
    transform: scale(1.15);
}

.bg-swatch.active {
    border-color: white;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 5;
}

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

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

.error-state {
    text-align: center;
    padding: 3rem 1.5rem;
}

.error-state h2 {
    margin-bottom: 0.5rem;
}

.error-state p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}
