/* ===== Layout ===== */
html, body {
    overscroll-behavior: none;
}

.fullscreen-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.app-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* ===== Paint mode: lock viewport, hide footer ===== */
body.paint-mode {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

body.paint-mode footer {
    display: none !important;
}

body.paint-mode .fullscreen-wrapper {
    height: calc(100dvh - var(--nav-h, 56px));
    height: calc(100vh - var(--nav-h, 56px)); /* fallback for older browsers */
}

@supports (height: 100dvh) {
    body.paint-mode .fullscreen-wrapper {
        height: calc(100dvh - var(--nav-h, 56px));
    }
}

/* ===== Create Screen ===== */
#createScreen {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.create-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
}

.create-title {
    font-size: 2rem;
    font-weight: 800;
    color: #1a1a2e;
    margin-bottom: 0.25rem;
}

.create-subtitle {
    color: #6c757d;
    margin-bottom: 2rem;
    font-size: 1rem;
}

.create-section {
    width: 100%;
    margin-bottom: 1.5rem;
}

.create-label {
    display: block;
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.grid-size-options {
    display: flex;
    gap: 0.5rem;
}

.grid-size-btn {
    flex: 1;
    padding: 0.6rem 0.5rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: #fff;
    color: #333;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s;
}

.grid-size-btn:hover {
    border-color: #adb5bd;
}

.grid-size-btn.active {
    border-color: #6c5ce7;
    background: #6c5ce7;
    color: #fff;
}

/* Palette preview cards */
.palette-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.palette-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: all 0.15s;
}

.palette-card:hover {
    border-color: #adb5bd;
}

.palette-card.active {
    border-color: #6c5ce7;
    background: #f8f7ff;
}

.palette-card-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: #333;
    white-space: nowrap;
    min-width: 90px;
}

.palette-card-colors {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    flex: 1;
}

.palette-card-swatch {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    border: 1px solid rgba(0,0,0,0.1);
}

/* Gallery */
.gallery-section {
    width: 100%;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #dee2e6;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
}

.gallery-card {
    position: relative;
    background: #fff;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.15s;
}

.gallery-card:hover {
    border-color: #6c5ce7;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.gallery-thumb {
    width: 100%;
    aspect-ratio: 1;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: #fff;
}

.gallery-info {
    padding: 0.35rem 0.5rem;
    font-size: 0.7rem;
    color: #6c757d;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gallery-size {
    font-weight: 600;
    color: #333;
}

.gallery-artist {
    font-weight: 600;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 70px;
}

/* Create actions */
.create-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.btn-primary {
    padding: 0.85rem 1.5rem;
    background: #6c5ce7;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary:hover {
    background: #5a4bd1;
}

.btn-secondary {
    padding: 0.85rem 1.5rem;
    background: #fff;
    color: #6c5ce7;
    border: 2px solid #6c5ce7;
    border-radius: 10px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-secondary:hover {
    background: #f8f7ff;
}

/* ===== Paint Screen ===== */
#paintScreen {
    overflow: hidden;
}

.paint-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.75rem;
    background: #1a1a2e;
    color: #fff;
    min-height: 44px;
    flex-shrink: 0;
}

.header-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.15s;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-btn:hover {
    opacity: 1;
}

.header-title {
    font-weight: 600;
    font-size: 1rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.collab-indicator {
    font-size: 0.75rem;
    background: rgba(108, 92, 231, 0.3);
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    color: #a29bfe;
}

/* Canvas area */
.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #16213e;
    padding: 8px;
    overflow: hidden;
    position: relative;
    min-height: 0; /* allow flex shrink */
}

#pixelCanvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: #ffffff;
    touch-action: none;
    cursor: crosshair;
    border: 2px solid #0f3460;
}

/* Grid overlay canvas */
#gridOverlay {
    position: absolute;
    pointer-events: none;
}

/* Palette bar */
.palette-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: #1a1a2e;
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
    min-height: 44px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.palette-bar::-webkit-scrollbar {
    display: none;
}

.palette-swatch {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s;
    box-sizing: border-box;
}

.palette-swatch:hover {
    transform: scale(1.1);
}

.palette-swatch.active {
    border-color: #fff;
    transform: scale(1.15);
    box-shadow: 0 0 6px rgba(255,255,255,0.5);
}

/* Controls bar */
.controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 2px 8px;
    background: #1a1a2e;
    border-top: 1px solid #0f3460;
    flex-shrink: 0;
    min-height: 44px;
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    background: none;
    border: none;
    color: #a0a0b8;
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 6px;
    transition: all 0.15s;
    min-width: 40px;
    min-height: 36px;
    justify-content: center;
}

.control-btn:hover,
.control-btn.active {
    color: #fff;
    background: rgba(108, 92, 231, 0.2);
}

.control-btn.active {
    color: #a29bfe;
}

.control-icon-svg {
    width: 18px;
    height: 18px;
}

.control-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.control-label {
    font-size: 0.55rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ===== Share Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    padding: 1.5rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.modal-content h3 {
    margin: 0 0 0.5rem;
    color: #1a1a2e;
}

.modal-content p {
    color: #6c757d;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.share-warning {
    background: #fff8e6;
    border: 1px solid #ffe0a0;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    color: #8a6d00;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.share-link-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.share-link-row input {
    flex: 1;
    padding: 0.6rem 0.75rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 0.85rem;
    color: #333;
    background: #f8f9fa;
}

.btn-copy {
    padding: 0.6rem 1rem;
    background: #6c5ce7;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.share-hint {
    font-size: 0.8rem;
    color: #6c757d;
}

.btn-close-modal {
    padding: 0.7rem 2rem;
    background: #1a1a2e;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.5rem;
}

.confirm-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1rem;
}

.btn-confirm-cancel {
    padding: 0.7rem 1.5rem;
    background: #f8f9fa;
    color: #333;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.btn-confirm-ok {
    padding: 0.7rem 1.5rem;
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    background: #1a1a2e;
    color: #fff;
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: toastIn 0.25s ease, toastOut 0.25s ease 1.75s forwards;
    white-space: nowrap;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-10px); }
}

/* ===== Fullscreen ===== */
.fullscreen-wrapper:fullscreen,
.fullscreen-wrapper:-webkit-full-screen {
    background: #16213e;
    height: 100vh !important;
    height: 100dvh !important;
}

.fullscreen-wrapper:fullscreen .paint-header,
.fullscreen-wrapper:-webkit-full-screen .paint-header {
    padding-top: env(safe-area-inset-top, 0);
}

/* ===== Responsive ===== */
@media (max-width: 360px) {
    .palette-swatch {
        width: 28px;
        height: 28px;
        min-width: 28px;
    }

    .control-label {
        font-size: 0.5rem;
    }

    .control-btn {
        padding: 3px 3px;
        min-width: 34px;
    }

    .control-icon-svg {
        width: 16px;
        height: 16px;
    }
}

@media (min-width: 768px) {
    .canvas-area {
        padding: 16px;
    }

    .palette-swatch {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }
}
