* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, Arial, sans-serif;
    background: #f9fafb;
    color: #111827;
}

button,
input {
    font-family: inherit;
}

a {
    text-decoration: none;
    color: inherit;
}

.topbar {
    height: 73px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 1px 8px rgba(15, 23, 42, 0.04);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 26px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand-area {
    display: flex;
    align-items: center;
    gap: 40px;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-box {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    background: #4f46e5;
    color: white;
    display: grid;
    place-items: center;
    font-size: 25px;
    font-weight: 900;
}

.brand-text {
    font-size: 24px;
    font-weight: 900;
}

.ai-badge {
    background: #eef2ff;
    color: #4f46e5;
    font-size: 11px;
    font-weight: 900;
    border-radius: 6px;
    padding: 3px 6px;
}

.top-title strong,
.top-title small {
    display: block;
}

.top-title strong {
    font-size: 15px;
}

.top-title small {
    color: #6b7280;
    margin-top: 2px;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.credit-pill {
    background: #eef2ff;
    color: #4f46e5;
    padding: 11px 24px;
    border-radius: 999px;
    font-weight: 800;
}

.history-link {
    color: #4b5563;
    font-weight: 700;
}

.divider {
    width: 1px;
    height: 36px;
    background: #e5e7eb;
}

.profile-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
}

.profile-menu img {
    width: 38px;
    height: 38px;
    object-fit: cover;
    border-radius: 50%;
}

.alert {
    max-width: 1100px;
    margin: 16px auto 0;
    padding: 13px 18px;
    border-radius: 14px;
    font-weight: 800;
}

.alert.success {
    background: #ecfdf5;
    color: #047857;
}

.alert.error {
    background: #fef2f2;
    color: #b91c1c;
}

.main-layout {
    min-height: calc(100vh - 73px);
    display: grid;
    grid-template-columns: 355px 1fr;
}

.left-panel {
    background: #ffffff;
    border-right: 1px solid #f1f5f9;
    padding: 22px 26px;
}

.section-box {
    margin-bottom: 28px;
}

.section-box h2 {
    font-size: 15px;
    margin: 0 0 16px;
    font-weight: 900;
}

.upload-card {
    height: 175px;
    border: 2px dashed #e5e7eb;
    border-radius: 20px;
    display: grid;
    place-items: center;
    cursor: pointer;
    overflow: hidden;
    background: white;
}

.upload-card input {
    display: none;
}

.upload-empty {
    display: flex;
    align-items: center;
    flex-direction: column;
    gap: 10px;
}

.upload-empty strong {
    font-size: 14px;
}

.upload-empty small {
    color: #9ca3af;
    font-size: 12px;
}

.upload-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: #eef2ff;
    color: #4f46e5;
    font-size: 28px;
    font-weight: 900;
}

.small-upload-preview {
    display: none;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.upload-card.has-image .upload-empty {
    display: none;
}

.upload-card.has-image .small-upload-preview {
    display: block;
}

.size-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 9px;
}

.size-option {
    height: 58px;
    border: 1px solid #f1f5f9;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    background: white;
}

.size-option input {
    display: none;
}

.size-option.active {
    border-color: #4f46e5;
    box-shadow: 0 0 0 1px #4f46e5;
    background: #eef2ff;
}

.size-icon {
    color: #94a3b8;
    font-size: 18px;
}

.size-option.active .size-icon,
.size-option.active strong {
    color: #4f46e5;
}

.size-option strong {
    font-size: 11px;
}

.section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.active-preset-box {
    display: grid;
    grid-template-columns: 54px 1fr;
    align-items: center;
    gap: 12px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 20px;
    padding: 13px;
    margin-bottom: 10px;
}

.active-preset-box img {
    width: 54px;
    height: 54px;
    object-fit: cover;
    border-radius: 10px;
}

.active-preset-box strong {
    font-size: 13px;
}

.preset-picker-btn {
    border: 1px solid #dbe4ff;
    background: #f8fafc;
    color: #4f46e5;
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 11px;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.08);
}

.preset-picker-btn:hover {
    background: #eef2ff;
}

.quality-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
}

.quality-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #f1f5f9;
    border-radius: 14px;
    height: 43px;
    padding: 0 14px;
    cursor: pointer;
    font-weight: 900;
    font-size: 13px;
}

.quality-option input {
    display: none;
}

.quality-option.active {
    border-color: #4f46e5;
    background: #eef2ff;
    color: #4f46e5;
}

.generate-btn {
    width: 100%;
    border: none;
    border-radius: 18px;
    background: #8b7cf6;
    color: white;
    height: 61px;
    font-weight: 900;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 14px 30px rgba(79, 70, 229, 0.22);
    transition: opacity 0.2s;
}

.generate-btn.is-loading {
    opacity: 0.75;
    cursor: not-allowed;
}

