@font-face {
    font-family: 'First Coffee';
    src: url('First-Coffee.ttf') format('truetype');
    font-display: swap;
}

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

body {
    font-family: 'First Coffee', monospace;
    background: url('nertwin_bday_timesqr_bg_v1.png') center/cover no-repeat fixed;
    color: #ffffff;
    line-height: 1.6;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: -1;
}

.preload-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
    transition: opacity 0.5s ease-out;
    opacity: 1;
}

.preload-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.preload-content {
    text-align: center;
    color: white;
}

.loading-animation {
    margin-bottom: 2rem;
}

.loading-character {
    width: 150px;
    height: auto;
    animation: bounce 1.5s infinite;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.5));
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-30px);
    }
    60% {
        transform: translateY(-15px);
    }
}

.loading-text {
    font-size: 1.5rem;
    font-weight: bold;
    color: #ffffff;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.9);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

header {
    text-align: center;
    margin-bottom: 3rem;
    background: rgba(0, 0, 0, 0.5);
    padding: 2rem;
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

header h1 {
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.9);
    -webkit-text-stroke: 0.1px rgb(169 49 128);
    color: #ffcaf2;
}

header p {
    font-size: 1.1rem;
    color: #ffffff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.optimized-link {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.75rem 1.5rem;
    background: rgba(59, 130, 246, 0.8);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.9rem;
    text-shadow: none;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.optimized-link:hover {
    background: rgba(59, 130, 246, 1);
    transform: translateY(-2px);
}

.creator-layout {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    align-items: center;
}

.controls-panel {
    background: rgba(0,0,0, 0.1);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 100%;
    max-width: 1000px;
    backdrop-filter: blur(15px);
}

.tabs-container {
    width: 100%;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-button {
    padding: 0.75rem 1.5rem;
    background: rgba(0, 0, 0, 0.3);
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 0.9rem;
    color: #ffffff;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    font-family: 'First Coffee', monospace;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    border-radius: 8px 8px 0 0;
}

.tab-button:hover {
    color: #ff4757;
    background: rgba(255, 71, 87, 0.2);
}

.tab-button.active {
    color: #ff4757;
    border-bottom-color: #ff4757;
    background: rgba(255, 71, 87, 0.3);
}

.tab-content {
    min-height: 300px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.layer-group {
    margin-bottom: 0;
}

.layer-group h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.75rem;
}

.layer-select {
    display: none;
}

.image-selector {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 1rem;
}

.image-option {
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    backdrop-filter: blur(10px);
}

.image-option:hover {
    border-color: #ff4757;
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(255, 71, 87, 0.3);
}

.image-option.active {
    border-color: #ff4757;
    background: rgba(255, 71, 87, 0.2);
}

.image-option img {
    width: 100%;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.image-option span {
    display: block;
    font-size: 0.8rem;
    color: #ffffff;
    line-height: 1.3;
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.no-image {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #ffffff;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.text-controls {
    padding: 1rem 0;
}

.text-controls-layout {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2rem;
    align-items: start;
}

#text-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-size: 0.95rem;
    min-height: 100px;
    resize: vertical;
    font-family: 'First Coffee', monospace;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    backdrop-filter: blur(10px);
}

.text-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 200px;
}

.text-options label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: #ffffff;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

#text-color {
    width: 40px;
    height: 30px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
}

#text-size {
    flex: 1;
    margin: 0 0.5rem;
}

#size-value {
    font-weight: 500;
    min-width: 40px;
}

.download-btn {
    width: 100%;
    padding: 1rem 2rem;
    background: linear-gradient(45deg, #ff4757, #ff6b7d);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 2rem;
    font-family: 'First Coffee', monospace;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.4);
}

.download-btn:hover {
    background: linear-gradient(45deg, #ff3742, #ff5865);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 71, 87, 0.6);
}

.preview-panel {
    background: rgba(0,0,0, 0.1);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 100%;
    max-width: 1000px;
    backdrop-filter: blur(15px);
}

.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 1rem;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

#preview-canvas {
    max-width: 100%;
    height: auto;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    display: block;
    cursor: crosshair;
}

#preview-canvas:active {
    cursor: grabbing;
}

.preset-controls {
    padding: 1rem 0;
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.preset-option {
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    backdrop-filter: blur(10px);
    min-height: 120px;
}

.preset-option:hover {
    border-color: #ff4757;
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(255, 71, 87, 0.3);
}

.preset-option.active {
    border-color: #ff4757;
    background: rgba(255, 71, 87, 0.2);
}

.preset-option img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
}

.preset-option span {
    display: block;
    font-size: 0.9rem;
    color: #ffffff;
    font-weight: bold;
    line-height: 1.3;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

#stroke-type {
    padding: 0.25rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-family: 'First Coffee', monospace;
    margin-right: 0.5rem;
}

@media (max-width: 1024px) {
    .creator-layout {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.75rem;
    }
    
    .text-controls-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .container {
        padding: 1rem;
    }
    
    .tabs {
        justify-content: center;
    }
    
    .tab-button {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    header p {
        font-size: 1rem;
    }
    
    .controls-panel,
    .preview-panel {
        padding: 1.5rem;
    }
    
    .canvas-container {
        padding: 0.5rem;
    }
    
    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 0.75rem;
    }
    
    .image-option {
        padding: 0.5rem;
    }
    
    .image-option img {
        height: 50px;
    }
    
    .image-option span {
        font-size: 0.7rem;
    }
    
    .no-image {
        height: 50px;
        font-size: 0.8rem;
    }
    
    .tabs {
        gap: 0.25rem;
        padding-bottom: 0.5rem;
    }
    
    .tab-button {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
        min-width: auto;
    }
    
    .text-controls-layout {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .text-options {
        min-width: auto;
    }
    
    #text-input {
        min-height: 80px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .download-btn {
        padding: 0.875rem 1.5rem;
        font-size: 0.95rem;
        margin-top: 1.5rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.75rem;
    }
    
    header h1 {
        font-size: 1.75rem;
    }
    
    .controls-panel,
    .preview-panel {
        padding: 1rem;
    }
    
    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
        gap: 0.5rem;
    }
    
    .image-option {
        padding: 0.375rem;
    }
    
    .image-option img {
        height: 40px;
    }
    
    .image-option span {
        font-size: 0.65rem;
    }
    
    .no-image {
        height: 40px;
        font-size: 0.7rem;
    }
    
    .tab-button {
        padding: 0.4rem 0.75rem;
        font-size: 0.75rem;
    }
    
    .text-options {
        gap: 0.75rem;
    }
    
    .text-options label {
        font-size: 0.8rem;
    }
    
    #text-color {
        width: 35px;
        height: 25px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    .image-option:hover {
        transform: none;
        box-shadow: none;
    }
    
    .image-option:active {
        transform: scale(0.95);
        background: #f8fafc;
    }
    
    .tab-button:hover {
        background: transparent;
    }
    
    .tab-button:active {
        background: #f8fafc;
    }
    
    .download-btn:hover {
        background: #3b82f6;
    }
    
    .download-btn:active {
        background: #2563eb;
        transform: scale(0.98);
    }
}