/* Reset and Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    touch-action: none;
}

/* Header */
header {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
    z-index: 100;
}

header h1 {
    color: white;
    font-size: 1.5rem;
    font-weight: 300;
    letter-spacing: 2px;
}

/* Instructions */
.instructions {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 1rem 2rem;
    border-radius: 12px;
    font-size: 0.9rem;
    color: #666;
    text-align: center;
    z-index: 50;
    animation: slideDown 0.5s ease;
    transition: opacity 0.3s;
}

.instructions.fade {
    opacity: 0.3;
}

@keyframes slideDown {
    from { transform: translateX(-50%) translateY(-20px); opacity: 0; }
    to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* Viewport and Card */
.viewport {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 2000px;
    overflow: hidden;
}

.card-container {
    position: relative;
    transform-style: preserve-3d;
    transition: none;
    cursor: grab;
}

.card-container.grabbing {
    cursor: grabbing;
}

.visa-card {
    width: 400px;
    height: 252px;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border-radius: 16px;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform-style: preserve-3d;
    cursor: pointer;
}

.card-sticker {
    position: absolute;
    inset: 0;
    border-radius: 16px;
    background: #ff6b6b;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    color: white;
    transition: background-color 0.3s, border-color 0.3s;
    border: 2px solid transparent;
}

/* Unified Area Styling */
.area {
    position: absolute;
    transition: border-color 0.3s, background 0.3s;
    border: 2px solid transparent;
    border-radius: 8px;
    z-index: 10;
}

.area.highlighted {
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.08);
    cursor: pointer;
}

.card-sticker.color-highlighted {
    border-color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
}

.area-label {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    position: absolute;
}

.area.highlighted .area-label,
.card-sticker.color-highlighted .color-label {
    opacity: 1;
}

/* Specific Areas */
.color-label {
    top: 20px;
    left: 20px;
}

.pin-area {
    top: 80px;
    left: 30px;
    width: 50px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pin-area .area-label {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.pin-cutout {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    border-radius: 8px;
    display: none;
    z-index: -1;
}

.pin-cutout.show {
    display: block;
}

.text-area {
    top: 130px;
    left: 30px;
    width: 160px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.sticker-text {
    text-align: left;
    word-wrap: break-word;
    color: white;
    font-size: 1.8rem;
    font-weight: bold;
    width: 100%;
    padding: 0;
    background: transparent;
    border: none;
    outline: none;
    font-family: inherit;
    transition: opacity 0.2s;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    caret-color: transparent;
}

.sticker-text::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.text-area.highlighted .sticker-text {
    opacity: 1;
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    caret-color: white;
}

.text-area.has-text .sticker-text {
    opacity: 1;
    pointer-events: auto;
    caret-color: transparent;
}

.text-area.has-text.highlighted .sticker-text {
    caret-color: white;
}

.qr-area {
    top: 80px;
    right: 20px;
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-area .area-label {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.qr-code {
    position: absolute;
    inset: 0;
    background: white;
    border-radius: 4px;
    display: none;
    pointer-events: none;
    padding: 4px;
}

.qr-code.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-code canvas {
    width: 100% !important;
    height: 100% !important;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

/* Popups */
.popup {
    position: absolute;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: none;
    z-index: 1000;
    animation: popIn 0.3s ease;
}

.popup.show {
    display: block;
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.color-popup {
    padding: 1.5rem;
    border-radius: 16px;
}

.qr-input-popup {
    padding: 1rem;
    min-width: 250px;
}

.popup-title {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 1rem;
    text-align: center;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.color-option {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s;
}

.color-option:hover {
    transform: scale(1.1);
}

.custom-color-input {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.custom-color-input input[type="color"] {
    width: 50px;
    height: 40px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.custom-color-input input[type="text"] {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-family: monospace;
}

.qr-input-popup input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
}

/* Controls */
.controls-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 1rem;
    background: rgba(255, 255, 255, 0.95);
    padding: 1rem;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 100;
}

.control-btn {
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
    white-space: nowrap;
}

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

.control-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.control-btn:active {
    transform: translateY(0);
}

.control-btn.etsy {
    background: linear-gradient(135deg, #f0932b 0%, #eb4d4b 100%);
}

/* PWA Install Prompt */
.pwa-install-prompt {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    padding: 1rem 1.5rem;
    z-index: 10000;
    animation: slideUp 0.5s ease;
    max-width: 300px;
    text-align: center;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.pwa-install-content p {
    margin: 0.5rem 0;
    color: #333;
    font-size: 0.9rem;
}

.pwa-install-content button {
    margin-top: 0.5rem;
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .visa-card {
        width: 320px;
        height: 200px;
    }

    .controls-bar {
        bottom: 10px;
        padding: 0.75rem;
        gap: 0.5rem;
    }

    .control-btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }

    .instructions {
        font-size: 0.8rem;
        padding: 0.75rem 1rem;
    }
}