.credit-cost-note {
    margin-bottom: 10px;
    color: #4f46e5;
    font-size: 13px;
    font-weight: 900;
    text-align: center;
}

.time-note {
    margin-top: 12px;
    text-align: center;
    color: #9ca3af;
    font-size: 11px;
    font-weight: 800;
}

.preview-area {
    padding: 36px;
    background: #fbfbfc;
}

.preview-header {
    display: flex;
    gap: 15px;
    align-items: center;
    margin-bottom: 28px;
}

.preview-icon {
    width: 33px;
    height: 33px;
    background: #eef2ff;
    color: #4f46e5;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: 20px;
}

.preview-header h1 {
    margin: 0;
    font-size: 16px;
}

.preview-header p {
    margin: 3px 0 0;
    color: #6b7280;
    font-size: 14px;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(320px, 540px));
    gap: 22px;
    align-items: start;
    justify-content: center;
}

.preview-card {
    position: relative;
    width: 100%;
    min-height: 0;
    aspect-ratio: 1 / 1;
    background: #f3f4f6;
    border-radius: 20px;
    overflow: hidden;
}

.preview-label {
    position: absolute;
    top: 18px;
    left: 18px;
    z-index: 5;
    border-radius: 8px;
    color: white;
    font-size: 11px;
    font-weight: 900;
    padding: 9px 14px;
}

.preview-label.original {
    background: rgba(0, 0, 0, 0.4);
}

.preview-label.result {
    background: #4f46e5;
    box-shadow: 0 10px 20px rgba(79, 70, 229, 0.25);
}

.preview-empty {
    height: 100%;
    display: grid;
    place-content: center;
    text-align: center;
    color: #9ca3af;
    gap: 8px;
}

.preview-empty div {
    font-size: 44px;
    opacity: 0.35;
}

.preview-empty p {
    font-size: 14px;
    font-weight: 700;
}

.preview-image {
    display: none;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #eef2f7;
}

.result-loading {
    height: 100%;
    display: grid;
    place-content: center;
    text-align: center;
    color: #9ca3af;
    gap: 8px;
}

.result-loading div {
    font-size: 44px;
    animation: pulse 1.2s ease-in-out infinite;
}

.result-loading p {
    font-size: 14px;
    font-weight: 700;
}

@keyframes pulse {
    0%, 100% { opacity: 0.35; }
    50% { opacity: 1; }
}

.preview-card.has-image .preview-empty {
    display: none;
}

.preview-card.has-image .preview-image {
    display: block;
}

.action-row {
    margin-top: 36px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.action-buttons {
    display: flex;
    gap: 14px;
}

.download-btn,
.secondary-btn {
    border: none;
    border-radius: 14px;
    height: 48px;
    padding: 0 28px;
    font-weight: 900;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    white-space: nowrap;
}

.download-btn {
    background: #8b7cf6;
    color: white;
}

.secondary-btn {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    color: #6b7280;
}

.history-preview-btn {
    background: #f8fafc;
    border-color: #dbe4ff;
    color: #4f46e5;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.08);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.history-preview-btn:hover {
    background: #eef2ff;
    box-shadow: 0 12px 26px rgba(79, 70, 229, 0.13);
    transform: translateY(-1px);
}

.action-row p {
    color: #9ca3af;
    font-size: 12px;
    font-style: italic;
}

.gallery-modal {
    display: none;
    position: fixed;
    z-index: 200;
    inset: 0;
    background: white;
    overflow-y: auto;
}

.gallery-modal.show {
    display: block;
}

.gallery-box {
    padding: 30px;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
}

.gallery-header h2 {
    margin: 0;
}

.gallery-header p {
    color: #6b7280;
    margin: 4px 0 0;
}

.gallery-header button {
    border: none;
    background: #f3f4f6;
    border-radius: 999px;
    padding: 12px 18px;
    cursor: pointer;
    font-weight: 900;
}

.preset-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 18px;
}

.gallery-preset-card {
    border: 1px solid #e5e7eb;
    background: white;
    border-radius: 20px;
    overflow: hidden;
    text-align: left;
    cursor: pointer;
}

.gallery-preset-card img {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

.gallery-preset-card strong,
.gallery-preset-card small {
    display: block;
    padding: 0 14px;
}

.gallery-preset-card strong {
    padding-top: 14px;
}

.gallery-preset-card small {
    padding-bottom: 14px;
    color: #6b7280;
    margin-top: 4px;
}

/* ── History Page ─────────────────────────────────────── */

.history-page {
    max-width: 1300px;
    margin: 0 auto;
    padding: 32px 28px;
}

.history-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    gap: 16px;
}

.history-head h1 {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 900;
}

.history-head p {
    margin: 0;
    color: #6b7280;
    font-size: 14px;
}

