/* CSS Reset & Robust Definiitons */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-dark: #0f0f11;
    --bg-card: #1c1c1e;
    --text-main: #ffffff;
    --text-muted: #a1a1aa;
    --primary: #0A84FF;
    --primary-hover: #0077e6;
    --danger: #ef4444;
    --accent-gradient: linear-gradient(135deg, #0A84FF 0%, #0056b3 100%);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Fluid Logic */
#fluidCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    opacity: 0.6;
}

/* Navbar */
.navbar {
    height: 70px;
    width: 100%;
    background: rgba(15, 15, 17, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 5%;
    position: fixed;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand {
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-menu span {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.nav-btn {
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.2s;
}

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

/* Main Layout */
.main-container {
    margin-top: 100px;
    width: 100%;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 20px;
    padding-bottom: 50px;
    display: flex;
    justify-content: center;
}

.app-box {
    width: 100%;
    background: rgba(28, 28, 30, 0.6);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

h1 {
    text-align: center;
    margin-bottom: 30px;
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -1px;
}

/* Form Controls */
textarea {
    width: 100%;
    height: 100px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    color: white;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    transition: border-color 0.2s;
}

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

.primary-btn {
    width: 100%;
    padding: 16px;
    margin-top: 20px;
    border: none;
    border-radius: 12px;
    background: var(--accent-gradient);
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.2s, transform 0.1s;
}

.primary-btn:hover {
    filter: brightness(1.1);
}

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

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

/* Grid */
.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
    margin-top: 50px;
}

.preview-card {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.card-header {
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Images & Canvas - The Critical Fix */
.preview-card img,
.preview-card canvas {
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
    max-height: 500px;
    /* Prevent gigantism */
    background: transparent;
    /* Letterbox filler */
}

/* Controls */
.control-panel {
    padding: 20px;
}

.btn-group {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.secondary-btn {
    flex: 1;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    border-radius: 8px;
    cursor: pointer;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.secondary-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

/* History */
.history-section {
    margin-top: 60px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 30px;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.history-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid transparent;
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.history-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Loader */
.loader {
    margin: 20px auto;
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s infinite;
    display: none;
}

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

/* Login Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: #2c2c2e;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 50px black;
}

.google-login-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: white;
    color: #333;
    padding: 12px 24px;
    border-radius: 30px;
    text-decoration: none;
    font-weight: 600;
    margin-top: 20px;
    gap: 10px;
}

@media(max-width: 768px) {
    h1 {
        font-size: 1.8rem;
    }

    .navbar {
        padding: 0 20px;
    }

    .app-box {
        padding: 20px;
    }

    .preview-grid {
        grid-template-columns: 1fr;
    }
}