@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg: #0a0a0f;
    --card: #141419;
    --card-hover: #1a1a22;
    --border: #2a2a35;
    --text: #ffffff;
    --text-muted: #8888aa;
    --accent: #ff6b9d;
    --accent-glow: rgba(255, 107, 157, 0.3);
    --success: #4ade80;
    --radius: 20px;
    --radius-sm: 12px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    min-height: 100dvh;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    max-width: 100vw;
    overscroll-behavior-x: none;
    touch-action: pan-y;
}

/* ===== APP CONTAINER ===== */
.app {
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
    overflow-x: hidden;
    max-width: 100vw;
}

/* ===== SCREEN SYSTEM ===== */
.screen {
    display: none;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 0 20px env(safe-area-inset-bottom);
    animation: fadeIn 0.3s ease;
    width: 100%;
    overflow-x: hidden;
}

.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== HEADER ===== */
.screen-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
}

.back-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--card);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.back-btn:active {
    transform: scale(0.95);
    background: var(--card-hover);
}

.step-indicator {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
}

/* ===== BODY ===== */
.screen-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding-bottom: 20px;
}

.screen-body.centered {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.screen-title {
    font-size: 28px;
    font-weight: 700;
    margin: 0 0 8px;
    letter-spacing: -0.02em;
}

.screen-desc {
    font-size: 16px;
    color: var(--text-muted);
    margin: 0 0 24px;
    line-height: 1.5;
}

/* ===== FOOTER ===== */
.screen-footer {
    padding: 20px 0;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, var(--bg) 80%, transparent);
}

.screen-footer.stacked {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ===== HOME SCREEN ===== */
.home-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px 20px;
}

.logo {
    font-size: 48px;
    font-weight: 700;
    margin-bottom: 12px;
    letter-spacing: -0.03em;
}

.logo-text {
    color: var(--text);
}

.logo-dot {
    color: var(--accent);
}

.home-subtitle {
    font-size: 18px;
    color: var(--text-muted);
    margin: 0 0 48px;
}

/* ===== BIG BUTTONS ===== */
.home-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 320px;
}