.back-generate-btn {
    background: #4f46e5;
    color: white;
    padding: 11px 22px;
    border-radius: 14px;
    font-weight: 900;
    font-size: 14px;
    white-space: nowrap;
}

.empty-history {
    text-align: center;
    padding: 80px 20px;
    color: #9ca3af;
}

.empty-icon {
    font-size: 56px;
    opacity: 0.3;
    margin-bottom: 16px;
}

.empty-history h2 {
    margin: 0 0 8px;
    color: #374151;
}

.empty-history p {
    margin: 0 0 24px;
}

.empty-history a {
    background: #4f46e5;
    color: white;
    padding: 12px 28px;
    border-radius: 14px;
    font-weight: 900;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 18px;
}

.history-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.history-image-box {
    position: relative;
    aspect-ratio: 1 / 1;
    background: #f3f4f6;
    overflow: hidden;
}

.history-image-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.history-no-image {
    height: 100%;
    display: grid;
    place-items: center;
    text-align: center;
    color: #9ca3af;
    gap: 6px;
}

.history-no-image span {
    font-size: 36px;
    opacity: 0.3;
}

.history-no-image p {
    margin: 0;
    font-size: 12px;
}

.history-status {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 11px;
    font-weight: 900;
    padding: 5px 10px;
    border-radius: 999px;
}

.history-status.success {
    background: #ecfdf5;
    color: #047857;
}

.history-status.failed {
    background: #fef2f2;
    color: #b91c1c;
}

.history-status.pending {
    background: #fffbeb;
    color: #b45309;
}

.history-content {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.history-content h2 {
    margin: 0;
    font-size: 13px;
    font-weight: 900;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.history-meta span {
    font-size: 11px;
    color: #6b7280;
    background: #f3f4f6;
    padding: 2px 8px;
    border-radius: 999px;
}

.history-error {
    margin: 0;
    font-size: 11px;
    color: #b91c1c;
    background: #fef2f2;
    padding: 6px 10px;
    border-radius: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-pending,
.history-success {
    margin: 0;
    font-size: 11px;
    color: #6b7280;
}

.history-actions {
    display: flex;
    gap: 8px;
    margin-top: auto;
    padding-top: 4px;
}

.download-history-btn,
.view-original-btn {
    flex: 1;
    text-align: center;
    padding: 7px 0;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 900;
}

.download-history-btn {
    background: #4f46e5;
    color: white;
}

.view-original-btn {
    background: #f3f4f6;
    color: #374151;
}

.delete-history-btn {
    flex: 1;
    border: none;
    cursor: pointer;
    padding: 7px 0;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 900;
    background: #fef2f2;
    color: #b91c1c;
    width: 100%;
}

.history-actions form {
    flex: 1;
    display: flex;
}

@media (max-width: 1100px) {
    .history-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 700px) {
    .history-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .history-page {
        padding: 20px 16px;
    }
}

@media (max-width: 480px) {
    .history-grid {
        grid-template-columns: 1fr;
    }
}

/* ── End History Page ─────────────────────────────────── */

@media (max-width: 900px) {
    .topbar {
        height: auto;
        flex-direction: column;
        align-items: flex-start;
        gap: 14px;
        padding: 18px;
    }

    .brand-area {
        gap: 16px;
        flex-direction: column;
        align-items: flex-start;
    }

    .top-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .main-layout {
        display: block;
    }

    .left-panel {
        border-right: none;
        border-bottom: 1px solid #f1f5f9;
    }

    .preview-area {
        padding: 22px;
    }

    .preview-grid {
        grid-template-columns: 1fr;
    }

    .action-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .action-buttons {
        flex-direction: column;
        width: 100%;
    }
}

/* ── Auth Login & Register Page ───────────────────────── */

.auth-wrapper {
    min-height: calc(100vh - 73px);
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    background:
        radial-gradient(circle at top left, rgba(79, 70, 229, 0.12), transparent 35%),
        #f9fafb;
}

.auth-visual {
    display: grid;
    place-items: center;
    padding: 48px;
}

.auth-brand-card {
    max-width: 560px;
    width: 100%;
    background: linear-gradient(135deg, #4f46e5, #8b5cf6);
    color: white;
    border-radius: 34px;
    padding: 44px;
    box-shadow: 0 24px 70px rgba(79, 70, 229, 0.25);
    position: relative;
    overflow: hidden;
}

.auth-brand-card::after {
    content: "";
    position: absolute;
    width: 260px;
    height: 260px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    right: -80px;
    bottom: -90px;
}

.auth-logo {
    width: 62px;
    height: 62px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.18);
    display: grid;
    place-items: center;
    font-size: 36px;
    font-weight: 900;
    margin-bottom: 28px;
}

.auth-brand-card h1 {
    margin: 0;
    font-size: 42px;
    font-weight: 900;
    letter-spacing: -1px;
}

.auth-brand-card p {
    margin: 16px 0 0;
    color: #ede9fe;
    font-size: 16px;
    line-height: 1.7;
    max-width: 440px;
}

.auth-feature-list {
    display: grid;
    gap: 14px;
    margin-top: 34px;
    position: relative;
    z-index: 2;
}

.auth-feature-list div {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.13);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 18px;
    padding: 14px 16px;
}

.auth-feature-list span {
    width: 34px;
    height: 34px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.18);
    display: grid;
    place-items: center;
    font-weight: 900;
}

.auth-feature-list p {
    margin: 0;
    color: white;
    font-weight: 800;
    font-size: 14px;
}

.auth-form-area {
    display: grid;
    place-items: center;
    padding: 48px;
}

.auth-card {
    width: min(440px, 100%);
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 30px;
    padding: 36px;
    box-shadow: 0 22px 70px rgba(15, 23, 42, 0.08);
}

.auth-card-head h2 {
    margin: 0;
    font-size: 28px;
    font-weight: 900;
    color: #111827;
}

.auth-card-head p {
    margin: 9px 0 24px;
    color: #6b7280;
    line-height: 1.6;
    font-size: 14px;
}

.google-auth-btn {
    height: 52px;
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 16px;
    background: #ffffff;
    color: #111827;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 900;
    font-size: 15px;
    cursor: pointer;
    transition: background 0.15s;
}

.google-auth-btn:hover {
    background: #f9fafb;
}

.google-icon {
    width: 28px;
    height: 28px;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: #f3f4f6;
    color: #4f46e5;
    font-weight: 900;
}

.auth-divider {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    margin: 24px 0;
}

.auth-divider span {
    height: 1px;
    background: #e5e7eb;
}

.auth-divider p {
    margin: 0;
    color: #9ca3af;
    font-size: 12px;
    font-weight: 800;
}

.auth-form label {
    display: block;
    margin: 16px 0 7px;
    font-size: 13px;
    font-weight: 900;
    color: #374151;
}

.auth-form input {
    width: 100%;
    height: 50px;
    border: 1px solid #d1d5db;
    border-radius: 15px;
    padding: 0 16px;
    outline: none;
    font-size: 14px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-form input:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px #eef2ff;
}

.auth-submit-btn {
    width: 100%;
    height: 54px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    font-weight: 900;
    font-size: 16px;
    margin-top: 24px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.3);
    transition: opacity 0.15s;
}

.auth-submit-btn:hover {
    opacity: 0.9;
}

.auth-switch {
    margin: 22px 0 0;
    text-align: center;
    color: #6b7280;
    font-size: 14px;
}

.auth-switch a {
    color: #4f46e5;
    font-weight: 900;
}

@media (max-width: 900px) {
    .auth-wrapper {
        grid-template-columns: 1fr;
    }

    .auth-visual {
        padding: 24px 20px 0;
    }

    .auth-brand-card {
        padding: 28px;
        border-radius: 26px;
    }

    .auth-brand-card h1 {
        font-size: 30px;
    }

    .auth-form-area {
        padding: 24px 20px 50px;
    }
}

/* ── End Auth Login & Register Page ───────────────────── */

.credit-link {
    background: #4f46e5;
    color: #ffffff;
    padding: 11px 18px;
    border-radius: 999px;
    font-weight: 900;
    font-size: 14px;
    box-shadow: 0 10px 24px rgba(79, 70, 229, 0.18);
}

.credit-link:hover {
    background: #4338ca;
    color: #ffffff;
}

.profile-menu {
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    cursor: pointer;
    color: #111827;
    padding: 0;
}

.profile-menu::after {
    margin-left: 4px;
}

.profile-menu img {
    width: 38px;
    height: 38px;
    object-fit: cover;
    border-radius: 50%;
}

.result-loading {
    min-height: 0;
    height: 100%;
    width: 100%;
    display: none;
    place-items: center;
    place-content: center;
    text-align: center;
    padding: 30px;
    color: #4f46e5;
    background: linear-gradient(135deg, #eef2ff, #f8fafc);
}

.result-loading strong {
    display: block;
    margin-top: 18px;
    font-size: 18px;
    font-weight: 900;
    color: #111827;
}

.result-loading p {
    margin-top: 8px;
    color: #6b7280;
    font-size: 14px;
    font-weight: 600;
}

.loading-spinner {
    width: 56px;
    height: 56px;
    border: 6px solid #c7d2fe;
    border-top-color: #4f46e5;
    border-radius: 50%;
    margin: 0 auto;
    animation: spinLoading 0.9s linear infinite;
}

@keyframes spinLoading {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.generate-btn.is-loading {
    opacity: 0.75;
    cursor: not-allowed;
}

.preview-card.has-image .preview-empty {
    display: none;
}

.preview-card.has-image .preview-image {
    display: block;
}