.big-btn {
    width: 100%;
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

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

.big-btn.primary {
    background: linear-gradient(135deg, var(--accent), #ff8a65);
    border: none;
    box-shadow: 0 8px 32px var(--accent-glow);
}

.big-btn.primary .btn-hint {
    color: rgba(255,255,255,0.8);
}

.btn-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.btn-label {
    font-size: 18px;
    font-weight: 600;
}

.btn-hint {
    font-size: 14px;
    color: var(--text-muted);
}

/* ===== NAV BUTTONS ===== */
.nav-btn {
    width: 100%;
    padding: 18px 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.nav-btn:not(:disabled):active {
    transform: scale(0.98);
}

.nav-btn.primary {
    background: var(--accent);
    border: none;
    color: #fff;
    box-shadow: 0 4px 20px var(--accent-glow);
}

/* ===== UPLOAD ZONE ===== */
.upload-zone {
    width: 100%;
    aspect-ratio: 1;
    max-height: 50vh;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    background: var(--card);
    transition: all 0.2s;
}

.upload-zone:active {
    border-color: var(--accent);
    background: var(--card-hover);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
}

.upload-icon {
    font-size: 48px;
}

.upload-text {
    font-size: 16px;
    font-weight: 500;
}

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

.hidden {
    display: none !important;
}

/* ===== SETTINGS ===== */
.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.setting-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-label {
    font-size: 16px;
    font-weight: 500;
}

.stepper {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px;
}

.stepper-btn {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 24px;
    font-weight: 300;
    cursor: pointer;
    transition: all 0.15s;
}

.stepper-btn:active {
    background: var(--card-hover);
}

.stepper input {
    width: 56px;
    text-align: center;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 18px;
    font-weight: 600;
    font-family: inherit;
}

.stepper input::-webkit-inner-spin-button,
.stepper input::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

/* ===== RESULT SCREEN ===== */
.result-preview {
    width: 100%;
    aspect-ratio: 1;
    max-height: 45vh;
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
}

.result-preview canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.palette-section {
    margin-bottom: 20px;
}

.palette-title {
    font-size: 14px;
    color: var(--text-muted);
    margin: 0 0 12px;
    font-weight: 500;
}

.palette {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.swatch {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.secondary-actions {
    display: flex;
    gap: 12px;
}

.icon-btn {
    flex: 1;
    padding: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.icon-btn:active {
    background: var(--card-hover);
}

/* ===== LOAD SCREEN ===== */
.load-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 320px;
}

.load-option {
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
    transition: all 0.2s;
}

.load-option:active {
    background: var(--card-hover);
}

.load-option:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.load-icon {
    font-size: 32px;
}

.load-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
}

/* ===== GUIDE SCREEN ===== */
.progress-mini {
    flex: 1;
    height: 6px;
    background: var(--card);
    border-radius: 3px;
    overflow: hidden;
}

.progress-mini-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--success));
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 40px;
    text-align: right;
}

.guide-body {
    gap: 12px;
    justify-content: flex-start;
    padding-top: 0;
}

.guide-instruction {
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    text-align: center;
}

.guide-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.guide-current {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 2px;
    line-height: 1.3;
}

.guide-next {
    font-size: 12px;
    color: var(--text-muted);
}

.guide-canvas-wrap {
    flex: 1;
    min-height: 0;
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

.guide-canvas-wrap canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.guide-footer {
    display: flex;
    gap: 12px;
    align-items: center;
}

.guide-btn {
    flex: 1;
    padding: 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
}

.guide-btn.icon-only {
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
    font-size: 20px;
    padding: 0;
}

.guide-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.guide-btn:not(:disabled):active {
    background: var(--card-hover);
}

.guide-btn.big {
    flex: 1;
}

.guide-btn.primary {
    background: var(--accent);
    border: none;
    color: #fff;
}

/* ===== TUTORIAL OVERLAY ===== */
.tutorial-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(8px);
    display: none;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.tutorial-overlay.show {
    display: flex;
}

.tutorial-modal {
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.tutorial-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.tutorial-title {
    font-size: 18px;
    font-weight: 600;
}

.tutorial-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bg);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
}

.tutorial-step {
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.tutorial-step strong {
    color: var(--accent);
}

.tutorial-progress {
    height: 4px;
    background: var(--bg);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 20px;
}

.tutorial-progress div {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s;
}

.tutorial-actions {
    display: flex;
    gap: 12px;
}

.tutorial-actions button {
    flex: 1;
    padding: 14px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}

.tutorial-actions #tutorialAction {
    background: var(--accent);
    color: #fff;
}

/* ===== FAB HELP ===== */
.fab-help {
    position: fixed;
    bottom: max(20px, env(safe-area-inset-bottom));
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--card);
    color: var(--text);
    font-size: 24px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 50;
    transition: all 0.2s;
}

.fab-help:active {
    transform: scale(0.95);
}

/* ===== SPINNER ===== */
.btn-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== TABLET+ ===== */
@media (min-width: 600px) {
    .screen {
        padding-left: 40px;
        padding-right: 40px;
    }
    
    .home-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        max-width: 700px;
    }
    
    .big-btn {
        flex: 1;
        min-width: 200px;
    }
    
    .settings-grid {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .setting-card {
        flex: 1;
        min-width: 200px;
    }
    
    .setting-card.full {
        flex-basis: 100%;
    }
    
    .load-options {
        flex-direction: row;
        max-width: 500px;
    }
    
    .load-option {
        flex: 1;
    }
}

/* ===== DESKTOP ===== */
@media (min-width: 900px) {
    .screen {
        max-width: 800px;
        margin: 0 auto;
    }
    
    .screen-title {
        font-size: 36px;
    }
    
    .logo {
        font-size: 64px;
    }
    
    .tutorial-modal {
        border-radius: var(--radius);
    }
    
    .tutorial-overlay {
        align-items: center;
    }
}

/* ===== PAINT BY NUMBERS ===== */
.big-btn.tertiary {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    border: none;
    box-shadow: 0 8px 32px rgba(79, 70, 229, 0.3);
}

.big-btn.tertiary .btn-hint {
    color: rgba(255,255,255,0.8);
}

.pbn-preview-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.pbn-toggle-group {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.pbn-toggle {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.pbn-toggle.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.pbn-toggle:hover:not(.active) {
    background: var(--card-hover);
}

.pbn-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    padding: 16px;
    background: var(--card);
    border-radius: var(--radius);
    margin-top: 16px;
}

.pbn-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.pbn-legend-num {
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
    min-width: 20px;
    text-align: center;
}

.pbn-legend-swatch {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--border);
}

.pbn-legend-name {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: capitalize;
}

#pbnResultCanvas {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}

